Skip to content

Commit

Permalink
Redo how the min health threshold is applied (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jul 1, 2024
1 parent 1aaff55 commit 5971cf3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
26 changes: 24 additions & 2 deletions dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,28 @@ int CBaseEntity::TakeHealth(CBaseEntity *pHealer, float flHealth, int bitsDamage

// inflict damage on this entity. bitsDamageType indicates type of damage inflicted, ie: DMG_CRUSH

void CBaseEntity::ApplyDamageToHealth(float flDamage)
{
const float healthBeforeDamage = pev->health;

// do the damage
pev->health -= flDamage;

if (m_healthMinThreshold > 0 && pev->health < m_healthMinThreshold)
{
if (IsPlayer())
{
pev->health = Q_max((int)m_healthMinThreshold, 1);
}
else
{
pev->health = Q_max(m_healthMinThreshold, 1.0f);
pev->health = Q_min(healthBeforeDamage, pev->health);
}
m_healthMinThreshold = 0.0f;
}
}

int CBaseEntity::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
Vector vecTemp;
Expand Down Expand Up @@ -612,8 +634,8 @@ int CBaseEntity::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, fl
pev->velocity = pev->velocity + vecDir * flForce;
}

// do the damage
pev->health -= flDamage;
ApplyDamageToHealth(flDamage);

if( pev->health <= 0 )
{
Killed( pevInflictor, pevAttacker, GIB_NORMAL );
Expand Down
3 changes: 3 additions & 0 deletions dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ class CBaseEntity

virtual void SendMessages(CBaseEntity* pClient) {}
virtual bool HandleDoorBlockage(CBaseEntity* pDoor) { return false; }

void ApplyDamageToHealth(float flDamage);
float m_healthMinThreshold;
};

// Ugly technique to override base member functions
Expand Down
3 changes: 1 addition & 2 deletions dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,7 @@ int CBaseMonster::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, f

AddScoreForDamage(pevAttacker, this, flTake);

// do the damage
pev->health -= flTake;
ApplyDamageToHealth(flTake);

// HACKHACK Don't kill monsters in a script. Let them break their scripts first
if( m_MonsterState == MONSTERSTATE_SCRIPT )
Expand Down
4 changes: 2 additions & 2 deletions dlls/func_break.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ int CBreakable::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, flo
// this global is still used for glass and other non-monster killables, along with decals.
g_vecAttackDir = vecTemp.Normalize();

// do the damage
pev->health -= flDamage;
ApplyDamageToHealth(flDamage);

if( pev->health <= 0 )
{
if (FBitSet(bitsDamageType, DMG_NONLETHAL))
Expand Down
18 changes: 2 additions & 16 deletions dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,19 +1551,12 @@ void CTriggerHurt::DoDamage(CBaseEntity *pTarget, float fldmg)
{
int damageType = DamageType();

const float healthBeforeDmg = pTarget->pev->health;
const float minHealthThreshold = pev->dmg_save;

if (minHealthThreshold > 0) {
damageType |= DMG_NONLETHAL;
pTarget->m_healthMinThreshold = minHealthThreshold;
}

pTarget->TakeDamage( pev, pev, fldmg, damageType );

if (minHealthThreshold > 0 && pTarget->pev->health < minHealthThreshold)
{
pTarget->pev->health = Q_min(minHealthThreshold, healthBeforeDmg);
}
}
}

Expand Down Expand Up @@ -5390,11 +5383,9 @@ void CTriggerHurtRemote::DoDamage(CBaseEntity* pTarget)
float fldmg = pev->dmg;
int damageType = DamageType();

const float healthBeforeDmg = pTarget->pev->health;
const float minHealthThreshold = pev->dmg_save;

if (minHealthThreshold > 0) {
damageType |= DMG_NONLETHAL;
pTarget->m_healthMinThreshold = minHealthThreshold;
}

entvars_t* pevAttacker = pActivator != 0 ? pActivator->pev : pev;
Expand All @@ -5414,11 +5405,6 @@ void CTriggerHurtRemote::DoDamage(CBaseEntity* pTarget)
{
pTarget->TakeDamage(pTarget->pev, pevAttacker, fldmg, damageType);
}

if (minHealthThreshold > 0 && pTarget->pev->health < minHealthThreshold)
{
pTarget->pev->health = Q_min(minHealthThreshold, healthBeforeDmg);
}
}
else
{
Expand Down

0 comments on commit 5971cf3

Please sign in to comment.