Skip to content

Commit

Permalink
Add UTIL_IsValidPlayer
Browse files Browse the repository at this point in the history
Ignore dormant players
Minor refactoring
  • Loading branch information
s1lentq committed May 28, 2024
1 parent c08e6d0 commit 7372573
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 204 deletions.
10 changes: 2 additions & 8 deletions regamedll/dlls/bot/cs_bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ int GetBotFollowCount(CBasePlayer *pLeader)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down Expand Up @@ -685,10 +682,7 @@ CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down
10 changes: 2 additions & 8 deletions regamedll/dlls/bot/cs_bot_chatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ void BotMeme::Transmit(CCSBot *pSender) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down Expand Up @@ -1525,10 +1522,7 @@ BotStatement *BotChatterInterface::GetActiveStatement()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down
18 changes: 11 additions & 7 deletions regamedll/dlls/bot/cs_bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer)
pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pevTemp);
AddEntityHashValue(pPlayer->pev, STRING(pPlayer->pev->classname), CLASSNAME);
pPlayer->pev->flags = FL_DORMANT;

#ifdef REGAMEDLL_FIXES
pPlayer->has_disconnected = true;
#endif
}

void PrintAllEntities()
Expand Down Expand Up @@ -396,10 +400,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

const char *name = STRING(pPlayer->pev->netname);
Expand All @@ -425,10 +427,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

const char *name = STRING(pPlayer->pev->netname);
Expand Down Expand Up @@ -665,6 +665,9 @@ void CCSBotManager::ServerCommand(const char *pcmd)
CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
{
if (FNullEnt(pEntity->edict()))
break;

if (!pEntity->IsPlayer())
continue;

Expand Down Expand Up @@ -1580,7 +1583,8 @@ void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || pPlayer->IsDormant())

if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (pPlayer->IsBot())
Expand Down
5 changes: 1 addition & 4 deletions regamedll/dlls/bot/cs_bot_pathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,10 +1118,7 @@ bool CCSBot::IsFriendInTheWay(const Vector *goalPos) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (!pPlayer->IsAlive())
Expand Down
7 changes: 2 additions & 5 deletions regamedll/dlls/bot/cs_bot_vision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ bool CCSBot::IsVisible(CBasePlayer *pPlayer, bool testFOV, unsigned char *visPar
if ((pPlayer->pev->flags & FL_NOTARGET) || (pPlayer->pev->effects & EF_NODRAW))
return false;
#endif

Vector spot = pPlayer->pev->origin;
unsigned char testVisParts = NONE;

Expand Down Expand Up @@ -701,10 +701,7 @@ CBasePlayer *CCSBot::FindMostDangerousThreat()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

// is it a player?
Expand Down
6 changes: 5 additions & 1 deletion regamedll/dlls/career_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ void CCareerTaskManager::HandleDeath(int team, CBasePlayer *pAttacker)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())

if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())
numEnemies++;
}

Expand Down
33 changes: 30 additions & 3 deletions regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ NOXREF int CountTeams()
if (FNullEnt(pEntity->edict()))
break;

if (pEntity->IsDormant())
continue;

CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);

if (pPlayer->m_iTeam == UNASSIGNED)
Expand Down Expand Up @@ -499,7 +502,8 @@ int CountTeamPlayers(int iTeam)
if (pEntity->IsDormant())
continue;

if (GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam)
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam == iTeam)
{
nCount++;
}
Expand Down Expand Up @@ -534,6 +538,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
if (FNullEnt(pTempEntity->edict()))
break;

if (pTempEntity->IsDormant())
continue;

pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);

if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
Expand Down Expand Up @@ -571,6 +578,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
if (FNullEnt(pTempEntity->edict()))
break;

if (pTempEntity->IsDormant())
continue;

pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);

if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
Expand Down Expand Up @@ -976,6 +986,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
if (pReceiver->edict() == pEntity)
continue;

if (pReceiver->IsDormant())
continue;

// Not a client ? (should never be true)
if (!pReceiver->IsNetClient())
continue;
Expand Down Expand Up @@ -2343,6 +2356,9 @@ CBaseEntity *EntityFromUserID(int userID)
if (FNullEnt(pTempEntity->edict()))
break;

if (pTempEntity->IsDormant())
continue;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);

if (pTempPlayer->m_iTeam != UNASSIGNED && userID == GETPLAYERUSERID(pTempEntity->edict()))
Expand All @@ -2363,6 +2379,9 @@ NOXREF int CountPlayersInServer()
if (FNullEnt(pTempEntity->edict()))
break;

if (pTempEntity->IsDormant())
continue;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);

if (pTempPlayer->m_iTeam != UNASSIGNED)
Expand Down Expand Up @@ -3343,7 +3362,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))

if (!UTIL_IsValidPlayer(pObserver))
continue;

if (pObserver->IsObservingPlayer(pPlayer))
{
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_off.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);

Expand All @@ -3368,7 +3391,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))

if (!UTIL_IsValidPlayer(pObserver))
continue;

if (pObserver->IsObservingPlayer(pPlayer))
{
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_on.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);

Expand Down
7 changes: 5 additions & 2 deletions regamedll/dlls/cmdhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ void SV_Continue_f()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (pPlayer && !pPlayer->IsBot())
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (!pPlayer->IsBot())
{
// at the end of the round is showed window with the proposal surrender or continue
// now of this time HUD is completely hidden
Expand Down Expand Up @@ -96,7 +99,7 @@ void SV_Career_EndRound_f()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer || FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (pPlayer->IsBot() && pPlayer->m_iTeam == pLocalPlayer->m_iTeam)
Expand Down
6 changes: 5 additions & 1 deletion regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))

if (!UTIL_IsValidPlayer(pObserver))
continue;

if (pObserver->IsObservingPlayer(pPlayer))
{
UTIL_ScreenFade(pObserver, color, fadeTime, fadeHold, alpha, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions regamedll/dlls/hostage/hostage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ void CHostage::SendHostagePositionMsg()
if (!pEntity->IsPlayer())
continue;

if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
Expand Down Expand Up @@ -1271,7 +1271,7 @@ void CHostage::SendHostageEventMsg()
if (!pEntity->IsPlayer())
continue;

if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
Expand Down
10 changes: 2 additions & 8 deletions regamedll/dlls/hostage/hostage_improv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ bool CHostageImprov::IsFriendInTheWay(const Vector &goalPos) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (!pPlayer->IsAlive() || pPlayer->m_iTeam == TERRORIST)
Expand Down Expand Up @@ -675,10 +672,7 @@ void CHostageImprov::UpdateVision()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);

if (!pPlayer)
continue;

if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;

if (FStrEq(STRING(pPlayer->pev->netname), ""))
Expand Down
Loading

0 comments on commit 7372573

Please sign in to comment.