// File: /workspace/github_cpp_makefile_star2_O2/essarrdee[P]mutantaliens/mutantaliens.cpp
// Function: init_map()
void init_map()
{
	for(int x=0;x<MAP_SIZE; x++)
	{
		for(int y=0;y<MAP_SIZE; y++)
		{
			map_occupants[x][y] = NULL;
			map_items[x][y] = NULL;
			map_seen[x][y] = false;
			map_access[x][y] = false;
			map_human_scent[x][y] = 0.001f*randfloat()+0.02f;
			if(x != 0 && x != MAP_SIZE-1 && y != 0 && y != MAP_SIZE-1)
			{
				switch(rand()%13)
				{
				case 0: case 1: case 2: case 3: case 4:
					map_terrain[x][y] = STREE; break;
				case 5: case 6: case 7:
					map_terrain[x][y] = BTREE;break;
				default:
					map_terrain[x][y] = DIRT;
				}
			}
			else
			{
				map_terrain[x][y] = WALL;
			}
		}
	}
	int buildings = (rand()%3)+5;
	int *building_xcentres = (int*)malloc(buildings*sizeof(int));
	int *building_ycentres = (int*)malloc(buildings*sizeof(int));
	for (int i=0;i<buildings;i++)
	{
		building_xcentres[i] = -BUILDING_SIZE;
		building_ycentres[i] = -BUILDING_SIZE;
	}
	for(int i=0;i<buildings;i++)
	{
		bool is_ok = false;
		int xcentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
		int ycentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
		while(!is_ok)
		{
			int xcentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
			int ycentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
			is_ok = true;
			for(int j=0;j<i;j++)
			{
				if(abs(xcentre-building_xcentres[j])<=2*BUILDING_SIZE+3)
				{
					is_ok = false;
					xcentre = rand()%(MAP_SIZE-2*BUILDING_SIZE-2)+BUILDING_SIZE;
					ycentre = rand()%(MAP_SIZE-2*BUILDING_SIZE-2)+BUILDING_SIZE;
				}
			}
		}
		std::vector<std::pair<int,int>> room_centres;
		room_centres.push_back(std::make_pair(xcentre,ycentre));
		std::vector<std::pair<int,int>> room_sizes;
		room_sizes.push_back(std::make_pair(rand()%5 + 2,rand()%5+2));
		std::vector<int> fail_counts;
		fail_counts.push_back(0);
		make_room(room_centres[0],room_sizes[0]);
		int successive_failures = 0;
		int room_count = 0;
		while(successive_failures < 10 && room_count < 10)
		{
			int x_size = rand()%5 + 3;
			int y_size = rand()%5 + 3;
			if(room_centres.size() == 0 || room_sizes.size() != room_centres.size())
			{
				successive_failures++;
				continue;
			}
			int parent_choice = rand()%room_centres.size();
			std::pair<int,int> parent_centre = room_centres[parent_choice];
			std::pair<int,int> parent_size = room_sizes[parent_choice];
			std::vector<std::pair<int,int>> centre_choices;
			std::vector<std::pair<int,int>> size_choices;
			int choice_range_x = rand()%(x_size-2)+parent_size.first+2;
			int choice_range_y = rand()%(y_size-2)+parent_size.second+2;
			std::pair<int,int> candidate;
			std::pair<int,int> candidate_size;
			for(int x=0;x<choice_range_x;x++)
			{
				candidate=std::make_pair(x+parent_centre.first-choice_range_x/2,parent_centre.second-choice_range_y/2);
				candidate_size = five_tries_to_make_room(candidate,xcentre,ycentre);
				if(candidate_size != std::make_pair(0,0)) {centre_choices.push_back(candidate); size_choices.push_back(candidate_size);}

				candidate=std::make_pair(x+parent_centre.first-choice_range_x/2,choice_range_y-1+parent_centre.second-choice_range_y/2);
				candidate_size = five_tries_to_make_room(candidate,xcentre,ycentre);
				if(candidate_size != std::make_pair(0,0)) {centre_choices.push_back(candidate); size_choices.push_back(candidate_size);}
			}
			for(int y=1;y<choice_range_y;y++)
			{
				candidate = std::make_pair(parent_centre.first-choice_range_x/2,y+parent_centre.second-choice_range_y/2);
				candidate_size = five_tries_to_make_room(candidate,xcentre,ycentre);
				if(candidate_size != std::make_pair(0,0)) {centre_choices.push_back(candidate); size_choices.push_back(candidate_size);}

				candidate=std::make_pair(parent_centre.first-choice_range_x/2+choice_range_x-1,y+parent_centre.second-choice_range_y/2);
				candidate_size = five_tries_to_make_room(candidate,xcentre,ycentre);
				if(candidate_size != std::make_pair(0,0)) {centre_choices.push_back(candidate); size_choices.push_back(candidate_size);}
			}
			if(centre_choices.size() == 0 || size_choices.size() != centre_choices.size())
			{
				successive_failures++;
			}
			else
			{
				successive_failures = 0;
				int choice = rand()%centre_choices.size();
				make_room(centre_choices[choice],size_choices[choice]);
				room_centres.push_back(centre_choices[choice]);
				room_sizes.push_back(size_choices[choice]);
				fail_counts.push_back(0);
				room_count++;
			}
			
		}
	}

	bool is_ok = false;
	int xcentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
	int ycentre = rand()%(MAP_SIZE-2*BUILDING_SIZE)+BUILDING_SIZE;
	while(!is_ok)
	{
		is_ok = true;
		for(int j=0;j<buildings;j++)
		{
			if(abs(xcentre-building_xcentres[j])<=BUILDING_SIZE+10)
			{
				is_ok = false;
				xcentre = rand()%(MAP_SIZE-2*BUILDING_SIZE-2)+BUILDING_SIZE;
				ycentre = rand()%(MAP_SIZE-2*BUILDING_SIZE-2)+BUILDING_SIZE;
			}
		}
	}
	draw_ship(xcentre,ycentre);

	free(building_xcentres); free(building_ycentres);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
leaq 0x13fbc(%rip), %rax     # 0x1e340
movq %rax, 0x10(%rsp)
leaq 0x61160(%rip), %r14     # 0x6b4f0
leaq 0x8d129(%rip), %r15     # 0x974c0
leaq 0x29f32(%rip), %r12     # 0x342d0
xorl %ebp, %ebp
xorl %edx, %edx
cmpq $0x96, %rdx
je 0xa487
testq %rdx, %rdx
setne %al
movq %rdx, 0x28(%rsp)
cmpq $0x95, %rdx
setne %r13b
andb %al, %r13b
xorl %ebx, %ebx
cmpq $0x96, %rbx
je 0xa45b
andq $0x0, (%r14,%rbx,8)
andq $0x0, (%r15,%rbx,8)
leaq (%rbx,%rbp), %rax
xorl %ecx, %ecx
leaq 0x55e02(%rip), %rdx     # 0x601f0
movb %cl, (%rdx,%rax)
leaq 0x5b5e8(%rip), %rdx     # 0x659e0
movb %cl, (%rdx,%rax)
callq 0x5c5a
mulss 0x9c7c(%rip), %xmm0     # 0x14084
addss 0x9c78(%rip), %xmm0     # 0x14088
movss %xmm0, (%r12,%rbx,4)
testq %rbx, %rbx
setne %cl
pushq $0x4
popq %rax
cmpq $0x95, %rbx
je 0xa44b
andb %r13b, %cl
je 0xa44b
callq 0x5080
cltd
pushq $0xd
popq %rcx
idivl %ecx
xorl %eax, %eax
cmpl $0x7, %edx
ja 0xa44b
movl %edx, %eax
leaq 0xcaf4(%rip), %rcx      # 0x16f3c
movl (%rcx,%rax,4), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
jmp 0xa3ca
movq 0x28(%rsp), %rdx
incq %rdx
movl $0x258, %eax            # imm = 0x258
addq %rax, 0x10(%rsp)
movl $0x4b0, %ecx            # imm = 0x4B0
addq %rcx, %r14
addq %rcx, %r15
addq $0x96, %rbp
addq %rax, %r12
jmp 0xa3a2
callq 0x5080
pushq $0x3
popq %rcx
cltd
idivl %ecx
movl %edx, %ebp
addl $0x5, %ebp
leaq (,%rbp,4), %rdi
callq 0x5320
movq %rax, %r14
xorl %eax, %eax
cmpq %rax, %rbp
je 0xa4bb
movl $0xffffffef, (%r14,%rax,4) # imm = 0xFFFFFFEF
incq %rax
jmp 0xa4a9
xorl %r13d, %r13d
pushq $0x74
popq %r15
pushq $0x72
popq %rbx
movq %rbp, 0xe8(%rsp)
callq 0x5080
cltd
idivl %r15d
movl %edx, %r12d
cmpq %rbp, %r13
je 0xaa59
callq 0x5080
cltd
idivl %r15d
movq %rdx, 0x10(%rsp)
callq 0x5080
cltd
idivl %r15d
movl %edx, %ebp
addl $0x11, %ebp
callq 0x5080
movb $0x1, %al
xorl %r15d, %r15d
cmpq %r15, %r13
je 0xa538
movl %ebp, %ecx
subl (%r14,%r15,4), %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
cmpl $0x25, %edx
ja 0xa533
callq 0x5080
cltd
idivl %ebx
movl %edx, %ebp
addl $0x11, %ebp
callq 0x5080
xorl %eax, %eax
incq %r15
jmp 0xa508
testb $0x1, %al
pushq $0x74
popq %r15
je 0xa4f0
addl $0x11, %r12d
movq 0x10(%rsp), %rax
addl $0x11, %eax
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
andq $0x0, 0xc0(%rsp)
movq %rax, 0x10(%rsp)
shlq $0x20, %rax
movq %r12, 0x28(%rsp)
addq %r12, %rax
movq %rax, 0x90(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x12216
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
callq 0x5080
cltd
pushq $0x5
popq %rbp
idivl %ebp
movl %edx, %r12d
addl $0x2, %r12d
callq 0x5080
cltd
idivl %ebp
addl $0x2, %edx
shlq $0x20, %rdx
orq %rdx, %r12
movq %r12, 0xd0(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %r12
movq %r12, %rsi
callq 0x12216
andq $0x0, 0xe0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
andl $0x0, 0x40(%rsp)
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x12344
movq 0xb0(%rsp), %rax
movq (%rax), %rdi
movq 0x90(%rsp), %rax
movq (%rax), %rsi
callq 0x98a1
movl $0x0, 0x3c(%rsp)
xorl %ebp, %ebp
cmpl $0x9, %ebp
jg 0xaa22
cmpl $0x9, 0x3c(%rsp)
jg 0xaa22
callq 0x5080
movl %eax, %r12d
callq 0x5080
movq 0xb8(%rsp), %rcx
subq 0xb0(%rsp), %rcx
je 0xa679
movq 0x98(%rsp), %rdx
subq 0x90(%rsp), %rdx
cmpq %rcx, %rdx
je 0xa67d
incl %ebp
jmp 0xa631
cltd
pushq $0x5
popq %rcx
idivl %ecx
movl %edx, 0x1c(%rsp)
movl %r12d, %eax
cltd
idivl %ecx
movl %edx, %r12d
callq 0x5080
cltq
movq 0xb0(%rsp), %rcx
movq 0xb8(%rsp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
xorl %edx, %edx
divq %rsi
movslq %edx, %rax
movl (%rcx,%rax,8), %edx
movl %edx, 0x60(%rsp)
movl 0x4(%rcx,%rax,8), %ecx
movq %rcx, 0x68(%rsp)
movq 0x90(%rsp), %rcx
movl (%rcx,%rax,8), %r15d
movl 0x4(%rcx,%rax,8), %eax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
callq 0x5080
incl %r12d
cltd
idivl %r12d
addl %edx, %r15d
addl $0x2, %r15d
callq 0x5080
movl 0x1c(%rsp), %ecx
incl %ecx
cltd
idivl %ecx
andq $0x0, 0x8(%rsp)
movq 0x30(%rsp), %rax
leal (%rdx,%rax), %r8d
andq $0x0, 0x20(%rsp)
leal (%rdx,%rax), %esi
addl $0x2, %esi
movl %r15d, %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
movl %eax, %edi
addl 0x60(%rsp), %edi
movl %esi, 0x1c(%rsp)
movl %esi, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movq 0x68(%rsp), %rdx
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, 0x30(%rsp)
addl %edx, %r8d
subl %eax, %r8d
incl %r8d
movl %r8d, 0xa8(%rsp)
testl %r15d, %r15d
movl $0x0, %r12d
movq %r15, 0xf0(%rsp)
cmovgl %r15d, %r12d
movq %rdi, 0x60(%rsp)
movl %edi, %r15d
subl $0x1, %r12d
jb 0xa852
movl %r15d, 0x8(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x9fc8
movq %rax, 0x20(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
testl %eax, %eax
sete %al
testq %rcx, %rcx
sete %cl
testb %al, %cl
jne 0xa7ed
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x11196
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11196
movl %r15d, 0x8(%rsp)
movl 0xa8(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x9fc8
movq %rax, 0x20(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
testl %eax, %eax
sete %al
testq %rcx, %rcx
sete %cl
testb %al, %cl
jne 0xa84a
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x11196
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11196
incl %r15d
jmp 0xa789
movl 0x1c(%rsp), %eax
cltd
pushq $-0x2
popq %rcx
idivl %ecx
movq 0x60(%rsp), %rcx
movq 0xf0(%rsp), %rdx
addl %edx, %ecx
decl %ecx
movl %ecx, 0x30(%rsp)
movq 0x68(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x68(%rsp)
pushq $0x1
popq %rax
movl %eax, %r15d
cmpl 0x1c(%rsp), %r15d
jge 0xa954
movq 0x68(%rsp), %rax
leal (%rax,%r15), %r12d
movq 0x60(%rsp), %rax
movl %eax, 0x8(%rsp)
movl %r12d, 0xc(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x9fc8
movq %rax, 0x20(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
testl %eax, %eax
sete %al
testq %rcx, %rcx
sete %cl
testb %al, %cl
jne 0xa8f2
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x11196
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11196
movl 0x30(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %r12d, 0xc(%rsp)
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x9fc8
movq %rax, 0x20(%rsp)
movq %rax, %rcx
shrq $0x20, %rcx
testl %eax, %eax
sete %al
testq %rcx, %rcx
sete %cl
testb %al, %cl
jne 0xa94c
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x11196
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11196
incl %r15d
jmp 0xa883
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
je 0xaa03
movq 0x78(%rsp), %rcx
subq 0x70(%rsp), %rcx
cmpq %rax, %rcx
jne 0xaa03
callq 0x5080
cltq
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
xorl %edx, %edx
divq %rsi
movslq %edx, %r12
movq (%rcx,%r12,8), %rdi
movq 0x70(%rsp), %rax
movq (%rax,%r12,8), %rsi
callq 0x98a1
pushq $0x74
popq %r15
leaq 0x90(%rsp), %rbp
shlq $0x3, %r12
movq 0x40(%rsp), %rsi
addq %r12, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x11196
addq 0x70(%rsp), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x11196
andl $0x0, 0xac(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xac(%rsp), %rsi
callq 0x12344
incl 0x3c(%rsp)
xorl %ebp, %ebp
jmp 0xaa09
incl %ebp
pushq $0x74
popq %r15
leaq 0x70(%rsp), %rdi
callq 0x116cc
leaq 0x40(%rsp), %rdi
callq 0x116cc
jmp 0xa631
leaq 0xd0(%rsp), %rdi
callq 0x12336
leaq 0x90(%rsp), %rdi
callq 0x116cc
leaq 0xb0(%rsp), %rdi
callq 0x116cc
incq %r13
movq 0xe8(%rsp), %rbp
jmp 0xa4cd
addl $0x11, %r12d
callq 0x5080
cltd
idivl %r15d
addl $0x11, %edx
xorl %eax, %eax
testb $0x1, %al
jne 0xaaad
movb $0x1, %al
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0xaa6b
movl %r12d, %ecx
subl (%r14,%r15,4), %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
cmpl $0x1b, %esi
ja 0xaaa8
callq 0x5080
cltd
idivl %ebx
movl %edx, %r12d
addl $0x11, %r12d
callq 0x5080
cltd
idivl %ebx
addl $0x11, %edx
xorl %eax, %eax
incq %r15
jmp 0xaa74
movl %r12d, %edi
movl %edx, %esi
callq 0xa004
movq %r14, %rdi
callq 0x52c0
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaae8
jmp 0xaae8
movq %rax, %rbx
jmp 0xab0c
jmp 0xaadc
movq %rax, %rbx
jmp 0xaaff
movq %rax, %rbx
jmp 0xab19
jmp 0xaae8
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x116cc
leaq 0x40(%rsp), %rdi
callq 0x116cc
leaq 0xd0(%rsp), %rdi
callq 0x12336
leaq 0x90(%rsp), %rdi
callq 0x116cc
leaq 0xb0(%rsp), %rdi
callq 0x116cc
movq %rbx, %rdi
callq 0x53c0