a little cleanup of code save point

This commit is contained in:
jeefo 2016-03-01 13:37:10 +03:00
commit f8344a464e
18 changed files with 1197 additions and 1141 deletions

View file

@ -45,7 +45,7 @@ BotManager::BotManager (void)
BotManager::~BotManager (void)
{
// this is a bot manager class destructor, do not use GetMaxClients () here !!
// this is a bot manager class destructor, do not use engine.MaxClients () here !!
Free ();
}
@ -117,12 +117,12 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
if (g_numWaypoints < 1) // don't allow creating bots with no waypoints loaded
{
CenterPrint ("Map is not waypointed. Cannot create bot");
engine.CenterPrintf ("Map is not waypointed. Cannot create bot");
return 0;
}
else if (g_waypointsChanged) // don't allow creating bots with changed waypoints (distance tables are messed up)
{
CenterPrint ("Waypoints have been changed. Load waypoints again...");
engine.CenterPrintf ("Waypoints have been changed. Load waypoints again...");
return 0;
}
@ -196,7 +196,7 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
if (IsEntityNull ((bot = (*g_engfuncs.pfnCreateFakeClient) (outputName))))
{
CenterPrint ("Maximum players reached (%d/%d). Unable to create Bot.", GetMaxClients (), GetMaxClients ());
engine.CenterPrintf ("Maximum players reached (%d/%d). Unable to create Bot.", engine.MaxClients (), engine.MaxClients ());
return 2;
}
int index = IndexOfEntity (bot) - 1;
@ -209,7 +209,7 @@ int BotManager::CreateBot (const String &name, int difficulty, int personality,
if (m_bots[index] == NULL)
TerminateOnMalloc ();
ServerPrint ("Connecting Bot...");
engine.Printf ("Connecting Bot...");
return 1;
}
@ -257,7 +257,7 @@ Bot *BotManager::FindOneValidAliveBot (void)
Array <int> foundBots;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (foundBots.GetSize () > 4)
break;
@ -276,7 +276,7 @@ void BotManager::Think (void)
{
// this function calls think () function for all available at call moment bots
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL)
m_bots[i]->Think ();
@ -287,7 +287,7 @@ void BotManager::PeriodicThink (void)
{
// this function calls periodic SecondThink () function for all available at call moment bots
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL)
m_bots[i]->PeriodicThink ();
@ -331,7 +331,7 @@ void BotManager::AdjustQuota (bool isPlayerConnection, edict_t *ent)
{
// this function increases or decreases bot quota amount depending on autovacate variables
if (!IsDedicatedServer () || !yb_autovacate.GetBool () || GetBot (ent) != NULL)
if (!engine.IsDedicatedServer () || !yb_autovacate.GetBool () || GetBot (ent) != NULL)
return;
if (isPlayerConnection)
@ -374,7 +374,7 @@ void BotManager::VerifyPlayersHasJoinedTeam (int &desiredCount)
if (!m_trackedPlayers.GetElementNumber ())
return;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Client &cl = g_clients[i];
@ -405,7 +405,7 @@ void BotManager::MaintainBotQuota (void)
return;
// bot's creation update
if (!m_creationTab.IsEmpty () && m_maintainTime < GetWorldTime ())
if (!m_creationTab.IsEmpty () && m_maintainTime < engine.Time ())
{
CreateQueue last = m_creationTab.Pop ();
int resultOfCall = CreateBot (last.name, last.difficulty, last.personality, last.team, last.member);
@ -421,11 +421,11 @@ void BotManager::MaintainBotQuota (void)
m_creationTab.RemoveAll (); // maximum players reached, so set quota to maximum players
yb_quota.SetInt (GetBotsNum ());
}
m_maintainTime = GetWorldTime () + 0.45f;
m_maintainTime = engine.Time () + 0.45f;
}
// now keep bot number up to date
if (m_quotaMaintainTime < GetWorldTime ())
if (m_quotaMaintainTime < engine.Time ())
{
// don't allow that quota is below zero
if (yb_quota.GetInt () < 0)
@ -447,9 +447,9 @@ void BotManager::MaintainBotQuota (void)
desiredCount = max (0, yb_quota.GetInt () * numHumans);
if (yb_autovacate.GetBool ())
desiredCount = min (desiredCount, GetMaxClients () - (numHumans + 1));
desiredCount = min (desiredCount, engine.MaxClients () - (numHumans + 1));
else
desiredCount = min (desiredCount, GetMaxClients () - numHumans);
desiredCount = min (desiredCount, engine.MaxClients () - numHumans);
if (yb_autovacate_smart_kick.GetBool () && numBots > 1 && desiredCount > 1)
VerifyPlayersHasJoinedTeam (desiredCount);
@ -459,7 +459,7 @@ void BotManager::MaintainBotQuota (void)
else if (desiredCount < numBots)
RemoveRandom ();
m_quotaMaintainTime = GetWorldTime () + 0.90f;
m_quotaMaintainTime = engine.Time () + 0.90f;
}
}
@ -467,8 +467,8 @@ void BotManager::InitQuota (void)
{
m_balanceCount = 0;
m_maintainTime = GetWorldTime () + 3.0f;
m_quotaMaintainTime = GetWorldTime () + 3.0f;
m_maintainTime = engine.Time () + 3.0f;
m_quotaMaintainTime = engine.Time () + 3.0f;
m_trackedPlayers.RemoveAll ();
m_creationTab.RemoveAll ();
@ -478,7 +478,7 @@ void BotManager::FillServer (int selection, int personality, int difficulty, int
{
// this function fill server with bots, with specified team & personality
if (GetBotsNum () >= GetMaxClients () - GetHumansNum ())
if (GetBotsNum () >= engine.MaxClients () - GetHumansNum ())
return;
if (selection == 1 || selection == 2)
@ -499,14 +499,14 @@ void BotManager::FillServer (int selection, int personality, int difficulty, int
{"Random"},
};
int toAdd = numToAdd == -1 ? GetMaxClients () - (GetHumansNum () + GetBotsNum ()) : numToAdd;
int toAdd = numToAdd == -1 ? engine.MaxClients () - (GetHumansNum () + GetBotsNum ()) : numToAdd;
for (int i = 0; i <= toAdd; i++)
AddBot ("", difficulty, personality, selection, -1);
yb_quota.SetInt (toAdd);
CenterPrint ("Fill Server with %s bots...", &teamDesc[selection][0]);
engine.CenterPrintf ("Fill Server with %s bots...", &teamDesc[selection][0]);
}
void BotManager::RemoveAll (bool zeroQuota)
@ -514,9 +514,9 @@ void BotManager::RemoveAll (bool zeroQuota)
// this function drops all bot clients from server (this function removes only yapb's)`q
if (zeroQuota)
CenterPrint ("Bots are removed from server.");
engine.CenterPrintf ("Bots are removed from server.");
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL) // is this slot used?
m_bots[i]->Kick ();
@ -535,7 +535,7 @@ void BotManager::RemoveFromTeam (Team team, bool removeAll)
{
// this function remove random bot from specified team (if removeAll value = 1 then removes all players from team)
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL && team == GetTeam (m_bots[i]->GetEntity ()))
{
@ -612,7 +612,7 @@ void BotManager::KillAll (int team)
{
// this function kills all bots on server (only this dll controlled bots)
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL)
{
@ -622,7 +622,7 @@ void BotManager::KillAll (int team)
m_bots[i]->Kill ();
}
}
CenterPrint ("All Bots died !");
engine.CenterPrintf ("All Bots died !");
}
void BotManager::RemoveRandom (void)
@ -633,7 +633,7 @@ void BotManager::RemoveRandom (void)
// first try to kick the bot that is currently dead
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL && !m_bots[i]->m_notKilled) // is this slot used?
{
@ -652,7 +652,7 @@ void BotManager::RemoveRandom (void)
float score = 9999.0f;
// search bots in this team
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
@ -671,7 +671,7 @@ void BotManager::RemoveRandom (void)
}
// worst case, just kick some random bot
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL) // is this slot used?
{
@ -730,16 +730,16 @@ void BotManager::SetWeaponMode (int selection)
else
yb_jasonmode.SetInt (0);
CenterPrint ("%s weapon mode selected", &modeName[selection][0]);
engine.CenterPrintf ("%s weapon mode selected", &modeName[selection][0]);
}
void BotManager::ListBots (void)
{
// this function list's bots currently playing on the server
ServerPrint ("%-3.5s %-9.13s %-17.18s %-3.4s %-3.4s %-3.4s", "index", "name", "personality", "team", "difficulty", "frags");
engine.Printf ("%-3.5s %-9.13s %-17.18s %-3.4s %-3.4s %-3.4s", "index", "name", "personality", "team", "difficulty", "frags");
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
edict_t *player = EntityOfIndex (i);
@ -749,7 +749,7 @@ void BotManager::ListBots (void)
Bot *bot = GetBot (player);
if (bot != NULL)
ServerPrint ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (player->v.netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", GetTeam (player) != 0 ? "CT" : "T", bot->m_difficulty, static_cast <int> (player->v.frags));
engine.Printf ("[%-3.1d] %-9.13s %-17.18s %-3.4s %-3.1d %-3.1d", i, STRING (player->v.netname), bot->m_personality == PERSONALITY_RUSHER ? "rusher" : bot->m_personality == PERSONALITY_NORMAL ? "normal" : "careful", GetTeam (player) != 0 ? "CT" : "T", bot->m_difficulty, static_cast <int> (player->v.frags));
}
}
}
@ -760,7 +760,7 @@ int BotManager::GetBotsNum (void)
int count = 0;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL)
count++;
@ -774,7 +774,7 @@ Bot *BotManager::GetHighestFragsBot (int team)
float bestScore = -1;
// search bots in this team
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = bots.GetBot (i);
@ -808,7 +808,7 @@ void BotManager::CheckTeamEconomics (int team, bool setTrue)
int numTeamPlayers = 0;
// start calculating
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
if (m_bots[i] != NULL && GetTeam (m_bots[i]->GetEntity ()) == team)
{
@ -889,7 +889,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
if (!IsNullString (rejectReason))
{
AddLogEntry (true, LL_WARNING, "Server refused '%s' connection (%s)", STRING (bot->v.netname), rejectReason);
ServerCommand ("kick \"%s\"", STRING (bot->v.netname)); // kick the bot player if the server refused it
engine.IssueCmd ("kick \"%s\"", STRING (bot->v.netname)); // kick the bot player if the server refused it
bot->v.flags |= FL_KILLME;
}
@ -918,8 +918,8 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
yb_difficulty.SetInt (difficulty);
}
m_lastCommandTime = GetWorldTime () - 0.1f;
m_frameInterval = GetWorldTime ();
m_lastCommandTime = engine.Time () - 0.1f;
m_frameInterval = engine.Time ();
m_timePeriodicUpdate = 0.0f;
switch (personality)
@ -952,7 +952,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
// copy them over to the temp level variables
m_agressionLevel = m_baseAgressionLevel;
m_fearLevel = m_baseFearLevel;
m_nextEmotionUpdate = GetWorldTime () + 0.5f;
m_nextEmotionUpdate = engine.Time () + 0.5f;
// just to be sure
m_actMessageIndex = 0;
@ -965,7 +965,7 @@ Bot::Bot (edict_t *bot, int difficulty, int personality, int team, int member, c
int newBotsNum = bots.GetBotsNum () + 1;
// keep quota number up to date
if (newBotsNum < GetMaxClients () && newBotsNum > yb_quota.GetInt ())
if (newBotsNum < engine.MaxClients () && newBotsNum > yb_quota.GetInt ())
yb_quota.SetInt (newBotsNum);
NewRound ();
@ -999,7 +999,7 @@ int BotManager::GetHumansNum (void)
int count = 0;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Client *cl = &g_clients[i];
@ -1015,7 +1015,7 @@ int BotManager::GetHumansAliveNum (void)
int count = 0;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Client *cl = &g_clients[i];
@ -1031,7 +1031,7 @@ int BotManager::GetHumansJoinedTeam (void)
int count = 0;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Client *cl = &g_clients[i];
@ -1072,7 +1072,7 @@ void Bot::NewRound (void)
for (i = 0; i < 5; i++)
m_prevWptIndex[i] = -1;
m_navTimeset = GetWorldTime ();
m_navTimeset = engine.Time ();
m_team = GetTeam (GetEntity ());
switch (m_personality)
@ -1106,9 +1106,9 @@ void Bot::NewRound (void)
m_minSpeed = 260.0f;
m_prevSpeed = 0.0f;
m_prevOrigin = Vector (9999.0f, 9999.0f, 9999.0f);
m_prevTime = GetWorldTime ();
m_blindRecognizeTime = GetWorldTime ();
m_lookUpdateTime = GetWorldTime ();
m_prevTime = engine.Time ();
m_blindRecognizeTime = engine.Time ();
m_lookUpdateTime = engine.Time ();
m_viewDistance = 4096.0f;
m_maxViewDistance = 4096.0f;
@ -1170,8 +1170,8 @@ void Bot::NewRound (void)
m_reloadState = RELOAD_NONE;
m_reloadCheckTime = 0.0f;
m_shootTime = GetWorldTime ();
m_playerTargetTime = GetWorldTime ();
m_shootTime = engine.Time ();
m_playerTargetTime = engine.Time ();
m_firePause = 0.0f;
m_timeLastFired = 0.0f;
@ -1185,7 +1185,7 @@ void Bot::NewRound (void)
m_jumpFinished = false;
m_isStuck = false;
m_sayTextBuffer.timeNextChat = GetWorldTime ();
m_sayTextBuffer.timeNextChat = engine.Time ();
m_sayTextBuffer.entityIndex = -1;
m_sayTextBuffer.sayText[0] = 0x0;
@ -1200,8 +1200,8 @@ void Bot::NewRound (void)
m_currentWeapon = 0;
}
m_knifeAttackTime = GetWorldTime () + Random.Float (1.3f, 2.6f);
m_nextBuyTime = GetWorldTime () + Random.Float (0.6f, 2.0f);
m_knifeAttackTime = engine.Time () + Random.Float (1.3f, 2.6f);
m_nextBuyTime = engine.Time () + Random.Float (0.6f, 2.0f);
m_buyPending = false;
m_inBombZone = false;
@ -1224,9 +1224,9 @@ void Bot::NewRound (void)
m_defendHostage = false;
m_headedTime = 0.0f;
m_timeLogoSpray = GetWorldTime () + Random.Float (0.5f, 2.0f);
m_spawnTime = GetWorldTime ();
m_lastChatTime = GetWorldTime ();
m_timeLogoSpray = engine.Time () + Random.Float (0.5f, 2.0f);
m_spawnTime = engine.Time ();
m_lastChatTime = engine.Time ();
m_timeCamping = 0;
m_campDirection = 0;
@ -1234,7 +1234,7 @@ void Bot::NewRound (void)
m_campButtons = 0;
m_soundUpdateTime = 0.0f;
m_heardSoundTime = GetWorldTime ();
m_heardSoundTime = engine.Time ();
// clear its message queue
for (i = 0; i < 32; i++)
@ -1270,13 +1270,13 @@ void Bot::Kick (void)
{
// this function kick off one bot from the server.
ServerCommand ("kick \"%s\"", STRING (pev->netname));
CenterPrint ("Bot '%s' kicked", STRING (pev->netname));
engine.IssueCmd ("kick \"%s\"", STRING (pev->netname));
engine.CenterPrintf ("Bot '%s' kicked", STRING (pev->netname));
int newBotsNum = bots.GetBotsNum () - 1;
// keep quota number up to date
if (newBotsNum < GetMaxClients () && newBotsNum < yb_quota.GetInt ())
if (newBotsNum < engine.MaxClients () && newBotsNum < yb_quota.GetInt ())
yb_quota.SetInt (newBotsNum);
}
@ -1351,7 +1351,7 @@ void BotManager::CalculatePingOffsets (void)
int averagePing = 0;
int numHumans = 0;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
edict_t *ent = EntityOfIndex (i + 1);
@ -1374,7 +1374,7 @@ void BotManager::CalculatePingOffsets (void)
else
averagePing = Random.Long (30, 40);
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = GetBot (i);
@ -1417,7 +1417,7 @@ void BotManager::SendPingDataOffsets (edict_t *to)
// missing from sdk
static const int SVC_PINGS = 17;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
{
Bot *bot = GetBot (i);
@ -1470,7 +1470,7 @@ void BotManager::SendDeathMsgFix (void)
{
m_deathMsgSent = false;
for (int i = 0; i < GetMaxClients (); i++)
for (int i = 0; i < engine.MaxClients (); i++)
SendPingDataOffsets (g_clients[i].ent);
}
}