CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const { CCSBotManager *ctrl = TheCSBots(); CBasePlayer *nearEnemy = NULL; float nearDist = 999999999.9f; for (int i = 1; i <= gpGlobals->maxClients; ++i) { CBaseEntity *entity = UTIL_PlayerByIndex(i); if (entity == NULL) continue; if (FNullEnt(entity->pev)) continue; if (FStrEq(STRING(entity->pev->netname), "")) continue; // is it a player? if (!entity->IsPlayer()) continue; CBasePlayer *player = static_cast<CBasePlayer *>(entity); // is it alive? if (!player->IsAlive()) continue; // skip friends if (player->m_iTeam == m_iTeam) continue; // is it "important" if (!ctrl->IsImportantPlayer(player)) continue; // is it closest? Vector d = pev->origin - player->pev->origin; float distSq = d.x * d.x + d.y * d.y + d.z * d.z; if (distSq < nearDist) { if (checkVisibility && !IsVisible(player, CHECK_FOV)) continue; nearEnemy = player; nearDist = distSq; } } return nearEnemy; }