// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::player_action(std::_List_iterator<Player>, Axn)
void Game::player_action(const list<Player>::iterator pit, const Axn action)
{
	// A spectator is outside of the rules logic, but can only move:
	if(pit->team == T_SPEC)
	{
		// Wants to move and is a "free spectator":
		if(action.xncode == XN_MOVE && pit->viewn_vp == pit->own_vp)
			pit->own_vp->move(e_Dir(action.var1));
		// Wants to switch followed player:
		else if(action.xncode == XN_FOLLOW_SWITCH)
		{
			list<Player>::const_iterator fit = pit->viewn_vp->get_owner();
			// follow next nonspectator (but allow following self)
			do {
				if(++fit == cur_players.end())
					fit = cur_players.begin();
			} while(!fit->is_alive() && fit != pit);
			follow_change(pit, fit);
		}
		else if(action.xncode == XN_FOLLOW_PREV)
		{
			list<Player>::const_iterator fit = pit->viewn_vp->get_owner();
			// follow prev nonspectator (but allow following self)
			do {
				if(fit == cur_players.begin())
					fit = cur_players.end();
				--fit;
			} while(!fit->is_alive() && fit != pit);
			follow_change(pit, fit);
		}
		return;
	}
	// Not spectator:
	if(pit->is_alive())
	{
		// Planewalkers' mind's eye movement is not restricted by timing:
		if(pit->cl == C_PLANEWALKER && pit->limiter && action.xncode == XN_MOVE)
		{
			pit->own_vp->move(e_Dir(action.var1));
			return;
		}
		// Everything else:
		if(action.xncode == XN_FOLLOW_SWITCH || action.xncode == XN_FOLLOW_PREV)
		{
			// these codes makes no sense when alive; resend class info
			send_full_state_refresh(pit);
			return;
		}
		// If this players hasn't acted this turn, we process this new action
		// immediately and empty the queue. Otherwise, we just push it to
		// the back of the queue.
		if(!pit->acted_this_turn && !pit->wait_turns)
		{
			pit->doing_a_chore = 0; // any chore is aborted
			validate_and_process(action, pit);
			pit->action_queue.clear();
		}
		else
			pit->action_queue.push_back(action);
		// Note that the possibility of the queue being full has already been
		// checked in network.cpp
	}
	else // player is dead
	{
		if(action.xncode == XN_FOLLOW_SWITCH)
		{
			list<Player>::const_iterator fit = pit->viewn_vp->get_owner();
			// follow next alive teammate or self:
			do {
				if(++fit == cur_players.end())
					fit = cur_players.begin();
			} while(fit != pit && (!fit->is_alive() || fit->team != pit->team));
			follow_change(pit, fit);
		}
		else if(action.xncode == XN_FOLLOW_PREV)
		{
			list<Player>::const_iterator fit = pit->viewn_vp->get_owner();
			// follow prev alive teammate or self:
			do {
				if(fit == cur_players.begin())
					fit = cur_players.end();
				--fit;
			} while(fit != pit && (!fit->is_alive() || fit->team != pit->team));
			follow_change(pit, fit);
		}
		else // client apparently thinks it's alive:
			send_full_state_refresh(pit);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movw %r14w, -0x1c(%rbp)
movl %esi, %eax
shrl $0x10, %eax
movb %al, -0x1a(%rbp)
movl %esi, %r15d
shrl $0x8, %r15d
cmpl $0x2, 0xbc(%rdi)
jne 0x16f92
cmpb $0x11, %r14b
je 0x1708c
movzbl %r14b, %eax
cmpl $0x10, %eax
je 0x17054
cmpl $0x4, %eax
jne 0x170e6
movq 0xd0(%rbx), %rdi
cmpq %rdi, 0xd8(%rbx)
jne 0x170e6
jmp 0x16fcb
leaq 0x10(%rbx), %rdi
callq 0xe68e
testb %al, %al
je 0x16fde
cmpl $0xa, 0xc0(%rbx)
jne 0x17038
cmpb $0x0, 0x140(%rbx)
setne %al
cmpb $0x4, %r14b
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x17038
movq 0xd0(%rbx), %rdi
movsbl %r15b, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x19460
cmpb $0x11, %r14b
je 0x170f1
movzbl %r14b, %eax
cmpl $0x10, %eax
jne 0x17042
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x290ad(%rip), %r15     # 0x400b0
movq (%r14), %r14
cmpq %r15, %r14
jne 0x1700e
movq (%r15), %r14
cmpq %rbx, %r14
je 0x17133
leaq 0x10(%r14), %rdi
callq 0xe68e
testb %al, %al
je 0x17003
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
jne 0x17003
jmp 0x17133
andb $-0x2, %r14b
cmpb $0x10, %r14b
jne 0x170c1
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x15092
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x2904a(%rip), %r15     # 0x400b0
movq (%r14), %r14
cmpq %r15, %r14
jne 0x17071
movq (%r15), %r14
leaq 0x10(%r14), %rdi
callq 0xe68e
testb %al, %al
jne 0x17133
cmpq %rbx, %r14
jne 0x17066
jmp 0x17133
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x29012(%rip), %r15     # 0x400b0
movq %r15, %rax
cmpq (%r15), %r14
je 0x170a9
movq %r14, %rax
movq 0x8(%rax), %r14
leaq 0x10(%r14), %rdi
callq 0xe68e
cmpq %rbx, %r14
je 0x17133
testb %al, %al
je 0x1709e
jmp 0x17133
cmpb $0x0, 0x138(%rbx)
jne 0x170d3
cmpb $0x0, 0x141(%rbx)
je 0x17145
addq $0xe8, %rbx
leaq -0x1c(%rbp), %rsi
movq %rbx, %rdi
callq 0x17eac
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x28fad(%rip), %r15     # 0x400b0
movq %r15, %rax
cmpq (%r15), %r14
je 0x1710e
movq %r14, %rax
movq 0x8(%rax), %r14
cmpq %rbx, %r14
je 0x17133
leaq 0x10(%r14), %rdi
callq 0xe68e
testb %al, %al
je 0x17103
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
jne 0x17103
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1716c
movb $0x0, 0x142(%rbx)
leaq -0x1c(%rbp), %rdi
movq %rbx, %rsi
callq 0x16ded
addq $0xe8, %rbx
movq %rbx, %rdi
callq 0x17e6e
jmp 0x170e6