From cd96c9133dceb954289462243d0b3abb8bad27f2 Mon Sep 17 00:00:00 2001 From: s1lent Date: Mon, 6 Feb 2017 02:49:19 +0700 Subject: [PATCH] Fix bot: do reset of the target when are the target (player or bot) left the game. --- regamedll/dlls/bot/cs_bot_manager.cpp | 20 ++++++++++++++++++++ regamedll/dlls/bot/cs_bot_manager.h | 1 + regamedll/dlls/bot/states/cs_bot_attack.cpp | 1 - regamedll/dlls/cbase.cpp | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index 16714325..96714388 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -1500,3 +1500,23 @@ void CCSBotManager::ResetRadioMessageTimestamps() } } } + +void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity) +{ + for (int i = 1; i <= gpGlobals->maxClients; i++) + { + CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); + if (!pPlayer || pPlayer->IsDormant()) + continue; + + if (pPlayer->IsBot()) + { + CCSBot *pBot = static_cast(pPlayer); + if (pBot->m_attacker == pEntity) + pBot->m_attacker = NULL; + + if (pBot->m_bomber == pEntity) + pBot->m_bomber = NULL; + } + } +} diff --git a/regamedll/dlls/bot/cs_bot_manager.h b/regamedll/dlls/bot/cs_bot_manager.h index 685397f0..2eaeda7b 100644 --- a/regamedll/dlls/bot/cs_bot_manager.h +++ b/regamedll/dlls/bot/cs_bot_manager.h @@ -76,6 +76,7 @@ public: public: void ValidateMapData(); + void OnFreeEntPrivateData(CBaseEntity *pEntity); bool IsLearningMap() const { return IMPL(m_isLearningMap); } void SetLearningMapFlag() { IMPL(m_isLearningMap) = true; } bool IsAnalysisRequested() const { return IMPL(m_isAnalysisRequested); } diff --git a/regamedll/dlls/bot/states/cs_bot_attack.cpp b/regamedll/dlls/bot/states/cs_bot_attack.cpp index 4af030d9..f9fc5f5d 100644 --- a/regamedll/dlls/bot/states/cs_bot_attack.cpp +++ b/regamedll/dlls/bot/states/cs_bot_attack.cpp @@ -456,7 +456,6 @@ void AttackState::__MAKE_VHOOK(OnUpdate)(CCSBot *me) if (gpGlobals->time > m_reacquireTimestamp) me->FireWeaponAtEnemy(); - // do dodge behavior // If sniping or crouching, stand still. if (m_dodge && !me->IsUsingSniperRifle() && !m_crouchAndHold) diff --git a/regamedll/dlls/cbase.cpp b/regamedll/dlls/cbase.cpp index 1b1f3a66..4710f597 100644 --- a/regamedll/dlls/cbase.cpp +++ b/regamedll/dlls/cbase.cpp @@ -1067,4 +1067,9 @@ void EXT_FUNC OnFreeEntPrivateData(edict_t *pEnt) } #endif +#ifdef REGAMEDLL_FIXES + if (TheCSBots()) { + TheCSBots()->OnFreeEntPrivateData(pEntity); + } +#endif }