From f96df77d2ff93cce0ed5f7f8ddb1282288b7f3d0 Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Wed, 19 Oct 2022 21:45:22 +0300 Subject: [PATCH] Fix grunt medic spending healing charge (#339) --- dlls/gearbox/fgrunt.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dlls/gearbox/fgrunt.cpp b/dlls/gearbox/fgrunt.cpp index aaaca6da..c4a28fd4 100644 --- a/dlls/gearbox/fgrunt.cpp +++ b/dlls/gearbox/fgrunt.cpp @@ -3556,11 +3556,16 @@ bool CMedic::Heal( void ) if ( !HasHealCharge() || !HasHealTarget() ) return false; - Vector target = m_hTargetEnt->pev->origin - pev->origin; + CBaseEntity* pTargetEnt = m_hTargetEnt; + Vector target = pTargetEnt->pev->origin - pev->origin; if ( target.Length() > 100 ) return false; - m_flHealCharge -= m_hTargetEnt->TakeHealth( Q_min(10, m_flHealCharge), DMG_GENERIC ); + const float maxHeal = Q_min(10, m_flHealCharge); + const float diff = pTargetEnt->pev->max_health - pTargetEnt->pev->health; + const int healAmount = static_cast(Q_min(maxHeal, diff)); // cast to avoid player having non-integer hp + pTargetEnt->TakeHealth( healAmount, DMG_GENERIC ); + m_flHealCharge -= healAmount; ALERT(at_aiconsole, "Medic grunt heal charge left: %f\n", m_flHealCharge); m_fHealing = TRUE; return true;