// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/chores.cpp
// Function: trap_detection(std::_List_iterator<Player>)
void trap_detection(const list<Player>::iterator pit)
{
	unsigned char req_turns = BASE_TURNS_TO_DETECT_TRAPS;
	if(pit->cl == C_SCOUT) req_turns = 3*req_turns/4;
	else if(pit->cl == C_TRAPPER) req_turns /= 2;

	if(pit->turns_without_axn >= req_turns)
	{
		pit->turns_without_axn = 0; // detection counts as an action!
		// Go through traps in a radius of 3 squares:
		Coords pos = pit->own_vp->get_pos(); /* Note: using viewpoint's pos
			instead of PC's assures that planewalkers can detect traps with mind's eye. */
		Coords c;
		short f;
		char line, ind;
		list<Trap>::iterator tr_i;
		bool ded = false; // detected any traps?
		for(line = 0; line < DETECT_TRAPS_RAD*8; ++line)
		{
			for(ind = 0; ind < 2*DETECT_TRAPS_RAD; ind += 2)
			{
				c.x = loslookup[DETECT_TRAPS_RAD-2][line*2*DETECT_TRAPS_RAD+ind] + pos.x;
				c.y = loslookup[DETECT_TRAPS_RAD-2][line*2*DETECT_TRAPS_RAD+ind+1] + pos.y;
				if(Game::curmap->point_out_of_map(c)
					|| !((f = Game::curmap->get_tile(c).flags) & TF_SEETHRU))
					break;
				else if(f & TF_TRAP && (req_turns < BASE_TURNS_TO_DETECT_TRAPS
					|| ((f & TF_LIT) && random()%100 < 75)
					|| (!(f & TF_LIT) && random()%100 < 60))
					&& !(tr_i = any_trap_at(c))->is_seen_by(pit->team))
				{
					tr_i->set_seen_by(pit->team);
					ded = true;
					event_set.insert(c);
				}
			}
		}
		if(ded)
		{
			string msg = "You detect some traps.";
			Network::construct_msg(msg, C_FIREB_TRAP);
			Network::send_to_player(*pit);
		}
	} // if should detect traps
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl 0xc0(%rdi), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
setne %al
movl %ecx, -0x3c(%rbp)
cmpl $0x4, %ecx
leal 0x5(%rax,%rax,4), %eax
pushq $0x7
popq %rcx
cmovnel %eax, %ecx
movzwl 0x13a(%rdi), %eax
cmpl %eax, %ecx
ja 0x215bd
movq %rdi, %rbx
andw $0x0, 0x13a(%rdi)
movq 0xd0(%rdi), %rax
movl 0x2(%rax), %eax
movl %eax, -0x30(%rbp)
leaq -0x2c(%rbp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
movq %rbx, -0x48(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0xde3e(%rip), %r12      # 0x2f280
leaq 0x2080f(%rip), %rbx     # 0x41c58
movl $0x0, -0x38(%rbp)
cmpl $0x18, %r14d
je 0x2156c
movl %r14d, -0x40(%rbp)
movslq %r14d, %rax
imulq $0x6, %rax, %r14
xorl %r15d, %r15d
movsbl %r15b, %r15d
cmpl $0x5, %r15d
jg 0x21560
movslq %r15d, %rax
addq %r14, %rax
movsbl (%r12,%rax), %ecx
addw -0x30(%rbp), %cx
movw %cx, -0x2c(%rbp)
movsbl 0x1(%r12,%rax), %eax
addw -0x2e(%rbp), %ax
movw %ax, -0x2a(%rbp)
movq (%rbx), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1256c
testb %al, %al
jne 0x21560
movq (%rbx), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx), %rax
movl (%rax,%rdx,4), %r13d
testb $0x4, %r13b
je 0x21560
btl $0xb, %r13d
jae 0x21534
cmpl $0x4, -0x3c(%rbp)
je 0x214e5
cmpl $0x9, -0x3c(%rbp)
jne 0x2153d
leaq -0x2c(%rbp), %rdi
callq 0x1bae4
movq %rax, %r13
addq $0x10, %r13
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x1cab8
testb %al, %al
jne 0x21534
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x1caa6
movb $0x1, %al
movl %eax, -0x38(%rbp)
leaq 0x21a9d(%rip), %rdi     # 0x42fc8
leaq -0x2c(%rbp), %rsi
callq 0x1c558
addl $0x2, %r15d
jmp 0x21468
callq 0x41e0
cqto
pushq $0x64
popq %rcx
idivq %rcx
testb $0x10, %r13b
jne 0x21558
cmpq $0x3b, %rdx
jle 0x214e5
jmp 0x21534
cmpq $0x4b, %rdx
jl 0x214e5
jmp 0x21534
movl -0x40(%rbp), %r14d
incl %r14d
jmp 0x21450
testb $0x1, -0x38(%rbp)
je 0x215ab
leaq 0xe008(%rip), %rsi      # 0x2f581
leaq -0x70(%rbp), %rdi
leaq -0x31(%rbp), %rdx
callq 0xb292
leaq -0x70(%rbp), %rdi
pushq $0x25
popq %rsi
callq 0xc0f2
leaq 0x1cb7f(%rip), %rsi     # 0x3e118
movq -0x50(%rbp), %rdi
callq 0xc3a6
leaq -0x70(%rbp), %rdi
callq 0x47e8
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
leaq -0x30(%rbp), %rdi
callq 0x24d9e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x215e3
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x47e8
jmp 0x215e6
movq %rax, %rbx
jmp 0x215ef
jmp 0x215e3
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
leaq -0x30(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710