From 1ac96b8180e40119de654b91de7cc47077ceca02 Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Mon, 21 Jun 2021 11:59:34 +0300 Subject: [PATCH] Implement `CBasePlayer::HasTimePassedSinceDeath()` for `m_fDeadTime` (#648) * Implement CBasePlayer::HasTimePassedSinceDied() for m_fDeadTime --- regamedll/dlls/observer.cpp | 4 ++-- regamedll/dlls/player.cpp | 2 +- regamedll/dlls/player.h | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/regamedll/dlls/observer.cpp b/regamedll/dlls/observer.cpp index f60f2004..b00aae43 100644 --- a/regamedll/dlls/observer.cpp +++ b/regamedll/dlls/observer.cpp @@ -288,12 +288,12 @@ void CBasePlayer::Observer_CheckTarget() else if (target->pev->effects & EF_NODRAW) { #ifdef REGAMEDLL_FIXES - bool bStillDying = (target->pev->deadflag == DEAD_DYING || (target->pev->deadflag == DEAD_DEAD && (gpGlobals->time <= target->m_fDeadTime + 2.0f))); + bool bStillDying = (target->pev->deadflag == DEAD_DYING || (target->pev->deadflag == DEAD_DEAD && !target->HasTimePassedSinceDeath(2.0f))); if (!bStillDying || (target->m_afPhysicsFlags & PFLAG_OBSERVER)) // keep observing to victim until dying, even if it is invisible #endif Observer_FindNextPlayer(false); } - else if (target->pev->deadflag == DEAD_DEAD && gpGlobals->time > target->m_fDeadTime + 2.0f) + else if (target->pev->deadflag == DEAD_DEAD && target->HasTimePassedSinceDeath(2.0f)) { // 2 secs after death change target Observer_FindNextPlayer(false); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 0b049e6d..b59badc5 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -3762,7 +3762,7 @@ void CBasePlayer::PlayerDeathThink() { // if the player has been dead for one second longer than allowed by forcerespawn, // forcerespawn isn't on. Send the player off to an intermission camera until they choose to respawn. - if (g_pGameRules->IsMultiplayer() && gpGlobals->time > m_fDeadTime + 3 && !(m_afPhysicsFlags & PFLAG_OBSERVER)) + if (g_pGameRules->IsMultiplayer() && HasTimePassedSinceDeath(3.0f) && !(m_afPhysicsFlags & PFLAG_OBSERVER)) { // Send message to everybody to spawn a corpse. SpawnClientSideCorpse(); diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 3108ba53..4fd978c5 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -578,6 +578,7 @@ public: bool IsHittingShield(Vector &vecDirection, TraceResult *ptr); bool SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pSpot); bool IsReloading() const; + bool HasTimePassedSinceDeath(float duration) const; bool IsBlind() const { return (m_blindUntilTime > gpGlobals->time); } bool IsAutoFollowAllowed() const { return (gpGlobals->time > m_allowAutoFollowTime); } void InhibitAutoFollow(float duration) { m_allowAutoFollowTime = gpGlobals->time + duration; } @@ -928,6 +929,11 @@ inline bool CBasePlayer::IsReloading() const return false; } +inline bool CBasePlayer::HasTimePassedSinceDeath(float duration) const +{ + return gpGlobals->time > (m_fDeadTime + duration); +} + #ifdef REGAMEDLL_API inline CCSPlayer *CBasePlayer::CSPlayer() const { return reinterpret_cast(this->m_pEntity);