// File: /workspace/github_cpp_makefile_star2_O3/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 0x1c2df
cmpb $0x11, %r14b
je 0x1c3da
movzbl %r14b, %eax
cmpl $0x10, %eax
je 0x1c3a9
cmpl $0x4, %eax
jne 0x1c4ef
movq 0xd0(%rbx), %rdi
cmpq %rdi, 0xd8(%rbx)
jne 0x1c4ef
jmp 0x1c318
leaq 0x10(%rbx), %rdi
callq 0x12496
testb %al, %al
je 0x1c32b
cmpl $0xa, 0xc0(%rbx)
jne 0x1c389
cmpb $0x0, 0x140(%rbx)
setne %al
cmpb $0x4, %r14b
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1c389
movq 0xd0(%rbx), %rdi
movsbl %r15b, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1eafc
cmpb $0x11, %r14b
je 0x1c469
movzbl %r14b, %eax
cmpl $0x10, %eax
jne 0x1c397
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
movq (%rax), %r14
leaq 0x26d6d(%rip), %r15     # 0x430c0
cmpq %r15, %r14
jne 0x1c35b
movq (%r15), %r14
cmpq %rbx, %r14
je 0x1c40d
leaq 0x10(%r14), %rdi
callq 0x12496
testb %al, %al
je 0x1c384
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
je 0x1c40d
movq (%r14), %r14
jmp 0x1c353
andb $-0x2, %r14b
cmpb $0x10, %r14b
jne 0x1c422
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x19b5d
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x26d05(%rip), %r15     # 0x430c0
movq (%r14), %r14
cmpq %r15, %r14
jne 0x1c3c6
movq (%r15), %r14
leaq 0x10(%r14), %rdi
callq 0x12496
testb %al, %al
jne 0x1c40d
cmpq %rbx, %r14
jne 0x1c3bb
jmp 0x1c40d
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x26cd4(%rip), %r15     # 0x430c0
movq %r15, %rax
cmpq (%r15), %r14
je 0x1c3f7
movq %r14, %rax
movq 0x8(%rax), %r14
leaq 0x10(%r14), %rdi
callq 0x12496
cmpq %rbx, %r14
je 0x1c40d
testb %al, %al
je 0x1c3ec
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1c4fa
cmpb $0x0, 0x138(%rbx)
jne 0x1c438
cmpb $0x0, 0x141(%rbx)
je 0x1c4cd
movq 0x118(%rbx), %rax
movq 0x128(%rbx), %rcx
addq $-0x3, %rcx
cmpq %rcx, %rax
je 0x1c4b8
movb -0x1a(%rbp), %cl
movb %cl, 0x2(%rax)
movzwl -0x1c(%rbp), %ecx
movw %cx, (%rax)
addq $0x3, 0x118(%rbx)
jmp 0x1c4ef
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
leaq 0x26c45(%rip), %r15     # 0x430c0
cmpq (%r15), %rax
cmoveq %r15, %rax
movq 0x8(%rax), %r14
cmpq %rbx, %r14
je 0x1c40d
leaq 0x10(%r14), %rdi
callq 0x12496
testb %al, %al
je 0x1c4ab
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
je 0x1c40d
cmpq (%r15), %r14
cmoveq %r15, %r14
movq 0x8(%r14), %r14
jmp 0x1c486
addq $0xe8, %rbx
leaq -0x1c(%rbp), %rsi
movq %rbx, %rdi
callq 0x1da64
jmp 0x1c4ef
movb $0x0, 0x142(%rbx)
leaq -0x1c(%rbp), %rdi
movq %rbx, %rsi
callq 0x1c138
addq $0xe8, %rbx
movq %rbx, %rdi
callq 0x1d668
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq