From c927284eec5d81855fcf2238769a4049264d1830 Mon Sep 17 00:00:00 2001 From: Sabian Roberts <31491602+sabianroberts@users.noreply.github.com> Date: Sat, 12 Aug 2023 09:50:16 +0100 Subject: [PATCH] Add suit regen --- dlls/Game/Game.cpp | 11 +++++++++++ dlls/Player.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++- dlls/Player.h | 5 +++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/dlls/Game/Game.cpp b/dlls/Game/Game.cpp index 94efaf51..248f80e3 100644 --- a/dlls/Game/Game.cpp +++ b/dlls/Game/Game.cpp @@ -492,6 +492,11 @@ cvar_t sk_player_leg1 = { "sk_player_leg1","1" }; cvar_t sk_player_leg2 = { "sk_player_leg2","1" }; cvar_t sk_player_leg3 = { "sk_player_leg3","1" }; +// BlueNightHawk : Suit Energy Regneration +cvar_t sv_regeneration = { "sv_regeneration", "1", FCVAR_SERVER }; +cvar_t sv_regeneration_rate = { "sv_regeneration_rate", "1", FCVAR_SERVER }; +cvar_t sv_regeneration_wait = { "sv_regeneration_wait", "0.05", FCVAR_SERVER }; + // END Cvars for Skill Level settings void PrintVersion() @@ -944,6 +949,12 @@ void GameDLLInit( void ) CVAR_REGISTER ( &sk_player_leg1 ); CVAR_REGISTER ( &sk_player_leg2 ); CVAR_REGISTER ( &sk_player_leg3 ); + + // BlueNightHawk : Suit Energy Regeneration + CVAR_REGISTER(&sv_regeneration); + CVAR_REGISTER(&sv_regeneration_rate); + CVAR_REGISTER(&sv_regeneration_wait); + // END REGISTER CVARS FOR SKILL LEVEL STUFF SERVER_COMMAND( "exec skill.cfg\n" ); diff --git a/dlls/Player.cpp b/dlls/Player.cpp index 2499ed02..0e38158a 100644 --- a/dlls/Player.cpp +++ b/dlls/Player.cpp @@ -58,6 +58,11 @@ extern edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer ); // the world node graph extern CGraph WorldGraph; +// BlueNightHawk : Suit Energy Regeneration +extern cvar_t sv_regeneration; +extern cvar_t sv_regeneration_rate; +extern cvar_t sv_regeneration_wait; + #define TRAIN_ACTIVE 0x80 #define TRAIN_NEW 0xc0 #define TRAIN_OFF 0x00 @@ -540,7 +545,7 @@ int CBasePlayer :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, else pev->armorvalue -= flArmor; - flDamage = flNew; + flDamage = 0; } // this cast to INT is critical!!! If a player ends up with 0.5 health, the engine will get that @@ -710,6 +715,12 @@ int CBasePlayer :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, SetSuitUpdate("!HEV_HLTH1", FALSE, SUIT_NEXT_IN_10MIN); // health dropping } + // BlueNightHawk : Suit Energy Regeneration + if (sv_regeneration.value != 0 && pev->armorvalue < MAX_NORMAL_BATTERY && fTookDamage) + { + m_flNextSuitRegenTime = gpGlobals->time + 2.75 + sv_regeneration_wait.value; + } + return fTookDamage; } @@ -4084,6 +4095,42 @@ void CBasePlayer :: UpdateClientData( void ) m_iClientHideHUD = m_iHideHUD; } + // BlueNightHawk : Suit Energy Regeneration + if (sv_regeneration.value != 0 && pev->armorvalue < MAX_NORMAL_BATTERY + && m_flNextSuitRegenTime < gpGlobals->time) + { + pev->armorvalue += sv_regeneration_rate.value; + pev->armorvalue = V_min(pev->armorvalue, MAX_NORMAL_BATTERY); + + if (pev->armorvalue == MAX_NORMAL_BATTERY) + { + m_flNextSuitRegenTime = 0.0f; + m_fRegenOn = false; + STOP_SOUND(ENT(pev), CHAN_STATIC, "items/suitcharge1.wav"); + EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeno1.wav", 0.85, ATTN_NORM); + } + else if (!m_fRegenOn) + { + m_fRegenOn = true; + EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM); + } + else + { + STOP_SOUND(ENT(pev), CHAN_STATIC, "items/suitcharge1.wav"); + // too loud + EMIT_SOUND(ENT(pev), CHAN_STATIC, "items/suitcharge1.wav", 0.25, ATTN_NORM); + } + + m_flNextSuitRegenTime = gpGlobals->time + sv_regeneration_wait.value; + } + else if (sv_regeneration.value == 0) + { + m_flNextSuitRegenTime = 0.0f; + m_fRegenOn = false; + m_fRegenOn = false; + } + + if ( m_iFOV != m_iClientFOV ) { MESSAGE_BEGIN( MSG_ONE, gmsgSetFOV, NULL, pev ); diff --git a/dlls/Player.h b/dlls/Player.h index 61d3ef5b..c5acd115 100644 --- a/dlls/Player.h +++ b/dlls/Player.h @@ -331,6 +331,11 @@ class CBasePlayer : public CBaseMonster float m_flStatusBarDisappearDelay; char m_SbarString0[ SBAR_STRING_SIZE ]; char m_SbarString1[ SBAR_STRING_SIZE ]; + + + // BlueNightHawk : Suit Energy Regeneration + float m_flNextSuitRegenTime; + bool m_fRegenOn; float m_flNextChatTime;