// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/chores.cpp
// Function: (anonymous namespace)::trigger_trap(std::_List_iterator<Player>, std::_List_iterator<Trap>, bool)
bool trigger_trap(const list<Player>::iterator pit, const list<Trap>::iterator tr,
	const bool intentional)
{
	Coords pos = pit->own_pc->getpos();
	switch(tr->get_m())
	{
	case TRAP_WATER:
		// Extinguish torch, make splash sound, possibly rust weapon
		if(pit->own_pc->torch_is_lit())
			pit->own_pc->toggle_torch();
		add_sound(pos, S_SPLASH);
		// Rusting happens only once; to see if it has happened we compare
		// the PCs 2-hit to the 2-hit of that class by default:
		if(pit->cl_props.tohit == classes[pit->cl].tohit
			&& random()%100 < CHANCE_RUST)
		{
			string msg = "Your weapon rusts!";
			Network::construct_msg(msg, C_WATER_TRAP_LIT);
			Network::send_to_player(*pit);
			pit->cl_props.tohit -= RUST_MOD;
			pit->cl_props.dam_add -= RUST_MOD;
			pit->needs_state_upd = true;
		}
		break;
	case TRAP_LIGHT:
		flash_at(pos);
		break;
	case TRAP_TELE:
		if(pit->nomagicres())
		{
			// Get a random tile that's walkable and not occupied:
			Coords tar(1 + random()%(Game::curmap->get_size()-1),
				1 + random()%(Game::curmap->get_size()-1));
			init_nearby(tar);
			unsigned short f = Game::curmap->get_tile(tar).flags;
			while(!(f & TF_WALKTHRU) || (f & TF_OCCUPIED))
				f = Game::curmap->get_tile((tar = next_nearby())).flags;
			event_set.insert(pos); // necessary if 'T'riggering the trap
			move_player_to(pit, tar, true);
			// NOTE: do not clear axn queue like in blinking
			return true; // do not make triggered teleportation traps seen
		}
		else
			add_action_ind(pos, A_MISS);
		break;
	case TRAP_BOOBY:
		if(test_hit(pit, 9, 2, 6, 0) // 2d6+0, +9 tohit
			&& pit->cl_props.hp <= 0)
		{
			string msg = " died to a trap.";
			if(tr->get_owner() != cur_players.end())
			{
				msg = intentional ? " decided to step into " : " failed to notice ";
				if(tr->get_owner() == pit)
					msg += "her own";
				else
				{
					if(tr->get_owner()->team == pit->team)
					{
						msg += teammate_str;
						if(!intentional)
							tr->get_owner()->stats_i->tks++;
					}
					else
						record_kill(tr->get_owner(), WTK_BOOBY);
					msg += tr->get_owner()->nick + "\'s";
				}
				msg += " boobytrap.";
			}
			player_death(pit, msg, true);
		}
		add_sound(pos, S_CREAK);
		// Boobytraps are always destroyed:
		traps.erase(tr);
		Game::curmap->mod_tile(pos)->flags &= ~(TF_TRAP);
		return !pit->is_alive(); // cannot set the destroyed trap as seen!
	case TRAP_FIREB:
		fireball_trigger(pos, pit, intentional);
		if(!pit->is_alive())
			return true;
		break;
	case TRAP_ACID:
		if(test_hit(pit, 7, 3, 3, 0) // 3d3+0, +7 tohit
			&& pit->cl_props.hp <= 0)
			player_death(pit, " dissolved.", true);
		add_sound(pos, S_SPLASH);
		if(!pit->is_alive())
			return true;
		break;
	//default: anything else is an error!
	}
	// If here, trap should be made known:
	tr->set_seen_by(pit->team);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x148(%rdi), %rdi
movl 0x8(%rdi), %eax
movl %eax, -0x24(%rbp)
movzbl 0x1f(%rsi), %eax
cmpq $0x5, %rax
ja 0x1f21f
movl %edx, %r12d
leaq 0x10(%rbx), %r15
leaq 0x10237(%rip), %rcx     # 0x2f190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x20(%rdi)
jne 0x1ef6d
callq 0x1cb8c
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
callq 0x1b202
movb 0x154(%rbx), %al
movl 0xc0(%rbx), %ecx
imulq $0xd, %rcx, %rcx
leaq 0x10251(%rip), %rdx     # 0x2f1e0
cmpb 0x4(%rcx,%rdx), %al
jne 0x1f21f
callq 0x41e0
pushq $0x64
popq %rcx
cqto
idivq %rcx
cmpq $0x40, %rdx
jg 0x1f21f
leaq 0x105e1(%rip), %rsi     # 0x2f598
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0xb292
leaq -0x48(%rbp), %rdi
pushq $0x35
popq %rsi
callq 0xc0f2
leaq 0x1f141(%rip), %rsi     # 0x3e118
movq %r15, %rdi
callq 0xc3a6
addb $-0x2, 0x154(%rbx)
addb $-0x2, 0x157(%rbx)
movb $0x1, 0x15d(%rbx)
leaq -0x48(%rbp), %rdi
callq 0x47e8
jmp 0x1f21f
movzbl %r12b, %edx
leaq -0x24(%rbp), %rdi
movq %rbx, %rsi
callq 0x2171a
movq %r15, %rdi
callq 0xe68e
jmp 0x1f20a
movq %r15, %rdi
callq 0xe7be
testb %al, %al
je 0x1f213
callq 0x41e0
leaq 0x22c1d(%rip), %r15     # 0x41c58
movq (%r15), %rcx
movswq (%rcx), %rcx
decq %rcx
cqto
idivq %rcx
movq %rdx, %r14
incl %r14d
callq 0x41e0
movq (%r15), %rcx
movswq (%rcx), %rcx
decq %rcx
cqto
idivq %rcx
incl %edx
movswl %r14w, %esi
movswl %dx, %edx
leaq -0x48(%rbp), %rdi
callq 0x24d90
leaq -0x48(%rbp), %rdi
callq 0x1d501
movq (%r15), %rax
movswq -0x46(%rbp), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq -0x48(%rbp), %rdx
movq (%rax,%rcx), %rax
movl (%rax,%rdx,4), %r12d
leaq -0x68(%rbp), %r14
andl $0x41, %r12d
cmpl $0x1, %r12d
je 0x1f24e
movq (%r15), %r12
movq %r14, %rdi
callq 0x1d529
movl -0x68(%rbp), %eax
movl %eax, -0x48(%rbp)
movswq %ax, %rcx
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r12), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
movl (%rax,%rcx,4), %r12d
movq %r14, %rdi
callq 0x24d9e
jmp 0x1f0a0
pushq $0x9
popq %rsi
pushq $0x2
popq %rdx
pushq $0x6
popq %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x20b21
testb %al, %al
je 0x1f2ee
cmpb $0x0, 0x153(%rbx)
jg 0x1f2ee
leaq 0x10496(%rip), %rsi     # 0x2f5ab
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0xb292
movq 0x28(%r14), %rax
cmpq 0x1de83(%rip), %rax     # 0x3cfb0
je 0x1f2d6
leaq 0x10482(%rip), %rax     # 0x2f5bc
leaq 0x10492(%rip), %rsi     # 0x2f5d3
testb %r12b, %r12b
cmovneq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x4780
movq 0x28(%r14), %rdi
cmpq %rbx, %rdi
je 0x1f27b
movl 0xbc(%rdi), %eax
cmpl 0xbc(%rbx), %eax
jne 0x1f28d
leaq 0x24dd1(%rip), %rsi     # 0x43f48
leaq -0x48(%rbp), %rdi
callq 0x4790
movq 0x28(%r14), %rsi
testb %r12b, %r12b
jne 0x1f299
movq 0x90(%rsi), %rax
incq 0xa0(%rax)
jmp 0x1f299
leaq -0x24(%rbp), %rdi
callq 0x1f635
jmp 0x1f21f
pushq $0x7
popq %rsi
pushq $0x3
popq %rcx
movq %rbx, %rdi
movl %ecx, %edx
xorl %r8d, %r8d
callq 0x20b21
testb %al, %al
je 0x1f1f7
cmpb $0x0, 0x153(%rbx)
jg 0x1f1f7
leaq 0x1041f(%rip), %rsi     # 0x2f5f1
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0xb292
leaq -0x48(%rbp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x1f393
leaq -0x48(%rbp), %rdi
callq 0x47e8
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
callq 0x1b202
movq %r15, %rdi
callq 0xe68e
movb $0x1, %r15b
testb %al, %al
jne 0x1f21f
jmp 0x1f235
leaq -0x24(%rbp), %rdi
pushq $0x5
popq %rsi
callq 0x1b103
addq $0x10, %r14
movzbl 0xbc(%rbx), %esi
movq %r14, %rdi
callq 0x1caa6
xorl %r15d, %r15d
leaq -0x24(%rbp), %rdi
callq 0x24d9e
movl %r15d, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23d73(%rip), %rdi     # 0x42fc8
leaq -0x24(%rbp), %rsi
callq 0x1c558
leaq -0x48(%rbp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x1f7f6
leaq -0x48(%rbp), %rdi
callq 0x24d9e
movb $0x1, %r15b
jmp 0x1f235
leaq 0x10364(%rip), %rsi     # 0x2f5e6
leaq -0x48(%rbp), %rdi
callq 0x4770
jmp 0x1f2c6
pushq $0x4
popq %rsi
callq 0x1f544
movq 0x28(%r14), %rsi
addq $0x98, %rsi
leaq 0x10347(%rip), %rdx     # 0x2f5ee
leaq -0x68(%rbp), %rdi
callq 0xc40d
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4790
leaq -0x68(%rbp), %rdi
callq 0x47e8
leaq 0x1027f(%rip), %rsi     # 0x2f54c
leaq -0x48(%rbp), %rdi
callq 0x4770
leaq -0x48(%rbp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x1f393
leaq -0x48(%rbp), %rdi
callq 0x47e8
leaq -0x24(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x1b202
leaq 0x23b57(%rip), %rdi     # 0x42e58
movq %r14, %rsi
callq 0x17f5c
leaq 0x22948(%rip), %rax     # 0x41c58
movq (%rax), %rax
movswq -0x22(%rbp), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq -0x24(%rbp), %rdx
movq (%rax,%rcx), %rax
andw $0xf7ff, (%rax,%rdx,4)  # imm = 0xF7FF
movq %r15, %rdi
callq 0xe68e
movl %eax, %r15d
xorb $0x1, %r15b
jmp 0x1f235
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x47e8
jmp 0x1f364
jmp 0x1f361
jmp 0x1f361
jmp 0x1f37f
jmp 0x1f37f
jmp 0x1f37f
jmp 0x1f361
jmp 0x1f371
jmp 0x1f37f
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x47e8
jmp 0x1f382
jmp 0x1f371
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x24d9e
jmp 0x1f382
movq %rax, %rbx
leaq -0x24(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710