// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x148(%rdi), %rdi
movl 0x8(%rdi), %eax
movl %eax, -0x2c(%rbp)
movzbl 0x1f(%rsi), %eax
cmpq $0x5, %rax
ja 0x24aae
movl %edx, %r12d
leaq 0x10(%rbx), %r15
leaq 0x10a19(%rip), %rcx     # 0x35150
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x20(%rdi)
jne 0x2474b
callq 0x2213a
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
callq 0x20b4f
movb 0x154(%rbx), %al
movl 0xc0(%rbx), %ecx
leaq (%rcx,%rcx,2), %rdx
leaq (%rcx,%rdx,4), %rcx
leaq 0x10a2f(%rip), %rdx     # 0x351a0
cmpb 0x4(%rdx,%rcx), %al
jne 0x24aae
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 $0x40, %rcx
jg 0x24aae
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x10d8d(%rip), %rsi     # 0x3554f
leaq 0x10d98(%rip), %rdx     # 0x35561
leaq -0x50(%rbp), %rdi
callq 0xdfec
leaq -0x50(%rbp), %rdi
movl $0x35, %esi
callq 0xf4ed
leaq 0x1c941(%rip), %rsi     # 0x41128
movq %r15, %rdi
callq 0xf816
addb $-0x2, 0x154(%rbx)
addb $-0x2, 0x157(%rbx)
movb $0x1, 0x15d(%rbx)
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x24aae
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x24aae
movzbl %r12b, %edx
leaq -0x2c(%rbp), %rdi
movq %rbx, %rsi
callq 0x275a0
movq %r15, %rdi
callq 0x125e6
jmp 0x24a97
movq %r15, %rdi
callq 0x1274e
testb %al, %al
je 0x24aa0
callq 0x41d0
leaq 0x2040d(%rip), %r15     # 0x44c68
movq (%r15), %rcx
movswq (%rcx), %rcx
decq %rcx
cqto
idivq %rcx
movq %rdx, %r14
incl %r14d
callq 0x41d0
movq (%r15), %rcx
movswq (%rcx), %rcx
decq %rcx
cqto
idivq %rcx
incl %edx
movswl %r14w, %esi
movswl %dx, %edx
leaq -0x50(%rbp), %rdi
callq 0x2bbe8
leaq -0x50(%rbp), %rdi
callq 0x22bc9
movq (%r15), %rax
movswq -0x4e(%rbp), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq -0x50(%rbp), %rdx
movq (%rax,%rcx,8), %rax
movl (%rax,%rdx,4), %eax
andl $0x41, %eax
cmpl $0x1, %eax
je 0x24904
leaq -0x70(%rbp), %r14
movq (%r15), %r12
movq %r14, %rdi
callq 0x22bf2
movl -0x70(%rbp), %eax
movl %eax, -0x50(%rbp)
movswq -0x4e(%rbp), %rcx
movq 0x8(%r12), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq %ax, %rax
movq (%rdx,%rcx,8), %rcx
movl (%rcx,%rax,4), %r12d
movq %r14, %rdi
callq 0x2bbf6
andl $0x41, %r12d
cmpl $0x1, %r12d
jne 0x248c7
leaq 0x216cd(%rip), %rdi     # 0x45fd8
leaq -0x2c(%rbp), %rsi
callq 0x21b9c
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x251a1
leaq -0x50(%rbp), %rdi
callq 0x2bbf6
movb $0x1, %r15b
jmp 0x24ac4
movq %rbx, %rdi
movl $0x9, %esi
movl $0x2, %edx
movl $0x6, %ecx
xorl %r8d, %r8d
callq 0x26743
testb %al, %al
je 0x24b74
cmpb $0x0, 0x153(%rbx)
jg 0x24b74
leaq -0x40(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x10bee(%rip), %rsi     # 0x35562
leaq 0x10bf7(%rip), %rdx     # 0x35572
leaq -0x50(%rbp), %rdi
callq 0xdfec
movq 0x28(%r14), %rax
cmpq 0x1b629(%rip), %rax     # 0x3ffb8
je 0x24b4e
leaq 0x10bd7(%rip), %rax     # 0x35573
leaq 0x10be7(%rip), %rsi     # 0x3558a
testb %r12b, %r12b
cmovneq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0x4580
movq 0x28(%r14), %rdi
cmpq %rbx, %rdi
je 0x24adf
movl 0xbc(%rdi), %eax
cmpl 0xbc(%rbx), %eax
jne 0x24af1
movq 0x2257f(%rip), %rsi     # 0x46f58
movq 0x22580(%rip), %rdx     # 0x46f60
leaq -0x50(%rbp), %rdi
callq 0x4130
testb %r12b, %r12b
jne 0x24afb
movq 0x28(%r14), %rax
movq 0x90(%rax), %rax
incq 0xa0(%rax)
jmp 0x24afb
leaq -0x2c(%rbp), %rdi
callq 0x24ff7
jmp 0x24aae
movq %rbx, %rdi
movl $0x7, %esi
movl $0x3, %edx
movl $0x3, %ecx
xorl %r8d, %r8d
callq 0x26743
testb %al, %al
je 0x24a84
cmpb $0x0, 0x153(%rbx)
jg 0x24a84
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x10b5a(%rip), %rsi     # 0x355a8
leaq 0x10b5e(%rip), %rdx     # 0x355b3
leaq -0x50(%rbp), %rdi
callq 0xdfec
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x24c43
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x24a84
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
callq 0x20b4f
movq %r15, %rdi
callq 0x125e6
movb $0x1, %r15b
testb %al, %al
jne 0x24aae
jmp 0x24ac4
leaq -0x2c(%rbp), %rdi
movl $0x5, %esi
callq 0x20a4f
addq $0x10, %r14
movzbl 0xbc(%rbx), %esi
movq %r14, %rdi
callq 0x2204e
xorl %r15d, %r15d
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10ab7(%rip), %rsi     # 0x3559d
leaq -0x50(%rbp), %rdi
callq 0x47c0
jmp 0x24b3e
movl $0x4, %esi
callq 0x24e7d
movl $0x98, %esi
addq 0x28(%r14), %rsi
leaq 0x10a9a(%rip), %rdx     # 0x355a5
leaq -0x70(%rbp), %rdi
callq 0x27d87
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x4130
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24b3e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq 0x109be(%rip), %rsi     # 0x35503
leaq -0x50(%rbp), %rdi
callq 0x47c0
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x24c43
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x24b74
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x2c(%rbp), %rdi
movl $0x1, %esi
callq 0x20b4f
leaq 0x212df(%rip), %rdi     # 0x45e68
movq %r14, %rsi
callq 0x1d882
leaq 0x200d0(%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 $0xf7ff, (%rax,%rdx,4)  # imm = 0xF7FF
movq %r15, %rdi
callq 0x125e6
movl %eax, %r15d
xorb $0x1, %r15b
jmp 0x24ac4
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24c08
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x24c08
jmp 0x24c05
jmp 0x24bf3
jmp 0x24c2f
jmp 0x24c2f
jmp 0x24c2f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
jne 0x24c11
jmp 0x24c32
jmp 0x24c21
jmp 0x24c2f
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x24c32
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x24c32
jmp 0x24c21
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x2bbf6
jmp 0x24c32
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750