// File: /workspace/github_cpp_makefile_star2_O1/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
movl %edi, -0x34(%rbp)
leaq 0x2d258(%rip), %rdi     # 0x43b00
movl $0xc4, %edx
movl $0x23, %esi
callq 0x4200
xorps %xmm0, %xmm0
movaps %xmm0, 0x2d30f(%rip)    # 0x43bd0
callq 0x41d0
movq %rax, %rbx
addl $0x3, %eax
testq %rbx, %rbx
cmovnsl %ebx, %eax
movl $0xfc, %r15d
andl %r15d, %eax
subl %eax, %ebx
callq 0x41d0
leal 0x3(%rax), %ecx
testq %rax, %rax
cmovnsl %eax, %ecx
andl %r15d, %ecx
subl %ecx, %eax
movsbl %bl, %edi
movsbl %al, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x18578
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x2c(%rbp), %r15
movw $0x0, 0x2(%r15)
leaq -0x38(%rbp), %r12
leaq -0x58(%rbp), %r14
movw $0x0, -0x2c(%rbp)
xorl %eax, %eax
movswq %ax, %rax
movswq -0x2a(%rbp), %rcx
leaq (%rcx,%rcx), %rdx
shlq $0x4, %rcx
subq %rdx, %rcx
addq %rax, %rcx
leaq 0x2d19a(%rip), %rax     # 0x43b00
movzbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
je 0x16a5e
cmpl $0x23, %eax
jne 0x16b89
movq $0x0, -0x50(%rbp)
movq -0x58(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, %r13b
xorl %ebx, %ebx
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x2bc76
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rdi
callq 0x2bbf6
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 0x16a18
movzwl %cx, %ecx
leaq (%rcx,%rcx), %rdx
movl %ecx, %esi
shll $0x4, %esi
subq %rdx, %rsi
addq %rax, %rsi
leaq 0x2d11c(%rip), %rdi     # 0x43b00
movzbl (%rdi,%rsi), %esi
cmpl $0x3a, %esi
je 0x169f2
cmpl $0x2e, %esi
jne 0x169f5
xorl %r13d, %r13d
testb $0x1, %bl
jne 0x16a2a
shll $0x4, %ecx
subq %rdx, %rcx
addq %rax, %rcx
leaq 0x2d0f6(%rip), %rax     # 0x43b00
movsbl (%rax,%rcx), %esi
movq %r14, %rdi
callq 0x4340
jmp 0x16a2a
testb $0x1, %bl
jne 0x16a2a
movq %r14, %rdi
movl $0x5f, %esi
callq 0x4340
incl %ebx
cmpl $0x8, %ebx
jne 0x16990
testb $0x1, %r13b
je 0x16ae0
movswq -0x2a(%rbp), %rcx
leaq (%rcx,%rcx), %rax
shlq $0x4, %rcx
subq %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rcx, %rax
movb $0x5f, %cl
jmp 0x16b7f
callq 0x41d0
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
movabsq $0x2aaaaaaaaaaaaaaa, %rcx # imm = 0x2AAAAAAAAAAAAAAA
addq %rcx, %rax
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
cmpq %rcx, %rax
jb 0x16b89
movswq -0x2a(%rbp), %rax
leaq (%rax,%rax), %rcx
shlq $0x4, %rax
subq %rcx, %rax
movswq -0x2c(%rbp), %rcx
leal (%rcx,%rax), %edx
addq %rcx, %rax
leaq 0x2d04d(%rip), %rsi     # 0x43b00
movb 0xe(%rax,%rsi), %cl
movslq %edx, %rax
cmpb -0xe(%rax,%rsi), %cl
jne 0x16b89
leaq 0x2d035(%rip), %rdx     # 0x43b00
movb 0x1(%rax,%rdx), %cl
cmpb -0x1(%rax,%rdx), %cl
jne 0x16b89
movb $0x2b, %cl
jmp 0x16b7f
movq %r14, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4550
cmpq $-0x1, %rax
je 0x16afd
movq -0x58(%rbp), %rax
movb $0x2e, 0x8(%rax)
movq %r14, %rdi
leaq 0x18250(%rip), %rsi     # 0x2ed57
callq 0x4120
testl %eax, %eax
je 0x16b65
movq %r14, %rdi
leaq 0x18242(%rip), %rsi     # 0x2ed5c
callq 0x4120
testl %eax, %eax
je 0x16b65
movq %r14, %rdi
leaq 0x18234(%rip), %rsi     # 0x2ed61
callq 0x4120
testl %eax, %eax
je 0x16b49
movq %r14, %rdi
leaq 0x18226(%rip), %rsi     # 0x2ed66
callq 0x4120
testl %eax, %eax
jne 0x16b89
movswq -0x2a(%rbp), %rcx
leaq (%rcx,%rcx), %rax
shlq $0x4, %rcx
subq %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rcx, %rax
movb $0x7c, %cl
jmp 0x16b7f
movswq -0x2a(%rbp), %rcx
leaq (%rcx,%rcx), %rax
shlq $0x4, %rcx
subq %rax, %rcx
movswq -0x2c(%rbp), %rax
addq %rcx, %rax
movb $0x2d, %cl
leaq 0x2cf7a(%rip), %rdx     # 0x43b00
movb %cl, (%rax,%rdx)
movzwl -0x2c(%rbp), %eax
incl %eax
movw %ax, -0x2c(%rbp)
cmpw $0xe, %ax
jl 0x16948
movzwl -0x2a(%rbp), %eax
incl %eax
movw %ax, -0x2a(%rbp)
cmpw $0xe, %ax
jl 0x16940
xorl %r15d, %r15d
movabsq $0x5397829cbc14e5e1, %rbx # imm = 0x5397829CBC14E5E1
callq 0x41d0
movq %rax, %rcx
imulq %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x6, %rdx
addq %rax, %rdx
imulq $0xc4, %rdx, %rax
subq %rax, %rcx
je 0x16c10
movzwl %cx, %ecx
leaq 0x2cf13(%rip), %rax     # 0x43b00
movzbl (%rcx,%rax), %eax
cmpl $0x7c, %eax
je 0x16c02
cmpl $0x2d, %eax
je 0x16c02
decw %cx
jne 0x16be3
jmp 0x16c10
leaq 0x2cef7(%rip), %rax     # 0x43b00
movb $0x2b, (%rcx,%rax)
movb $0x1, %r15b
testb $0x1, %r15b
je 0x16bbe
xorl %ebx, %ebx
movabsq $-0x3333333333333333, %r15 # imm = 0xCCCCCCCCCCCCCCCD
movabsq $0x1999999999999998, %r12 # imm = 0x1999999999999998
movabsq $-0x1111111111111111, %r14 # imm = 0xEEEEEEEEEEEEEEEF
xorl %r13d, %r13d
leaq 0x2cec0(%rip), %rax     # 0x43b00
movzbl (%rbx,%rax), %eax
cmpl $0x7c, %eax
je 0x16c4e
cmpl $0x2d, %eax
jne 0x16c84
cmpb $0x2, %r13b
jg 0x16c68
callq 0x41d0
imulq %r15, %rax
addq %r12, %rax
rorq %rax
cmpq %r12, %rax
jbe 0x16cc0
cmpb $0x0, -0x34(%rbp)
je 0x16c77
callq 0x41d0
testb $0x3, %al
je 0x16cce
leaq 0x2ce82(%rip), %rax     # 0x43b00
movb $0x23, (%rbx,%rax)
jmp 0x16cce
cmpb $0x23, %al
setne %al
orb -0x34(%rbp), %al
jne 0x16cce
callq 0x41d0
imulq %r14, %rax
movabsq $0x888888888888888, %rcx # imm = 0x888888888888888
addq %rcx, %rax
movabsq $0x1111111111111110, %rcx # imm = 0x1111111111111110
cmpq %rcx, %rax
ja 0x16cce
leaq 0x2ce46(%rip), %rax     # 0x43b00
movb $0x49, (%rbx,%rax)
jmp 0x16cce
leaq 0x2ce39(%rip), %rax     # 0x43b00
movb $0x2b, (%rbx,%rax)
incb %r13b
incq %rbx
cmpq $0xc4, %rbx
jne 0x16c39
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x16cf7
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x16d44
jmp 0x16d1f
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x16d3b
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750
nop