From 10e06f919ebee4d872f8a98c5c5355144a6b4348 Mon Sep 17 00:00:00 2001 From: d3fault Date: Fri, 7 Jun 2019 02:44:19 -0700 Subject: [PATCH] respawn is now instant, but rate limited to 3 sec unless player clicks mouse1 --- src/game/server/entities/character.cpp | 3 ++- src/game/server/player.cpp | 7 ++++++- src/game/server/player.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 533ac1502..9acb2489a 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -901,7 +901,8 @@ void CCharacter::Die(int Killer, int Weapon) // a nice sound GameServer()->CreateSound(m_Pos, SOUND_PLAYER_DIE, Teams()->TeamMask(Team(), -1, m_pPlayer->GetCID())); - // this is for auto respawn after 3 secs + // this is to rate limit respawning to 3 secs + m_pPlayer->m_PreviousDieTick = m_pPlayer->m_DieTick; m_pPlayer->m_DieTick = Server()->Tick(); m_Alive = false; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index e31c7853b..c3af10a24 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -12,6 +12,7 @@ #include "gamemodes/DDRace.h" #include +#include MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS) @@ -37,6 +38,7 @@ CPlayer::~CPlayer() void CPlayer::Reset() { m_DieTick = Server()->Tick(); + m_PreviousDieTick = m_DieTick; m_JoinTick = Server()->Tick(); delete m_pCharacter; m_pCharacter = 0; @@ -196,7 +198,9 @@ void CPlayer::Tick() if(!GameServer()->m_World.m_Paused) { - if(!m_pCharacter && m_DieTick+Server()->TickSpeed()*3 <= Server()->Tick()) + int EarliestRespawnTick = m_PreviousDieTick+Server()->TickSpeed()*3; + int RespawnTick = std::max(m_DieTick, EarliestRespawnTick); + if(!m_pCharacter && RespawnTick <= Server()->Tick()) m_Spawning = true; if(m_pCharacter) @@ -219,6 +223,7 @@ void CPlayer::Tick() else { ++m_DieTick; + ++m_PreviousDieTick; ++m_JoinTick; ++m_LastActionTick; ++m_TeamChangeTick; diff --git a/src/game/server/player.h b/src/game/server/player.h index 09272b847..af93fde90 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -92,6 +92,7 @@ public: } m_TeeInfos; int m_DieTick; + int m_PreviousDieTick; int m_Score; int m_JoinTick; bool m_ForceBalanced;