// File: /workspace/github_cpp_makefile_star2_O2/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 0x21016(%rip), %r13     # 0x41c58
movq (%r13), %rax
movswq 0x2(%rsi), %rcx
movq 0x8(%rax), %rdx
imulq $0x18, %rcx, %rcx
movswq (%rsi), %rax
movq (%rdx,%rcx), %rcx
movzwl (%rcx,%rax,4), %edx
testb $0x1, %dl
jne 0x20d92
testq %rbx, %rbx
je 0x20dc4
cmpb $0x2b, 0x2(%rcx,%rax,4)
je 0x20dc4
leaq 0x1c0d5(%rip), %rsi     # 0x3cd58
leaq 0x1c0b6(%rip), %rdx     # 0x3cd40
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4450
testq %rax, %rax
je 0x20dc4
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 0x24e0c
leaq -0x30(%rbp), %rdi
pushq $0x3
popq %rsi
callq 0x1b202
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x24d90
testb $0x1, %r12b
movq %r15, -0x50(%rbp)
movl %r12d, -0x44(%rbp)
jne 0x20e00
leaq -0x34(%rbp), %rdi
callq 0x24d4c
movq %rax, %rdi
callq 0x24d4c
movq (%r13), %r15
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
callq 0x24e0c
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq %ax, %r12
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r15), %rcx
imulq $0x18, %rax, %rax
shlq $0x2, %r12
addq (%rcx,%rax), %r12
callq 0x24d9e
movq (%r13), %r13
movl -0x34(%rbp), %edi
callq 0x24d7c
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x24e0c
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x38(%rbp)
movswq %ax, %r15
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r13), %rcx
imulq $0x18, %rax, %rax
shlq $0x2, %r15
addq (%rcx,%rax), %r15
jmp 0x20e90
testb $0x40, %dl
jne 0x20db3
cmpb $0x54, 0x2(%rcx,%rax,4)
jne 0x20dab
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
testb %al, %al
jne 0x20dc4
xorl %r15d, %r15d
jmp 0x20f95
movq %r14, %rdi
callq 0x1bb64
cmpq 0x1c216(%rip), %rax     # 0x3cfd8
je 0x20ddb
movb $0x1, 0xe(%rbx)
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x1b103
movb $0x1, %r15b
jmp 0x20f95
movq %r14, %rdi
callq 0x1b9db
cmpq 0x1c1be(%rip), %rax     # 0x3cfa8
je 0x20fa7
movq 0x20(%rax), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x21033
jmp 0x20dd3
leaq -0x34(%rbp), %rdi
callq 0x24d64
movq (%r13), %r12
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x24e0c
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x38(%rbp)
movswq %ax, %r15
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r12), %rcx
imulq $0x18, %rax, %rax
shlq $0x2, %r15
addq (%rcx,%rax), %r15
callq 0x24d9e
leaq -0x34(%rbp), %rdi
callq 0x24d4c
movq %rax, %rdi
callq 0x24d4c
movq (%r13), %r13
movl -0x34(%rbp), %edx
leaq -0x2c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x24e0c
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, -0x30(%rbp)
movswq %ax, %r12
shrl $0x10, %eax
movswq %ax, %rax
movq 0x8(%r13), %rcx
imulq $0x18, %rax, %rax
shlq $0x2, %r12
addq (%rcx,%rax), %r12
callq 0x24d9e
movzwl (%r12), %eax
andl $0x1, %eax
movzwl (%r15), %ecx
andl $0x1, %ecx
cmpw %cx, %ax
jne 0x20f01
movl -0x44(%rbp), %r12d
movl %r12d, %edi
callq 0x24d7c
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x1d408
movb $0x1, %r15b
testb %al, %al
jne 0x20f7a
movl (%r14), %eax
movl %eax, 0x8(%rbx)
movl %r12d, %edi
callq 0x24d7c
leaq -0x2c(%rbp), %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x24e0c
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x20c24
movl %eax, %r15d
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
jmp 0x20f7a
testw %ax, %ax
movq -0x50(%rbp), %r14
jne 0x20f23
leaq -0x3c(%rbp), %rdi
callq 0x24d64
movq %rax, %rdi
callq 0x24d64
movl -0x38(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x20f34
leaq -0x3c(%rbp), %rdi
callq 0x24d4c
movq %rax, %rdi
callq 0x24d4c
movl -0x3c(%rbp), %esi
movq %r14, %rdi
callq 0x1d408
movb $0x1, %r15b
testb %al, %al
jne 0x20f7a
movl -0x3c(%rbp), %edi
callq 0x24d7c
leaq -0x2c(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl %eax, %edx
callq 0x24e0c
leaq -0x2c(%rbp), %rdi
movl (%rdi), %eax
movl %eax, 0x8(%rbx)
callq 0x24d9e
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x20c24
movl %eax, %r15d
leaq -0x38(%rbp), %rdi
callq 0x24d9e
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x40(%rbp), %rdi
callq 0x24d9e
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 0x1bbe4
movb %r15b, 0xe(%rax)
movq (%r13), %rax
movswq 0x2(%r14), %rcx
movq 0x8(%rax), %rax
imulq $0x18, %rcx, %rcx
movswq (%r14), %rdx
movq (%rax,%rcx), %rax
andw $-0x41, (%rax,%rdx,4)
pushq $0x5
popq %rsi
movq %r14, %rdi
callq 0x1b103
jmp 0x20f95
movq %rax, %rbx
leaq -0x2c(%rbp), %rdi
callq 0x24d9e
jmp 0x21010
jmp 0x2100d
jmp 0x2100d
jmp 0x2100d
jmp 0x2100d
jmp 0x2100d
jmp 0x2100d
jmp 0x21003
jmp 0x21008
movq %rax, %rbx
jmp 0x21019
movq %rax, %rbx
jmp 0x21022
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x24d9e
leaq -0x30(%rbp), %rdi
callq 0x24d9e
leaq -0x40(%rbp), %rdi
callq 0x24d9e
movq %rbx, %rdi
callq 0x4710