Explosives should now do more accurate damage calculation.

This commit is contained in:
Marco Cawthorne 2023-04-17 00:36:36 -07:00
parent 2aed2e5f72
commit 9eaa455ba2
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
4 changed files with 47 additions and 2 deletions

View File

@ -17,6 +17,7 @@
class HLGameRules:NSGameRules
{
virtual void DamageApply(entity, entity, float, int, damageType_t);
virtual void DamageRadius(vector, entity, float, float, int, int);
virtual void PlayerConnect(NSClientPlayer);
virtual void PlayerDisconnect(NSClientPlayer);
virtual void PlayerKill(NSClientPlayer);

View File

@ -50,6 +50,50 @@ HLGameRules::DamageApply(entity t, entity c, float dmg, int w, damageType_t type
super::DamageApply(t, c, dmg, w, type);
}
void
HLGameRules::DamageRadius(vector org, entity attacker, float dmg, float r, int check, int w)
{
float new_dmg;
float dist;
float diff;
vector pos;
for (entity e = world; (e = findfloat(e, ::takedamage, DAMAGE_YES));) {
pos[0] = e.absmin[0] + (0.5 * (e.absmax[0] - e.absmin[0]));
pos[1] = e.absmin[1] + (0.5 * (e.absmax[1] - e.absmin[1]));
pos[2] = e.absmin[2] + (0.5 * (e.absmax[2] - e.absmin[2]));
/* don't bother if it's not anywhere near us */
dist = vlen(org - pos);
if (dist > r)
continue;
/* can we physically hit this thing? */
if (check == TRUE)
if (DamageCheckTrace(e, org) == FALSE)
continue;
/* calculate new damage values */
diff = (r - dist) / r;
new_dmg = rint(dmg * diff);
if (diff > 0) {
g_dmg_vecLocation = org;
if (e == attacker)
new_dmg *= 0.5f;
DamageApply(e, attacker, new_dmg, w, DMG_EXPLODE);
/* approximate, feel free to tweak */
if (e.movetype == MOVETYPE_WALK) {
makevectors(vectoangles(e.origin - org));
e.velocity += v_forward * (new_dmg * 5);
}
}
}
}
void
HLGameRules::LevelDecodeParms(NSClientPlayer pp)
{

View File

@ -95,7 +95,7 @@ w_grenadelauncher_shootnade(player pl)
static void Grenade_Explode(void) {
float dmg = Skill_GetValue("plr_grenadelauncher", 120);
FX_Explosion(self.origin);
Damage_Radius(self.origin, self.owner, dmg, dmg * 2.5f, TRUE, WEAPON_GRENADELAUNCHER);
Damage_Radius(self.origin, self.owner, dmg, dmg + 40, TRUE, WEAPON_GRENADELAUNCHER);
sound(self, CHAN_WEAPON, sprintf("weapons/explode%d.wav", floor(random() * 2) + 3), 1, ATTN_NORM);
remove(self);
}

View File

@ -117,7 +117,7 @@ w_rocketlauncher_primary(player pl)
}
FX_Explosion(self.origin);
Damage_Radius(self.origin, self.owner, radiusDamage, radiusDamage * 2.5f, TRUE, WEAPON_ROCKETLAUNCHER);
Damage_Radius(self.origin, self.owner, radiusDamage, radiusDamage + 40, TRUE, WEAPON_ROCKETLAUNCHER);
sound(self, CHAN_WEAPON, sprintf("weapons/explode%d.wav", floor(random() * 2) + 3), 1, ATTN_NORM);
remove(self);
}