// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a2b4(%rip), %eax     # 0x44c70
cmpq $0x6, %rax
ja 0x1ae3c
leaq 0x143d7(%rip), %rcx     # 0x2eda4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2a28b(%rip), %rbx     # 0x44c68
testq %rbx, %rbx
je 0x1a9f7
movq %rbx, %rdi
callq 0x16f16
movl $0x20, %esi
movq %rbx, %rdi
callq 0x43f0
movl $0x20, %edi
callq 0x43e0
movq %rax, %r14
leaq 0x27e95(%rip), %rax     # 0x428a0
movswl 0x8(%rax), %esi
movswl 0xc(%rax), %edx
leaq 0x286a6(%rip), %rax     # 0x430c0
movswl 0x10(%rax), %ecx
movq %r14, %rdi
callq 0x15348
movq %r14, 0x2a23b(%rip)     # 0x44c68
jmp 0x1ae3c
movq 0x2a22f(%rip), %rdi     # 0x44c68
leaq -0x4b0(%rbp), %rsi
callq 0x17078
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq 0x2b367(%rip), %r15     # 0x45dc0
addq $0x78, %r15
leaq -0x68(%rbp), %rbx
movq %r15, %r12
movq (%r12), %r12
cmpq %r15, %r12
je 0x1ac07
leaq 0x10(%r12), %r14
movl 0x18(%r12), %eax
movl %eax, -0x68(%rbp)
movl %eax, -0x24(%rbp)
movq %rbx, %rdi
callq 0x2b7a6
movswl -0x24(%rbp), %ecx
leal (%rcx,%rcx,2), %eax
shll $0x3, %eax
subl %ecx, %eax
movq 0x2a1cc(%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 0x21d1a
jmp 0x1aa64
movw $0x0, 0x2a16d(%rip)     # 0x44c60
callq 0x119f1
movl %eax, %ecx
movl %eax, 0x29724(%rip)     # 0x44224
movq 0x2a161(%rip), %rax     # 0x44c68
movswl (%rax), %esi
addl $0x95, %esi
movl $0xffffd120, %eax       # imm = 0xFFFFD120
cltd
idivl %esi
addb $0x78, %al
movb %al, 0x2a154(%rip)      # 0x44c74
testl %ecx, %ecx
je 0x1ac5c
cmpl $0x4, %ecx
je 0x1ac49
cmpl $0x3, %ecx
jne 0x1ac7d
movzbl %al, %eax
addl %eax, %eax
leal (%rax,%rax,2), %eax
imull $0x3334, %eax, %eax     # imm = 0x3334
shrl $0x10, %eax
cmpw $0x78, %ax
movl $0x78, %ecx
cmovbl %eax, %ecx
jmp 0x1ac77
callq 0x1f64c
cmpl $0x3, 0x296bc(%rip)     # 0x44224
jne 0x1ae3c
callq 0x1aeaa
jmp 0x1ae3c
leaq 0x2b241(%rip), %rax     # 0x45dc0
movq 0x90(%rax), %r14
addq $0x90, %rax
cmpq %rax, %r14
je 0x1ae3c
leaq -0x4b0(%rbp), %rbx
movl $0x90, %r15d
addq 0x25417(%rip), %r15     # 0x3ffc0
movl 0x18(%r14), %eax
movl %eax, -0x4b0(%rbp)
movq %rbx, %rdi
callq 0x20b88
movq %rbx, %rdi
callq 0x2b7a6
movq (%r14), %r14
cmpq %r15, %r14
jne 0x1aba9
jmp 0x1ae3c
leaq 0x284e9(%rip), %rbx     # 0x430c0
movq (%rbx), %r14
cmpq %rbx, %r14
je 0x1ae3c
leaq 0x10(%r14), %rdi
callq 0x1246e
movw $0x0, 0xb8(%r14)
movq 0xd0(%r14), %rdi
callq 0x1dd3e
movq (%r14), %r14
jmp 0x1abda
movw $0xb01, -0x8e(%rbp)     # imm = 0xB01
movb $0xa, -0x8c(%rbp)
movl 0x29607(%rip), %eax     # 0x44224
cmpq $0x4, %rax
ja 0x1adc3
movl $0x8, %r8d
leaq 0x1418c(%rip), %rcx     # 0x2edc0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x142fc(%rip), %rcx     # 0x2ef40
jmp 0x1ad4e
movb $0x28, 0x2a024(%rip)    # 0x44c74
movl $0x0, 0x295ce(%rip)     # 0x44228
jmp 0x1ac7d
movzbl %al, %eax
leal (%rax,%rax,4), %eax
imull $0x2aab, %eax, %eax     # imm = 0x2AAB
shrl $0x10, %eax
cmpw $0x29, %ax
movl $0x28, %ecx
cmovael %eax, %ecx
movb %cl, 0x29ff7(%rip)      # 0x44c74
leaq 0x2b38c(%rip), %rax     # 0x46010
movb $0x0, (%rax)
leaq 0x28432(%rip), %rax     # 0x430c0
leaq 0x2b373(%rip), %rcx     # 0x46008
movq %rax, (%rcx)
jmp 0x1ae3c
movl $0xf, %r8d
leaq 0x142c3(%rip), %rcx     # 0x2ef6d
jmp 0x1ad4e
movl 0x25767(%rip), %eax     # 0x4041c
shlq $0x5, %rax
leaq 0x28f20(%rip), %rdx     # 0x43be0
addq %rax, %rdx
leaq 0x14288(%rip), %rsi     # 0x2ef52
leaq -0x48(%rbp), %rdi
callq 0x11c74
leaq -0x48(%rbp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
movl $0x29, %r8d
callq 0x47a0
jmp 0x1ad23
movl 0x25727(%rip), %eax     # 0x4041c
shlq $0x5, %rax
leaq 0x28ee0(%rip), %rdx     # 0x43be0
addq %rax, %rdx
leaq 0x14250(%rip), %rsi     # 0x2ef5a
leaq -0x48(%rbp), %rdi
callq 0x11c74
leaq 0x14249(%rip), %rsi     # 0x2ef63
leaq -0x48(%rbp), %rdi
callq 0x47b0
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1ad65
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x1ad6c
leaq 0x141fb(%rip), %rcx     # 0x2ef49
movq 0x29ef3(%rip), %rdx     # 0x44c48
leaq 0x29ee4(%rip), %rdi     # 0x44c40
xorl %esi, %esi
callq 0x4630
jmp 0x1adc3
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 0x29eb2(%rip), %rdi     # 0x44c40
movq %rbx, %rsi
callq 0x44c0
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x1adaa
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1adc3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x8b(%rbp), %rdi
movq 0x29e6f(%rip), %rsi     # 0x44c40
callq 0x43c0
movl $0x426, %ebx            # imm = 0x426
addl 0x29e67(%rip), %ebx     # 0x44c48
leaq 0x29648(%rip), %rdi     # 0x44430
callq 0x2af20
leaq 0x2963c(%rip), %rdi     # 0x44430
movl $0x3, %esi
callq 0x2af34
leaq 0x2962b(%rip), %rdi     # 0x44430
xorl %esi, %esi
callq 0x2af48
movzwl %bx, %edx
leaq 0x2961a(%rip), %rdi     # 0x44430
leaq -0x4b0(%rbp), %rsi
callq 0x2afc0
leaq 0x29607(%rip), %rsi     # 0x44430
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xe3b3
leaq -0x24(%rbp), %rdi
callq 0x2b7a6
incl 0x29e2e(%rip)           # 0x44c70
addq $0x490, %rsp            # imm = 0x490
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ae54
movq %rax, %rbx
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1ae99
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x1ae99
jmp 0x1ae96
jmp 0x1ae96
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x43f0
jmp 0x1aea2
jmp 0x1ae96
movq %rax, %rbx
leaq -0x4b0(%rbp), %rdi
jmp 0x1ae9d
movq %rax, %rbx
leaq -0x24(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740