// File: 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
subq $0x5b0, %rsp            # imm = 0x5B0
movl 0x5a7cf(%rip), %eax     # 0x91de0
movq %rax, -0x560(%rbp)
subq $0x6, %rax
ja 0x37ddf
movq -0x560(%rbp), %rax
leaq 0x2c8c4(%rip), %rcx     # 0x63ef4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x37dee
cmpq $0x0, 0x5a792(%rip)     # 0x91dd8
je 0x3767b
movq 0x5a789(%rip), %rax     # 0x91dd8
movq %rax, -0x568(%rbp)
cmpq $0x0, %rax
je 0x37679
movq -0x568(%rbp), %rdi
callq 0x2ba20
movq -0x568(%rbp), %rdi
movl $0x20, %esi
callq 0x5530
jmp 0x3767b
movl $0x20, %edi
callq 0x5520
movq %rax, -0x578(%rbp)
movq %rax, -0x580(%rbp)
leaq 0x58376(%rip), %rax     # 0x8fa10
movswl 0x8(%rax), %ecx
movl %ecx, -0x570(%rbp)
movswl 0xc(%rax), %eax
movl %eax, -0x56c(%rbp)
leaq 0x58b7b(%rip), %rdi     # 0x90230
callq 0x25070
movq -0x578(%rbp), %rdi
movl -0x570(%rbp), %esi
movl -0x56c(%rbp), %edx
movswl %ax, %ecx
callq 0x291a0
jmp 0x376d7
movq -0x580(%rbp), %rax
movq %rax, 0x5a6f3(%rip)     # 0x91dd8
jmp 0x37ddf
movq -0x580(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x8(%rbp)
movl %eax, -0xc(%rbp)
movl $0x20, %esi
callq 0x5530
jmp 0x37df7
movw $0x0, 0x5a6bb(%rip)     # 0x91dd0
callq 0x1efc0
movl %eax, 0x59c74(%rip)     # 0x91394
movq 0x5a6b1(%rip), %rdi     # 0x91dd8
callq 0x3c930
movswl %ax, %ecx
addl $0x96, %ecx
subl $0x1, %ecx
movl $0xffffd120, %eax       # imm = 0xFFFFD120
cltd
idivl %ecx
addl $0x78, %eax
movb %al, 0x5a69b(%rip)      # 0x91de4
cmpl $0x3, 0x59c44(%rip)     # 0x91394
jne 0x37785
movzbl 0x5a68b(%rip), %eax     # 0x91de4
imull $0x6, %eax, %eax
movl $0x5, %ecx
cltd
idivl %ecx
movl %eax, -0x10(%rbp)
movl $0x78, -0x14(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x2eb70
movl (%rax), %eax
movb %al, 0x5a661(%rip)      # 0x91de4
jmp 0x377e7
cmpl $0x0, 0x59c08(%rip)     # 0x91394
jne 0x377c1
movzbl 0x5a64f(%rip), %eax     # 0x91de4
imull $0x5, %eax, %eax
movl $0x6, %ecx
cltd
idivl %ecx
movl %eax, -0x18(%rbp)
movl $0x28, -0x1c(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x2eb30
movl (%rax), %eax
movb %al, 0x5a625(%rip)      # 0x91de4
jmp 0x377e5
cmpl $0x4, 0x59bcc(%rip)     # 0x91394
jne 0x377e3
movb $0x28, 0x5a613(%rip)    # 0x91de4
movw $0x0, 0x59bc0(%rip)     # 0x9139a
movw $0x0, 0x59bb5(%rip)     # 0x91398
jmp 0x377e5
jmp 0x377e7
leaq 0x5b992(%rip), %rax     # 0x93180
movb $0x0, (%rax)
leaq 0x58a38(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x18a20
leaq 0x5b963(%rip), %rax     # 0x93178
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x37ddf
callq 0x465a0
cmpl $0x3, 0x59b67(%rip)     # 0x91394
jne 0x37834
callq 0x37e00
jmp 0x37ddf
movw $0x426, -0x472(%rbp)    # imm = 0x426
movq 0x5a58f(%rip), %rdi     # 0x91dd8
leaq -0x470(%rbp), %rsi
callq 0x2bce0
leaq -0x478(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
leaq 0x5b6c4(%rip), %rdi     # 0x92f30
addq $0x78, %rdi
callq 0x3c950
movq %rax, -0x488(%rbp)
leaq -0x480(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x3c980
leaq 0x5b69a(%rip), %rdi     # 0x92f30
addq $0x78, %rdi
callq 0x3c9d0
movq %rax, -0x498(%rbp)
leaq -0x490(%rbp), %rdi
leaq -0x498(%rbp), %rsi
callq 0x3c980
leaq -0x480(%rbp), %rdi
leaq -0x490(%rbp), %rsi
callq 0x3c9a0
testb $0x1, %al
jne 0x378d5
jmp 0x379fb
leaq -0x480(%rbp), %rdi
callq 0x3ca00
movq %rax, %rsi
leaq -0x49c(%rbp), %rdi
callq 0x1b190
jmp 0x378f2
movl -0x49c(%rbp), %eax
movl %eax, -0x478(%rbp)
leaq -0x49c(%rbp), %rdi
callq 0x60460
movswl -0x478(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
shll $0x3, %eax
subl %ecx, %eax
movl %eax, -0x588(%rbp)
movq 0x5a4b0(%rip), %rdi     # 0x91dd8
callq 0x3c930
movw %ax, -0x582(%rbp)
jmp 0x37936
movl -0x588(%rbp), %eax
movw -0x582(%rbp), %cx
movswl %cx, %ecx
cltd
idivl %ecx
movw %ax, -0x478(%rbp)
movswl -0x476(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
shll $0x3, %eax
subl %ecx, %eax
movl %eax, -0x590(%rbp)
movq 0x5a46a(%rip), %rdi     # 0x91dd8
callq 0x3c930
movw %ax, -0x58a(%rbp)
jmp 0x3797c
movl -0x590(%rbp), %eax
movw -0x58a(%rbp), %cx
movswl %cx, %ecx
cltd
idivl %ecx
movw %ax, -0x476(%rbp)
leaq -0x480(%rbp), %rdi
callq 0x3ca00
movq %rax, %rdi
movswl -0x476(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
shll $0x3, %eax
subl %ecx, %eax
movswl -0x478(%rbp), %ecx
addl %ecx, %eax
addl %eax, %eax
cltq
leaq -0x470(%rbp,%rax), %rsi
movl $0x1, %edx
callq 0x4d6c0
jmp 0x379d7
jmp 0x379d9
leaq -0x480(%rbp), %rdi
callq 0x3ca30
jmp 0x3788f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x8(%rbp)
movl %eax, -0xc(%rbp)
jmp 0x37c5c
movb $0x1, -0x4e(%rbp)
movb $0xb, -0x4d(%rbp)
movb $0xa, -0x4c(%rbp)
movl 0x59987(%rip), %eax     # 0x91394
movq %rax, -0x598(%rbp)
subq $0x4, %rax
ja 0x37b9f
movq -0x598(%rbp), %rax
leaq 0x2c4e4(%rip), %rcx     # 0x63f10
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5a374(%rip), %rdi     # 0x91db0
leaq 0x2c65e(%rip), %rsi     # 0x640a1
callq 0x5760
jmp 0x37a4a
jmp 0x37b9f
leaq 0x5a35a(%rip), %rdi     # 0x91db0
leaq 0x2c64d(%rip), %rsi     # 0x640aa
callq 0x5760
jmp 0x37a64
jmp 0x37b9f
movl 0x55b21(%rip), %eax     # 0x8d590
shlq $0x5, %rax
leaq 0x592d6(%rip), %rdx     # 0x90d50
addq %rax, %rdx
leaq 0x2c62f(%rip), %rsi     # 0x640b3
leaq -0x4e0(%rbp), %rdi
callq 0x1f390
jmp 0x37a92
leaq -0x4c0(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
movl $0x29, %edx
callq 0x3ca50
jmp 0x37aac
leaq 0x5a2fd(%rip), %rdi     # 0x91db0
leaq -0x4c0(%rbp), %rsi
callq 0x5640
leaq -0x4c0(%rbp), %rdi
callq 0x5a48
leaq -0x4e0(%rbp), %rdi
callq 0x5a48
jmp 0x37b9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x8(%rbp)
movl %eax, -0xc(%rbp)
leaq -0x4e0(%rbp), %rdi
callq 0x5a48
jmp 0x37c5c
movl 0x55a91(%rip), %eax     # 0x8d590
shlq $0x5, %rax
leaq 0x59246(%rip), %rdx     # 0x90d50
addq %rax, %rdx
leaq 0x2c5a7(%rip), %rsi     # 0x640bb
leaq -0x520(%rbp), %rdi
callq 0x1f390
jmp 0x37b22
leaq 0x2c59b(%rip), %rdx     # 0x640c4
leaq -0x500(%rbp), %rdi
leaq -0x520(%rbp), %rsi
callq 0x18a40
jmp 0x37b3e
leaq 0x5a26b(%rip), %rdi     # 0x91db0
leaq -0x500(%rbp), %rsi
callq 0x5640
leaq -0x500(%rbp), %rdi
callq 0x5a48
leaq -0x520(%rbp), %rdi
callq 0x5a48
jmp 0x37b9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x8(%rbp)
movl %eax, -0xc(%rbp)
leaq -0x520(%rbp), %rdi
callq 0x5a48
jmp 0x37c5c
leaq 0x5a221(%rip), %rdi     # 0x91db0
leaq 0x2c538(%rip), %rsi     # 0x640ce
callq 0x5760
jmp 0x37b9d
jmp 0x37b9f
leaq -0x4b(%rbp), %rax
movq %rax, -0x5a8(%rbp)
leaq 0x5a1ff(%rip), %rdi     # 0x91db0
movq %rdi, -0x5a0(%rbp)
callq 0x5200
movq -0x5a8(%rbp), %rdi
movq %rax, %rsi
callq 0x54d0
movq -0x5a0(%rbp), %rdi
callq 0x5340
movq %rax, %rcx
movzwl -0x472(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x472(%rbp)
leaq 0x599ae(%rip), %rdi     # 0x915a0
callq 0x5f370
jmp 0x37bf9
leaq 0x599a0(%rip), %rdi     # 0x915a0
movl $0x3, %esi
callq 0x5f390
jmp 0x37c0c
leaq 0x5998d(%rip), %rdi     # 0x915a0
xorl %esi, %esi
callq 0x5f3d0
jmp 0x37c1c
movzwl -0x472(%rbp), %edx
leaq 0x59976(%rip), %rdi     # 0x915a0
leaq -0x470(%rbp), %rsi
callq 0x5f4e0
jmp 0x37c38
leaq 0x59961(%rip), %rsi     # 0x915a0
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x19160
jmp 0x37c4b
leaq -0x478(%rbp), %rdi
callq 0x60460
jmp 0x37ddf
leaq -0x478(%rbp), %rdi
callq 0x60460
jmp 0x37df7
leaq 0x5b2bc(%rip), %rdi     # 0x92f30
addq $0x90, %rdi
callq 0x3c950
movq %rax, -0x530(%rbp)
leaq -0x528(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0x3c980
leaq 0x5b28f(%rip), %rdi     # 0x92f30
addq $0x90, %rdi
callq 0x3c9d0
movq %rax, -0x540(%rbp)
leaq -0x538(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0x3c980
leaq -0x528(%rbp), %rdi
leaq -0x538(%rbp), %rsi
callq 0x3c9a0
testb $0x1, %al
jne 0x37ce0
jmp 0x37d4a
leaq -0x528(%rbp), %rdi
callq 0x3ca00
movq %rax, %rsi
leaq -0x544(%rbp), %rdi
movq %rdi, -0x5b0(%rbp)
callq 0x1b190
movq -0x5b0(%rbp), %rdi
callq 0x482e0
jmp 0x37d10
leaq -0x544(%rbp), %rdi
callq 0x60460
leaq -0x528(%rbp), %rdi
callq 0x3ca30
jmp 0x37c9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x8(%rbp)
movl %eax, -0xc(%rbp)
leaq -0x544(%rbp), %rdi
callq 0x60460
jmp 0x37df7
jmp 0x37ddf
leaq 0x584da(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0x550(%rbp)
leaq 0x584c7(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x558(%rbp)
leaq -0x550(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x1b100
testb $0x1, %al
jne 0x37d8e
jmp 0x37ddd
leaq -0x550(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21c90
leaq -0x550(%rbp), %rdi
callq 0x1b050
movw $0x0, 0xa8(%rax)
leaq -0x550(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
callq 0x40db0
leaq -0x550(%rbp), %rdi
callq 0x1b3c0
jmp 0x37d62
jmp 0x37ddf
movl 0x59ffb(%rip), %eax     # 0x91de0
addl $0x1, %eax
movl %eax, 0x59ff2(%rip)     # 0x91de0
addq $0x5b0, %rsp            # imm = 0x5B0
popq %rbp
retq
movq -0x8(%rbp), %rdi
callq 0x5920