// File: 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
subq $0x70, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movw $0x0, -0x4(%rbp)
movzwl -0x4(%rbp), %eax
cmpl $0xc4, %eax
jge 0x2ae20
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65e62(%rip), %rax     # 0x90c70
movb $0x23, (%rax,%rcx)
movw -0x4(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x4(%rbp)
jmp 0x2adf6
movw $0x0, -0x4(%rbp)
movzwl -0x4(%rbp), %eax
cmpl $0x10, %eax
jge 0x2ae4e
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65f04(%rip), %rax     # 0x90d40
movb $0x0, (%rax,%rcx)
movw -0x4(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x4(%rbp)
jmp 0x2ae26
callq 0x5270
movq %rax, %rcx
movl %ecx, %eax
movl %eax, %edx
addl $0x3, %edx
testq %rcx, %rcx
movl %eax, %ecx
cmovsl %edx, %ecx
andl $0xfc, %ecx
subl %ecx, %eax
movl %eax, -0x60(%rbp)
callq 0x5270
movl -0x60(%rbp), %ecx
movq %rax, %rdx
movl %edx, %eax
movl %eax, %esi
addl $0x3, %esi
testq %rdx, %rdx
movl %eax, %edx
cmovsl %esi, %edx
andl $0xfc, %edx
subl %edx, %eax
movsbl %cl, %edi
movsbl %al, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2df00
leaq -0x8(%rbp), %rdi
xorl %edx, %edx
movl %edx, -0x5c(%rbp)
movl %edx, %esi
callq 0x60430
movl -0x5c(%rbp), %edx
leaq -0xc(%rbp), %rdi
movl %edx, %esi
callq 0x60430
jmp 0x2aec2
leaq -0x40(%rbp), %rdi
callq 0x5770
movw $0x0, -0x6(%rbp)
movswl -0x6(%rbp), %eax
cmpl $0xe, %eax
jge 0x2b294
movw $0x0, -0x8(%rbp)
movswl -0x8(%rbp), %eax
cmpl $0xe, %eax
jge 0x2b281
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65d68(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x23, %eax
jne 0x2b194
leaq -0x40(%rbp), %rdi
callq 0x5730
movb $0x1, -0x41(%rbp)
movw $0x0, -0x4(%rbp)
movzwl -0x4(%rbp), %eax
cmpl $0x8, %eax
jge 0x2b07d
movzwl -0x4(%rbp), %edx
leaq -0x54(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x60550
jmp 0x2af48
movl -0x54(%rbp), %eax
movl %eax, -0xc(%rbp)
leaq -0x54(%rbp), %rdi
callq 0x60460
movswl -0xc(%rbp), %eax
cmpl $0x0, %eax
jl 0x2b045
movswl -0xa(%rbp), %eax
cmpl $0x0, %eax
jl 0x2b045
movswl -0xc(%rbp), %eax
cmpl $0xe, %eax
jge 0x2b045
movswl -0xa(%rbp), %eax
cmpl $0xe, %eax
jge 0x2b045
movswl -0xa(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0xc(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65cce(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
je 0x2afcb
movswl -0xa(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0xc(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65cae(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x2b005
movb $0x0, -0x41(%rbp)
jmp 0x2b005
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x2b437
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x5a48
leaq -0xc(%rbp), %rdi
callq 0x60460
jmp 0x2b437
movzwl -0x4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2b043
movswl -0xa(%rbp), %eax
movl %eax, %ecx
addl %ecx, %ecx
shll $0x4, %eax
subl %ecx, %eax
movswl -0xc(%rbp), %ecx
addl %ecx, %eax
cltq
leaq 0x65c3e(%rip), %rcx     # 0x90c70
movsbl (%rax,%rcx), %esi
leaq -0x40(%rbp), %rdi
callq 0x5310
jmp 0x2b041
jmp 0x2b043
jmp 0x2b06a
movzwl -0x4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2b068
leaq -0x40(%rbp), %rdi
movl $0x5f, %esi
callq 0x5310
jmp 0x2b066
jmp 0x2b068
jmp 0x2b06a
jmp 0x2b06c
movw -0x4(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x4(%rbp)
jmp 0x2af28
testb $0x1, -0x41(%rbp)
je 0x2b0a3
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65bd6(%rip), %rax     # 0x90c70
movb $0x5f, (%rax,%rcx)
jmp 0x2b18f
leaq -0x40(%rbp), %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5720
movq %rax, -0x50(%rbp)
cmpq $-0x1, %rax
je 0x2b0db
movzwl -0x4(%rbp), %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
callq 0x5a10
movq %rax, -0x68(%rbp)
jmp 0x2b0d4
movq -0x68(%rbp), %rax
movb $0x2e, (%rax)
leaq 0x38dc9(%rip), %rsi     # 0x63eab
leaq -0x40(%rbp), %rdi
callq 0x18930
movb %al, -0x69(%rbp)
jmp 0x2b0f0
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x2b117
jmp 0x2b0f9
leaq 0x38db0(%rip), %rsi     # 0x63eb0
leaq -0x40(%rbp), %rdi
callq 0x18930
movb %al, -0x6a(%rbp)
jmp 0x2b10e
movb -0x6a(%rbp), %al
testb $0x1, %al
jne 0x2b117
jmp 0x2b134
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65b42(%rip), %rax     # 0x90c70
movb $0x2d, (%rax,%rcx)
jmp 0x2b18d
leaq 0x38d7a(%rip), %rsi     # 0x63eb5
leaq -0x40(%rbp), %rdi
callq 0x18930
movb %al, -0x6b(%rbp)
jmp 0x2b149
movb -0x6b(%rbp), %al
testb $0x1, %al
jne 0x2b170
jmp 0x2b152
leaq 0x38d61(%rip), %rsi     # 0x63eba
leaq -0x40(%rbp), %rdi
callq 0x18930
movb %al, -0x6c(%rbp)
jmp 0x2b167
movb -0x6c(%rbp), %al
testb $0x1, %al
jne 0x2b170
jmp 0x2b18b
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65ae9(%rip), %rax     # 0x90c70
movb $0x7c, (%rax,%rcx)
jmp 0x2b18d
jmp 0x2b18f
jmp 0x2b26e
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65ac5(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x2b26c
callq 0x5270
movl $0x3, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x2b26c
movswl -0x6(%rbp), %eax
addl $0x1, %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65a85(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
movswl -0x6(%rbp), %ecx
subl $0x1, %ecx
imull $0xe, %ecx, %ecx
movswl -0x8(%rbp), %edx
addl %edx, %ecx
movslq %ecx, %rdx
leaq 0x65a67(%rip), %rcx     # 0x90c70
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x2b26c
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x65a45(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
movswl -0x6(%rbp), %ecx
imull $0xe, %ecx, %ecx
movswl -0x8(%rbp), %edx
addl %edx, %ecx
subl $0x1, %ecx
movslq %ecx, %rdx
leaq 0x65a27(%rip), %rcx     # 0x90c70
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x2b26c
movswl -0x6(%rbp), %eax
imull $0xe, %eax, %eax
movswl -0x8(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rcx
leaq 0x65a08(%rip), %rax     # 0x90c70
movb $0x2b, (%rax,%rcx)
jmp 0x2b26e
jmp 0x2b270
movw -0x8(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x8(%rbp)
jmp 0x2aee4
jmp 0x2b283
movw -0x6(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x6(%rbp)
jmp 0x2aed1
movb $0x0, -0x41(%rbp)
callq 0x5270
movl $0xc4, %ecx
cqto
idivq %rcx
movw %dx, %ax
movw %ax, -0x4(%rbp)
cmpw $0x0, -0x4(%rbp)
je 0x2b306
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x659ae(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x7c, %eax
je 0x2b2e1
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65998(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x2b2f8
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65982(%rip), %rax     # 0x90c70
movb $0x2b, (%rax,%rcx)
movb $0x1, -0x41(%rbp)
jmp 0x2b306
movw -0x4(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0x4(%rbp)
jmp 0x2b2ae
jmp 0x2b308
movb -0x41(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b298
movb $0x0, -0x55(%rbp)
movw $0x0, -0x4(%rbp)
movzwl -0x4(%rbp), %eax
cmpl $0xc4, %eax
jge 0x2b416
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65939(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x7c, %eax
je 0x2b356
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65923(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x2b3bf
movsbl -0x55(%rbp), %eax
cmpl $0x3, %eax
jge 0x2b38f
callq 0x5270
movl $0xa, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x2b38f
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x658ef(%rip), %rax     # 0x90c70
movb $0x2b, (%rax,%rcx)
movb -0x55(%rbp), %al
addb $0x1, %al
movb %al, -0x55(%rbp)
jmp 0x2b3bd
testb $0x1, -0x1(%rbp)
je 0x2b3aa
callq 0x5270
movl $0x4, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0x2b3bb
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x658b9(%rip), %rax     # 0x90c70
movb $0x23, (%rax,%rcx)
jmp 0x2b3bd
jmp 0x2b403
testb $0x1, -0x1(%rbp)
jne 0x2b401
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x6589e(%rip), %rax     # 0x90c70
movsbl (%rax,%rcx), %eax
cmpl $0x23, %eax
jne 0x2b401
callq 0x5270
movl $0xf, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x2b401
movzwl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x65873(%rip), %rax     # 0x90c70
movb $0x49, (%rax,%rcx)
jmp 0x2b403
jmp 0x2b405
movw -0x4(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x4(%rbp)
jmp 0x2b31b
leaq -0x40(%rbp), %rdi
callq 0x5a48
leaq -0xc(%rbp), %rdi
callq 0x60460
leaq -0x8(%rbp), %rdi
callq 0x60460
addq $0x70, %rsp
popq %rbp
retq
leaq -0x8(%rbp), %rdi
callq 0x60460
movq -0x18(%rbp), %rdi
callq 0x5920
nopl (%rax)