From 12c07d45b904183386b2b54a48d04a12104f4ec6 Mon Sep 17 00:00:00 2001 From: Vaqtincha Date: Sat, 12 Jun 2021 17:50:58 +0500 Subject: [PATCH] refactoring --- regamedll/game_shared/bot/bot_manager.cpp | 60 +++++++++-------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/regamedll/game_shared/bot/bot_manager.cpp b/regamedll/game_shared/bot/bot_manager.cpp index e71893f9c..79c2c907b 100644 --- a/regamedll/game_shared/bot/bot_manager.cpp +++ b/regamedll/game_shared/bot/bot_manager.cpp @@ -218,49 +218,37 @@ const char *CBotManager::GetNavMapFilename() const // TODO: This has become the game-wide event dispatcher. We should restructure this. void CBotManager::OnEvent(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOther) { -#ifdef REGAMEDLL_ADD - if (event == EVENT_PLAYER_TOOK_DAMAGE && pOther->IsPlayer()) - { - CBasePlayer *pAttacker = static_cast(pOther); - - if (pAttacker && !pAttacker->IsBot()) - { - CBasePlayer *pPlayer = static_cast(pEntity); - - if (pPlayer && pPlayer->IsBot()) - { - CBot *bot = static_cast(pPlayer); - bot->OnEvent(event, pEntity, pOther); - } - } - } - else -#endif + // propogate event to all bots + for (int i = 1; i <= gpGlobals->maxClients; i++) { - // propogate event to all bots - for (int i = 1; i <= gpGlobals->maxClients; i++) - { - CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); - - if (!pPlayer) - continue; + CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); - if (FNullEnt(pPlayer->pev)) - continue; + if (!pPlayer) + continue; - if (FStrEq(STRING(pPlayer->pev->netname), "")) - continue; + if (FNullEnt(pPlayer->pev)) + continue; - if (!pPlayer->IsBot()) - continue; + if (FStrEq(STRING(pPlayer->pev->netname), "")) + continue; - // do not send self-generated event - if (pEntity == pPlayer) - continue; + if (!pPlayer->IsBot()) + continue; - CBot *bot = static_cast(pPlayer); - bot->OnEvent(event, pEntity, pOther); +#ifdef REGAMEDLL_ADD + if ((event != EVENT_PLAYER_TOOK_DAMAGE && pEntity == pPlayer) + || (event == EVENT_PLAYER_TOOK_DAMAGE && pEntity != pPlayer)) + { + continue; } +#else + // do not send self-generated event + if (pEntity == pPlayer) + continue; +#endif + + CBot *bot = static_cast(pPlayer); + bot->OnEvent(event, pEntity, pOther); } if (TheTutor)