// File: /workspace/github_cpp_makefile_star2_O2/essarrdee[P]mutantaliens/mutantaliens.cpp
// Function: init()
void init()
{
	rlmessages.push_back(" ");
	initscr();
	if(has_colors() == FALSE)
	{
		endwin();
		printf("Your terminal does not support colour\n");
		exit(1);
	}
    start_color();
	for(int i=0;i<8;i++)
	{
		init_pair(i,i,COLOR_BLACK);
	}
	noecho();
	cbreak();
	curs_set(0);
	keypad(stdscr,TRUE);
	mvaddstr(4,10,"Choose a difficulty level (0 to 9):");
	mvaddstr(5,13,"2 is too easy, 9 is too hard,");
	mvaddstr(6,10,"3 is ok for beginners, 7 is standard");
	//mvaddstr(8,12,"Press t for the tutorial");
	move(7,15);
	int kp = 0;
	while((kp - '0' < 0 || kp - '0' > 9) /*&& kp != 't' && kp != 'T'*/)
	{
		kp = getch();
	}
	//if (kp == 't' || kp == 'T')
	//{
	//	difficulty = -1;
	//	init_tutorial_species();
	//	init_tutorial_map();
	//	init_tutorial_actors();
	//	init_tutorial_items();
	//}
	//else
	{
		difficulty = kp - '0';
		if(difficulty > 6) difficulty += (difficulty-6)*3;
		//scratch = newpad(viewport_height,viewport_width);
		init_species();
		init_map();
		init_actors();
		init_items();
		add_message("The ship plays a cheerful tune, and the door opens. \"Automatic docking completed. Welcome to Spaceport X7/3A! Please enjoy your stay.\"");
		std::vector<std::pair<int,int>> transmitter_options;
		int acceptable_range = 70;
		while(transmitter_options.size() == 0)
		{
			for(int x = 0; x < MAP_SIZE; x++)
			{
				for(int y = 0; y < MAP_SIZE; y++)
				{
					if(map_terrain[x][y] == FLOOR && d22(x,y,ship_x, ship_y) > acceptable_range*acceptable_range)
						transmitter_options.push_back(std::make_pair(x,y));
				}
			}
			acceptable_range--;
		}

		std::pair<int,int> target_pair = transmitter_options[rand()%transmitter_options.size()];
		target_x = target_pair.first; target_y = target_pair.second;
		//target_x = rand()%MAP_SIZE; target_y = rand()%MAP_SIZE;
	
		/*while(map_terrain[target_x][target_y] != FLOOR || d22(ship_x,ship_y,target_x,target_y) <= squarei(acceptable_range))
		{
			target_x = rand()%MAP_SIZE; target_y = rand()%MAP_SIZE;
			if(rand()%4 != 0) acceptable_range--;
		}*/
		add_junk("radio transmitter","So this is what's been causing you so much trouble!",'?',COLOR_CYAN,target_x,target_y);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
leaq 0xad90(%rip), %rsi      # 0x160bb
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5110
leaq 0x5fef7(%rip), %rdi     # 0x6b238
leaq 0x20(%rsp), %rsi
callq 0x12a30
leaq 0x20(%rsp), %rdi
callq 0x5418
callq 0x5350
callq 0x5370
testb %al, %al
je 0xb5ff
callq 0x5060
xorl %ebx, %ebx
cmpl $0x8, %ebx
je 0xb383
movswl %bx, %edi
movl %edi, %esi
xorl %edx, %edx
callq 0x5040
incl %ebx
jmp 0xb36e
callq 0x5290
callq 0x50c0
xorl %edi, %edi
callq 0x51c0
movq 0x12c3d(%rip), %rbx     # 0x1dfd8
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x5100
movq (%rbx), %rdi
pushq $0x4
popq %rsi
pushq $0xa
popq %rdx
callq 0x5260
cmpl $-0x1, %eax
je 0xb3cb
movq (%rbx), %rdi
leaq 0x9a04(%rip), %rsi      # 0x14dc7
pushq $-0x1
popq %rdx
callq 0x50d0
movq (%rbx), %rdi
pushq $0x5
popq %rsi
pushq $0xd
popq %rdx
callq 0x5260
cmpl $-0x1, %eax
je 0xb3f0
movq (%rbx), %rdi
leaq 0x9a03(%rip), %rsi      # 0x14deb
pushq $-0x1
popq %rdx
callq 0x50d0
movq (%rbx), %rdi
pushq $0x6
popq %rsi
pushq $0xa
popq %rdx
callq 0x5260
cmpl $-0x1, %eax
je 0xb415
movq (%rbx), %rdi
leaq 0x99fc(%rip), %rsi      # 0x14e09
pushq $-0x1
popq %rdx
callq 0x50d0
pushq $0x7
popq %rdi
pushq $0xf
popq %rsi
callq 0x51a0
xorl %eax, %eax
leal -0x3a(%rax), %ecx
cmpl $-0xb, %ecx
ja 0xb434
movq (%rbx), %rdi
callq 0x50f0
jmp 0xb422
xorl %ecx, %ecx
cmpl $0x37, %eax
leal -0xa2(%rax,%rax,2), %edx
cmovbl %ecx, %edx
addl %edx, %eax
addl $-0x30, %eax
movl %eax, 0x12ebe(%rip)     # 0x1e30c
callq 0x7d5a
callq 0xa36c
callq 0xab2e
callq 0xb119
leaq 0x99c5(%rip), %rsi      # 0x14e2e
leaq 0x88(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x5110
leaq 0x88(%rsp), %rdi
callq 0x5c6e
leaq 0x88(%rsp), %rdi
callq 0x5418
leaq 0x20(%rsp), %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
pushq $0x46
popq %r13
xorl %eax, %eax
movabsq $0x100000000, %r12      # imm = 0x100000000
xorl %ecx, %ecx
cmpq %rax, %rcx
jne 0xb550
movl %r13d, 0x1c(%rsp)
imull %r13d, %r13d
leaq 0x12e70(%rip), %r15     # 0x1e340
xorl %ebx, %ebx
cmpq $0x96, %rbx
je 0xb539
movq %rbx, %rbp
xorl %r14d, %r14d
cmpq $0x96, %r14
je 0xb52d
cmpl $0x3, (%r15,%r14,4)
jne 0xb525
movl %ebx, %eax
subl 0x5fd03(%rip), %eax     # 0x6b1fc
imull %eax, %eax
movl 0x5fcfe(%rip), %ecx     # 0x6b200
movl %r14d, %edx
subl %ecx, %edx
imull %edx, %edx
addl %eax, %edx
cmpl %r13d, %edx
jbe 0xb525
movq %rbp, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12216
incq %r14
addq %r12, %rbp
jmp 0xb4e1
incq %rbx
addq $0x258, %r15            # imm = 0x258
jmp 0xb4d2
movl 0x1c(%rsp), %r13d
decl %r13d
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
jmp 0xb4b7
callq 0x5080
cltq
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
xorl %edx, %edx
divq %rsi
movl (%rcx,%rdx,8), %eax
movl 0x4(%rcx,%rdx,8), %ecx
movl %eax, 0x5fc7a(%rip)     # 0x6b1f4
movl %ecx, 0x5fc78(%rip)     # 0x6b1f8
leaq 0x992e(%rip), %rsi      # 0x14eb5
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5110
leaq 0x992a(%rip), %rsi      # 0x14ec7
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5110
movl 0x5fc41(%rip), %r8d     # 0x6b1f4
movl 0x5fc3e(%rip), %r9d     # 0x6b1f8
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
pushq $0x3f
popq %rdx
pushq $0x6
popq %rcx
callq 0x96dd
leaq 0x48(%rsp), %rdi
callq 0x5418
leaq 0x68(%rsp), %rdi
callq 0x5418
leaq 0x20(%rsp), %rdi
callq 0x116cc
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x52b0
leaq 0xb908(%rip), %rdi      # 0x16f13
callq 0x5360
pushq $0x1
popq %rdi
callq 0x52d0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5418
jmp 0xb62a
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5418
jmp 0xb65e
jmp 0xb65b
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0xb64f
jmp 0xb656
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5418
jmp 0xb668
movq %rax, %rbx
jmp 0xb668
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x116cc
movq %rbx, %rdi
callq 0x53c0