// File: /workspace/github_cpp_makefile_star2_O1/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 0x27413
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 0x2bbe8
movq %rbx, -0x48(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x50(%rbp)
leaq 0xdfe2(%rip), %rbx      # 0x35240
leaq 0x1da03(%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 0x1704c
testb %al, %al
jne 0x27398
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 0x27398
btl $0xb, %r13d
jae 0x27339
cmpl $0x4, -0x38(%rbp)
je 0x272ea
cmpl $0x9, -0x38(%rbp)
jne 0x2734d
leaq -0x2c(%rbp), %rdi
callq 0x21528
movq %rax, %r13
addq $0x10, %r13
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x22060
testb %al, %al
jne 0x27339
movq -0x48(%rbp), %rax
movzbl 0xbc(%rax), %esi
movq %r13, %rdi
callq 0x2204e
movb $0x1, %al
movl %eax, -0x34(%rbp)
leaq 0x1eca8(%rip), %rdi     # 0x45fd8
leaq -0x2c(%rbp), %rsi
callq 0x21b9c
addb $0x2, %r15b
movsbl %r15b, %r15d
cmpl $0x6, %r15d
jl 0x2727d
jmp 0x27398
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 0x2738c
cmpq $0x3b, %rcx
jle 0x272ea
jmp 0x27339
cmpq $0x4b, %rcx
jl 0x272ea
jmp 0x27339
movl -0x3c(%rbp), %r15d
incl %r15d
cmpl $0x18, %r15d
jne 0x2726c
testb $0x1, -0x34(%rbp)
je 0x27401
leaq -0x60(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xe17a(%rip), %rsi      # 0x35538
leaq 0xe189(%rip), %rdx      # 0x3554e
leaq -0x70(%rbp), %rdi
callq 0xdfec
leaq -0x70(%rbp), %rdi
movl $0x25, %esi
callq 0xf4ed
leaq 0x19d45(%rip), %rsi     # 0x41128
movq -0x50(%rbp), %rdi
callq 0xf816
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x27401
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x27445
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x27448
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0x27448
movq %rax, %rbx
jmp 0x27451
jmp 0x27445
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750