// File: 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
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movb $0xa, -0x9(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
cmpl $0x4, 0xb0(%rax)
jne 0x572c9
movzbl -0x9(%rbp), %eax
imull $0x3, %eax, %eax
movl $0x4, %ecx
cltd
idivl %ecx
movb %al, -0x9(%rbp)
jmp 0x572ec
leaq -0x8(%rbp), %rdi
callq 0x1b050
cmpl $0x9, 0xb0(%rax)
jne 0x572ea
movzbl -0x9(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movb %al, -0x9(%rbp)
jmp 0x572ec
leaq -0x8(%rbp), %rdi
callq 0x1b050
movzwl 0x12a(%rax), %eax
movzbl -0x9(%rbp), %ecx
cmpl %ecx, %eax
jl 0x576a9
leaq -0x8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x1b050
movq -0x80(%rbp), %rdi
movw $0x0, 0x12a(%rax)
callq 0x1b050
movq 0xc0(%rax), %rsi
leaq -0xe(%rbp), %rdi
callq 0x3d450
leaq -0x12(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
jmp 0x57346
leaq -0x30(%rbp), %rdi
callq 0x4a660
movb $0x0, -0x31(%rbp)
movb $0x0, -0x27(%rbp)
movsbl -0x27(%rbp), %eax
cmpl $0x18, %eax
jge 0x575e2
movb $0x0, -0x28(%rbp)
movsbl -0x28(%rbp), %eax
cmpl $0x6, %eax
jge 0x575d3
movq 0x359bc(%rip), %rax     # 0x8cd38
movsbl -0x27(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %esi
movsbl -0x28(%rbp), %edx
movl %edx, %ecx
movl %esi, %edx
leal (%rcx,%rdx,2), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movzwl -0xe(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x12(%rbp)
movq 0x35990(%rip), %rcx     # 0x8cd38
movsbl -0x27(%rbp), %edx
movl %edx, %eax
leal (%rax,%rax,2), %esi
movsbl -0x28(%rbp), %edx
movl %edx, %eax
movl %esi, %edx
leal (%rax,%rdx,2), %eax
cltq
movsbl 0x1(%rax,%rcx), %eax
movzwl -0xc(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x10(%rbp)
leaq 0x3aa04(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
leaq -0x12(%rbp), %rsi
callq 0x2ba40
movb %al, -0x81(%rbp)
jmp 0x573e8
movb -0x81(%rbp), %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x82(%rbp)
jne 0x5743b
jmp 0x573fd
leaq 0x3a9d4(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
leaq -0x12(%rbp), %rsi
callq 0x3dcd0
movl %eax, -0x88(%rbp)
jmp 0x57418
movl -0x88(%rbp), %eax
movl %eax, -0x36(%rbp)
movw -0x36(%rbp), %ax
movw %ax, -0x26(%rbp)
cwtl
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
testb $0x1, %al
jne 0x57447
jmp 0x5746e
jmp 0x575d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x5769e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x57695
movswl -0x26(%rbp), %ecx
andl $0x800, %ecx            # imm = 0x800
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x89(%rbp)
je 0x5754f
movzbl -0x9(%rbp), %eax
cmpl $0xa, %eax
jl 0x574e8
movswl -0x26(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x574b3
callq 0x5270
movl $0x64, %ecx
cqto
idivq %rcx
cmpq $0x4b, %rdx
jl 0x574e8
movswl -0x26(%rbp), %ecx
andl $0x10, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x89(%rbp)
jne 0x5754f
callq 0x5270
movl $0x64, %ecx
cqto
idivq %rcx
xorl %eax, %eax
cmpq $0x3c, %rdx
movb %al, -0x89(%rbp)
jge 0x5754f
leaq -0x12(%rbp), %rdi
callq 0x494b0
movq %rax, -0x98(%rbp)
jmp 0x574fa
movq -0x98(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3daa0
movq %rax, -0xa8(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movq -0xa8(%rbp), %rdi
movzbl 0xac(%rax), %esi
callq 0x4d890
movb %al, -0x99(%rbp)
jmp 0x57541
movb -0x99(%rbp), %al
xorb $-0x1, %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x5755b
jmp 0x575c0
leaq -0x30(%rbp), %rdi
callq 0x3daa0
movq %rax, -0xb0(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x1b050
movq -0xb0(%rbp), %rdi
movzbl 0xac(%rax), %esi
callq 0x4d860
jmp 0x57589
movb $0x1, -0x31(%rbp)
leaq 0x3bbb4(%rip), %rdi     # 0x93148
leaq -0x12(%rbp), %rsi
callq 0x4a010
movb %dl, -0xb9(%rbp)
movq %rax, -0xb8(%rbp)
jmp 0x575ac
movb -0xb9(%rbp), %al
movq -0xb8(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movb %al, -0x48(%rbp)
jmp 0x575c2
jmp 0x575c4
movsbl -0x28(%rbp), %eax
addl $0x2, %eax
movb %al, -0x28(%rbp)
jmp 0x57368
jmp 0x575d5
movb -0x27(%rbp), %al
addb $0x1, %al
movb %al, -0x27(%rbp)
jmp 0x57357
testb $0x1, -0x31(%rbp)
je 0x57681
leaq -0x71(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x5930
movq -0xc8(%rbp), %rdx
leaq 0x14e97(%rip), %rsi     # 0x6c4a1
leaq -0x70(%rbp), %rdi
callq 0x18880
jmp 0x57615
leaq -0x71(%rbp), %rdi
callq 0x5590
leaq -0x70(%rbp), %rdi
movl $0x25, %esi
callq 0x1ab10
jmp 0x5762e
leaq -0x8(%rbp), %rdi
callq 0x28450
movq %rax, %rdi
leaq 0x36c57(%rip), %rsi     # 0x8e298
callq 0x1af60
jmp 0x57648
leaq -0x70(%rbp), %rdi
callq 0x5a48
jmp 0x57681
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x5590
jmp 0x57695
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x5a48
jmp 0x57695
leaq -0x12(%rbp), %rdi
callq 0x60460
leaq -0xe(%rbp), %rdi
callq 0x60460
jmp 0x576a9
leaq -0x12(%rbp), %rdi
callq 0x60460
leaq -0xe(%rbp), %rdi
callq 0x60460
jmp 0x576b2
addq $0xd0, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x5920
nopl (%rax,%rax)