// File: lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::team_switch(std::_List_iterator<Player>)
void Game::team_switch(const list<Player>::iterator pit)
{
	if(pit->team != T_SPEC)
	{
		if(int_settings[IS_TEAMBALANCE] != TB_OFF
			&& num_players[pit->team] <= num_players[opp_team[pit->team]])
		{
			string s = "You cannot switch team at this time.";
		 	Network::construct_msg(s, team_colour[pit->team]);
		 	Network::send_to_player(*pit);
		}
		else // ok w.r.t. team balance
		{
			// do the change:
			--num_players[pit->team];
			++num_players[(pit->team = opp_team[pit->team])];

			// Switch class until find one not limited by classlimit (ALL of
			// them cannot be limited due to check in settings.cpp!)
			e_Class newcl = pit->next_cl;
			while(check_class_limit(pit->team, newcl))
			{
				if((newcl = e_Class(newcl + 1)) == NO_CLASS)
					newcl = e_Class(0);
			}
			pit->next_cl = newcl;

			player_left_team(pit);
			post_spawn_msg(pit);
			send_state_change(pit);
			pit->own_vp->clear_memory();
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
cmpl $0x2, 0xac(%rax)
je 0x3c21d
leaq 0x53a27(%rip), %rax     # 0x8fa10
cmpl $0x0, 0x4(%rax)
je 0x3c0f5
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
movl %eax, %ecx
leaq 0x55386(%rip), %rax     # 0x91391
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movl -0x5c(%rbp), %eax
movl 0xac(%rcx), %ecx
movl %ecx, %edx
leaq 0x27f9c(%rip), %rcx     # 0x63fcc
movl (%rcx,%rdx,4), %ecx
movl %ecx, %edx
leaq 0x55355(%rip), %rcx     # 0x91391
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jg 0x3c0f5
leaq -0x29(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x5930
movq -0x68(%rbp), %rdx
leaq 0x2817a(%rip), %rsi     # 0x641da
leaq -0x28(%rbp), %rdi
callq 0x18880
jmp 0x3c06b
leaq -0x29(%rbp), %rdi
callq 0x5590
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
leaq 0x27f35(%rip), %rcx     # 0x63fbf
movzbl (%rax,%rcx), %esi
leaq -0x28(%rbp), %rdi
callq 0x1ab10
jmp 0x3c099
leaq -0x8(%rbp), %rdi
callq 0x28450
movq %rax, %rdi
leaq 0x521ec(%rip), %rsi     # 0x8e298
callq 0x1af60
jmp 0x3c0b3
leaq -0x28(%rbp), %rdi
callq 0x5a48
jmp 0x3c21b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x5590
jmp 0x3c223
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5a48
jmp 0x3c223
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
movl %eax, %ecx
leaq 0x55284(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $-0x1, %dl
leaq 0x55277(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
movl %eax, %ecx
leaq 0x27e97(%rip), %rax     # 0x63fcc
movl (%rax,%rcx,4), %eax
movl %eax, -0x6c(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movl -0x6c(%rbp), %eax
movl %eax, 0xac(%rcx)
movl %eax, %eax
movl %eax, %ecx
leaq 0x55236(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $0x1, %dl
leaq 0x55229(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xb4(%rax), %eax
movl %eax, -0x40(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %edi
movl -0x40(%rbp), %esi
callq 0x3bd10
testb $0x1, %al
jne 0x3c19a
jmp 0x3c1b1
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
cmpl $0xb, %eax
jne 0x3c1af
movl $0x0, -0x40(%rbp)
jmp 0x3c17d
movl -0x40(%rbp), %eax
movl %eax, -0x70(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movl -0x70(%rbp), %ecx
movl %ecx, 0xb4(%rax)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x3bc40
leaq -0x50(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x18a20
movq -0x50(%rbp), %rdi
callq 0x3bec0
leaq -0x58(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x18a20
movq -0x58(%rbp), %rdi
callq 0x3b290
leaq -0x8(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
callq 0x40f20
jmp 0x3c21d
addq $0x70, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x5920
nopl (%rax)