// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movl %edx, %r12d
leaq -0x4154(%rip), %r8      # 0xd8e1
callq 0xfb30
movl %eax, %ebx
testb %al, %al
je 0x11b6f
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x78db(%rip), %rsi      # 0x19332
leaq 0x78d9(%rip), %rdx      # 0x19337
leaq 0x118(%rsp), %r14
movq %r14, %rdi
callq 0x16274
movq %r14, %rdi
callq 0x5eae
movb %bl, 0xb(%rsp)
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x11a8c
callq 0x5230
movl 0xf862(%rip), %ebx      # 0x212f4
xorl %r14d, %r14d
cmpq $0x3, %rbx
jae 0x11ada
leaq 0x6b6e(%rip), %r14      # 0x18610
leaq 0xf2c7(%rip), %rax      # 0x20d70
movq (%rax,%rbx,8), %r13
movq (%rax,%rbx,8), %r15
callq 0x5070
cltd
idivl (%r14,%rbx,4)
movl %edx, %r14d
leaq 0x6b57(%rip), %rax      # 0x1861c
addl (%rax,%rbx,4), %r14d
movl (%r13), %eax
leaq 0x6b54(%rip), %rcx      # 0x18628
addl (%rcx,%rbx,4), %eax
movl %eax, (%r15)
movslq %r12d, %rax
movslq %ebp, %rcx
imulq $0x4b0, %rax, %rax      # imm = 0x4B0
leaq 0x5ca12(%rip), %rdx     # 0x6e500
addq %rax, %rdx
movq (%rdx,%rcx,8), %r15
testq %r15, %r15
je 0x11bbd
movl %r12d, 0xc(%rsp)
movq %rbp, 0x50(%rsp)
movq %r14, %r12
movq %r15, %rbp
movq (%r15), %rbx
movl 0x3c(%rbx), %r14d
movl %r14d, %r15d
subl 0x40(%rbx), %r15d
callq 0x5070
cltd
idivl %r15d
movl %edx, %r13d
callq 0x5070
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
addl $0x2aaaaaaa, %eax       # imm = 0x2AAAAAAA
cmpl $0x55555555, %eax       # imm = 0x55555555
jb 0x11b4b
callq 0x5070
cltd
idivl %r14d
movl %edx, %r13d
testl %r13d, %r13d
sete %al
movq %r12, %r14
je 0x11bc1
cmpl %r15d, %r13d
movq %rbp, %r15
movq 0x50(%rsp), %rbp
movl 0xc(%rsp), %r12d
jge 0x11bd6
movl 0x40(%rbx), %ecx
incl %ecx
jmp 0x11bd3
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x77d3(%rip), %rsi      # 0x19355
leaq 0x77e3(%rip), %rdx      # 0x1936c
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
callq 0x16274
movq %r14, %rdi
callq 0x5eae
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x11bb3
callq 0x5230
callq 0x74e9
jmp 0x12091
xorl %eax, %eax
jmp 0x11bee
movl 0x3c(%rbx), %ecx
decl %ecx
movq %rbp, %r15
movq 0x50(%rsp), %rbp
movl 0xc(%rsp), %r12d
movl %ecx, 0x40(%rbx)
movl 0x3c(%rbx), %edx
movl 0x40(%rbx), %esi
leal -0x1(%rdx), %ecx
cmpl %ecx, %esi
jne 0x11be7
movb $0x1, 0x44(%rbx)
cmpl %edx, %esi
jl 0x11bee
movl %ecx, 0x40(%rbx)
cmpl $0x2, 0xf6ff(%rip)      # 0x212f4
movb 0xb(%rsp), %bl
jne 0x11c5f
testb %al, %al
je 0x11e6f
movl $0xf0, %edx
addq (%r15), %rdx
leaq 0x75e2(%rip), %rsi      # 0x191f4
leaq 0x98(%rsp), %r13
movq %r13, %rdi
callq 0x15e6b
leaq 0x770f(%rip), %rsi      # 0x19338
movq %r13, %rdi
callq 0x5420
leaq 0x40(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11d20
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x11d26
testq %r15, %r15
je 0x11e8b
movl $0xf0, %edx
testb %al, %al
je 0x11cc9
addq (%r15), %rdx
leaq 0x7579(%rip), %rsi      # 0x191f4
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x15e6b
leaq 0x76a6(%rip), %rsi      # 0x19338
movq %r12, %rdi
callq 0x5420
leaq 0x40(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11efe
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x11f06
movq %r15, %r13
addq (%r15), %rdx
leaq 0x751e(%rip), %rsi      # 0x191f4
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x15e6b
leaq 0x7662(%rip), %rsi      # 0x1934c
movq %r12, %rdi
callq 0x5420
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11f5f
movq %rdx, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0x11f66
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%r15), %rax
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
callq 0x50c0
leaq 0x20(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
movl %r12d, %r13d
cmpq %rcx, %rdx
je 0x11d82
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x11d88
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %r15, %r12
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x759a(%rip), %rsi      # 0x19348
callq 0x5420
leaq 0xc8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11de3
movq %rdx, 0xb8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc8(%rsp)
jmp 0x11dea
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 0x5eae
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x11e20
callq 0x5230
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movq %r12, %r15
je 0x11e37
callq 0x5230
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
movl %r13d, %r12d
je 0x11e4e
callq 0x5230
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11e64
callq 0x5230
movq %r15, %rdi
movl %r14d, %esi
callq 0x11581
movl %r12d, %eax
movq %rbp, %rdi
shlq $0x20, %rdi
orq %rax, %rdi
shlq $0x20, %r14
incq %r14
movq %r14, %rsi
callq 0x1159e
cmpl %r12d, 0x5c372(%rip)    # 0x6e204
jne 0x12091
cmpl %ebp, 0x5c36a(%rip)     # 0x6e208
jne 0x12091
cmpl $0x1, 0xf449(%rip)      # 0x212f4
ja 0x12091
leaq 0xe8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x74a9(%rip), %rsi      # 0x1936d
leaq 0x74cc(%rip), %rdx      # 0x19397
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
callq 0x16274
movq %r14, %rdi
callq 0x5eae
movq 0xd8(%rsp), %rdi
cmpq %r15, %rdi
je 0x12091
callq 0x5230
jmp 0x12091
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%r15), %rax
movq 0x130(%rax), %rsi
movq 0x138(%rax), %rdx
callq 0x50c0
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11fb5
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x11fbd
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 0x5eae
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x11f96
callq 0x5230
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq %r13, %r15
je 0x12086
callq 0x5230
jmp 0x12086
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq %r15, %rbp
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x7365(%rip), %rsi      # 0x19348
callq 0x5420
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x12015
movq %rdx, 0x78(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x88(%rsp)
jmp 0x1201c
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 0x5eae
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x1204c
callq 0x5230
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
movq %rbp, %r15
je 0x1205e
callq 0x5230
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x1206d
callq 0x5230
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12083
callq 0x5230
addl %r14d, %r14d
movq %r15, %rdi
movl %r14d, %esi
callq 0x11581
movl %ebx, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x120bc
callq 0x5230
jmp 0x120bc
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x120e4
callq 0x5230
jmp 0x120e4
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x120f3
callq 0x5230
jmp 0x120f3
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
jne 0x1213e
jmp 0x12148
movq %rax, %rbx
leaq 0x20(%rsp), %rax
jmp 0x12150
jmp 0x12145
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r15, %rdi
je 0x12116
callq 0x5230
jmp 0x12116
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1212f
callq 0x5230
jmp 0x1212f
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x12148
callq 0x5230
jmp 0x12148
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x12185
jmp 0x1218a
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
jmp 0x12180
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
jmp 0x12180
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0x1218a
callq 0x5230
movq %rbx, %rdi
callq 0x53d0