// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_combat.c
// Function: T_RadiusDamage
void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod)
{
	float	points;
	edict_t	*ent = NULL;
	vec3_t	v;
	vec3_t	dir;

#ifdef WEAP_BALANCE_OK	
	float vlength, adjuster; //surt weaponbalance
#endif

	while ((ent = findradius(ent, inflictor->s.origin, radius)) != NULL)
	{
		if (ent == ignore)
			continue;
		if (!ent->takedamage)
			continue;

		VectorAdd (ent->mins, ent->maxs, v);
		VectorMA (ent->s.origin, 0.5, v, v);
		VectorSubtract (inflictor->s.origin, v, v);

#ifdef WEAP_BALANCE_OK	
		if ((int)ctfflags->value & CTF_WEAP_BALANCE)
		{
			vlength = VectorLength(v); //hopefully in id-units
			//'corrected' radius damage formula
			if (vlength < 1)
				vlength = 0; //no negatives
			if (radius < 1)
				radius = 1; //no divide by zero, no negatives
			adjuster = 1 - (vlength / radius);
			//as vlength approaches radius, adjuster approaches zero
			//we then multiply this value into the damage, so that
			//damage approaches zero at the radius of the explosion
			points = damage * adjuster;
			//assuming id calculated the vector length correctly, then
			//this should be a drop off of r over the radius, making
			//it worst to be very close to the center of an explosion,
			//but also allowing you to 'feel' a big explosion nearby
		}
		else //original id code
			points = damage - 0.5 * VectorLength (v);
#else
		points = damage - 0.5 * VectorLength (v);
#endif

		if (ent == attacker)
			points = points * 0.5;
		if (points > 0)
		{
			if (CanDamage (ent, inflictor))
			{
				VectorSubtract (ent->s.origin, inflictor->s.origin, dir);
				T_Damage (ent, inflictor, attacker, dir, inflictor->s.origin, vec3_origin, (int)points, (int)points, DAMAGE_RADIUS, mod);
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x18(%rsp)
movss %xmm1, 0x14(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
leaq 0x4(%rdi), %r13
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %ebx, %ebx
movq %rsp, %rbp
movq %rbx, %rdi
movq %r13, %rsi
movss 0x14(%rsp), %xmm0
callq 0x19a50
testq %rax, %rax
je 0x29b73
movq %rax, %rbx
cmpq %r14, %rax
je 0x29a2f
cmpl $0x0, 0x27c(%rbx)
je 0x29a2f
movsd 0xcc(%rbx), %xmm0
movsd 0xd8(%rbx), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%rsp)
movss 0xd4(%rbx), %xmm0
addss 0xe0(%rbx), %xmm0
movss %xmm0, 0x8(%rsp)
leaq 0x4(%rbx), %rdi
movss 0x2696d(%rip), %xmm0    # 0x50400
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x19940
movsd 0x4(%r12), %xmm0
movsd (%rsp), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, (%rsp)
movss 0xc(%r12), %xmm0
subss 0x8(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq %rbp, %rdi
callq 0x19460
cvtss2sd %xmm0, %xmm0
mulsd 0x28120(%rip), %xmm0    # 0x51bf8
addsd 0x20(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
cmpq %r15, %rbx
jne 0x29aef
mulss 0x26911(%rip), %xmm0    # 0x50400
ucomiss 0x25e9a(%rip), %xmm0    # 0x4f990
jbe 0x29a2f
movq %rbx, %rdi
movq %r12, %rsi
movss %xmm0, 0x10(%rsp)
callq 0x189b0
movss 0x10(%rsp), %xmm2
testl %eax, %eax
je 0x29a2f
movsd 0x4(%rbx), %xmm0
movsd 0x4(%r12), %xmm1
subps %xmm1, %xmm0
movlps %xmm0, 0x28(%rsp)
movss 0xc(%rbx), %xmm0
subss 0xc(%r12), %xmm0
movss %xmm0, 0x30(%rsp)
cvttss2si %xmm2, %eax
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
leaq 0x28(%rsp), %rcx
movq %r13, %r8
movq 0x3cc0b(%rip), %r9      # 0x66768
pushq 0x18(%rsp)
pushq $0x1
pushq %rax
pushq %rax
callq 0x19260
addq $0x20, %rsp
jmp 0x29a2f
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop