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 aea936c
Show file tree
Hide file tree
Showing 22 changed files with 287 additions and 247 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
21 changes: 11 additions & 10 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,10 +665,10 @@ void CCSBotManager::ServerCommand(const char *pcmd)
CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
{
if (!pEntity->IsPlayer())
continue;
if (FNullEnt(pEntity->edict()))
break;

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

CBasePlayer *playerOrBot = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
Expand Down Expand Up @@ -1580,7 +1580,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
37 changes: 30 additions & 7 deletions regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ NOXREF int CountTeams()
break;

CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
continue;

if (pPlayer->m_iTeam == UNASSIGNED)
continue;
Expand Down Expand Up @@ -469,10 +471,10 @@ void ListPlayers(CBasePlayer *current)
if (FNullEnt(pEntity->edict()))
break;

if (pEntity->IsDormant())
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
continue;

CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
int iUserID = GETPLAYERUSERID(ENT(pPlayer->pev));

Q_sprintf(cNumber, "%d", iUserID);
Expand All @@ -496,10 +498,11 @@ int CountTeamPlayers(int iTeam)
if (FNullEnt(pEntity->edict()))
break;

if (pEntity->IsDormant())
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (!pPlayer->IsPlayer() || pPlayer->IsDormant())
continue;

if (GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam)
if (pPlayer->m_iTeam == iTeam)
{
nCount++;
}
Expand Down Expand Up @@ -535,10 +538,12 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
break;

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

if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
continue;

if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
continue;

if (pTempPlayer->m_iTeam == pVotingPlayer->m_iTeam && pTempPlayer->m_iCurrentKickVote == iVoteID)
iValidVotes++;
}
Expand Down Expand Up @@ -576,6 +581,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
continue;

if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
continue;

if (pTempPlayer->m_iTeam == pVotingPlayer->m_iTeam && pTempPlayer->m_iCurrentKickVote == iVoteID)
pTempPlayer->m_iCurrentKickVote = 0;
}
Expand Down Expand Up @@ -976,6 +984,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
if (pReceiver->edict() == pEntity)
continue;

if (!pReceiver->IsPlayer() || pReceiver->IsDormant())
continue;

// Not a client ? (should never be true)
if (!pReceiver->IsNetClient())
continue;
Expand Down Expand Up @@ -2344,6 +2355,8 @@ CBaseEntity *EntityFromUserID(int userID)
break;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
continue;

if (pTempPlayer->m_iTeam != UNASSIGNED && userID == GETPLAYERUSERID(pTempEntity->edict()))
{
Expand All @@ -2364,6 +2377,8 @@ NOXREF int CountPlayersInServer()
break;

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (!pTempPlayer->IsPlayer() || pTempPlayer->IsDormant())
continue;

if (pTempPlayer->m_iTeam != UNASSIGNED)
{
Expand Down Expand Up @@ -3343,7 +3358,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 +3387,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
10 changes: 2 additions & 8 deletions regamedll/dlls/hostage/hostage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,10 +1239,7 @@ void CHostage::SendHostagePositionMsg()
if (FNullEnt(pEntity->edict()))
break;

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

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

CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
Expand All @@ -1268,10 +1265,7 @@ void CHostage::SendHostageEventMsg()
if (FNullEnt(pEntity->edict()))
break;

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

if (pEntity->pev->flags == FL_DORMANT)
if (!pEntity->IsPlayer() || 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 aea936c

Please sign in to comment.