// File: /workspace/github_cpp_makefile_star2_O3/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, -0x38(%rbp)
cmpl $0x4, %ecx
leal 0x5(%rax,%rax,4), %eax
movl $0x7, %ecx
cmovnel %eax, %ecx
movzwl 0x13a(%rdi), %eax
cmpl %eax, %ecx
ja 0x2720d
movq %rdi, %rbx
movw $0x0, 0x13a(%rdi)
movq 0xd0(%rdi), %rax
movl 0x2(%rax), %eax
movl %eax, -0x30(%rbp)
leaq -0x2c(%rbp), %rdi
xorl %r15d, %r15d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
movq %rbx, -0x48(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0xe1d8(%rip), %rbx      # 0x35230
leaq 0x1dc09(%rip), %r14     # 0x44c68
movl $0x0, -0x34(%rbp)
movl %r15d, -0x3c(%rbp)
movslq %r15d, %rax
addq %rax, %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
movslq %r15d, %rax
addq %r12, %rax
movsbl (%rbx,%rax), %ecx
addw -0x30(%rbp), %cx
movw %cx, -0x2c(%rbp)
movsbl 0x1(%rbx,%rax), %eax
addw -0x2e(%rbp), %ax
movw %ax, -0x2a(%rbp)
movq (%r14), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x16f24
testb %al, %al
jne 0x27192
movq (%r14), %rax
movswq -0x2a(%rbp), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq -0x2c(%rbp), %rdx
movq (%rax,%rcx,8), %rax
movl (%rax,%rdx,4), %r13d
testb $0x4, %r13b
je 0x27192
btl $0xb, %r13d
jae 0x27133
cmpl $0x4, -0x38(%rbp)
je 0x270e4
cmpl $0x9, -0x38(%rbp)
jne 0x27147
leaq -0x2c(%rbp), %rdi
callq 0x2134d
movq %rax, %r13
addq $0x10, %r13
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x21df0
testb %al, %al
jne 0x27133
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x21dde
movb $0x1, %al
movl %eax, -0x34(%rbp)
leaq 0x1eeae(%rip), %rdi     # 0x45fd8
leaq -0x2c(%rbp), %rsi
callq 0x21934
addb $0x2, %r15b
movsbl %r15b, %r15d
cmpl $0x6, %r15d
jl 0x27077
jmp 0x27192
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
testb $0x10, %r13b
jne 0x27186
cmpq $0x3b, %rcx
jle 0x270e4
jmp 0x27133
cmpq $0x4b, %rcx
jl 0x270e4
jmp 0x27133
movl -0x3c(%rbp), %r15d
incl %r15d
cmpl $0x18, %r15d
jne 0x27066
testb $0x1, -0x34(%rbp)
je 0x271fb
leaq -0x60(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe370(%rip), %rsi      # 0x35528
leaq 0xe37f(%rip), %rdx      # 0x3553e
leaq -0x70(%rbp), %rdi
callq 0xe01c
leaq -0x70(%rbp), %rdi
movl $0x25, %esi
callq 0xf3f0
leaq 0x19f4b(%rip), %rsi     # 0x41128
movq -0x50(%rbp), %rdi
callq 0xf719
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x271fb
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2723f
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x27242
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x27242
movq %rax, %rbx
jmp 0x2724b
jmp 0x2723f
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740