// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_combat.c
// Function: CheckPowerArmor
static int CheckPowerArmor (edict_t *ent, vec3_t point, vec3_t normal, int damage, int dflags)
{
	gclient_t	*client;
	int			save;
	int			power_armor_type;
	int			index = 0; //MJD Fixes Compiler Warning
	int			damagePerCell;
	int			pa_te_type;
	int			power=0;
	int			power_used;

	if (!damage)
		return 0;

	client = ent->client;

	if (dflags & DAMAGE_NO_ARMOR)
		return 0;

	if (client)
	{
		power_armor_type = PowerArmorType (ent);
		if (power_armor_type != POWER_ARMOR_NONE)
		{
			index = ITEM_INDEX(FindItem("Cells"));
			power = client->pers.inventory[index];
		}
	}
#ifdef MONSTERS_OK
	else if (ent->svflags & SVF_MONSTER)
	{
		power_armor_type = ent->monsterinfo.power_armor_type;
		power = ent->monsterinfo.power_armor_power;
	}
#endif
	else
		return 0;

	if (power_armor_type == POWER_ARMOR_NONE)
		return 0; //MJD This catches the uninitilized index
		          //case, but I initilized it anyway...
	if (!power)
		return 0;

	if (power_armor_type == POWER_ARMOR_SCREEN)
	{
		vec3_t		vec;
		float		dot;
		vec3_t		forward;

		// only works if damage point is in front
		AngleVectors (ent->s.angles, forward, NULL, NULL);
		VectorSubtract (point, ent->s.origin, vec);
		VectorNormalize (vec);
		dot = DotProduct (vec, forward);
		if (dot <= 0.3)
			return 0;

		damagePerCell = 1;
		pa_te_type = TE_SCREEN_SPARKS;
#ifdef WEAP_BALANCE_OK	
		if ((int)ctfflags->value & CTF_WEAP_BALANCE) // LM_Jorm -- Reduce effectiveness
			damage = damage / 8;
		else
			damage = damage / 3;
#else
	  	damage = damage / 3;
#endif

	}
	else
	{
		damagePerCell = 1;
		if ((int)ctfflags->value & CTF_DM_POWER_ARMOR_STRENGTH)
			damagePerCell++;
		pa_te_type = TE_SHIELD_SPARKS;

#ifdef WEAP_BALANCE_OK
		if ((int)ctfflags->value & CTF_WEAP_BALANCE) // LM_Jorm -- Reduce effectiveness
			damage = damage / 4;
		else
			damage = (2 * damage) / 3;
#else
	  	damage = (2 * damage) / 3;
#endif

	}

	save = power * damagePerCell;
	if (!save)
		return 0;
	if (save > damage)
		save = damage;

	SpawnDamage (pa_te_type, point, normal, save);
	ent->powerarmor_time = level.time + 0.2;

	power_used = save / damagePerCell;

#ifdef WEAP_BALANCE_OK	
	if ((int)ctfflags->value & CTF_WEAP_BALANCE) //surt, cells get sucked faster
		power_used *= 3;
#endif

	if (client)
		client->pers.inventory[index] -= power_used;
	else
		ent->monsterinfo.power_armor_power -= power_used;
	return save;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x48(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x32e1b
movl $0x0, -0x4(%rbp)
jmp 0x33093
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x28(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x32e3e
movl $0x0, -0x4(%rbp)
jmp 0x33093
cmpq $0x0, -0x30(%rbp)
je 0x32e8e
movq -0x10(%rbp), %rdi
callq 0x18b80
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x32e8c
leaq 0x3fd15(%rip), %rdi     # 0x72b73
callq 0x18a90
movq 0x4ffd6(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0x318(%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
jmp 0x32e9a
movl $0x0, -0x4(%rbp)
jmp 0x33093
cmpl $0x0, -0x38(%rbp)
jne 0x32eac
movl $0x0, -0x4(%rbp)
jmp 0x33093
cmpl $0x0, -0x48(%rbp)
jne 0x32ebe
movl $0x0, -0x4(%rbp)
jmp 0x33093
cmpl $0x1, -0x38(%rbp)
jne 0x32fa1
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
leaq -0x68(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x183e0
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x4(%rax), %xmm0
movss %xmm0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x8(%rax), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0xc(%rax), %xmm0
movss %xmm0, -0x50(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x183d0
movss -0x58(%rbp), %xmm1
movss -0x68(%rbp), %xmm2
movss -0x54(%rbp), %xmm0
mulss -0x64(%rbp), %xmm0
mulss %xmm2, %xmm1
addss %xmm0, %xmm1
movss -0x50(%rbp), %xmm0
movss -0x60(%rbp), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x3fbc7(%rip), %xmm0    # 0x72b38
ucomisd %xmm1, %xmm0
jb 0x32f83
movl $0x0, -0x4(%rbp)
jmp 0x33093
movl $0x1, -0x40(%rbp)
movl $0xc, -0x44(%rbp)
movl -0x24(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
jmp 0x32fe1
movl $0x1, -0x40(%rbp)
movq 0x4fba9(%rip), %rax     # 0x82b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x32fca
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0xd, -0x44(%rbp)
movl -0x24(%rbp), %eax
shll %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movl -0x48(%rbp), %eax
imull -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x32ffd
movl $0x0, -0x4(%rbp)
jmp 0x33093
movl -0x34(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x3300b
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x34(%rbp), %ecx
callq 0x19cb0
movq 0x4fd7b(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3fb0a(%rip), %xmm1    # 0x72b40
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x268(%rax)
movl -0x34(%rbp), %eax
cltd
idivl -0x40(%rbp)
movl %eax, -0x4c(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x33078
movl -0x4c(%rbp), %esi
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0x318(%rax,%rcx,4), %edx
subl %esi, %edx
movl %edx, 0x318(%rax,%rcx,4)
jmp 0x3308d
movl -0x4c(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x45c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x45c(%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)