diff --git a/regamedll/game_shared/bot/bot.cpp b/regamedll/game_shared/bot/bot.cpp index e5849b9b..33f0d808 100644 --- a/regamedll/game_shared/bot/bot.cpp +++ b/regamedll/game_shared/bot/bot.cpp @@ -491,9 +491,15 @@ void ActiveGrenade::OnEntityGone() m_entity = nullptr; } +void ActiveGrenade::CheckOnEntityGone() +{ + if (m_dieTimestamp == 0 && !m_entity.IsValid()) + OnEntityGone(); +} + bool ActiveGrenade::IsValid() const { - if (!m_entity) + if (!m_entity.IsValid()) { if (gpGlobals->time > m_dieTimestamp) return false; @@ -502,7 +508,7 @@ bool ActiveGrenade::IsValid() const return true; } -const Vector *ActiveGrenade::GetPosition() const +const Vector *ActiveGrenade::GetPosition() { return &m_entity->pev->origin; } diff --git a/regamedll/game_shared/bot/bot_manager.cpp b/regamedll/game_shared/bot/bot_manager.cpp index 285a26a3..7e10f1bc 100644 --- a/regamedll/game_shared/bot/bot_manager.cpp +++ b/regamedll/game_shared/bot/bot_manager.cpp @@ -147,6 +147,8 @@ void CBotManager::StartFrame() ActiveGrenade *ag = (*iter); // lazy validation + ag->CheckOnEntityGone(); + if (!ag->IsValid()) { delete ag; @@ -203,6 +205,8 @@ void CBotManager::StartFrame() pBot->BotThink(); } } + + ValidateActiveGrenades(); } // Return the filename for this map's "nav map" file @@ -278,13 +282,16 @@ void CBotManager::RemoveGrenade(CGrenade *grenade) } // Destroy any invalid active grenades -NOXREF void CBotManager::ValidateActiveGrenades() +void CBotManager::ValidateActiveGrenades() { auto iter = m_activeGrenadeList.begin(); while (iter != m_activeGrenadeList.end()) { ActiveGrenade *ag = (*iter); + // lazy validation + ag->CheckOnEntityGone(); + if (!ag->IsValid()) { delete ag; @@ -314,6 +321,8 @@ bool CBotManager::IsInsideSmokeCloud(const Vector *pos) ActiveGrenade *ag = (*iter); // lazy validation + ag->CheckOnEntityGone(); + if (!ag->IsValid()) { delete ag; @@ -358,6 +367,8 @@ bool CBotManager::IsLineBlockedBySmoke(const Vector *from, const Vector *to) ActiveGrenade *ag = (*iter); // lazy validation + ag->CheckOnEntityGone(); + if (!ag->IsValid()) { delete ag; diff --git a/regamedll/game_shared/bot/bot_manager.h b/regamedll/game_shared/bot/bot_manager.h index dfcfd8ed..a985fc1d 100644 --- a/regamedll/game_shared/bot/bot_manager.h +++ b/regamedll/game_shared/bot/bot_manager.h @@ -42,16 +42,17 @@ public: ActiveGrenade(int weaponID, CGrenade *grenadeEntity); void OnEntityGone(); + void CheckOnEntityGone(); bool IsValid() const; - bool IsEntity(CGrenade *grenade) const { return (grenade == m_entity) ? true : false; } + bool IsEntity(CGrenade *grenade) const { return grenade == m_entity; } int GetID() const { return m_id; } const Vector *GetDetonationPosition() const { return &m_detonationPosition; } - const Vector *GetPosition() const; + const Vector *GetPosition(); private: int m_id; - CGrenade *m_entity; + EntityHandle m_entity; Vector m_detonationPosition; float m_dieTimestamp; };