// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %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 0x194b2
leaq 0x237c3(%rip), %rax     # 0x42ff8
cmpq %rbx, (%rax)
je 0x1f84b
leaq 0x23787(%rip), %rdi     # 0x42fc8
movq %r14, %rsi
callq 0x1c558
jmp 0x1f856
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x1b103
movl %r15d, -0x34(%rbp)
leaq 0x223f7(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq (%r14), %r13
movq (%rax,%rcx), %r15
movzwl (%r15,%r13,4), %eax
btl $0x9, %eax
jb 0x1f916
btl $0xb, %eax
jae 0x1f8d8
movq %r14, %rdi
callq 0x1bae4
movq %rax, %r12
leaq 0x10(%rax), %rdi
movzbl 0xbc(%rbx), %esi
callq 0x1cab8
movq %r12, -0x60(%rbp)
testb %al, %al
je 0x1f8c2
movq 0xd0(%rbx), %rax
cmpb $0x0, 0x20(%rax)
je 0x1fc6f
movq %rbx, %rdi
movq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x1ef1b
testb %al, %al
jne 0x1f97d
movzwl (%r15,%r13,4), %eax
btl $0xa, %eax
jb 0x1fa09
testb $0x2, %al
movl -0x34(%rbp), %r12d
je 0x1fa2e
movl 0xc0(%rbx), %eax
cmpl $0x4, %eax
je 0x1fa2e
cmpl $0x9, %eax
je 0x1fa2e
incb 0x141(%rbx)
jmp 0x1fa2e
movzbl 0x172(%rbx), %eax
leaq 0x1ff6c(%rip), %rcx     # 0x3f890
cmpl %eax, 0x28(%rcx)
jne 0x1f9a7
leaq 0xfd5e(%rip), %rsi      # 0x2f68e
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xb292
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1f393
leaq -0x58(%rbp), %rdi
callq 0x47e8
leaq 0xfd48(%rip), %rsi      # 0x2f6a3
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xb292
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0x1b258
leaq -0x58(%rbp), %rdi
callq 0x47e8
leaq 0x222d4(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx), %rax
andw $-0x41, (%rax,%rdx,4)
jmp 0x1fc57
incb %al
movb %al, 0x172(%rbx)
leaq 0xfcf9(%rip), %rsi      # 0x2f6af
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xb292
leaq -0x58(%rbp), %rdi
pushq $0x2e
popq %rsi
callq 0xc0f2
leaq 0x10(%rbx), %rdi
leaq 0x1e73e(%rip), %rsi     # 0x3e118
callq 0xc3a6
movq 0x148(%rbx), %rax
leaq -0x2c(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, 0x8(%rax)
movq 0xd0(%rbx), %rdi
callq 0x194b2
leaq -0x58(%rbp), %rdi
callq 0x47e8
jmp 0x1fc57
addb $0x2, 0x141(%rbx)
movl 0xc0(%rbx), %eax
cmpl $0x1, %eax
movl -0x34(%rbp), %r12d
je 0x1fa2e
cmpl $0x4, %eax
je 0x1fa2e
movq %r14, %rdi
xorl %esi, %esi
callq 0x1b202
leaq 0x22223(%rip), %rax     # 0x41c58
movq (%rax), %rdi
testb %r12b, %r12b
je 0x1fa6e
movswq -0x2a(%rbp), %rax
movq 0x8(%rdi), %rcx
imulq $0x18, %rax, %rax
movswq -0x2c(%rbp), %rdx
movq (%rcx,%rax), %rax
andw $-0x41, (%rax,%rdx,4)
movswq 0x2(%r14), %rax
imulq $0x18, %rax, %rax
movswq (%r14), %rdx
movq (%rcx,%rax), %rax
orw $0x40, (%rax,%rdx,4)
movq %r14, %rsi
callq 0x128ac
cmpl %eax, 0x16c(%rbx)
je 0x1fa8b
movl %eax, 0x16c(%rbx)
movb $0x1, 0x15d(%rbx)
movl 0x168(%rbx), %edx
leaq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x24e0c
movl 0x168(%rbx), %edx
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x24e0c
leaq -0x58(%rbp), %rdi
movl (%rdi), %eax
leaq -0x2c(%rbp), %r15
movl %eax, (%r15)
callq 0x24d9e
leaq -0x30(%rbp), %rdi
callq 0x24d9e
movq %r15, %rdi
callq 0x1b9db
movq %rax, %r15
cmpq 0x1d4cb(%rip), %rax     # 0x3cfa8
je 0x1fb2d
cmpb $0x0, 0x1e(%r15)
jne 0x1fb2d
movl 0x28(%r15), %eax
cmpl 0xbc(%rbx), %eax
jne 0x1fb2d
leaq 0x2215f(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx), %rax
testb $0x10, (%rax,%rdx,4)
jne 0x1fb25
leaq -0x2c(%rbp), %rdi
callq 0x1b84e
testb %al, %al
je 0x1fb2d
movl $0x3, 0x28(%r15)
movq 0x148(%rbx), %rax
movl 0xbc(%rbx), %ecx
leaq 0xf72f(%rip), %rdx      # 0x2f270
movl 0x18(%rax), %esi
cmpl (%rdx,%rcx,4), %esi
je 0x1fc50
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq 0x220f7(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq (%r14), %rdx
movq (%rax,%rcx), %rax
xorl %ecx, %ecx
testb $0x10, (%rax,%rdx,4)
setne %cl
leal (%rcx,%rcx,4), %eax
addl $0x5, %eax
leaq 0x20521(%rip), %r15     # 0x400b0
movsbl %al, %eax
movl %eax, -0x34(%rbp)
leaq -0x30(%rbp), %r13
movq %r15, %r12
movq (%r12), %r12
cmpq %r15, %r12
je 0x1fc40
movl 0xbc(%r12), %eax
cmpl 0xbc(%rbx), %eax
je 0x1fb9c
cmpl $0x4, 0xc0(%r12)
jne 0x1fb9c
leaq 0x10(%r12), %rdi
callq 0xe68e
testb %al, %al
je 0x1fb9c
movq %rbx, %r15
leaq 0x2207c(%rip), %rax     # 0x41c58
movq (%rax), %rdi
movq 0x148(%r12), %rax
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq %r14, %rbx
movq %r14, %rsi
movq %r13, %rdx
movl -0x34(%rbp), %ecx
pushq $-0x1
popq %r8
callq 0x1293c
movl %eax, %r14d
movq %r13, %rdi
callq 0x24d9e
testb %r14b, %r14b
movq %rbx, %r14
movq %r15, %rbx
leaq 0x20493(%rip), %r15     # 0x400b0
je 0x1fb9c
movq 0x148(%rbx), %rax
movl 0xbc(%r12), %ecx
movl %ecx, 0x1c(%rax)
leaq -0x58(%rbp), %rdi
callq 0x24d9e
jmp 0x1fc57
leaq -0x58(%rbp), %rdi
callq 0x24d9e
movq 0x148(%rbx), %rax
movl $0x3, 0x1c(%rax)
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x10, (%r15,%r13,4)
jne 0x1f8d8
callq 0x41e0
pushq $0x64
popq %rcx
cqto
idivq %rcx
cmpq $0xe, %rdx
jg 0x1f8d8
movq %r14, %rdi
callq 0x1b84e
testb %al, %al
je 0x1f8c2
jmp 0x1f8d8
jmp 0x1fcf1
jmp 0x1fcf1
jmp 0x1fcf1
jmp 0x1fcd5
jmp 0x1fcf1
jmp 0x1fcd5
jmp 0x1fcf1
jmp 0x1fcf1
jmp 0x1fcf1
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
jmp 0x1fcea
jmp 0x1fcf1
jmp 0x1fcf1
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x24d9e
jmp 0x1fce6
jmp 0x1fcf1
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x47e8
jmp 0x1fcf4
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x24d9e
jmp 0x1fcf4
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710