// File: /workspace/github_cpp_makefile_star2_O3/lotuskip[P]yuxtapa/server/chores.cpp
// Function: missile_coll(OwnedEnt*, Coords const&)
bool missile_coll(OwnedEnt* mis, const Coords &c)
{
	Tile* tar = Game::curmap->mod_tile(c);
	if(!(tar->flags & TF_WALKTHRU))
	{
		Zap* mis_as_z;
		if(tar->symbol != '+' // zaps don't bounce off of doors!
			&& (mis_as_z = dynamic_cast<Zap*>(mis)))
		{
			// Handle zap bouncing off of walls. This is a bit complicated.
			Coords now_at = mis->getpos();
			/* We want to get the tiles marked by 1 and 2 here, and they are
			 * defined differently for diagonal/nondiagonal movement:
			      2     2#
		 	   ---#     /1
			      1    /    */
			e_Dir d = mis_as_z->get_dir();
			e_Dir dtest = d;
			add_sound(now_at.in(d), S_ZAP);
			Tile *t1, *t2;
			Coords c1, c2;
			if(d%2) // a diagonal direction
			{
				--dtest;
				t2 = Game::curmap->mod_tile((c2 = now_at.in(dtest)));
				++(++dtest);
				t1 = Game::curmap->mod_tile((c1 = now_at.in(dtest)));
			}
			else // not diagonal dir
			{
				++(++dtest);
				t1 = Game::curmap->mod_tile((c1 = c.in(dtest)));
				t2 = Game::curmap->mod_tile((c2 = c.in(!dtest)));
			}
			// If BOTH or NEITHER of 1&2 are blocked, we bounce back. If exactly one
			// is blocked, we bounce to the direction that is not blocked.
			if(bool(t1->flags & TF_WALKTHRU) != bool(t2->flags & TF_WALKTHRU))
			{
				if(t1->flags & TF_WALKTHRU) // go to t1
					++(++d);
				else // go to t2
				{
					--(--d);
					c1 = c2;
				}
				// Now 'd' holds the new movement direction and c1 is the next location.
				if(mis_as_z->bounce(d))
					return true; // didn't have energy to bounce any more
				// else: imitate moving to c1:
				mis->setpos(c1.in(!d));
				return missile_coll(mis, c1);
			}
			// else both or neither is walkthru; bounce back
			if(mis_as_z->bounce(!d))
				return true;
			mis->setpos(c);
			return missile_coll(mis, c.in(!d));
		}
		//else
		mis->makevoid(); // caller has unset occupied flag
		add_action_ind(c, A_MISS);
		return true;
	}
	/*else*/ if(tar->flags & TF_OCCUPIED)
	{
		// There is something. A boulder?
		list<OccEnt>::iterator bl_it = any_boulder_at(c);
		if(bl_it != boulders.end())
		{
			// Missile hits a boulder: missile is destroyed.
			mis->makevoid(); // caller has unset occ flag for missile; for block no change
			add_action_ind(c, A_MISS);
			return true;
		}
		//else: PC?
		list<PCEnt>::iterator pc_it = any_pc_at(c);
		if(pc_it != PCs.end())
		{
			missile_hit_PC(pc_it->get_owner(), mis, false);
			return true;
		}
		// else may assume it's another missile.
		// Missile hits missile -- both are destroyed:
		mis->makevoid();
		any_missile_at(c)->makevoid();
		Game::curmap->mod_tile(c)->flags &= ~(TF_OCCUPIED);
		add_action_ind(c, A_MISS);
		return true;
	}
	// else tile is passable and not occupied -- check for trees:
	/*else*/ if(tar->symbol == 'T' && mis->hit_tree())
	{
		mis->makevoid();
		add_action_ind(c, A_MISS);
		return true;
	}
	
	return false; // no collision or bounced
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1e537(%rip), %r13     # 0x44c68
movq (%r13), %rax
movswq 0x2(%rsi), %rcx
movq 0x8(%rax), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq (%rsi), %rax
movq (%rdx,%rcx,8), %rcx
movzwl (%rcx,%rax,4), %edx
testb $0x1, %dl
jne 0x26883
testq %rbx, %rbx
je 0x268b5
cmpb $0x2b, 0x2(%rcx,%rax,4)
je 0x268b5
leaq 0x195d6(%rip), %rsi     # 0x3fd48
leaq 0x195b7(%rip), %rdx     # 0x3fd30
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4450
testq %rax, %rax
je 0x268b5
movq %rax, %r15
movl 0x8(%rbx), %eax
leaq -0x40(%rbp), %rsi
movl %eax, (%rsi)
movl 0x18(%r15), %r12d
movl %r12d, -0x3c(%rbp)
movl %r12d, -0x34(%rbp)
leaq -0x30(%rbp), %rdi
movl %r12d, %edx
callq 0x2b818
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x209ed
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2b798
testb $0x1, %r12b
movq %r15, -0x50(%rbp)
movl %r12d, -0x44(%rbp)
jne 0x268f3
leaq -0x34(%rbp), %rdi
callq 0x2b74c
movq %rax, %rdi
callq 0x2b74c
movq (%r13), %r15
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
callq 0x2b818
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq %ax, %r12
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r15), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x2, %r12
addq (%rcx,%rax,8), %r12
callq 0x2b7a6
movq (%r13), %r13
movl -0x34(%rbp), %edi
callq 0x2b77c
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x2b818
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x38(%rbp)
movswq %ax, %r15
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r13), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x2, %r15
addq (%rcx,%rax,8), %r15
jmp 0x26983
testb $0x40, %dl
jne 0x268a4
cmpb $0x54, 0x2(%rcx,%rax,4)
jne 0x2689c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
jne 0x268b5
xorl %r15d, %r15d
jmp 0x26a88
movq %r14, %rdi
callq 0x213e3
cmpq 0x1971d(%rip), %rax     # 0x3ffd0
je 0x268ce
movb $0x1, 0xe(%rbx)
movq %r14, %rdi
movl $0x5, %esi
callq 0x208ed
movb $0x1, %r15b
jmp 0x26a88
movq %r14, %rdi
callq 0x2122a
cmpq 0x196cb(%rip), %rax     # 0x3ffa8
je 0x26a9a
movq 0x20(%rax), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x26b28
jmp 0x268c6
leaq -0x34(%rbp), %rdi
callq 0x2b764
movq (%r13), %r12
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2b818
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x38(%rbp)
movswq %ax, %r15
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r12), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x2, %r15
addq (%rcx,%rax,8), %r15
callq 0x2b7a6
leaq -0x34(%rbp), %rdi
callq 0x2b74c
movq %rax, %rdi
callq 0x2b74c
movq (%r13), %r13
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2b818
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq %ax, %r12
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r13), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x2, %r12
addq (%rcx,%rax,8), %r12
callq 0x2b7a6
movzwl (%r12), %eax
andl $0x1, %eax
movzwl (%r15), %ecx
andl $0x1, %ecx
cmpw %cx, %ax
jne 0x269f4
movl -0x44(%rbp), %r12d
movl %r12d, %edi
callq 0x2b77c
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x22822
movb $0x1, %r15b
testb %al, %al
jne 0x26a6d
movl (%r14), %eax
movl %eax, 0x8(%rbx)
movl %r12d, %edi
callq 0x2b77c
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x2b818
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x26713
movl %eax, %r15d
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
jmp 0x26a6d
testw %ax, %ax
movq -0x50(%rbp), %r14
jne 0x26a16
leaq -0x3c(%rbp), %rdi
callq 0x2b764
movq %rax, %rdi
callq 0x2b764
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x26a27
leaq -0x3c(%rbp), %rdi
callq 0x2b74c
movq %rax, %rdi
callq 0x2b74c
movl -0x3c(%rbp), %esi
movq %r14, %rdi
callq 0x22822
movb $0x1, %r15b
testb %al, %al
jne 0x26a6d
movl -0x3c(%rbp), %edi
callq 0x2b77c
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %eax, %edx
callq 0x2b818
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, 0x8(%rbx)
callq 0x2b7a6
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x26713
movl %eax, %r15d
leaq -0x38(%rbp), %rdi
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
leaq -0x40(%rbp), %rdi
callq 0x2b7a6
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r15b
movb %r15b, 0xe(%rbx)
movq %r14, %rdi
callq 0x21479
movb %r15b, 0xe(%rax)
movq (%r13), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
leaq (%rcx,%rcx,2), %rcx
movswq (%r14), %rdx
movq (%rax,%rcx,8), %rax
andw $-0x41, (%rax,%rdx,4)
movq %r14, %rdi
movl $0x5, %esi
callq 0x208ed
jmp 0x26a88
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2b7a6
jmp 0x26b05
jmp 0x26b02
jmp 0x26b02
jmp 0x26b02
jmp 0x26b02
jmp 0x26b02
jmp 0x26b02
jmp 0x26af8
jmp 0x26afd
movq %rax, %rbx
jmp 0x26b0e
movq %rax, %rbx
jmp 0x26b17
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x2b7a6
leaq -0x30(%rbp), %rdi
callq 0x2b7a6
leaq -0x40(%rbp), %rdi
callq 0x2b7a6
movq %rbx, %rdi
callq 0x4740