// File: 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:
subq $0x138, %rsp            # imm = 0x138
leaq 0x117(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x5490
movq 0x40(%rsp), %rdx
leaq 0x1b1b1(%rip), %rsi     # 0x2f356
leaq 0x118(%rsp), %rdi
callq 0x53d0
jmp 0x141b4
leaq 0x740ed(%rip), %rdi     # 0x882a8
leaq 0x118(%rsp), %rsi
callq 0x21370
jmp 0x141ca
leaq 0x118(%rsp), %rdi
callq 0x54f8
leaq 0x117(%rsp), %rdi
callq 0x5310
callq 0x5400
callq 0x5420
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1425e
callq 0x5340
leaq 0x19e37(%rip), %rdi     # 0x2e03b
movb $0x0, %al
callq 0x5050
movl $0x1, %edi
callq 0x5360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1424c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x54f8
leaq 0x117(%rsp), %rdi
callq 0x5310
jmp 0x147b7
callq 0x5090
movl $0x0, 0x100(%rsp)
cmpl $0x8, 0x100(%rsp)
jge 0x142a9
movl 0x100(%rsp), %eax
movw %ax, %cx
movl 0x100(%rsp), %eax
xorl %edx, %edx
movswl %cx, %edi
movswl %ax, %esi
callq 0x5070
movl 0x100(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x100(%rsp)
jmp 0x1426e
callq 0x5330
callq 0x50f0
xorl %edi, %edi
callq 0x5250
movq 0x26d1f(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x5130
movq 0x26d0b(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
movl $0x4, %esi
movl $0xa, %edx
callq 0x52f0
cmpl $-0x1, %eax
jne 0x142ee
jmp 0x14309
movq 0x26ceb(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
leaq 0x19d63(%rip), %rsi     # 0x2e062
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5100
movq 0x26cd0(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
movl $0x5, %esi
movl $0xd, %edx
callq 0x52f0
cmpl $-0x1, %eax
jne 0x14329
jmp 0x14344
movq 0x26cb0(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
leaq 0x19d4c(%rip), %rsi     # 0x2e086
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5100
movq 0x26c95(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
movl $0x6, %esi
movl $0xa, %edx
callq 0x52f0
cmpl $-0x1, %eax
jne 0x14364
jmp 0x1437f
movq 0x26c75(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
leaq 0x19d2f(%rip), %rsi     # 0x2e0a4
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5100
movl $0x7, %edi
movl $0xf, %esi
callq 0x5230
movl $0x0, 0xfc(%rsp)
movl 0xfc(%rsp), %ecx
subl $0x30, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, 0x3f(%rsp)
jl 0x143c2
movl 0xfc(%rsp), %eax
subl $0x30, %eax
cmpl $0x9, %eax
setg %al
movb %al, 0x3f(%rsp)
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x143cc
jmp 0x143e4
movq 0x26c0d(%rip), %rax     # 0x3afe0
movq (%rax), %rdi
callq 0x5120
movl %eax, 0xfc(%rsp)
jmp 0x14399
movl 0xfc(%rsp), %eax
subl $0x30, %eax
movl %eax, 0x26f88(%rip)     # 0x3b37c
cmpl $0x6, 0x26f81(%rip)     # 0x3b37c
jle 0x14415
movl 0x26f79(%rip), %eax     # 0x3b37c
subl $0x6, %eax
imull $0x3, %eax, %eax
addl 0x26f6d(%rip), %eax     # 0x3b37c
movl %eax, 0x26f67(%rip)     # 0x3b37c
callq 0xbe10
callq 0x11ea0
callq 0x13050
callq 0x13e70
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x5490
movq 0x30(%rsp), %rdx
leaq 0x19c82(%rip), %rsi     # 0x2e0c9
leaq 0xd8(%rsp), %rdi
callq 0x53d0
jmp 0x14456
leaq 0xd8(%rsp), %rdi
callq 0x6670
jmp 0x14465
leaq 0xd8(%rsp), %rdi
callq 0x54f8
leaq 0xd7(%rsp), %rdi
callq 0x5310
leaq 0xb8(%rsp), %rdi
callq 0x20d50
movl $0x46, 0xb4(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x20ef0
cmpq $0x0, %rax
jne 0x14631
movl $0x0, 0xb0(%rsp)
cmpl $0x96, 0xb0(%rsp)
jge 0x1461b
movl $0x0, 0xac(%rsp)
cmpl $0x96, 0xac(%rsp)
jge 0x14603
movslq 0xb0(%rsp), %rcx
leaq 0x26ebb(%rip), %rax     # 0x3b3b0
imulq $0x258, %rcx, %rcx      # imm = 0x258
addq %rcx, %rax
movslq 0xac(%rsp), %rcx
cmpl $0x3, (%rax,%rcx,4)
jne 0x145eb
movl 0xb0(%rsp), %edi
movl 0xac(%rsp), %esi
movl 0x73d47(%rip), %edx     # 0x8826c
movl 0x73d45(%rip), %ecx     # 0x88270
callq 0x6610
movl 0xb4(%rsp), %ecx
imull 0xb4(%rsp), %ecx
cmpl %ecx, %eax
jle 0x145eb
leaq 0xb0(%rsp), %rdi
leaq 0xac(%rsp), %rsi
callq 0x207c0
movq %rax, 0x28(%rsp)
jmp 0x14563
movq 0x28(%rsp), %rax
movq %rax, 0xa4(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xa4(%rsp), %rsi
callq 0x20dc0
jmp 0x14587
jmp 0x145eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x145c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x54f8
leaq 0xd7(%rsp), %rdi
callq 0x5310
jmp 0x147b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x147aa
jmp 0x145ed
movl 0xac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xac(%rsp)
jmp 0x144d5
jmp 0x14605
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x144b9
movl 0xb4(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x14497
callq 0x50b0
cltq
movq %rax, 0x18(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x20ef0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x18(%rsp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
callq 0x20f10
movq (%rax), %rax
movq %rax, 0x98(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0x73be3(%rip)     # 0x88264
movl 0x9c(%rsp), %eax
movl %eax, 0x73bda(%rip)     # 0x88268
leaq 0x77(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x5490
movq 0x20(%rsp), %rdx
leaq 0x19aa7(%rip), %rsi     # 0x2e150
leaq 0x78(%rsp), %rdi
callq 0x53d0
jmp 0x146b5
leaq 0x4f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x5490
movq 0x8(%rsp), %rdx
leaq 0x19a92(%rip), %rsi     # 0x2e162
leaq 0x50(%rsp), %rdi
callq 0x53d0
jmp 0x146dc
movl 0x73b81(%rip), %r8d     # 0x88264
movl 0x73b7e(%rip), %r9d     # 0x88268
leaq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x3f, %edx
movl $0x6, %ecx
callq 0xfcf0
jmp 0x14705
leaq 0x50(%rsp), %rdi
callq 0x54f8
leaq 0x4f(%rsp), %rdi
callq 0x5310
leaq 0x78(%rsp), %rdi
callq 0x54f8
leaq 0x77(%rsp), %rdi
callq 0x5310
leaq 0xb8(%rsp), %rdi
callq 0x1fcd0
addq $0x138, %rsp            # imm = 0x138
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x147a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0x1478c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x54f8
leaq 0x4f(%rsp), %rdi
callq 0x5310
leaq 0x78(%rsp), %rdi
callq 0x54f8
leaq 0x77(%rsp), %rdi
callq 0x5310
leaq 0xb8(%rsp), %rdi
callq 0x1fcd0
movq 0x108(%rsp), %rdi
callq 0x5480
nopw %cs:(%rax,%rax)