// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/map.cpp
// Function: (anonymous namespace)::gen_house(bool)
void gen_house(const bool outdoor)
{
	unsigned short sh;
	for(sh = 0; sh < MAX_HS*MAX_HS; ++sh)
		house[sh] = '#';
	for(sh = 0; sh < ROOM_NUM*ROOM_NUM; ++sh)
		rooms[sh] = false;
	
	// This calls itself recursively:
	room_recur(random()%ROOM_NUM, random()%ROOM_NUM, -1);

	// Remove extra (surrounding) walls; any wall that has as neighbours
	// only '#' or '_' becomes '_'. While looping, also place doors and
	// windows.
	Coords c, d;
	string card;
	bool outwall;
	size_t i;
	for(c.y = 0; c.y < MAX_HS; ++(c.y))
	{
		for(c.x = 0; c.x < MAX_HS; ++(c.x))
		{
			if(house[c.y*MAX_HS+c.x] == '#')
			{
				card.clear();
				outwall = true;
				for(sh = 0; sh < MAX_D; ++sh)
				{
					d = c.in(e_Dir(sh));
					if(d.x >= 0 && d.y >= 0 && d.x < MAX_HS && d.y < MAX_HS)
					{
						if(house[d.y*MAX_HS+d.x] == '.' || house[d.y*MAX_HS+d.x] == ':')
							outwall = false;
						if(!(sh%2)) // cardinal direction
							card += house[d.y*MAX_HS+d.x];
					}
					else if(!(sh%2))
						card += '_'; // outside of buffer
				}
				if(outwall)
					house[c.y*MAX_HS+c.x] = '_';
				else // See if this is a wall we could place a window on
				{
					// replace any ':' with '.' (there can be at most one)
					if((i = card.find(':')) != string::npos)
						card[sh] = '.';
					if(card == "_#.#" || card == ".#_#")
						house[c.y*MAX_HS+c.x] = '-';
					else if(card == "#.#_" || card == "#_#.")
						house[c.y*MAX_HS+c.x] = '|';
				}
			}
			// Check if could place a door:
			else if(house[c.y*MAX_HS+c.x] == ':'
				&& random()%3 // skip every 2nd potential door loc
				&& house[(c.y+1)*MAX_HS+c.x] == house[(c.y-1)*MAX_HS+c.x]
				&& house[c.y*MAX_HS+c.x+1] == house[c.y*MAX_HS+c.x-1])
				house[c.y*MAX_HS+c.x] = '+';
		}
	}

	// The windows we placed above were only "preliminary plans". At least one
	// of them must be replaced by our front door, and if we are not outside,
	// there can be no windows!
	//First place a front door:
	outwall = false;
	do {
		sh = random()%(MAX_HS*MAX_HS);
		while(sh)
		{
			if(house[sh] == '|' || house[sh] == '-')
			{
				house[sh] = '+';
				outwall = true;
				break;
			}
			--sh;
		}
	} while(!outwall);
	// Next, remove all or some windows and add more doors:
	char num = 0; // number of additional doors
	for(sh = 0; sh < MAX_HS*MAX_HS; ++sh)
	{
		if(house[sh] == '|' || house[sh] == '-')
		{
			if(num < 3 && !(random()%10)) // another front door
			{
				house[sh] = '+';
				++num;
			}
			else if(!outdoor || random()%4)
				house[sh] = '#';
		}
		// possibly turn some walls into illusions: 
		else if(!outdoor && house[sh] == '#' && !(random()%15))
			house[sh] = 'I';
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %eax, %eax
leaq 0x2ec32(%rip), %r15     # 0x40af0
cmpq $0xc4, %rax
je 0x11ed0
movb $0x23, (%rax,%r15)
incq %rax
jmp 0x11ebe
xorl %eax, %eax
leaq 0x2ece7(%rip), %rcx     # 0x40bc0
cmpq $0x10, %rax
je 0x11ee8
movb $0x0, (%rax,%rcx)
incq %rax
jmp 0x11ed9
movl %edi, -0x34(%rbp)
callq 0x41e0
pushq $0x4
popq %r14
cqto
idivq %r14
movq %rdx, %rbx
callq 0x41e0
cqto
idivq %r14
movsbl %bl, %edi
movsbl %dl, %esi
pushq $-0x1
popq %rdx
callq 0x1364b
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %eax, %eax
leaq -0x58(%rbp), %r14
leaq -0x38(%rbp), %rbx
leaq -0x2c(%rbp), %r13
movw %ax, -0x2a(%rbp)
cmpw $0xd, %ax
jg 0x12164
xorl %eax, %eax
movw %ax, -0x2c(%rbp)
cmpw $0xd, %ax
jg 0x12159
movswq %ax, %rcx
movswq -0x2a(%rbp), %rdx
imulq $0xe, %rdx, %rdx
addq %rcx, %rdx
movzbl (%r15,%rdx), %ecx
cmpl $0x3a, %ecx
je 0x12037
cmpl $0x23, %ecx
jne 0x1210e
andq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, %r15b
xorl %r12d, %r12d
cmpl $0x8, %r12d
je 0x1208b
movq %rbx, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x24e0c
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x24d9e
movzwl -0x30(%rbp), %eax
cmpq $0xe, %rax
setb %dl
movzwl -0x2e(%rbp), %ecx
cmpw $0xe, %cx
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1201e
movzwl %cx, %ecx
imulq $0xe, %rcx, %rcx
addq %rax, %rcx
leaq 0x2eaf6(%rip), %rax     # 0x40af0
movzbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x12008
cmpl $0x2e, %eax
jne 0x1200b
xorl %r15d, %r15d
testb $0x1, %r12b
jne 0x1202f
movsbl %al, %esi
movq %r14, %rdi
callq 0x4340
jmp 0x1202f
testb $0x1, %r12b
jne 0x1202f
movq %r14, %rdi
pushq $0x5f
popq %rsi
callq 0x4340
incl %r12d
jmp 0x11fa3
callq 0x41e0
cqto
pushq $0x3
popq %rcx
idivq %rcx
movzwl -0x2c(%rbp), %eax
testq %rdx, %rdx
je 0x1210e
movswq %ax, %rdx
movswq -0x2a(%rbp), %rcx
imulq $0xe, %rcx, %rcx
addq %rdx, %rcx
movb 0xe(%rcx,%r15), %dl
cmpb -0xe(%rcx,%r15), %dl
jne 0x1210e
movb 0x1(%rcx,%r15), %dl
cmpb -0x1(%rcx,%r15), %dl
jne 0x1210e
movb $0x2b, (%rcx,%r15)
jmp 0x1210e
testb $0x1, %r15b
je 0x120b0
movswq -0x2a(%rbp), %rax
imulq $0xe, %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rax, %rcx
leaq 0x2ea47(%rip), %r15     # 0x40af0
movb $0x5f, (%r15,%rcx)
jmp 0x1210e
movq %r14, %rdi
pushq $0x3a
popq %rsi
xorl %edx, %edx
callq 0x4560
cmpq $-0x1, %rax
leaq 0x2ea28(%rip), %r15     # 0x40af0
je 0x120d2
movq -0x58(%rbp), %rax
movb $0x2e, 0x8(%rax)
movq %r14, %rdi
leaq 0x16cab(%rip), %rsi     # 0x28d87
callq 0xb2cd
testb %al, %al
jne 0x120f8
movq %r14, %rdi
leaq 0x16c9d(%rip), %rsi     # 0x28d8c
callq 0xb2cd
testb %al, %al
je 0x12115
movswq -0x2a(%rbp), %rax
imulq $0xe, %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rax, %rcx
movb $0x2d, (%r15,%rcx)
incl %eax
jmp 0x11f5c
movq %r14, %rdi
leaq 0x16c72(%rip), %rsi     # 0x28d91
callq 0xb2cd
testb %al, %al
jne 0x1213b
movq %r14, %rdi
leaq 0x16c64(%rip), %rsi     # 0x28d96
callq 0xb2cd
testb %al, %al
je 0x12153
movswq -0x2a(%rbp), %rax
imulq $0xe, %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rax, %rcx
movb $0x7c, (%r15,%rcx)
jmp 0x1210e
movzwl -0x2c(%rbp), %eax
jmp 0x1210e
movzwl -0x2a(%rbp), %eax
incl %eax
jmp 0x11f4c
movl $0xc4, %ebx
movl -0x34(%rbp), %r13d
callq 0x41e0
cqto
idivq %rbx
movzwl %dx, %eax
movq %rax, %rcx
subq $0x1, %rax
jb 0x1216d
movzbl (%rcx,%r15), %edx
cmpl $0x2d, %edx
je 0x12192
cmpl $0x7c, %edx
jne 0x1217a
movb $0x2b, (%rcx,%r15)
xorl %ebx, %ebx
pushq $0xa
popq %r14
pushq $0xf
popq %r15
xorl %r12d, %r12d
cmpq $0xc4, %rbx
je 0x12232
leaq 0x2e938(%rip), %rax     # 0x40af0
movzbl (%rbx,%rax), %eax
cmpl $0x7c, %eax
je 0x121c6
cmpl $0x2d, %eax
jne 0x121f6
cmpb $0x2, %r12b
jg 0x121db
callq 0x41e0
cqto
idivq %r14
testq %rdx, %rdx
je 0x1221c
testb %r13b, %r13b
je 0x121e9
callq 0x41e0
testb $0x3, %al
je 0x1222a
leaq 0x2e900(%rip), %rax     # 0x40af0
movb $0x23, (%rbx,%rax)
jmp 0x1222a
cmpb $0x23, %al
setne %al
orb %r13b, %al
jne 0x1222a
callq 0x41e0
cqto
idivq %r15
testq %rdx, %rdx
jne 0x1222a
leaq 0x2e8da(%rip), %rax     # 0x40af0
movb $0x49, (%rbx,%rax)
jmp 0x1222a
leaq 0x2e8cd(%rip), %rax     # 0x40af0
movb $0x2b, (%rbx,%rax)
incb %r12b
incq %rbx
jmp 0x121a4
leaq -0x58(%rbp), %rdi
callq 0x47e8
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x12278
jmp 0x12263
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x47e8
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710
nop