// File: 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
subq $0x220, %rsp            # imm = 0x220
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq 0x138(%rax), %rsi
leaq -0x1e(%rbp), %rdi
callq 0x1b190
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3d8b0
movb %al, -0x162(%rbp)
jmp 0x50dcc
movb -0x162(%rbp), %al
movzbl %al, %ecx
movq %rcx, -0x170(%rbp)
subb $0x5, %al
ja 0x51765
movq -0x170(%rbp), %rax
leaq 0x194be(%rip), %rcx     # 0x6a2b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x517b8
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq 0x138(%rax), %rdi
callq 0x3d0d0
testb $0x1, %al
jne 0x50e27
jmp 0x50e40
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq 0x138(%rax), %rdi
callq 0x4da90
jmp 0x50e3e
jmp 0x50e40
leaq -0x1e(%rbp), %rdi
xorl %esi, %esi
callq 0x48080
jmp 0x50e4d
leaq -0x10(%rbp), %rdi
callq 0x1b050
movsbl 0x144(%rax), %eax
movl %eax, -0x174(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movl -0x174(%rbp), %eax
movl 0xb0(%rcx), %ecx
movl %ecx, %edx
leaq 0x1947c(%rip), %rcx     # 0x6a300
imulq $0xd, %rdx, %rdx
addq %rdx, %rcx
movsbl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0x50f8d
callq 0x5270
movl $0x64, %ecx
cqto
idivq %rcx
cmpq $0x41, %rdx
jge 0x50f8d
leaq -0x51(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x5930
movq -0x180(%rbp), %rdx
leaq 0x1b5ea(%rip), %rsi     # 0x6c4b8
leaq -0x50(%rbp), %rdi
callq 0x18880
jmp 0x50ed9
leaq -0x51(%rbp), %rdi
callq 0x5590
leaq -0x50(%rbp), %rdi
movl $0x35, %esi
callq 0x1ab10
jmp 0x50ef2
leaq -0x10(%rbp), %rdi
callq 0x28450
movq %rax, %rdi
leaq 0x3d393(%rip), %rsi     # 0x8e298
callq 0x1af60
jmp 0x50f0c
leaq -0x10(%rbp), %rdi
callq 0x1b050
movsbl 0x144(%rax), %ecx
subl $0x2, %ecx
movb %cl, 0x144(%rax)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movsbl 0x147(%rax), %ecx
subl $0x2, %ecx
movb %cl, 0x147(%rax)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movb $0x1, 0x14d(%rax)
leaq -0x50(%rbp), %rdi
callq 0x5a48
jmp 0x50f8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x5590
jmp 0x517b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x5a48
jmp 0x517b8
jmp 0x51765
leaq -0x1e(%rbp), %rdi
callq 0x53530
jmp 0x50f9d
jmp 0x51765
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21f00
movb %al, -0x181(%rbp)
jmp 0x50fbb
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x50fca
jmp 0x51198
callq 0x5270
movq %rax, -0x190(%rbp)
leaq 0x40dfb(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
callq 0x3c930
movw %ax, -0x184(%rbp)
jmp 0x50fee
movq -0x190(%rbp), %rax
movw -0x184(%rbp), %cx
movswl %cx, %ecx
decl %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movl %edx, %eax
incl %eax
movw %ax, -0x1a2(%rbp)
callq 0x5270
movq %rax, -0x1a0(%rbp)
leaq 0x40db1(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
callq 0x3c930
movw %ax, -0x192(%rbp)
jmp 0x51038
movq -0x1a0(%rbp), %rax
movw -0x192(%rbp), %cx
movswl %cx, %ecx
decl %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movw -0x1a2(%rbp), %ax
movl %edx, %ecx
incl %ecx
movswl %cx, %edx
movswl %ax, %esi
leaq -0x56(%rbp), %rdi
callq 0x60430
jmp 0x5106f
leaq -0x56(%rbp), %rdi
callq 0x4ebf0
jmp 0x5107a
leaq 0x40d57(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
leaq -0x56(%rbp), %rsi
callq 0x3dcd0
movl %eax, -0x5c(%rbp)
movw -0x5c(%rbp), %ax
movw %ax, -0x58(%rbp)
movzwl -0x58(%rbp), %ecx
andl $0x1, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x1a3(%rbp)
je 0x510bf
movzwl -0x58(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x1a3(%rbp)
movb -0x1a3(%rbp), %al
testb $0x1, %al
jne 0x510cb
jmp 0x5112d
leaq 0x40d06(%rip), %rax     # 0x91dd8
movq (%rax), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x4ec30
jmp 0x510e7
movq -0x1b0(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, -0x56(%rbp)
leaq -0x56(%rbp), %rsi
callq 0x3dcd0
movl %eax, -0x60(%rbp)
movw -0x60(%rbp), %ax
movw %ax, -0x58(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x60460
jmp 0x51098
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x60460
jmp 0x517b8
leaq 0x42014(%rip), %rdi     # 0x93148
leaq -0x1e(%rbp), %rsi
callq 0x4a010
movb %dl, -0x1b9(%rbp)
movq %rax, -0x1b8(%rbp)
jmp 0x5114c
movb -0x1b9(%rbp), %al
movq -0x1b8(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movb %al, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
leaq -0x56(%rbp), %rsi
movl $0x1, %edx
callq 0x53890
jmp 0x5117c
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x56(%rbp), %rdi
callq 0x60460
jmp 0x517a1
leaq -0x1e(%rbp), %rdi
movl $0x5, %esi
callq 0x47f20
jmp 0x511a8
jmp 0x511aa
jmp 0x51765
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movl $0x9, %esi
movl $0x2, %edx
movl $0x6, %ecx
xorl %r8d, %r8d
callq 0x56120
movb %al, -0x1ba(%rbp)
jmp 0x511e0
movb -0x1ba(%rbp), %al
testb $0x1, %al
jne 0x511ef
jmp 0x5153a
leaq -0x10(%rbp), %rdi
callq 0x1b050
movsbl 0x143(%rax), %eax
cmpl $0x0, %eax
jg 0x5153a
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x5930
movq -0x1c8(%rbp), %rdx
leaq 0x1b2a2(%rip), %rsi     # 0x6c4cb
leaq -0xb0(%rbp), %rdi
callq 0x18880
jmp 0x51237
leaq -0xb1(%rbp), %rdi
callq 0x5590
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x1d0(%rbp)
jmp 0x5125d
movq -0x1d0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq 0x3efbe(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x1b100
testb $0x1, %al
jne 0x5129a
jmp 0x514f6
movb -0x19(%rbp), %cl
leaq 0x1b238(%rip), %rax     # 0x6c4dc
leaq 0x1b248(%rip), %rsi     # 0x6c4f3
testb $0x1, %cl
cmovneq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x5760
jmp 0x512c0
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x1d8(%rbp)
jmp 0x512da
movq -0x1d8(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x3d990
testb $0x1, %al
jne 0x512fe
jmp 0x51346
leaq 0x1b201(%rip), %rsi     # 0x6c506
leaq -0xb0(%rbp), %rdi
callq 0x54f0
jmp 0x51313
jmp 0x514df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x5590
jmp 0x517b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x51529
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x1e0(%rbp)
jmp 0x51360
movq -0x1e0(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
movl %eax, -0x1e4(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movl -0x1e4(%rbp), %eax
cmpl 0xac(%rcx), %eax
jne 0x51412
leaq 0x42d21(%rip), %rsi     # 0x940c8
leaq -0xb0(%rbp), %rdi
callq 0x56e0
jmp 0x513b5
testb $0x1, -0x19(%rbp)
jne 0x51410
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x1f0(%rbp)
jmp 0x513d5
movq -0x1f0(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq 0x90(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x90(%rax)
jmp 0x5144f
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x1f8(%rbp)
jmp 0x5142c
movq -0x1f8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
movl $0x4, %esi
callq 0x51b40
jmp 0x5144d
jmp 0x5144f
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, %rdi
callq 0x3dad0
movq %rax, -0x200(%rbp)
jmp 0x51469
movq -0x200(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x1b050
movq %rax, %rsi
addq $0x88, %rsi
leaq 0x1b07a(%rip), %rdx     # 0x6c50e
leaq -0x108(%rbp), %rdi
callq 0x1b080
jmp 0x514a2
leaq -0xb0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x56e0
jmp 0x514b7
leaq -0x108(%rbp), %rdi
callq 0x5a48
jmp 0x514df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x5a48
jmp 0x51529
leaq 0x1af86(%rip), %rsi     # 0x6c46c
leaq -0xb0(%rbp), %rdi
callq 0x54f0
jmp 0x514f4
jmp 0x514f6
movq -0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x1, %edx
callq 0x517d0
jmp 0x5151b
leaq -0xb0(%rbp), %rdi
callq 0x5a48
jmp 0x5153a
leaq -0xb0(%rbp), %rdi
callq 0x5a48
jmp 0x517b8
leaq -0x1e(%rbp), %rdi
movl $0x1, %esi
callq 0x48080
jmp 0x5154a
leaq -0x120(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x3db40
movq -0x120(%rbp), %rsi
leaq 0x41a70(%rip), %rdi     # 0x92fd8
callq 0x3daf0
movq %rax, -0x128(%rbp)
leaq 0x4085d(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x3d2d0
movb 0x1(%rax), %cl
andb $-0x9, %cl
movb %cl, 0x1(%rax)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21cd0
movb %al, -0x201(%rbp)
jmp 0x515a9
movb -0x201(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x517a1
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rsi
movzbl -0x19(%rbp), %edx
andl $0x1, %edx
leaq -0x1e(%rbp), %rdi
callq 0x57830
jmp 0x515e9
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21cd0
movb %al, -0x202(%rbp)
jmp 0x51602
movb -0x202(%rbp), %al
testb $0x1, %al
jne 0x51621
jmp 0x5160e
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x517a1
jmp 0x51765
movq -0x10(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
movl $0x7, %esi
movl $0x3, %ecx
xorl %r8d, %r8d
movl %ecx, %edx
callq 0x56120
movb %al, -0x203(%rbp)
jmp 0x51654
movb -0x203(%rbp), %al
testb $0x1, %al
jne 0x51663
jmp 0x51721
leaq -0x10(%rbp), %rdi
callq 0x1b050
movsbl 0x143(%rax), %eax
cmpl $0x0, %eax
jg 0x51721
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x161(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x5930
movq -0x210(%rbp), %rdx
leaq 0x1ae69(%rip), %rsi     # 0x6c511
leaq -0x160(%rbp), %rdi
callq 0x18880
jmp 0x516b6
movq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
movl $0x1, %edx
callq 0x517d0
jmp 0x516d0
leaq -0x160(%rbp), %rdi
callq 0x5a48
leaq -0x161(%rbp), %rdi
callq 0x5590
jmp 0x51721
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x51710
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x5a48
leaq -0x161(%rbp), %rdi
callq 0x5590
jmp 0x517b8
leaq -0x1e(%rbp), %rdi
xorl %esi, %esi
callq 0x48080
jmp 0x5172e
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21cd0
movb %al, -0x211(%rbp)
jmp 0x51747
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x51763
jmp 0x51753
movb $0x1, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x517a1
jmp 0x51765
leaq -0x18(%rbp), %rdi
callq 0x3daa0
movq %rax, -0x220(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq -0x220(%rbp), %rdi
movzbl 0xac(%rax), %esi
callq 0x4d860
jmp 0x51793
movb $0x0, -0x1(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x1e(%rbp), %rdi
callq 0x60460
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
leaq -0x1e(%rbp), %rdi
callq 0x60460
movq -0x28(%rbp), %rdi
callq 0x5920
nopw (%rax,%rax)