// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::class_switch(std::_List_iterator<Player>, e_Class)
void Game::class_switch(const list<Player>::iterator pit, e_Class newcl)
{
	if(newcl == NO_CLASS) // going spectator / resetting spectating state
	{
		if(pit->team != T_SPEC)
		{
			pit->own_vp->move_watchers();
			if(pit->is_alive())
				kill_player(pit); /* see player_left_team; it won't call this
				after we've set the team to spec! */
			--num_players[pit->team];
			pit->team = T_SPEC;
			player_left_team(pit);
			pit->cl = pit->next_cl = NO_CLASS;
			send_state_change(pit);
			pit->own_vp->set_losr(SPEC_LOS_RAD);
		}

		// place own viewpoint at the location of the viewn viewpoint:
		pit->own_vp->set_pos(pit->viewn_vp->get_pos());
		follow_change(pit, pit);
	}
	else if(newcl != pit->cl || newcl != pit->next_cl)
	{
		e_Team newteam = (pit->team != T_SPEC) ? pit->team
			: e_Team(num_players[T_PURPLE] < num_players[T_GREEN]);
		
		/* Class limit checking. In case the desired class is unavailable,
		 * human players (or what we think are human players...) just get
		 * a message and nothing happens. But for bots we just give some
		 * other class. */
		string s;
		while(check_class_limit(newteam, newcl))
		{
			// In case teams are even and player is joining a team, check
			// the other team, too:
			if(pit->team == T_SPEC && num_players[T_PURPLE] == num_players[T_GREEN]
				&& !check_class_limit(T_PURPLE, newcl))
			{
				newteam = T_PURPLE;
				break; // okay to join the purple team with this class
			}
			// else
			if(pit->botpid == -1) // not bot
			{
				s = "That class is not available.";
				Network::construct_msg(s, C_FIREB_TRAP_LIT);
				Network::send_to_player(*pit);
				return;
			}
			// else
			if((newcl = e_Class(newcl+1)) == NO_CLASS)
				newcl = C_ARCHER;
		}
		// if here, okay to change class/team
		if(pit->team == T_SPEC)
		{
			// Currently a spectator: join the weaker team (or green)
			++num_players[(pit->team = newteam)];
			post_join_msg(pit);
			if(!intermission)
			{
				send_times(pit);
				pit->stats_i->time_specced += time(NULL)
					- pit->last_switched_cl;
				time(&(pit->last_switched_cl));
			}
			send_team_upds(cur_players.end());
			// The ex-spectator might be following a now-enemy:
			if(pit->viewn_vp->get_owner()->team != pit->team)
				follow_change(pit, pit);
			pit->own_vp->clear_memory();
		}

		pit->next_cl = newcl; // will set pit->cl = pit->next_cl at spawn
		post_spawn_msg(pit);
		if(!pit->is_alive())
			send_state_change(pit);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
cmpl $0xb, %esi
jne 0x17544
cmpl $0x2, 0xbc(%rbx)
jne 0x175f5
movq 0xd0(%rbx), %rdi
jmp 0x1765e
movl %esi, %r15d
cmpl %esi, 0xc0(%rbx)
jne 0x1755c
cmpl %r15d, 0xc4(%rbx)
je 0x177a6
movl 0xbc(%rbx), %edx
movb 0x29caa(%rip), %al      # 0x41212
movb 0x29ca3(%rip), %cl      # 0x41211
xorl %r12d, %r12d
movb %al, -0x29(%rbp)
movb %cl, -0x2a(%rbp)
cmpb %cl, %al
setb %r12b
setne %al
cmpl $0x2, %edx
setne %r14b
movl %r12d, -0x30(%rbp)
movl %edx, -0x34(%rbp)
cmovnel %edx, %r12d
leaq -0x50(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movb $0x0, (%rcx)
andq $0x0, -0x8(%rcx)
leaq 0x10(%rbx), %rcx
movq %rcx, -0x40(%rbp)
orb %al, %r14b
xorl %r13d, %r13d
movl %r12d, %edi
movl %r15d, %esi
callq 0x1783e
testb %al, %al
je 0x1768c
testb %r14b, %r14b
jne 0x175db
pushq $0x1
popq %rdi
movl %r15d, %esi
callq 0x1783e
testb %al, %al
je 0x176df
cmpl $-0x1, 0x174(%rbx)
je 0x176ae
incl %r15d
cmpl $0xb, %r15d
cmovel %r13d, %r15d
jmp 0x175b0
leaq 0x10(%rbx), %r14
movq 0xd0(%rbx), %rdi
callq 0x19584
movq %r14, %rdi
callq 0xe68e
testb %al, %al
je 0x17619
movq %rbx, %rdi
callq 0x1fe5c
movl 0xbc(%rbx), %eax
leaq 0x29beb(%rip), %rcx     # 0x41211
decb (%rax,%rcx)
movl $0x2, 0xbc(%rbx)
movq %rbx, %rdi
callq 0x177d9
movabsq $0xb0000000b, %rax      # imm = 0xB0000000B
movq %rax, 0xc0(%rbx)
movq %rbx, %rdi
callq 0x1732d
movq 0xd0(%rbx), %rdi
movb $0xa, (%rdi)
movq 0xd8(%rbx), %rax
movl 0x2(%rax), %eax
leaq -0x60(%rbp), %rsi
movl %eax, (%rsi)
callq 0x194b2
leaq -0x60(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1716c
jmp 0x177a6
cmpl $0x2, -0x34(%rbp)
jne 0x17779
movb -0x2a(%rbp), %al
cmpb %al, -0x29(%rbp)
leaq 0x29b6e(%rip), %rax     # 0x41211
adcq $0x0, %rax
movb (%rax), %dl
movl -0x30(%rbp), %eax
jmp 0x176e5
leaq 0x119e0(%rip), %rsi     # 0x29095
leaq -0x60(%rbp), %rdi
callq 0x4780
leaq -0x60(%rbp), %rdi
pushq $0x39
popq %rsi
callq 0xc0f2
leaq 0x26a47(%rip), %rsi     # 0x3e118
movq -0x40(%rbp), %rdi
callq 0xc3a6
jmp 0x1779d
pushq $0x1
popq %rax
movb -0x29(%rbp), %dl
movl %eax, 0xbc(%rbx)
movl %eax, %eax
leaq 0x29b1d(%rip), %rcx     # 0x41211
incb %dl
movb %dl, (%rax,%rcx)
movq %rbx, %rdi
callq 0x1789e
leaq 0x25cf8(%rip), %rax     # 0x3d400
cmpb $0x0, (%rax)
jne 0x1773d
movq %rbx, %rdi
callq 0x15ea4
xorl %edi, %edi
callq 0x43c0
leaq 0xc8(%rbx), %rdi
subq 0xc8(%rbx), %rax
movq 0x90(%rbx), %rcx
addq %rax, 0xb8(%rcx)
callq 0x43c0
leaq 0x2896c(%rip), %rdi     # 0x400b0
callq 0x152e9
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
movl 0xbc(%rax), %eax
cmpl 0xbc(%rbx), %eax
je 0x1776d
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x1716c
movq 0xd0(%rbx), %rdi
callq 0x188f6
movl %r15d, 0xc4(%rbx)
movq %rbx, %rdi
callq 0x1792c
movq -0x40(%rbp), %rdi
callq 0xe68e
testb %al, %al
jne 0x1779d
movq %rbx, %rdi
callq 0x1732d
leaq -0x60(%rbp), %rdi
callq 0x47e8
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x177c5
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x24d9e
jmp 0x177d1
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x47e8
movq %rbx, %rdi
callq 0x4710