From e0d253ae0140ee132fb9831ea66f531ff4e9b036 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 22 May 2016 12:45:55 +0000 Subject: [PATCH] Add fast recharger --- dlls/h_battery.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/dlls/h_battery.cpp b/dlls/h_battery.cpp index b8a3e7b0..306deb65 100644 --- a/dlls/h_battery.cpp +++ b/dlls/h_battery.cpp @@ -197,4 +197,87 @@ void CRecharge::Off(void) } else SetThink( &CBaseEntity::SUB_DoNothing ); -} +} + +class CMegaCharge: public CRecharge +{ + void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) + { + // if it's not a player, ignore + if (!FClassnameIs(pActivator->pev, "player")) + return; + + // if there is no juice left, turn it off + if (m_iJuice <= 0) + { + pev->frame = 1; + Off(); + } + + // if the player doesn't have the suit, or there is no juice left, make the deny noise + if ((m_iJuice <= 0) || (!(pActivator->pev->weapons & (1<time) + { + m_flSoundTime = gpGlobals->time + 0.62; + EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeno1.wav", 0.85, ATTN_NORM ); + } + return; + } + + pev->nextthink = pev->ltime + 0.25; + SetThink( &CRecharge::Off); + + // Time to recharge yet? + + if (m_flNextCharge >= gpGlobals->time) + return; + + // Make sure that we have a caller + if (!pActivator) + return; + + m_hActivator = pActivator; + + //only recharge the player + + if (!m_hActivator->IsPlayer() ) + return; + + // Play the on sound or the looping charging sound + if (!m_iOn) + { + m_iOn++; + EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM ); + m_flSoundTime = 0.56 + gpGlobals->time; + } + if ((m_iOn == 1) && (m_flSoundTime <= gpGlobals->time)) + { + m_iOn++; + EMIT_SOUND(ENT(pev), CHAN_STATIC, "items/suitcharge1.wav", 0.85, ATTN_NORM ); + } + + + // charge the player + if( m_hActivator->pev->health < 100 ) + { + m_hActivator->pev->health += 50; + if (m_hActivator->pev->health > 100) + m_hActivator->pev->armorvalue = 100; + m_iJuice -= 5; + } + else if (m_hActivator->pev->armorvalue < 200) + { + m_iJuice -= 5; + m_hActivator->pev->armorvalue += 50; + + if (m_hActivator->pev->armorvalue > 200) + m_hActivator->pev->armorvalue = 200; + } + + // govern the rate of charge + m_flNextCharge = gpGlobals->time + 0.1; + } +}; + +LINK_ENTITY_TO_CLASS(func_megacharge, CMegaCharge);