Skip to content

Commit

Permalink
Minor rework bot_quota_mode fill
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Jun 2, 2024
1 parent c7be8bf commit bdc96d2
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions regamedll/dlls/bot/cs_bot_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ void CCSBotManager::ServerCommand(const char *pcmd)
else
kickThemAll = false;

#ifdef REGAMEDLL_ADD
bool fillMode = FStrEq(cv_bot_quota_mode.string, "fill");
#else
bool fillMode = false;
#endif

for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
Expand All @@ -443,7 +449,11 @@ void CCSBotManager::ServerCommand(const char *pcmd)
// adjust bot quota so kicked bot is not immediately added back in
int newQuota = cv_bot_quota.value - 1;
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", name));
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, int(cv_bot_quota.value)));

if (kickThemAll || !fillMode)
{
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, int(cv_bot_quota.value)));
}
}
}
}
Expand Down Expand Up @@ -790,7 +800,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota
if (!isFromConsole)
{
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
#endif

Expand Down Expand Up @@ -824,7 +835,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
if (isFromConsole)
{
// increase the bot quota to account for manually added bot
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value + 1);
int newQuota = cv_bot_quota.value + 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, gpGlobals->maxClients));
}
}
#ifdef REGAMEDLL_FIXES
Expand All @@ -833,7 +845,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota
if (!isFromConsole)
{
CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
}
#endif
Expand Down Expand Up @@ -863,10 +876,17 @@ void CCSBotManager::MaintainBotQuota()
int desiredBotCount = int(cv_bot_quota.value);
int occupiedBotSlots = UTIL_BotsInGame();

bool isRoundInDeathmatch = false;

#ifdef REGAMEDLL_ADD
if (round_infinite.value > 0)
isRoundInDeathmatch = true; // is no round end gameplay
#endif

// isRoundInProgress is true if the round has progressed far enough that new players will join as dead.
bool isRoundInProgress = CSGameRules()->IsGameStarted() &&
!TheCSBots()->IsRoundOver() &&
(CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime());
(CSGameRules()->GetRoundRespawnTime() != -1 && CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime()) && !isRoundInDeathmatch;

#ifdef REGAMEDLL_ADD
if (FStrEq(cv_bot_quota_mode.string, "fill"))
Expand All @@ -875,7 +895,7 @@ void CCSBotManager::MaintainBotQuota()
// unless the round is already in progress, in which case we play with what we've been dealt
if (!isRoundInProgress)
{
desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame + spectatorPlayersInGame);
desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame);
}
else
{
Expand Down Expand Up @@ -922,13 +942,15 @@ void CCSBotManager::MaintainBotQuota()
if (cv_bot_auto_vacate.value > 0.0)
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - (humanPlayersInGame + 1));
else
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame + spectatorPlayersInGame);
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame);

#ifdef REGAMEDLL_FIXES
// Try to balance teams, if we are in the first specified seconds of a round and bots can join either team.
if (occupiedBotSlots > 0 && desiredBotCount == occupiedBotSlots && CSGameRules()->IsGameStarted())
if (occupiedBotSlots > 0 && desiredBotCount == occupiedBotSlots && (CSGameRules()->IsGameStarted() || isRoundInDeathmatch))
{
if (CSGameRules()->GetRoundElapsedTime() < CSGameRules()->GetRoundRespawnTime()) // new bots can still spawn during this time
if (isRoundInDeathmatch ||
(CSGameRules()->GetRoundRespawnTime() == -1 || // means no time limit
CSGameRules()->GetRoundElapsedTime() < CSGameRules()->GetRoundRespawnTime())) // new bots can still spawn during this time
{
if (autoteambalance.value > 0.0f)
{
Expand Down Expand Up @@ -1045,7 +1067,8 @@ void CCSBotManager::MaintainBotQuota()
UTIL_KickBotFromTeam(TERRORIST);
}

CVAR_SET_FLOAT("bot_quota", cv_bot_quota.value - 1.0f);
int newQuota = cv_bot_quota.value - 1;
CVAR_SET_FLOAT("bot_quota", clamp(newQuota, 0, (int)cv_bot_quota.value));
}
}

Expand Down

0 comments on commit bdc96d2

Please sign in to comment.