Skip to content

Commit

Permalink
treat dmg key as a literal value, not a multiplier
Browse files Browse the repository at this point in the history
for custom weapon damage
  • Loading branch information
wootguy committed Dec 20, 2024
1 parent 53f3518 commit 97161ae
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 85 deletions.
3 changes: 2 additions & 1 deletion cl_dll/hl/hl_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ int CBaseMonster::TaskIsRunning( void ) { return 0; }
void CBaseMonster::ScheduleChange( void ) { }
void CBaseMonster::SetClassify( int ) { }
void CBaseMonster::Revive( void ) { }
float CBaseMonster::GetDamage(float defaultDamage) { return defaultDamage; }
int CBaseEntity::IRelationship ( CBaseEntity *pTarget ) { return 0; }
BOOL CBaseMonster :: FindCover ( Vector vecThreat, Vector vecViewOffset, float flMinDist, float flMaxDist ) { return FALSE; }
BOOL CBaseMonster :: BuildNearestRoute ( Vector vecThreat, Vector vecViewOffset, float flMinDist, float flMaxDist ) { return FALSE; }
Expand Down Expand Up @@ -330,6 +331,7 @@ void CBasePlayer::AddPointsToTeam( int score, BOOL bAllowNegativeScore ) { }
Vector CBasePlayer::BodyTarget(const Vector& posSrc) { return Vector(); }
void CBasePlayer::Revive() { }
float CBasePlayer::GetDamageModifier() { return 0; }
float CBasePlayer::GetDamage(float defaultDamage) { return defaultDamage; }

void ClearMultiDamage(void) { }
void ApplyMultiDamage(entvars_t *pevInflictor, entvars_t *pevAttacker ) { }
Expand Down Expand Up @@ -369,7 +371,6 @@ BOOL CBasePlayerWeapon :: AddSecondaryAmmo( int iCount, char *szName, int iMax )
BOOL CBasePlayerWeapon :: IsUseable( void ) { return TRUE; }
int CBasePlayerWeapon::PrimaryAmmoIndex( void ) { return -1; }
int CBasePlayerWeapon::SecondaryAmmoIndex( void ) { return -1; }
float CBasePlayerWeapon::GetDamageModifier() { return 1.0f; }
void CBasePlayerAmmo::Spawn( void ) { }
CBaseEntity* CBasePlayerAmmo::Respawn( void ) { return this; }
void CBasePlayerAmmo::Materialize( void ) { }
Expand Down
13 changes: 6 additions & 7 deletions dlls/CBaseEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,7 @@ Vector CBaseEntity::FireBulletsPlayer(ULONG cShots, Vector vecSrc, Vector vecDir
ClearMultiDamage();
gMultiDamage.type = DMG_BULLET | DMG_NEVERGIB;

float dmg_mult = GetDamageModifier();
iDamage *= dmg_mult;
iDamage = GetDamage(iDamage);

for (ULONG iShot = 1; iShot <= cShots; iShot++)
{
Expand Down Expand Up @@ -836,24 +835,24 @@ Vector CBaseEntity::FireBulletsPlayer(ULONG cShots, Vector vecSrc, Vector vecDir
{
default:
case BULLET_PLAYER_9MM:
pEntity->TraceAttack(pevAttacker, gSkillData.sk_plr_9mm_bullet * dmg_mult, vecDir, &tr, DMG_BULLET);
pEntity->TraceAttack(pevAttacker, GetDamage(gSkillData.sk_plr_9mm_bullet), vecDir, &tr, DMG_BULLET);
break;

case BULLET_PLAYER_MP5:
pEntity->TraceAttack(pevAttacker, gSkillData.sk_plr_9mmAR_bullet * dmg_mult, vecDir, &tr, DMG_BULLET);
pEntity->TraceAttack(pevAttacker, GetDamage(gSkillData.sk_plr_9mmAR_bullet), vecDir, &tr, DMG_BULLET);
break;

case BULLET_PLAYER_BUCKSHOT:
// make distance based!
pEntity->TraceAttack(pevAttacker, gSkillData.sk_plr_buckshot * dmg_mult, vecDir, &tr, DMG_BULLET);
pEntity->TraceAttack(pevAttacker, GetDamage(gSkillData.sk_plr_buckshot), vecDir, &tr, DMG_BULLET);
break;

case BULLET_PLAYER_357:
pEntity->TraceAttack(pevAttacker, gSkillData.sk_plr_357_bullet * dmg_mult, vecDir, &tr, DMG_BULLET);
pEntity->TraceAttack(pevAttacker, GetDamage(gSkillData.sk_plr_357_bullet), vecDir, &tr, DMG_BULLET);
break;

case BULLET_NONE: // FIX
pEntity->TraceAttack(pevAttacker, 50 * dmg_mult, vecDir, &tr, DMG_CLUB);
pEntity->TraceAttack(pevAttacker, GetDamage(50), vecDir, &tr, DMG_CLUB);
TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
// only decal glass
if (!FNullEnt(tr.pHit) && VARS(tr.pHit)->rendermode != 0)
Expand Down
2 changes: 2 additions & 0 deletions dlls/CBaseEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class EXPORT CBaseEntity

virtual float GetDamageModifier() { return 1.0f; }

virtual float GetDamage(float defaultDamage) { return (pev->dmg ? pev->dmg : defaultDamage) * GetDamageModifier(); }

// Smooths the movement of projectile models or sprites that use one of the following movetypes:
// NONE, STEP, WALK, FLY.
// Call this in a think function which has a constant interval, and pass that interval as flInterval.
Expand Down
9 changes: 9 additions & 0 deletions dlls/monster/CBaseMonster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7834,3 +7834,12 @@ float CBaseMonster::GetDamageModifier() {

return self_damage_mult * owner_damage_mult;
}

float CBaseMonster::GetDamage(float defaultDamage) {
CBaseEntity* owner = CBaseEntity::Instance(pev->owner);
CBaseMonster* mon = owner ? owner->MyMonsterPointer() : NULL;

// owner damage overrides self damage (snarks, grenades, etc.)
float self_damage = pev->dmg ? pev->dmg : defaultDamage;
return (mon ? mon->GetDamage(defaultDamage) : self_damage) * GetDamageModifier();
}
2 changes: 2 additions & 0 deletions dlls/monster/CBaseMonster.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ class EXPORT CBaseMonster : public CBaseToggle
virtual void Revive();

virtual float GetDamageModifier();

virtual float GetDamage(float defaultDamage);
};


Expand Down
6 changes: 2 additions & 4 deletions dlls/monster/CHornet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,14 @@ void CHornet :: Spawn( void )
if ( !pSoundEnt )
pSoundEnt = edict();

float dmg_mult = GetDamageModifier();

if ( !FNullEnt(pev->owner) && (pev->owner->v.flags & FL_CLIENT) )
{
pev->dmg = gSkillData.sk_plr_hornet * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_plr_hornet);
}
else
{
// no real owner, or owner isn't a client.
pev->dmg = gSkillData.sk_hornet_dmg * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_hornet_dmg);
}

m_lastPos = pev->origin;
Expand Down
8 changes: 3 additions & 5 deletions dlls/monster/CSqueakGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ void CSqueakGrenade :: Spawn( void )
pev->gravity = 0.5;
pev->friction = 0.5;

float dmg_mult = GetDamageModifier();

pev->dmg = gSkillData.sk_snark_dmg_pop * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_snark_dmg_pop);

m_flDie = gpGlobals->time + SQUEEK_DETONATE_DELAY;

Expand Down Expand Up @@ -355,12 +353,12 @@ void CSqueakGrenade::SuperBounceTouch( CBaseEntity *pOther )
{
edict_t* oldOwner = pev->owner;
pev->owner = m_hOwner.GetEdict();
float dmg_mult = GetDamageModifier();
float dmg = GetDamage(gSkillData.sk_snark_dmg_bite);
pev->owner = oldOwner;

// ALERT( at_console, "hit enemy\n");
ClearMultiDamage( );
pOther->TraceAttack(pev, gSkillData.sk_snark_dmg_bite*dmg_mult, gpGlobals->v_forward, &tr, DMG_SLASH );
pOther->TraceAttack(pev, dmg, gpGlobals->v_forward, &tr, DMG_SLASH );
if (m_hOwner != NULL)
ApplyMultiDamage( pev, m_hOwner->pev );
else
Expand Down
4 changes: 4 additions & 0 deletions dlls/player/CBasePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6048,6 +6048,10 @@ float CBasePlayer::GetDamageModifier() {
return CBaseMonster::GetDamageModifier() * weapon_damage_mult;
}

float CBasePlayer::GetDamage(float defaultDamage) {
return m_pActiveItem ? m_pActiveItem->GetDamage(defaultDamage) : CBaseMonster::GetDamage(defaultDamage);
}

void CBasePlayer::PenalizeDeath() {
m_iDeaths += 1;
m_scoreMultiplier = GetScoreMultiplier();
Expand Down
2 changes: 2 additions & 0 deletions dlls/player/CBasePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ class EXPORT CBasePlayer : public CBaseMonster

float GetDamageModifier();

float GetDamage(float defaultDamage);

// accounts for active cameras and view offset
Vector GetViewPosition() { return m_hViewEntity ? m_hViewEntity->pev->origin : GetGunPosition(); }

Expand Down
4 changes: 0 additions & 4 deletions dlls/weapon/CBasePlayerWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,4 @@ void CBasePlayerWeapon::SolidifyNearbyCorpses(bool solidState) {
UTIL_SetOrigin(&ent->v, ent->v.origin); // reset abs bbox
}
}
}

float CBasePlayerWeapon::GetDamageModifier() {
return pev->dmg ? pev->dmg : 1.0f;
}
2 changes: 0 additions & 2 deletions dlls/weapon/CBasePlayerWeapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class EXPORT CBasePlayerWeapon : public CBasePlayerItem
// hack to allow corpse gibbing of non-solid corpses
void SolidifyNearbyCorpses(bool solidState);

float GetDamageModifier();

float m_flPumpTime;
int m_fInSpecialReload; // Are we in the middle of a reload for the shotguns
float m_flNextPrimaryAttack; // soonest time ItemPostFrame will call PrimaryAttack
Expand Down
10 changes: 3 additions & 7 deletions dlls/weapon/CCrossbow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
// UNDONE: this needs to call TraceAttack instead
ClearMultiDamage( );

float dmg_mult = GetDamageModifier();

if ( pOther->IsPlayer() )
{
pOther->TraceAttack(pevOwner, gSkillData.sk_plr_xbow_bolt_client*dmg_mult, pev->velocity.Normalize(), &tr, DMG_NEVERGIB );
pOther->TraceAttack(pevOwner, GetDamage(gSkillData.sk_plr_xbow_bolt_client), pev->velocity.Normalize(), &tr, DMG_NEVERGIB );
}
else
{
pOther->TraceAttack(pevOwner, gSkillData.sk_plr_xbow_bolt_monster*dmg_mult, pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB );
pOther->TraceAttack(pevOwner, GetDamage(gSkillData.sk_plr_xbow_bolt_monster), pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB );
}

ApplyMultiDamage( pev, pevOwner );
Expand Down Expand Up @@ -381,11 +379,9 @@ void CCrossbow::FireSniperBolt()
#ifndef CLIENT_DLL
if ( tr.pHit->v.takedamage )
{
float dmg_mult = GetDamageModifier();

ClearMultiDamage( );
CBaseEntity::Instance(tr.pHit)->TraceAttack(m_pPlayer->pev,
gSkillData.sk_plr_xbow_sniper_bullet * dmg_mult, vecDir, &tr, DMG_BULLET | DMG_NEVERGIB );
GetDamage(gSkillData.sk_plr_xbow_sniper_bullet), vecDir, &tr, DMG_BULLET | DMG_NEVERGIB );
ApplyMultiDamage( pev, m_pPlayer->pev );
}
#endif
Expand Down
6 changes: 2 additions & 4 deletions dlls/weapon/CCrowbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,17 @@ int CCrowbar::Swing( int fFirst )

ClearMultiDamage( );

float dmg_mult = GetDamageModifier();

// JoshA: Changed from < -> <= to fix the full swing logic since client weapon prediction.
// -1.0f + 1.0f = 0.0f. UTIL_WeaponTimeBase is always 0 with client weapon prediction (0 time base vs curtime base)
if ( (m_flNextPrimaryAttack + 1 <= UTIL_WeaponTimeBase() ) || g_pGameRules->IsMultiplayer() )
{
// first swing does full damage
pEntity->TraceAttack(m_pPlayer->pev, gSkillData.sk_plr_crowbar* dmg_mult, gpGlobals->v_forward, &tr, DMG_CLUB );
pEntity->TraceAttack(m_pPlayer->pev, GetDamage(gSkillData.sk_plr_crowbar), gpGlobals->v_forward, &tr, DMG_CLUB );
}
else
{
// subsequent swings do half
pEntity->TraceAttack(m_pPlayer->pev, (gSkillData.sk_plr_crowbar / 2) * dmg_mult, gpGlobals->v_forward, &tr, DMG_CLUB );
pEntity->TraceAttack(m_pPlayer->pev, GetDamage(gSkillData.sk_plr_crowbar) / 2, gpGlobals->v_forward, &tr, DMG_CLUB );
}
ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );

Expand Down
8 changes: 2 additions & 6 deletions dlls/weapon/CDisplacerBall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ void CDisplacerBall::FizzleThink()
{
ClearBeams();

float dmg_mult = GetDamageModifier();

pev->dmg = gSkillData.sk_plr_displacer_other * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_plr_displacer_other);

MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, pev->origin);
WRITE_BYTE(TE_DLIGHT);
Expand All @@ -285,9 +283,7 @@ void CDisplacerBall::ExplodeThink()
{
ClearBeams();

float dmg_mult = GetDamageModifier();

pev->dmg = gSkillData.sk_plr_displacer_other * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_plr_displacer_other);

edict_t* pOwner = pev->owner;
pev->owner = nullptr;
Expand Down
8 changes: 3 additions & 5 deletions dlls/weapon/CEgon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ void CEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )

float timedist = 0;

float dmg_mult = GetDamageModifier();

switch ( m_fireMode )
{
case FIRE_NARROW:
Expand All @@ -328,7 +326,7 @@ void CEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
ClearMultiDamage();
if (pEntity->pev->takedamage)
{
pEntity->TraceAttack( m_pPlayer->pev, gSkillData.sk_plr_egon_narrow*dmg_mult, vecDir, &tr, DMG_ENERGYBEAM );
pEntity->TraceAttack( m_pPlayer->pev, GetDamage(gSkillData.sk_plr_egon_narrow), vecDir, &tr, DMG_ENERGYBEAM );
}
ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);

Expand Down Expand Up @@ -365,14 +363,14 @@ void CEgon::Fire( const Vector &vecOrigSrc, const Vector &vecDir )
ClearMultiDamage();
if (pEntity->pev->takedamage)
{
pEntity->TraceAttack( m_pPlayer->pev, gSkillData.sk_plr_egon_wide * dmg_mult, vecDir, &tr, DMG_ENERGYBEAM | DMG_ALWAYSGIB);
pEntity->TraceAttack( m_pPlayer->pev, GetDamage(gSkillData.sk_plr_egon_wide), vecDir, &tr, DMG_ENERGYBEAM | DMG_ALWAYSGIB);
}
ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);

if ( g_pGameRules->IsMultiplayer() )
{
// radius damage a little more potent in multiplayer.
::RadiusDamage( tr.vecEndPos, pev, m_pPlayer->pev, (gSkillData.sk_plr_egon_wide/4) * dmg_mult, 128, CLASS_NONE, DMG_ENERGYBEAM | DMG_ALWAYSGIB);
::RadiusDamage( tr.vecEndPos, pev, m_pPlayer->pev, GetDamage(gSkillData.sk_plr_egon_wide) / 4, 128, CLASS_NONE, DMG_ENERGYBEAM | DMG_ALWAYSGIB);
}

if ( !m_pPlayer->IsAlive() )
Expand Down
8 changes: 3 additions & 5 deletions dlls/weapon/CGauss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,14 @@ void CGauss::StartFire( void )
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecAiming = gpGlobals->v_forward;
Vector vecSrc = m_pPlayer->GetGunPosition( ); // + gpGlobals->v_up * -8 + gpGlobals->v_right * 8;

float dmg_mult = GetDamageModifier();

if ( gpGlobals->time - m_pPlayer->m_flStartCharge > GetFullChargeTime() )
{
flDamage = secondaryBaseDamage * dmg_mult;
flDamage = GetDamage(secondaryBaseDamage);
}
else
{
flDamage = secondaryBaseDamage * dmg_mult *
flDamage = GetDamage(secondaryBaseDamage) *
(( gpGlobals->time - m_pPlayer->m_flStartCharge) / GetFullChargeTime() );
}

Expand All @@ -379,7 +377,7 @@ void CGauss::StartFire( void )
#ifdef CLIENT_DLL
flDamage = 20;
#else
flDamage = gSkillData.sk_plr_gauss * dmg_mult;
flDamage = GetDamage(gSkillData.sk_plr_gauss);
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions dlls/weapon/CGrapple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ void CGrapple::PrimaryAttack()
ClearMultiDamage();

//float flDamage = GetSkillFloat("plr_grapple"sv);
float dmg_mult = GetDamageModifier();
float flDamage = 50 * dmg_mult;
float flDamage = GetDamage(50);

pHit->TraceAttack(this->pev, flDamage, gpGlobals->v_forward, &tr, DMG_ALWAYSGIB | DMG_CLUB);

Expand Down
9 changes: 3 additions & 6 deletions dlls/weapon/CGrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ CGrenade *CGrenade::ShootContact( entvars_t *pevOwner, Vector vecStart, Vector v
// Explode on contact
pGrenade->SetTouch( &CGrenade::ExplodeTouch );

float dmg_mult = pGrenade->GetDamageModifier();
pGrenade->pev->dmg = gSkillData.sk_plr_9mmAR_grenade * dmg_mult;
pGrenade->pev->dmg = pGrenade->GetDamage(gSkillData.sk_plr_9mmAR_grenade);

return pGrenade;
}
Expand Down Expand Up @@ -454,8 +453,7 @@ CGrenade * CGrenade:: ShootTimed( entvars_t *pevOwner, Vector vecStart, Vector v
pGrenade->pev->gravity = 0.5;
pGrenade->pev->friction = 0.8;

float dmg_mult = pGrenade->GetDamageModifier();
pGrenade->pev->dmg = 100 * dmg_mult;
pGrenade->pev->dmg = pGrenade->GetDamage(100);

SET_MODEL(ENT(pGrenade->pev), model ? model : pGrenade->GetModel());

Expand All @@ -481,8 +479,7 @@ CGrenade * CGrenade :: ShootSatchelCharge( entvars_t *pevOwner, Vector vecStart,
pGrenade->pev->angles = g_vecZero;
pGrenade->pev->owner = ENT(pevOwner);

float dmg_mult = pGrenade->GetDamageModifier();
pGrenade->pev->dmg = 200 * dmg_mult;
pGrenade->pev->dmg = pGrenade->GetDamage(200);

// Detonate in "time" seconds
pGrenade->SetThink( &CGrenade::SUB_DoNothing );
Expand Down
8 changes: 2 additions & 6 deletions dlls/weapon/CPipewrench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,7 @@ bool CPipewrench::Swing(const bool bFirst)
}
}

float dmg_mult = GetDamageModifier();

pEntity->TraceAttack(m_pPlayer->pev, flDamage*dmg_mult, gpGlobals->v_forward, &tr, DMG_CLUB);
pEntity->TraceAttack(m_pPlayer->pev, GetDamage(flDamage), gpGlobals->v_forward, &tr, DMG_CLUB);

ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
}
Expand Down Expand Up @@ -476,9 +474,7 @@ void CPipewrench::BigSwing()
}
}

float dmg_mult = GetDamageModifier();

pEntity->TraceAttack(m_pPlayer->pev, flDamage * dmg_mult, gpGlobals->v_forward, &tr, DMG_CLUB);
pEntity->TraceAttack(m_pPlayer->pev, GetDamage(flDamage), gpGlobals->v_forward, &tr, DMG_CLUB);

ApplyMultiDamage(m_pPlayer->pev, m_pPlayer->pev);
}
Expand Down
4 changes: 1 addition & 3 deletions dlls/weapon/CRpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ void CRpgRocket :: Spawn( void )

pev->nextthink = gpGlobals->time + 0.4;

float dmg_mult = GetDamageModifier();

pev->dmg = gSkillData.sk_plr_rpg * dmg_mult;
pev->dmg = GetDamage(gSkillData.sk_plr_rpg);
}

//=========================================================
Expand Down
Loading

0 comments on commit 97161ae

Please sign in to comment.