// File: /workspace/github_cpp_makefile_star2_O1/lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::init_game()
void Game::init_game()
{
	switch(init_phase)
	{
	case IPH_DONE: return;
	case IPH_GEN_MAP:
		// generate a map:
		if(curmap)
			delete curmap;
		curmap = new Map(Config::int_settings[Config::IS_MAPSIZE],
			Config::int_settings[Config::IS_MAPSIZEVAR], cur_players.size());
		break;
	case IPH_GENERALS:
		curturn = 0;
		// figure out game mode:
		gamemode = Config::next_game_mode();
		// base spawn cycle length is determined by mapsize:
		spawn_cycle = (MIN_SPAWN_CYCLE - MAX_SPAWN_CYCLE)*AVG_SC_MAPSIZE/
			(curmap->get_size() + AVG_SC_MAPSIZE - 1) + MAX_SPAWN_CYCLE;
		if(gamemode == GM_DESTR) // Destroy objective has a longer spawn_cycle:
			spawn_cycle = min(6*spawn_cycle/5, int(MAX_SPAWN_CYCLE));
		else if(gamemode == GM_DOM) // Dominion has a shorter spawn_cycle:
			spawn_cycle = max(5*spawn_cycle/6, int(MIN_SPAWN_CYCLE));
		else if(gamemode == GM_TDM) // Team death match has a VERY short spawn cycle:
		{
			spawn_cycle = MIN_SPAWN_CYCLE;
			tdm_kills[T_GREEN] = tdm_kills[T_PURPLE] = 0;
		}
		// Do these regardless of whether mode is steal or not:
		item_moved = false;
		pl_with_item = cur_players.end();
		break;
	case IPH_PLACEMENT:
		do_placement();
		if(gamemode == GM_DESTR)
			upd_num_boulders();
		break;
	case IPH_MINIMAP:
	{
		// normal view (2*size^2) + num of titles (1)
		//  + one title (at most [size] chars, + '\0' + 2 char coords)
		char miniview[VIEWSIZE*VIEWSIZE*2+VIEWSIZE+4];
		short bufsize = VIEWSIZE*VIEWSIZE*2+4; // all except the title (the size of which varies)
		Game::curmap->gen_miniview(miniview); // raw minimap
		// add flags:
		Coords tmpc;
		for(list<NOccEnt>::const_iterator it = noccents[NOE_FLAG].begin();
			it != noccents[NOE_FLAG].end(); ++it)
		{
			// If flag is at (x,y), it is placed on the minimap at
			// (x*VIEWSIZE/mapsize, y*VIEWSIZE/mapsize) =: (x',y').
			// Now, the point (x',y') is in the buffer at (y'*VIEWSIZE+x')*2.
			// But we can't simplify all this into a single expression, because
			// intermediate integer rounding must take place!
			tmpc = it->getpos();
			tmpc.x = tmpc.x*VIEWSIZE/Game::curmap->get_size();
			tmpc.y = tmpc.y*VIEWSIZE/Game::curmap->get_size();
			it->draw(miniview + 2*(tmpc.y*VIEWSIZE+tmpc.x), true);
		}
		miniview[VIEWSIZE*VIEWSIZE*2] = 1; // num of titles
		miniview[VIEWSIZE*VIEWSIZE*2 + 1] = VIEWSIZE/2; // x-pos
		miniview[VIEWSIZE*VIEWSIZE*2 + 2] = VIEWSIZE/2-1; // y-pos
		switch(gamemode)
		{
		case GM_DOM:
			objective_str = "Dominion";
			break;
		case GM_CONQ:
			objective_str = "Conquest";
			break;
		case GM_STEAL:
			objective_str = "Steal (" + short_sector_name[obj_sector] + ')';
			break;
		case GM_DESTR:
			objective_str = "Destroy " + short_sector_name[obj_sector] + " boulders";
			break;
		case GM_TDM:
			objective_str = "Team deathmatch";
			break;
		}
		strcpy(miniview + VIEWSIZE*VIEWSIZE*2 + 3, objective_str.c_str());
		bufsize += objective_str.size();
		// compress, so it's ready to be sent:
		miniv_buf.clear();
		miniv_buf.add((unsigned char)MID_VIEW_UPD);
		miniv_buf.add((unsigned short)0); // turn number, which must be there
		miniv_buf.write_compressed(miniview, bufsize);
		// send to all players:
		Network::broadcast(0xFFFF, miniv_buf);
		break;
	}
	case IPH_LIGHTMAP:
		for(list<NOccEnt>::const_iterator i = noccents[NOE_TORCH].begin();
			i != noccents[NOE_TORCH].end(); ++i)
			update_static_light(i->getpos());
		break;
	case IPH_PLAYERS:
		// stuff that has to be done for all players:
		for(list<Player>::iterator it = cur_players.begin();
			it != cur_players.end(); ++it)
		{
			it->clear_acts();
			it->last_heard_of = 0;
			it->own_vp->newmap();
		}
		break;
	}
	init_phase = e_InitPhase(init_phase+1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x490, %rsp            # imm = 0x490
movl 0x2a15c(%rip), %eax     # 0x44c70
cmpq $0x6, %rax
ja 0x1af96
leaq 0x1427f(%rip), %rcx     # 0x2eda4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2a133(%rip), %rbx     # 0x44c68
testq %rbx, %rbx
je 0x1ab4f
movq %rbx, %rdi
callq 0x1703e
movl $0x20, %esi
movq %rbx, %rdi
callq 0x43f0
movl $0x20, %edi
callq 0x43e0
movq %rax, %r14
leaq 0x27d3d(%rip), %rax     # 0x428a0
movswl 0x8(%rax), %esi
movswl 0xc(%rax), %edx
leaq 0x2854e(%rip), %rax     # 0x430c0
movswl 0x10(%rax), %ecx
movq %r14, %rdi
callq 0x15474
movq %r14, 0x2a0e3(%rip)     # 0x44c68
jmp 0x1af96
movq 0x2a0d7(%rip), %rdi     # 0x44c68
leaq -0x4b0(%rbp), %rsi
callq 0x171a0
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq 0x2b20f(%rip), %r15     # 0x45dc0
addq $0x78, %r15
leaq -0x68(%rbp), %rbx
movq %r15, %r12
movq (%r12), %r12
cmpq %r15, %r12
je 0x1ad60
leaq 0x10(%r12), %r14
movl 0x18(%r12), %eax
movl %eax, -0x68(%rbp)
movl %eax, -0x24(%rbp)
movq %rbx, %rdi
callq 0x2bbf6
movswl -0x24(%rbp), %ecx
leal (%rcx,%rcx,2), %eax
shll $0x3, %eax
subl %ecx, %eax
movq 0x2a074(%rip), %rcx     # 0x44c68
movswl (%rcx), %esi
cltd
idivl %esi
movl %eax, %ecx
movw %cx, -0x24(%rbp)
movswl -0x22(%rbp), %edx
leal (%rdx,%rdx,2), %eax
shll $0x3, %eax
subl %edx, %eax
cltd
idivl %esi
movw %ax, -0x22(%rbp)
cwtl
leal (%rax,%rax,2), %edx
shll $0x3, %edx
subl %eax, %edx
movswl %cx, %eax
addl %edx, %eax
addl %eax, %eax
cltq
leaq (%rax,%rbp), %rsi
addq $-0x4b0, %rsi           # imm = 0xFB50
movq %r14, %rdi
movl $0x1, %edx
callq 0x21f8a
jmp 0x1abbc
movw $0x0, 0x2a015(%rip)     # 0x44c60
callq 0x11b48
movl %eax, %ecx
movl %eax, 0x295cc(%rip)     # 0x44224
movq 0x2a009(%rip), %rax     # 0x44c68
movswl (%rax), %esi
addl $0x95, %esi
movl $0xffffd120, %eax       # imm = 0xFFFFD120
cltd
idivl %esi
addb $0x78, %al
movb %al, 0x29ffc(%rip)      # 0x44c74
testl %ecx, %ecx
je 0x1adb5
cmpl $0x4, %ecx
je 0x1ada2
cmpl $0x3, %ecx
jne 0x1add7
movzbl %al, %eax
addl %eax, %eax
leal (%rax,%rax,2), %eax
imulq $0x33333334, %rax, %rax # imm = 0x33333334
shrq $0x20, %rax
cmpl $0x78, %eax
movl $0x78, %ecx
cmovbl %eax, %ecx
jmp 0x1add1
callq 0x1f7e8
cmpl $0x3, 0x29563(%rip)     # 0x44224
jne 0x1af96
callq 0x1b004
jmp 0x1af96
leaq 0x2b0e8(%rip), %rax     # 0x45dc0
movq 0x90(%rax), %r14
addq $0x90, %rax
cmpq %rax, %r14
je 0x1af96
leaq -0x4b0(%rbp), %rbx
movl $0x90, %r15d
addq 0x252c6(%rip), %r15     # 0x3ffc8
movl 0x18(%r14), %eax
movl %eax, -0x4b0(%rbp)
movq %rbx, %rdi
callq 0x20cea
movq %rbx, %rdi
callq 0x2bbf6
movq (%r14), %r14
cmpq %r15, %r14
jne 0x1ad02
jmp 0x1af96
leaq 0x28390(%rip), %rbx     # 0x430c0
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x1af96
leaq 0x10(%r14), %rdi
callq 0x125be
movw $0x0, 0xb8(%r14)
movq 0xd0(%r14), %rdi
callq 0x1deee
movq (%r14), %r14
jmp 0x1ad33
movw $0xb01, -0x8e(%rbp)     # imm = 0xB01
movb $0xa, -0x8c(%rbp)
movl 0x294ae(%rip), %eax     # 0x44224
cmpq $0x4, %rax
ja 0x1af1d
movl $0x8, %r8d
leaq 0x14033(%rip), %rcx     # 0x2edc0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x141a3(%rip), %rcx     # 0x2ef40
jmp 0x1aea8
movb $0x28, 0x29ecb(%rip)    # 0x44c74
movl $0x0, 0x29475(%rip)     # 0x44228
jmp 0x1add7
movzbl %al, %eax
leal (%rax,%rax,4), %eax
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
shrq $0x20, %rax
cmpl $0x29, %eax
movl $0x28, %ecx
cmovael %eax, %ecx
movb %cl, 0x29e9d(%rip)      # 0x44c74
leaq 0x2b232(%rip), %rax     # 0x46010
movb $0x0, (%rax)
leaq 0x282d8(%rip), %rax     # 0x430c0
leaq 0x2b219(%rip), %rcx     # 0x46008
movq %rax, (%rcx)
jmp 0x1af96
movl $0xf, %r8d
leaq 0x14169(%rip), %rcx     # 0x2ef6d
jmp 0x1aea8
movl 0x25615(%rip), %eax     # 0x40424
shlq $0x5, %rax
leaq 0x28dc6(%rip), %rdx     # 0x43be0
addq %rax, %rdx
leaq 0x1412e(%rip), %rsi     # 0x2ef52
leaq -0x48(%rbp), %rdi
callq 0x11dd6
leaq -0x48(%rbp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
movl $0x29, %r8d
callq 0x47b0
jmp 0x1ae7d
movl 0x255d5(%rip), %eax     # 0x40424
shlq $0x5, %rax
leaq 0x28d86(%rip), %rdx     # 0x43be0
addq %rax, %rdx
leaq 0x140f6(%rip), %rsi     # 0x2ef5a
leaq -0x48(%rbp), %rdi
callq 0x11dd6
leaq 0x140ef(%rip), %rsi     # 0x2ef63
leaq -0x48(%rbp), %rdi
callq 0x47c0
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1aebf
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x1aec6
leaq 0x140a1(%rip), %rcx     # 0x2ef49
movq 0x29d99(%rip), %rdx     # 0x44c48
leaq 0x29d8a(%rip), %rdi     # 0x44c40
xorl %esi, %esi
callq 0x4640
jmp 0x1af1d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x68(%rbp), %rbx
movq %rdx, 0x8(%rbx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x29d58(%rip), %rdi     # 0x44c40
movq %rbx, %rsi
callq 0x44c0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x1af04
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1af1d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x8b(%rbp), %rdi
movq 0x29d15(%rip), %rsi     # 0x44c40
callq 0x43c0
movl $0x426, %ebx            # imm = 0x426
addl 0x29d0d(%rip), %ebx     # 0x44c48
leaq 0x294ee(%rip), %rdi     # 0x44430
callq 0x2b340
leaq 0x294e2(%rip), %rdi     # 0x44430
movl $0x3, %esi
callq 0x2b354
leaq 0x294d1(%rip), %rdi     # 0x44430
xorl %esi, %esi
callq 0x2b368
movzwl %bx, %edx
leaq 0x294c0(%rip), %rdi     # 0x44430
leaq -0x4b0(%rbp), %rsi
callq 0x2b3dc
leaq 0x294ad(%rip), %rsi     # 0x44430
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xe383
leaq -0x24(%rbp), %rdi
callq 0x2bbf6
incl 0x29cd4(%rip)           # 0x44c70
addq $0x490, %rsp            # imm = 0x490
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1afae
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1aff3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1aff3
jmp 0x1aff0
jmp 0x1aff0
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x43f0
jmp 0x1affc
jmp 0x1aff0
movq %rax, %rbx
leaq -0x4b0(%rbp), %rdi
jmp 0x1aff7
movq %rax, %rbx
leaq -0x24(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750