some rework of autovacate... again
This commit is contained in:
parent
c6422c19a9
commit
c850e45ed2
3 changed files with 96 additions and 17 deletions
|
|
@ -9,11 +9,10 @@
|
|||
|
||||
#include <core.h>
|
||||
|
||||
ConVar yb_autovacate ("yb_autovacate", "-1");
|
||||
ConVar yb_autovacate ("yb_autovacate", "0");
|
||||
|
||||
ConVar yb_quota ("yb_quota", "0");
|
||||
ConVar yb_quota_match ("yb_quota_match", "0");
|
||||
ConVar yb_quota_match_max ("yb_quota_match_max", "0");
|
||||
ConVar yb_quota ("yb_quota", "0", VT_NORMAL);
|
||||
ConVar yb_quota_mode ("yb_quota_mode", "normal");
|
||||
|
||||
ConVar yb_join_after_player ("yb_join_after_player", "0");
|
||||
ConVar yb_join_team ("yb_join_team", "any");
|
||||
|
|
@ -333,9 +332,21 @@ void BotManager::AddBot (const String &name, const String &difficulty, const Str
|
|||
|
||||
m_creationTab.Push (bot);
|
||||
|
||||
int newBotsNum = GetBotsNum () + 1;
|
||||
|
||||
// keep quota number up to date
|
||||
if (GetBotsNum () + 1 > yb_quota.GetInt ())
|
||||
yb_quota.SetInt (GetBotsNum () + 1);
|
||||
if (newBotsNum < GetMaxClients () && newBotsNum > yb_quota.GetInt ())
|
||||
yb_quota.SetInt (newBotsNum);
|
||||
}
|
||||
|
||||
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)
|
||||
return;
|
||||
|
||||
m_quotaOption = isPlayerConnection ? QUOTA_DECREMENT : QUOTA_INCREMENT;
|
||||
}
|
||||
|
||||
void BotManager::MaintainBotQuota (void)
|
||||
|
|
@ -346,12 +357,7 @@ void BotManager::MaintainBotQuota (void)
|
|||
if (g_numWaypoints < 1 || g_waypointsChanged)
|
||||
return;
|
||||
|
||||
if (yb_join_after_player.GetInt () > 0 && GetHumansJoinedTeam () == 0)
|
||||
{
|
||||
RemoveAll (false);
|
||||
return;
|
||||
}
|
||||
|
||||
// bot's creation update
|
||||
if (!m_creationTab.IsEmpty () && m_maintainTime < GetWorldTime ())
|
||||
{
|
||||
CreateQueue last = m_creationTab.Pop ();
|
||||
|
|
@ -374,6 +380,46 @@ void BotManager::MaintainBotQuota (void)
|
|||
// now keep bot number up to date
|
||||
if (m_maintainTime < GetWorldTime ())
|
||||
{
|
||||
// don't allow that quota is below zero
|
||||
if (yb_quota.GetInt () < 0)
|
||||
yb_quota.SetInt (0);
|
||||
|
||||
int numBots = GetBotsNum ();
|
||||
int numHumans = GetHumansJoinedTeam ();
|
||||
int desiredCount = yb_quota.GetInt ();
|
||||
|
||||
if (yb_join_after_player.GetInt () > 0 && !numHumans)
|
||||
desiredCount = 0;
|
||||
|
||||
if (m_quotaOption != QUOTA_NONE && numBots > 1 && desiredCount > 1)
|
||||
{
|
||||
if (m_quotaOption == QUOTA_INCREMENT)
|
||||
desiredCount++;
|
||||
else
|
||||
desiredCount--;
|
||||
}
|
||||
|
||||
// quota mode
|
||||
char mode = yb_quota_mode.GetString ()[0];
|
||||
|
||||
if (mode == 'f') // fill
|
||||
desiredCount = max (0, desiredCount - numHumans);
|
||||
else if (mode == 'm') // match
|
||||
desiredCount = max (0, yb_quota.GetInt () * numHumans);
|
||||
|
||||
if (yb_autovacate.GetBool ())
|
||||
desiredCount = min (desiredCount, GetMaxClients () - (numHumans + 1));
|
||||
else
|
||||
desiredCount = min (desiredCount, GetMaxClients () - numHumans);
|
||||
|
||||
m_quotaOption = QUOTA_NONE;
|
||||
|
||||
if (desiredCount > numBots)
|
||||
AddRandom ();
|
||||
else if (desiredCount < numBots)
|
||||
RemoveRandom ();
|
||||
|
||||
#if 0
|
||||
int botNumber = GetBotsNum ();
|
||||
int humanNumber = GetHumansNum ();
|
||||
|
||||
|
|
@ -396,7 +442,7 @@ void BotManager::MaintainBotQuota (void)
|
|||
|
||||
if (yb_autovacate.GetBool ())
|
||||
{
|
||||
if (botNumber < yb_quota.GetInt () && botNumber < GetMaxClients () - 1)
|
||||
if (botNumber < yb_quota.GetInt () && humanNumber < GetMaxClients () - 1)
|
||||
AddRandom ();
|
||||
|
||||
if (humanNumber >= GetMaxClients ())
|
||||
|
|
@ -404,11 +450,11 @@ void BotManager::MaintainBotQuota (void)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (botNumber < yb_quota.GetInt () && botNumber < GetMaxClients ())
|
||||
if (botNumber < yb_quota.GetInt () && humanNumber < GetMaxClients ())
|
||||
AddRandom ();
|
||||
}
|
||||
|
||||
int botQuota = yb_autovacate.GetBool () ? (GetMaxClients () - 1 - (humanNumber + 1)) : GetMaxClients ();
|
||||
int botQuota = yb_autovacate.GetBool () ? GetMaxClients () - humanNumber : GetMaxClients ();
|
||||
|
||||
// check valid range of quota
|
||||
if (yb_quota.GetInt () > botQuota)
|
||||
|
|
@ -416,7 +462,7 @@ void BotManager::MaintainBotQuota (void)
|
|||
|
||||
else if (yb_quota.GetInt () < 0)
|
||||
yb_quota.SetInt (0);
|
||||
|
||||
#endif
|
||||
m_maintainTime = GetWorldTime () + 0.15f;
|
||||
}
|
||||
}
|
||||
|
|
@ -425,6 +471,7 @@ void BotManager::InitQuota (void)
|
|||
{
|
||||
m_maintainTime = GetWorldTime () + 3.0f;
|
||||
m_creationTab.RemoveAll ();
|
||||
m_quotaOption = QUOTA_NONE;
|
||||
}
|
||||
|
||||
void BotManager::FillServer (int selection, int personality, int difficulty, int numToAdd)
|
||||
|
|
@ -458,7 +505,6 @@ void BotManager::FillServer (int selection, int personality, int difficulty, int
|
|||
AddBot ("", difficulty, personality, selection, -1);
|
||||
|
||||
yb_quota.SetInt (toAdd);
|
||||
yb_quota_match.SetInt (0);
|
||||
|
||||
CenterPrint ("Fill Server with %s bots...", &teamDesc[selection][0]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue