// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, %rbx
movw %si, -0x1c(%rbp)
shrl $0x10, %esi
movb %sil, -0x1a(%rbp)
cmpl $0x2, 0xbc(%rdi)
jne 0x1c462
movzbl -0x1c(%rbp), %eax
cmpl $0x11, %eax
je 0x1c511
cmpl $0x10, %eax
je 0x1c42a
cmpl $0x4, %eax
jne 0x1c626
movq 0xd0(%rbx), %rdi
cmpq %rdi, 0xd8(%rbx)
je 0x1c48e
cmpl $0x11, %eax
je 0x1c511
cmpl $0x10, %eax
jne 0x1c626
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x26c84(%rip), %r15     # 0x430c0
movq (%r14), %r14
cmpq %r15, %r14
jne 0x1c447
movq (%r15), %r14
leaq 0x10(%r14), %rdi
callq 0x125e6
testb %al, %al
jne 0x1c544
cmpq %rbx, %r14
jne 0x1c43c
jmp 0x1c544
leaq 0x10(%rbx), %rdi
callq 0x125e6
testb %al, %al
je 0x1c4a1
cmpl $0xa, 0xc0(%rbx)
jne 0x1c4f6
cmpb $0x0, 0x140(%rbx)
je 0x1c4f6
cmpb $0x4, -0x1c(%rbp)
jne 0x1c4f6
movq 0xd0(%rbx), %rdi
movsbl -0x1b(%rbp), %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1ec96
movzbl -0x1c(%rbp), %eax
cmpl $0x11, %eax
je 0x1c5a0
cmpl $0x10, %eax
jne 0x1c4ff
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
movq (%rax), %r14
leaq 0x26bf8(%rip), %r15     # 0x430c0
cmpq %r15, %r14
jne 0x1c4d0
movq (%r15), %r14
cmpq %rbx, %r14
je 0x1c544
leaq 0x10(%r14), %rdi
callq 0x125e6
testb %al, %al
je 0x1c4f1
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
je 0x1c544
movq (%r14), %r14
jmp 0x1c4c8
movb -0x1c(%rbp), %al
andb $-0x2, %al
cmpb $0x10, %al
jne 0x1c559
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x19c91
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %r14
leaq 0x26b9d(%rip), %r15     # 0x430c0
movq %r15, %rax
cmpq (%r15), %r14
je 0x1c52e
movq %r14, %rax
movq 0x8(%rax), %r14
leaq 0x10(%r14), %rdi
callq 0x125e6
cmpq %rbx, %r14
je 0x1c544
testb %al, %al
je 0x1c523
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1c631
cmpb $0x0, 0x138(%rbx)
jne 0x1c56f
cmpb $0x0, 0x141(%rbx)
je 0x1c604
movq 0x118(%rbx), %rax
movq 0x128(%rbx), %rcx
addq $-0x3, %rcx
cmpq %rcx, %rax
je 0x1c5ef
movb -0x1a(%rbp), %cl
movb %cl, 0x2(%rax)
movzwl -0x1c(%rbp), %ecx
movw %cx, (%rax)
addq $0x3, 0x118(%rbx)
jmp 0x1c626
movq 0xd8(%rbx), %rax
movq 0x28(%rax), %rax
leaq 0x26b0e(%rip), %r15     # 0x430c0
cmpq (%r15), %rax
cmoveq %r15, %rax
movq 0x8(%rax), %r14
cmpq %rbx, %r14
je 0x1c544
leaq 0x10(%r14), %rdi
callq 0x125e6
testb %al, %al
je 0x1c5e2
movl 0xbc(%r14), %eax
cmpl 0xbc(%rbx), %eax
je 0x1c544
cmpq (%r15), %r14
cmoveq %r15, %r14
movq 0x8(%r14), %r14
jmp 0x1c5bd
addq $0xe8, %rbx
leaq -0x1c(%rbp), %rsi
movq %rbx, %rdi
callq 0x1dc14
jmp 0x1c626
movb $0x0, 0x142(%rbx)
leaq -0x1c(%rbp), %rdi
movq %rbx, %rsi
callq 0x1c288
addq $0xe8, %rbx
movq %rbx, %rdi
callq 0x1d788
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq