// File: 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
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x3b9fe(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x3d2d0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x56a05
movq -0x20(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2b, %eax
je 0x569e5
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x56446
movq -0xb0(%rbp), %rdi
leaq 0x365eb(%rip), %rsi     # 0x8ca18
leaq 0x368e4(%rip), %rdx     # 0x8cd18
xorl %eax, %eax
movl %eax, %ecx
callq 0x55e0
movq %rax, -0xb8(%rbp)
jmp 0x56451
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x56451
movq -0xb8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x569e5
movq -0x10(%rbp), %rsi
leaq -0x2c(%rbp), %rdi
callq 0x1b190
movq -0x28(%rbp), %rdi
callq 0x584d0
movl %eax, -0xbc(%rbp)
jmp 0x56484
movl -0xbc(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x30(%rbp), %edx
leaq -0x44(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x60550
jmp 0x564a5
leaq -0x44(%rbp), %rdi
movl $0x3, %esi
callq 0x48080
jmp 0x564b5
leaq -0x44(%rbp), %rdi
callq 0x60460
leaq -0x5c(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
jmp 0x564cd
leaq -0x60(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x60430
jmp 0x564dc
movl -0x30(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x5664d
leaq -0x40(%rbp), %rdi
callq 0x603d0
jmp 0x564fb
leaq 0x3b8d6(%rip), %rax     # 0x91dd8
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movl -0x40(%rbp), %edx
leaq -0x64(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x60550
jmp 0x5651e
movq -0xc8(%rbp), %rdi
movl -0x64(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x3d2d0
movq %rax, -0xd0(%rbp)
jmp 0x5653d
movq -0xd0(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x60460
leaq -0x40(%rbp), %rdi
callq 0x60390
movq %rax, -0xd8(%rbp)
jmp 0x56563
movq -0xd8(%rbp), %rdi
callq 0x60390
jmp 0x56571
leaq 0x3b860(%rip), %rax     # 0x91dd8
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
movl -0x40(%rbp), %edx
leaq -0x68(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x60550
jmp 0x56594
movq -0xe0(%rbp), %rdi
movl -0x68(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rsi
callq 0x3d2d0
movq %rax, -0xe8(%rbp)
jmp 0x565b3
movq -0xe8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x60460
jmp 0x56770
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x569d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x44(%rbp), %rdi
callq 0x60460
jmp 0x569d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x569ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x569c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x64(%rbp), %rdi
callq 0x60460
jmp 0x569c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x60460
jmp 0x569c5
leaq -0x40(%rbp), %rdi
callq 0x60390
movq %rax, -0xf0(%rbp)
jmp 0x5665f
movq -0xf0(%rbp), %rdi
callq 0x60390
jmp 0x5666d
leaq 0x3b764(%rip), %rax     # 0x91dd8
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x18(%rbp), %rsi
movl -0x40(%rbp), %edx
leaq -0x6c(%rbp), %rdi
callq 0x60550
jmp 0x56690
movq -0xf8(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rsi
callq 0x3d2d0
movq %rax, -0x100(%rbp)
jmp 0x566af
movq -0x100(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x6c(%rbp), %rdi
callq 0x60460
leaq 0x3b70e(%rip), %rax     # 0x91dd8
movq (%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0x40(%rbp), %edi
callq 0x60410
movl %eax, -0x104(%rbp)
jmp 0x566ef
movl -0x104(%rbp), %edx
movq -0x110(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x60550
jmp 0x56707
movq -0x118(%rbp), %rdi
movl -0x70(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x3d2d0
movq %rax, -0x120(%rbp)
jmp 0x56726
movq -0x120(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x60460
jmp 0x56770
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x6c(%rbp), %rdi
callq 0x60460
jmp 0x569c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x60460
jmp 0x569c5
movq -0x50(%rbp), %rax
movzwl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movq -0x58(%rbp), %rcx
movzwl (%rcx), %ecx
andl $0x1, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x568bb
movq -0x50(%rbp), %rax
movzwl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x567d4
leaq -0x30(%rbp), %rdi
callq 0x60390
movq %rax, -0x128(%rbp)
jmp 0x567c4
movq -0x128(%rbp), %rdi
callq 0x60390
jmp 0x567d2
jmp 0x567fa
leaq -0x30(%rbp), %rdi
callq 0x603d0
movq %rax, -0x130(%rbp)
jmp 0x567e6
movq -0x130(%rbp), %rdi
callq 0x603d0
jmp 0x567f4
movl -0x60(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x4e940
movb %al, -0x131(%rbp)
jmp 0x5680e
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x5681a
jmp 0x5682a
movb $0x1, -0x1(%rbp)
movl $0x1, -0x74(%rbp)
jmp 0x569a5
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0x30(%rbp), %edi
callq 0x60410
movl %eax, -0x138(%rbp)
jmp 0x56845
movl -0x138(%rbp), %edx
leaq -0x78(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x60550
jmp 0x5685a
movq -0x140(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x49fd0
jmp 0x5686c
leaq -0x78(%rbp), %rdi
callq 0x60460
movq -0x10(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x563c0
movb %al, -0x141(%rbp)
jmp 0x5688a
movb -0x141(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x74(%rbp)
jmp 0x569a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x60460
jmp 0x569c5
movq -0x28(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x30(%rbp), %edi
callq 0x60410
movl %eax, -0x148(%rbp)
jmp 0x568d6
movl -0x148(%rbp), %esi
movq -0x150(%rbp), %rdi
callq 0x4e940
movb %al, -0x151(%rbp)
jmp 0x568f0
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x568fc
jmp 0x5690c
movb $0x1, -0x1(%rbp)
movl $0x1, -0x74(%rbp)
jmp 0x569a5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x49fd0
jmp 0x5691b
movq -0x10(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x30(%rbp), %edi
callq 0x60410
movl %eax, -0x158(%rbp)
jmp 0x56941
movl -0x158(%rbp), %edx
movq -0x160(%rbp), %rsi
leaq -0x7c(%rbp), %rdi
callq 0x60550
jmp 0x56959
movq -0x168(%rbp), %rdi
leaq -0x7c(%rbp), %rsi
callq 0x563c0
movb %al, -0x169(%rbp)
jmp 0x56971
movb -0x169(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
leaq -0x7c(%rbp), %rdi
callq 0x60460
movl $0x1, -0x74(%rbp)
jmp 0x569a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x7c(%rbp), %rdi
callq 0x60460
jmp 0x569c5
leaq -0x60(%rbp), %rdi
callq 0x60460
leaq -0x5c(%rbp), %rdi
callq 0x60460
leaq -0x2c(%rbp), %rdi
callq 0x60460
jmp 0x56b6e
leaq -0x60(%rbp), %rdi
callq 0x60460
leaq -0x5c(%rbp), %rdi
callq 0x60460
leaq -0x2c(%rbp), %rdi
callq 0x60460
jmp 0x56b7c
movq -0x10(%rbp), %rdi
callq 0x4d8d0
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x47f20
movb $0x1, -0x1(%rbp)
jmp 0x56b6e
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x56b30
movq -0x18(%rbp), %rdi
callq 0x495b0
movq %rax, -0x88(%rbp)
leaq 0x3c5c1(%rip), %rdi     # 0x92ff0
callq 0x3d190
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3d160
testb $0x1, %al
jne 0x56a54
jmp 0x56a74
movq -0x10(%rbp), %rdi
callq 0x4d8d0
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x47f20
movb $0x1, -0x1(%rbp)
jmp 0x56b6e
movq -0x18(%rbp), %rdi
callq 0x49290
movq %rax, -0x98(%rbp)
leaq 0x3c5c5(%rip), %rdi     # 0x93050
callq 0x3d010
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3cfe0
testb $0x1, %al
jne 0x56ab0
jmp 0x56ae6
leaq -0x98(%rbp), %rdi
callq 0x3d040
movq %rax, %rdi
callq 0x3d0f0
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rsi
movq -0xa8(%rbp), %rdi
xorl %edx, %edx
callq 0x56b90
movb $0x1, -0x1(%rbp)
jmp 0x56b6e
movq -0x10(%rbp), %rdi
callq 0x4d8d0
movq -0x18(%rbp), %rdi
callq 0x496b0
movq %rax, %rdi
callq 0x4d8d0
leaq 0x3b2d1(%rip), %rax     # 0x91dd8
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x3d2d0
movzwl (%rax), %ecx
andl $-0x41, %ecx
movw %cx, (%rax)
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x47f20
movb $0x1, -0x1(%rbp)
jmp 0x56b6e
movq -0x20(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x54, %eax
jne 0x56b6a
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0x56b4d
jmp 0x56b6a
movq -0x10(%rbp), %rdi
callq 0x4d8d0
movq -0x18(%rbp), %rdi
movl $0x5, %esi
callq 0x47f20
movb $0x1, -0x1(%rbp)
jmp 0x56b6e
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x5920
nopw %cs:(%rax,%rax)