Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaqtincha committed Jun 12, 2021
1 parent 46deaf5 commit 12c07d4
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions regamedll/game_shared/bot/bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CBasePlayer *>(pOther);

if (pAttacker && !pAttacker->IsBot())
{
CBasePlayer *pPlayer = static_cast<CBasePlayer *>(pEntity);

if (pPlayer && pPlayer->IsBot())
{
CBot *bot = static_cast<CBot *>(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<CBot *>(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<CBot *>(pPlayer);
bot->OnEvent(event, pEntity, pOther);
}

if (TheTutor)
Expand Down

0 comments on commit 12c07d4

Please sign in to comment.