// File: /workspace/github_cpp_makefile_star2_O1/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 0x1e324(%rip), %r12     # 0x44c68
movq (%r12), %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 0x26993
cmpb $0x2b, 0x2(%rcx,%rax,4)
je 0x26ae9
testq %rbx, %rbx
je 0x269f5
leaq 0x1912b(%rip), %rsi     # 0x3faa8
leaq 0x193cc(%rip), %rdx     # 0x3fd50
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4450
movq %rax, %r15
jmp 0x269f8
testb $0x40, %dl
jne 0x269b8
cmpb $0x54, 0x2(%rcx,%rax,4)
jne 0x269b0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
jne 0x26ae9
xorl %r15d, %r15d
jmp 0x26c8e
movq %r14, %rdi
callq 0x215ae
cmpq 0x19611(%rip), %rax     # 0x3ffd8
jne 0x26ae9
movq %r14, %rdi
callq 0x21415
cmpq 0x195d4(%rip), %rax     # 0x3ffb0
je 0x26ca0
movq 0x20(%rax), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x26d2e
jmp 0x26afa
xorl %r15d, %r15d
testq %r15, %r15
je 0x26ae9
movl 0x8(%rbx), %eax
leaq -0x40(%rbp), %rsi
movl %eax, (%rsi)
movl 0x18(%r15), %edx
movl %edx, -0x3c(%rbp)
movl %edx, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2bc76
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x20b4f
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
leaq -0x34(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2bbe8
testb $0x1, -0x3c(%rbp)
movq %r15, -0x48(%rbp)
jne 0x26b02
leaq -0x38(%rbp), %rdi
callq 0x2bb9c
movq %rax, %rdi
callq 0x2bb9c
movq (%r12), %r15
movl -0x38(%rbp), %edx
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
callq 0x2bc76
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq -0x2e(%rbp), %rcx
movq 0x8(%r15), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq %ax, %r15
shlq $0x2, %r15
addq (%rdx,%rcx,8), %r15
callq 0x2bbf6
movq (%r12), %r12
movl -0x38(%rbp), %edi
callq 0x2bbcc
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x2bc76
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x34(%rbp)
movswq -0x32(%rbp), %rcx
movq 0x8(%r12), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq %ax, %r13
shlq $0x2, %r13
addq (%rdx,%rcx,8), %r13
jmp 0x26b8d
movb $0x1, 0xe(%rbx)
movq %r14, %rdi
movl $0x5, %esi
callq 0x20a4f
movb $0x1, %r15b
jmp 0x26c8e
leaq -0x38(%rbp), %rdi
callq 0x2bbb4
movq (%r12), %r15
movl -0x38(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2bc76
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x34(%rbp)
movswq -0x32(%rbp), %rcx
movq 0x8(%r15), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq %ax, %r13
shlq $0x2, %r13
addq (%rdx,%rcx,8), %r13
callq 0x2bbf6
leaq -0x38(%rbp), %rdi
callq 0x2bb9c
movq %rax, %rdi
callq 0x2bb9c
movq (%r12), %r15
movl -0x38(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x2bc76
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq -0x2e(%rbp), %rcx
movq 0x8(%r15), %rdx
leaq (%rcx,%rcx,2), %rcx
movswq %ax, %r15
shlq $0x2, %r15
addq (%rdx,%rcx,8), %r15
callq 0x2bbf6
movzwl (%r15), %eax
andl $0x1, %eax
movzwl (%r13), %ecx
andl $0x1, %ecx
cmpw %cx, %ax
jne 0x26bfa
movl -0x3c(%rbp), %edi
callq 0x2bbcc
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x22ace
movb $0x1, %r15b
testb %al, %al
jne 0x26c73
movl (%r14), %eax
movl %eax, 0x8(%rbx)
movl -0x3c(%rbp), %edi
callq 0x2bbcc
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x2bc76
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x26926
movl %eax, %r15d
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
jmp 0x26c73
testw %ax, %ax
movq -0x48(%rbp), %r14
jne 0x26c1c
leaq -0x3c(%rbp), %rdi
callq 0x2bbb4
movq %rax, %rdi
callq 0x2bbb4
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x26c2d
leaq -0x3c(%rbp), %rdi
callq 0x2bb9c
movq %rax, %rdi
callq 0x2bb9c
movl -0x3c(%rbp), %esi
movq %r14, %rdi
callq 0x22ace
movb $0x1, %r15b
testb %al, %al
jne 0x26c73
movl -0x3c(%rbp), %edi
callq 0x2bbcc
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %eax, %edx
callq 0x2bc76
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, 0x8(%rbx)
callq 0x2bbf6
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x26926
movl %eax, %r15d
leaq -0x34(%rbp), %rdi
callq 0x2bbf6
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x40(%rbp), %rdi
callq 0x2bbf6
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 0x21634
movb %r15b, 0xe(%rax)
movq (%r12), %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 0x20a4f
jmp 0x26c8e
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x2bbf6
jmp 0x26d0b
jmp 0x26d08
jmp 0x26d08
jmp 0x26d08
jmp 0x26d08
jmp 0x26d08
jmp 0x26d08
jmp 0x26cfe
jmp 0x26d03
movq %rax, %rbx
jmp 0x26d14
movq %rax, %rbx
jmp 0x26d1d
movq %rax, %rbx
leaq -0x34(%rbp), %rdi
callq 0x2bbf6
leaq -0x30(%rbp), %rdi
callq 0x2bbf6
leaq -0x40(%rbp), %rdi
callq 0x2bbf6
movq %rbx, %rdi
callq 0x4750