// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movl 0x2c350(%rip), %eax     # 0x41c60
cmpq $0x6, %rax
ja 0x15cdc
leaq 0x134b3(%rip), %rcx     # 0x28dd4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2c327(%rip), %rbx     # 0x41c58
testq %rbx, %rbx
je 0x15949
movq %rbx, %rdi
callq 0x1255e
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x4400
pushq $0x20
popq %rdi
callq 0x43f0
movq %rax, %r14
leaq 0x29f35(%rip), %rax     # 0x3f890
movswl 0x8(%rax), %esi
movswl 0xc(%rax), %edx
leaq 0x2a746(%rip), %rax     # 0x400b0
movswl 0x10(%rax), %ecx
movq %r14, %rdi
callq 0x10dec
movq %r14, 0x2c2db(%rip)     # 0x41c58
jmp 0x15cdc
movq 0x2c2cf(%rip), %rdi     # 0x41c58
leaq -0x4b0(%rbp), %rsi
callq 0x126b8
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq 0x2d407(%rip), %r12     # 0x42db0
addq $0x78, %r12
leaq -0x70(%rbp), %rbx
pushq $0x1
popq %r14
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0x15b27
leaq 0x10(%r13), %r15
movl 0x18(%r13), %eax
movl %eax, -0x70(%rbp)
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x24d9e
movswl -0x2c(%rbp), %eax
imull $0x17, %eax, %eax
movq 0x2c26f(%rip), %rcx     # 0x41c58
movswl (%rcx), %esi
cltd
idivl %esi
movl %eax, %ecx
movw %cx, -0x2c(%rbp)
movswl -0x2a(%rbp), %eax
imull $0x17, %eax, %eax
cltd
idivl %esi
movw %ax, -0x2a(%rbp)
cwtl
imull $0x17, %eax, %eax
movswl %cx, %ecx
addl %eax, %ecx
addl %ecx, %ecx
movslq %ecx, %rax
leaq (%rax,%rbp), %rsi
addq $-0x4b0, %rsi           # imm = 0xFB50
movq %r15, %rdi
movl %r14d, %edx
callq 0x1c9e6
jmp 0x159b8
andw $0x0, 0x2c21f(%rip)     # 0x41c50
callq 0xdc8b
movl %eax, %ecx
movl %eax, 0x2b7d6(%rip)     # 0x41214
movq 0x2c213(%rip), %rax     # 0x41c58
movswl (%rax), %esi
addl $0x95, %esi
movl $0xffffd120, %eax       # imm = 0xFFFFD120
cltd
idivl %esi
addb $0x78, %al
movb %al, 0x2c206(%rip)      # 0x41c64
testl %ecx, %ecx
je 0x15b73
cmpl $0x4, %ecx
je 0x15b63
cmpl $0x3, %ecx
jne 0x15b92
movzbl %al, %eax
imull $0x6, %eax, %eax
movw $0x5, %cx
xorl %edx, %edx
divw %cx
cmpw $0x78, %ax
pushq $0x78
popq %rcx
cmovbl %eax, %ecx
jmp 0x15b8c
callq 0x1a210
cmpl $0x3, 0x2b772(%rip)     # 0x41214
jne 0x15cdc
callq 0x15d3a
jmp 0x15cdc
movl $0x90, %r14d
addq 0x27509(%rip), %r14     # 0x3cfc8
leaq -0x4b0(%rbp), %rbx
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x15cdc
movl 0x18(%r15), %eax
movl %eax, -0x4b0(%rbp)
movq %rbx, %rdi
callq 0x1b38e
movq %rbx, %rdi
callq 0x24d9e
jmp 0x15ac9
leaq 0x2a5b8(%rip), %rbx     # 0x400b0
movq %rbx, %r14
movq (%r14), %r14
cmpq %rbx, %r14
je 0x15cdc
leaq 0x10(%r14), %rdi
callq 0xe664
andw $0x0, 0xb8(%r14)
movq 0xd0(%r14), %rdi
callq 0x18820
jmp 0x15afb
movw $0xb01, -0x8e(%rbp)     # imm = 0xB01
movb $0xa, -0x8c(%rbp)
movl 0x2b6d7(%rip), %eax     # 0x41214
cmpq $0x4, %rax
ja 0x15c65
leaq 0x132a2(%rip), %rcx     # 0x28df0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1341b(%rip), %rsi     # 0x28f79
jmp 0x15c59
movb $0x28, 0x2c0fa(%rip)    # 0x41c64
andl $0x0, 0x2b6a7(%rip)     # 0x41218
jmp 0x15b92
movzbl %al, %eax
leal (%rax,%rax,4), %eax
movw $0x6, %cx
xorl %edx, %edx
divw %cx
cmpw $0x29, %ax
pushq $0x28
popq %rcx
cmovael %eax, %ecx
movb %cl, 0x2c0d2(%rip)      # 0x41c64
leaq 0x2d467(%rip), %rax     # 0x43000
movb $0x0, (%rax)
leaq 0x2a50d(%rip), %rax     # 0x400b0
leaq 0x2d44e(%rip), %rcx     # 0x42ff8
movq %rax, (%rcx)
jmp 0x15cdc
leaq 0x133ed(%rip), %rsi     # 0x28fa6
jmp 0x15c59
movl 0x27850(%rip), %eax     # 0x3d414
shlq $0x5, %rax
leaq 0x2b001(%rip), %rdx     # 0x40bd0
addq %rax, %rdx
leaq 0x133b2(%rip), %rsi     # 0x28f8b
leaq -0x50(%rbp), %rdi
callq 0xde6a
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
pushq $0x29
popq %rdx
callq 0x17d8b
jmp 0x15c2c
movl 0x2781a(%rip), %eax     # 0x3d414
shlq $0x5, %rax
leaq 0x2afcb(%rip), %rdx     # 0x40bd0
addq %rax, %rdx
leaq 0x13384(%rip), %rsi     # 0x28f93
leaq -0x50(%rbp), %rdi
callq 0xde6a
leaq 0x1337d(%rip), %rdx     # 0x28f9c
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xb309
leaq 0x2bffd(%rip), %rdi     # 0x41c30
leaq -0x70(%rbp), %rbx
movq %rbx, %rsi
callq 0x44b0
movq %rbx, %rdi
callq 0x47e8
leaq -0x50(%rbp), %rdi
callq 0x47e8
jmp 0x15c65
leaq 0x13329(%rip), %rsi     # 0x28f82
leaq 0x2bfd0(%rip), %rdi     # 0x41c30
callq 0x4780
leaq -0x8b(%rbp), %rdi
movq 0x2bfbd(%rip), %rsi     # 0x41c30
callq 0x43d0
movl $0x426, %ebx            # imm = 0x426
addl 0x2bfb5(%rip), %ebx     # 0x41c38
leaq 0x2b796(%rip), %rdi     # 0x41420
callq 0x24712
leaq 0x2b78a(%rip), %rdi     # 0x41420
pushq $0x3
popq %rsi
callq 0x24724
leaq 0x2b77b(%rip), %rdi     # 0x41420
xorl %esi, %esi
callq 0x24738
movzwl %bx, %edx
leaq 0x2b76a(%rip), %rdi     # 0x41420
leaq -0x4b0(%rbp), %rsi
callq 0x247b0
leaq 0x2b757(%rip), %rsi     # 0x41420
movl $0xffff, %edi           # imm = 0xFFFF
callq 0xb61b
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
incl 0x2bf7e(%rip)           # 0x41c60
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15cf6
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x47e8
jmp 0x15d29
jmp 0x15d26
jmp 0x15d26
movq %rax, %rbx
pushq $0x20
popq %rsi
movq %r14, %rdi
callq 0x4400
jmp 0x15d32
jmp 0x15d26
movq %rax, %rbx
leaq -0x4b0(%rbp), %rdi
jmp 0x15d2d
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710