// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/chores.cpp
// Function: (anonymous namespace)::move_player_to(std::_List_iterator<Player>, Coords const&, bool)
void move_player_to(const list<Player>::iterator p, const Coords &c,
	const bool do_flags)
{
	Coords opos = p->own_pc->getpos();
	// must move both the PC entity and the viewpoint:
	p->own_pc->setpos(c);
	p->own_vp->set_pos(c);
	if(p == pl_with_item)
		add_action_ind(c, A_TRAP);
	else // add_action inserts to event_set
		event_set.insert(c);

	// Check if ended up in some special tile: (note that some of
	// these are checked only when *walking* into them, but in
	// this function we don't know the "method of arrival")
	Tile* tile = Game::curmap->mod_tile(c);
	if(tile->flags & TF_KILLS) // chasm
	{
		if(p->warned_of_chasm == Config::int_settings[Config::IS_SAFE_CHASMS])
		{
			player_death(p, " fell into oblivion.", false);
			add_voice(c, "Aieeeee...!");	
			Game::curmap->mod_tile(opos)->flags &= ~(TF_OCCUPIED);
		}
		else
		{
			p->warned_of_chasm++;
			string msg = "You almost fall into a chasm!";
			Network::construct_msg(msg, C_WALL_LIT);
			Network::send_to_player(*p);
			// revert original coords:
			p->own_pc->setpos(opos);
			p->own_vp->set_pos(opos);
		}
		return; // either died or did not move
	}

	if(tile->flags & TF_TRAP)
	{
		list<Trap>::iterator tr_it = any_trap_at(c);
		// A trap is triggered always if not seen and sometimes if it's dark:
		if(!tr_it->is_seen_by(p->team) || p->own_vp->is_blind()
			|| (!(tile->flags & TF_LIT) && random()%100 < 15 && !is_dynlit(c)))
		{
			if(trigger_trap(p, tr_it, false))
			{
				// if returned true, PC died or teleported
				Game::curmap->mod_tile(opos)->flags &= ~(TF_OCCUPIED);
				return;
			}
		}
	}
	
	// If we made it here, the PC survived the checks.
	if(tile->flags & TF_DROWNS) // water slows down
	{
		p->wait_turns += 2;
		if(p->cl != C_ASSASSIN && p->cl != C_SCOUT)
			add_sound(c, S_SPLASH);
	}
	else if((tile->flags & TF_SLOWWALK) // slow non-trappers/scouts
		&& p->cl != C_TRAPPER && p->cl != C_SCOUT)
		p->wait_turns++;
	
	// The occupied flags don't need to be changed when switching places:
	if(do_flags)
	{
		Game::curmap->mod_tile(opos)->flags &= ~(TF_OCCUPIED);
		Game::curmap->mod_tile(c)->flags |= TF_OCCUPIED;
	}
	
	// Check if moved to another sector:
	e_Dir newsector = Game::curmap->coords_in_sector(c);
	if(p->sector != newsector)
	{
		p->sector = newsector;
		p->needs_state_upd = true;
	}

	// Whenever a PC moves, we check if they spot some hiding enemies.
	// The requirement for this is that this PC is facing directly at a hiding
	// enemy, whose position is lit, at a distance of 2.
	opos = c.in(p->facing).in(p->facing); // reusing opos
	list<PCEnt>::iterator pc_it = any_pc_at(opos);
	if(pc_it != PCs.end() && !pc_it->isvoid() && !pc_it->visible_to_team(p->team)
		&& ((Game::curmap->get_tile(opos).flags & TF_LIT) || is_dynlit(opos)))
		pc_it->set_invis_to_team(T_NO_TEAM); // seen!

	// Also, whenever a PC moves, we check if they are seen by enemy scouts:
	if(p->own_pc->visible_to_team(opp_team[p->team]))
	{
		Coords thc; // "their coords"
		char d = classes[C_SCOUT].losr;
		if(!(Game::curmap->get_tile(c).flags & TF_LIT))
			d = (d+5)/3; // not lit, shorter radius
		for(list<Player>::const_iterator pit = cur_players.begin();
			pit != cur_players.end(); ++pit)
		{
			// Search for opponent scouts who are alive...
			if(pit->team != p->team && pit->cl == C_SCOUT && pit->is_alive()
				&& Game::curmap->LOS_between(c, pit->own_pc->getpos(), d))
			{
				p->own_pc->set_seen_by_team(pit->team);
				return; // done
			}
		} // loop through current players
	}
	// If we end up here, was not seen by enemy scouts:
	p->own_pc->set_seen_by_team(T_NO_TEAM);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq 0x148(%rdi), %rax
movl 0x8(%rax), %ecx
movl %ecx, -0x2c(%rbp)
movl (%rsi), %ecx
movl %ecx, 0x8(%rax)
movq 0xd0(%rdi), %rdi
callq 0x1eb62
leaq 0x2109e(%rip), %rax     # 0x46008
cmpq %rbx, (%rax)
je 0x24f80
leaq 0x21062(%rip), %rdi     # 0x45fd8
movq %r14, %rsi
callq 0x21934
jmp 0x24f8d
movq %r14, %rdi
movl $0x1, %esi
callq 0x208ed
movl %r15d, -0x34(%rbp)
leaq 0x1fcd0(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq (%r14), %r13
movq (%rax,%rcx,8), %r15
movzwl (%r15,%r13,4), %eax
btl $0x9, %eax
jb 0x2504d
btl $0xb, %eax
jae 0x2500f
movq %r14, %rdi
callq 0x2134d
movq %rax, %r12
leaq 0x10(%rax), %rdi
movzbl 0xbc(%rbx), %esi
callq 0x21df0
movq %r12, -0x60(%rbp)
testb %al, %al
je 0x24ff9
movq 0xd0(%rbx), %rax
cmpb $0x0, 0x20(%rax)
je 0x253e1
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2449c
testb %al, %al
jne 0x250e1
movzwl (%r15,%r13,4), %eax
btl $0xa, %eax
jb 0x2518a
testb $0x2, %al
movl -0x34(%rbp), %r12d
je 0x251af
movl 0xc0(%rbx), %eax
cmpl $0x4, %eax
je 0x251af
cmpl $0x9, %eax
je 0x251af
incb 0x141(%rbx)
jmp 0x251af
movzbl 0x172(%rbx), %eax
leaq 0x1d845(%rip), %rcx     # 0x428a0
cmpl %eax, 0x28(%rcx)
jne 0x2510b
leaq -0x48(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x105c2(%rip), %rsi     # 0x35635
leaq 0x105cf(%rip), %rdx     # 0x35649
leaq -0x58(%rbp), %rdi
callq 0xe01c
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x249ec
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
je 0x250a6
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x58(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x10596(%rip), %rsi     # 0x3564a
leaq 0x1059a(%rip), %rdx     # 0x35655
callq 0xe01c
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x20a43
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
je 0x250e1
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq 0x1fb80(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx,8), %rax
andw $-0x41, (%rax,%rdx,4)
jmp 0x253c9
incb %al
movb %al, 0x172(%rbx)
leaq -0x48(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x10534(%rip), %rsi     # 0x35656
leaq 0x1054a(%rip), %rdx     # 0x35673
leaq -0x58(%rbp), %rdi
callq 0xe01c
leaq -0x58(%rbp), %rdi
movl $0x2e, %esi
callq 0xf3f0
leaq 0x10(%rbx), %rdi
leaq 0x1bfdd(%rip), %rsi     # 0x41128
callq 0xf719
movq 0x148(%rbx), %rax
leaq -0x2c(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, 0x8(%rax)
movq 0xd0(%rbx), %rdi
callq 0x1eb62
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x253c9
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x253c9
addb $0x2, 0x141(%rbx)
movl 0xc0(%rbx), %eax
cmpl $0x1, %eax
movl -0x34(%rbp), %r12d
je 0x251af
cmpl $0x4, %eax
je 0x251af
movq %r14, %rdi
xorl %esi, %esi
callq 0x209ed
leaq 0x1fab2(%rip), %rax     # 0x44c68
movq (%rax), %rdi
testb %r12b, %r12b
je 0x251ef
movswq -0x2a(%rbp), %rax
movq 0x8(%rdi), %rcx
leaq (%rax,%rax,2), %rax
movswq -0x2c(%rbp), %rdx
movq (%rcx,%rax,8), %rax
andw $-0x41, (%rax,%rdx,4)
movswq 0x2(%r14), %rax
leaq (%rax,%rax,2), %rax
movswq (%r14), %rdx
movq (%rcx,%rax,8), %rax
orw $0x40, (%rax,%rdx,4)
movq %r14, %rsi
callq 0x172ce
cmpl %eax, 0x16c(%rbx)
je 0x2520c
movl %eax, 0x16c(%rbx)
movb $0x1, 0x15d(%rbx)
movl 0x168(%rbx), %edx
leaq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x2b818
movl 0x168(%rbx), %edx
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2b818
leaq -0x58(%rbp), %rdi
movl (%rdi), %eax
leaq -0x2c(%rbp), %r15
movl %eax, (%r15)
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
movq %r15, %rdi
callq 0x2122a
movq %rax, %r15
cmpq 0x1ad4a(%rip), %rax     # 0x3ffa8
je 0x252ae
cmpb $0x0, 0x1e(%r15)
jne 0x252ae
movl 0x28(%r15), %eax
cmpl 0xbc(%rbx), %eax
jne 0x252ae
leaq 0x1f9ee(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx,8), %rax
testb $0x10, (%rax,%rdx,4)
jne 0x252a6
leaq -0x2c(%rbp), %rdi
callq 0x2106c
testb %al, %al
je 0x252ae
movl $0x3, 0x28(%r15)
movq 0x148(%rbx), %rax
movl 0xbc(%rbx), %ecx
leaq 0xff5e(%rip), %rdx      # 0x35220
movl 0x18(%rax), %esi
cmpl (%rdx,%rcx,4), %esi
je 0x253c2
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq 0x1f986(%rip), %rax     # 0x44c68
movq (%rax), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq (%r14), %rdx
movq (%rax,%rcx,8), %rcx
xorl %eax, %eax
testb $0x10, (%rcx,%rdx,4)
setne %cl
leaq 0x1ddb6(%rip), %r15     # 0x430c0
movq (%r15), %r12
cmpq %r15, %r12
je 0x253b2
movb %cl, %al
leal (%rax,%rax,4), %eax
addl $0x5, %eax
movzbl %al, %eax
movl %eax, -0x34(%rbp)
leaq -0x30(%rbp), %r13
movq %rbx, -0x68(%rbp)
movl 0xbc(%r12), %eax
cmpl 0xbc(%rbx), %eax
je 0x253a5
cmpl $0x4, 0xc0(%r12)
jne 0x253a5
leaq 0x10(%r12), %rdi
callq 0x12496
testb %al, %al
je 0x253a5
movq %r15, %rbx
leaq 0x1f909(%rip), %rax     # 0x44c68
movq (%rax), %rdi
movq 0x148(%r12), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq %r14, %r15
movq %r14, %rsi
movq %r13, %rdx
movl -0x34(%rbp), %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x1736e
movl %eax, %r14d
movq %r13, %rdi
callq 0x2b7a6
testb %r14b, %r14b
movq %r15, %r14
movq %rbx, %r15
movq -0x68(%rbp), %rbx
jne 0x25438
movq (%r12), %r12
cmpq %r15, %r12
jne 0x2532c
leaq -0x58(%rbp), %rdi
callq 0x2b7a6
movq 0x148(%rbx), %rax
movl $0x3, 0x1c(%rax)
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, (%r15,%r13,4)
jne 0x2500f
callq 0x41d0
movq %rax, %rcx
movabsq $-0x5c28f5c28f5c28f5, %rdx # imm = 0xA3D70A3D70A3D70B
imulq %rdx
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x6, %rdx
addq %rax, %rdx
imulq $0x64, %rdx, %rax
subq %rax, %rcx
cmpq $0xe, %rcx
jg 0x2500f
movq %r14, %rdi
callq 0x2106c
testb %al, %al
je 0x24ff9
jmp 0x2500f
movq 0x148(%rbx), %rax
movl 0xbc(%r12), %ecx
movl %ecx, 0x1c(%rax)
leaq -0x58(%rbp), %rdi
callq 0x2b7a6
jmp 0x253c9
jmp 0x254bb
jmp 0x254bb
jmp 0x254bb
jmp 0x25462
jmp 0x254bb
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r15, %rdi
jne 0x2549f
jmp 0x254be
jmp 0x254bb
jmp 0x254bb
jmp 0x254bb
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
jmp 0x254b4
jmp 0x254bb
jmp 0x254bb
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
jmp 0x254b0
jmp 0x254bb
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x254be
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x254be
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2b7a6
jmp 0x254be
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740