// File: /workspace/github_cpp_makefile_star2_O3/essarrdee[P]mutantaliens/mutantaliens.cpp
// Function: fire_weapon(int, int, int, int)
bool fire_weapon(int x1, int y1, int x2, int y2)
{
	if(los_exists(x1,y1,x2,y2,blocks_shots))
	{
		add_message("BANG!");
		int damage = 0;
		switch(current_weapon)
		{
			case PISTOL:
				damage = rand()%2 + 1;
				ammo[PISTOL] -= 1;
				break;
			case RIFLE:
				damage = rand()%4+1;
				ammo[RIFLE] -= 4;
				break;
			case CANNON:
				damage = rand()%4+5;
				ammo[CANNON] -= 1;
				break;
		}
		actor* victim = map_occupants[x2][y2];
		bool crit = false;
		if(victim != NULL)
		{
			species* vsp = victim->sspecies;

			int bss = vsp->body_sections;
			int bst = vsp->body_sections_tried;
			int bsr = bss - bst; // body sections remaining. 1 if crit_known
			int bs = rand()%bsr; // aim at a body section that could be the crit section
			if(rand()%3) // miss
			{
				bs = rand()%bss; // hit anywhere
			}
			crit = (bs == 0);
			if(crit) {vsp->body_sections_tried = vsp->body_sections - 1;} // if you crit, you learn how
			else if(bs < bsr) {vsp->body_sections_tried += 1;}
			if(vsp->body_sections_tried == vsp->body_sections - 1) {vsp->crit_known = true;}
			if(vsp->body_sections_tried >= vsp->body_sections) {vsp->body_sections_tried = vsp->body_sections - 1;} // just make sure
		}
		
		if(current_weapon == CANNON)
		{
			if(crit)
			{
				add_message("The "+victim->sspecies->name+" is hit in the "+victim->sspecies->crit_part_name+"!!!");
				hurt_actor(victim,damage);
			}
			explosion ex;
			ex.x = x2; ex.y = y2;
			ex.centre_damage = damage; ex.radius = 1;
			do_explosion(ex);
		}
		else
		if(victim != NULL)
		{
			if(crit)
			{
				add_message("The "+victim->sspecies->name+" is hit in the "+victim->sspecies->crit_part_name+"!!!");
				hurt_actor(victim,2*damage);
			}
			else
			{
			add_message("The "+victim->sspecies->name+" is hit!");
			hurt_actor(victim,damage);
			}
			return true;
		}
	}
	else
	{
		add_message("Can't get a clear shot!"); 
		draw_last_msg();
		return false;
	}
	if(target_x == x2 && target_y == y2)
	{
		if(current_weapon == PISTOL || current_weapon == RIFLE)
		{
			add_message("Use explosives to destroy the transmitter!");
		}
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %ecx, %r12d
movl %edx, %ebp
leaq -0x4065(%rip), %r8      # 0xd3c3
callq 0xf58f
movl %eax, %ebx
testb %al, %al
je 0x1154e
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7f58(%rip), %rsi      # 0x193a2
leaq 0x7f56(%rip), %rdx      # 0x193a7
leaq 0x118(%rsp), %r14
movq %r14, %rdi
callq 0x15b1a
movq %r14, %rdi
callq 0x5f0e
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x1147b
callq 0x5230
movb %bl, 0x7(%rsp)
movl 0xfe5f(%rip), %ebx      # 0x212e4
xorl %r14d, %r14d
cmpq $0x3, %rbx
jae 0x114c7
leaq 0x71ef(%rip), %r14      # 0x18684
leaq 0xf8d4(%rip), %rax      # 0x20d70
movq (%rax,%rbx,8), %r13
leaq 0x71f5(%rip), %rax      # 0x1869c
movl (%rax,%rbx,4), %r15d
callq 0x5070
cltd
idivl (%r14,%rbx,4)
movl %edx, %r14d
leaq 0x71d1(%rip), %rax      # 0x18690
addl (%rax,%rbx,4), %r14d
addl %r15d, (%r13)
movslq %ebp, %rax
movslq %r12d, %rcx
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
leaq 0x5d015(%rip), %rdx     # 0x6e4f0
addq %rax, %rdx
movq (%rdx,%rcx,8), %rax
testq %rax, %rax
je 0x1159c
movl %ebp, 0x14(%rsp)
movq %r12, %rbp
movq %r14, %r12
movq %rax, 0x8(%rsp)
movq (%rax), %r15
movl 0x3c(%r15), %r14d
movl %r14d, %ebx
subl 0x40(%r15), %ebx
callq 0x5070
cltd
idivl %ebx
movl %edx, %r13d
callq 0x5070
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
addl $0x2aaaaaaa, %eax       # imm = 0x2AAAAAAA
cmpl $0x55555555, %eax       # imm = 0x55555555
jb 0x11536
callq 0x5070
cltd
idivl %r14d
movl %edx, %r13d
testl %r13d, %r13d
movq %r12, %r14
je 0x115b0
movl 0x40(%r15), %eax
cmpl %ebx, %r13d
movq %rbp, %r12
jge 0x115c3
incl %eax
jmp 0x115b9
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7e64(%rip), %rsi      # 0x193c5
leaq 0x7e74(%rip), %rdx      # 0x193dc
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
callq 0x15b1a
movq %r14, %rdi
callq 0x5f0e
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x11592
callq 0x5230
callq 0x74d7
jmp 0x11a88
movl 0xfd42(%rip), %eax      # 0x212e4
cmpl $0x2, %eax
je 0x11972
jmp 0x11993
movl 0x3c(%r15), %eax
decl %eax
movq %rbp, %r12
movl 0x14(%rsp), %ebp
movl %eax, 0x40(%r15)
jmp 0x115c7
movl 0x14(%rsp), %ebp
movl 0x3c(%r15), %edx
leal -0x1(%rdx), %ecx
cmpl %ecx, %eax
jne 0x115d7
movb $0x1, 0x44(%r15)
cmpl %edx, %eax
jl 0x115df
movl %ecx, 0x40(%r15)
cmpl $0x2, 0xfcfe(%rip)      # 0x212e4
jne 0x11655
testl %r13d, %r13d
jne 0x11972
movl $0xf0, %edx
movq 0x8(%rsp), %rax
addq (%rax), %rdx
leaq 0x7c5f(%rip), %rsi      # 0x19264
leaq 0x98(%rsp), %r13
movq %r13, %rdi
callq 0x157ab
leaq 0x7d8c(%rip), %rsi      # 0x193a8
movq %r13, %rdi
callq 0x5410
leaq 0x48(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11765
movq %rsi, %rbx
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x1176e
movl $0xf0, %edx
testl %r13d, %r13d
je 0x116b6
movq 0x8(%rsp), %r13
addq (%r13), %rdx
leaq 0x7bf5(%rip), %rsi      # 0x19264
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x157ab
leaq 0x7d39(%rip), %rsi      # 0x193bc
movq %r12, %rdi
callq 0x5410
movb 0x7(%rsp), %bl
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11713
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x1171a
movq 0x8(%rsp), %rbx
addq (%rbx), %rdx
leaq 0x7b9f(%rip), %rsi      # 0x19264
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x157ab
leaq 0x7ccc(%rip), %rsi      # 0x193a8
movq %r12, %rdi
callq 0x5410
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x117cc
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0x117d4
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x58(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0x5f0e
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x1174a
callq 0x5230
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1175d
callq 0x5230
movq %r13, %rdi
jmp 0x11a80
movups (%rcx), %xmm0
movq %rsi, %rbx
movups %xmm0, (%rsi)
movq 0x8(%rsp), %rsi
movq 0x8(%rax), %rdx
leaq 0x38(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rsi), %rax
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
callq 0x50c0
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1182d
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x11835
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x38(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rbx), %rax
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
callq 0x50c0
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1188d
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x11895
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x7b60(%rip), %rsi      # 0x193b8
callq 0x5410
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x118f1
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x118f8
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x7b00(%rip), %rsi      # 0x193b8
callq 0x5410
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11a06
movq %rdx, 0x78(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x88(%rsp)
jmp 0x11a0d
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0xb8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0x5f0e
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x1192e
callq 0x5230
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x1193d
callq 0x5230
movq 0x38(%rsp), %rdi
cmpq %rbx, %rdi
movq 0x8(%rsp), %rbx
je 0x11951
callq 0x5230
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11967
callq 0x5230
movq %rbx, %rdi
movl %r14d, %esi
callq 0x10f8c
movl %ebp, %eax
movq %r12, %rdi
shlq $0x20, %rdi
orq %rax, %rdi
shlq $0x20, %r14
incq %r14
movq %r14, %rsi
callq 0x10fa9
movl 0xf951(%rip), %eax      # 0x212e4
cmpl %ebp, 0x5c85b(%rip)     # 0x6e1f4
movb 0x7(%rsp), %bl
jne 0x11a88
cmpl %r12d, 0x5c84e(%rip)    # 0x6e1f8
jne 0x11a88
cmpl $0x1, %eax
ja 0x11a88
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x7a11(%rip), %rsi      # 0x193dd
leaq 0x7a34(%rip), %rdx      # 0x19407
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0x15b1a
movq %r14, %rdi
callq 0x5f0e
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x11a88
callq 0x5230
jmp 0x11a88
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x78(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0x5f0e
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x11a3d
callq 0x5230
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x11a4c
callq 0x5230
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
movb 0x7(%rsp), %bl
movq 0x8(%rsp), %r15
je 0x11a64
callq 0x5230
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11a7a
callq 0x5230
addl %r14d, %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0x10f8c
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x11aca
callq 0x5230
jmp 0x11aca
movq %rax, %r14
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x11ade
callq 0x5230
jmp 0x11ade
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x11af2
callq 0x5230
jmp 0x11af2
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x11b01
callq 0x5230
jmp 0x11b01
movq %rax, %r14
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
jne 0x11b0b
jmp 0x11b17
movq %rax, %r14
movq 0x38(%rsp), %rdi
cmpq %rbx, %rdi
je 0x11b17
callq 0x5230
jmp 0x11b17
jmp 0x11b14
movq %rax, %r14
leaq 0xa8(%rsp), %rax
jmp 0x11b3d
movq %rax, %r14
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x11b38
callq 0x5230
jmp 0x11b38
movq %rax, %r14
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x11b72
jmp 0x11b77
movq %rax, %r14
movq 0xd8(%rsp), %rdi
jmp 0x11b6d
movq %rax, %r14
movq 0xf8(%rsp), %rdi
jmp 0x11b6d
movq %rax, %r14
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x11b77
callq 0x5230
movq %r14, %rdi
callq 0x53d0