Minor rework bot_quota_mode fill

This commit is contained in:
s1lentq 2024-06-01 20:24:44 +07:00
parent c7be8bfe7c
commit bdc96d26d9

View File

@ -424,6 +424,12 @@ void CCSBotManager::ServerCommand(const char *pcmd)
else else
kickThemAll = false; 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++) for (int i = 1; i <= gpGlobals->maxClients; i++)
{ {
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
@ -443,7 +449,11 @@ void CCSBotManager::ServerCommand(const char *pcmd)
// adjust bot quota so kicked bot is not immediately added back in // adjust bot quota so kicked bot is not immediately added back in
int newQuota = cv_bot_quota.value - 1; int newQuota = cv_bot_quota.value - 1;
SERVER_COMMAND(UTIL_VarArgs("kick \"%s\"\n", name)); 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)));
}
} }
} }
} }
@ -790,7 +800,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota // decrease the bot quota
if (!isFromConsole) 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 #endif
@ -824,7 +835,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
if (isFromConsole) if (isFromConsole)
{ {
// increase the bot quota to account for manually added bot // 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 #ifdef REGAMEDLL_FIXES
@ -833,7 +845,8 @@ bool CCSBotManager::BotAddCommand(BotProfileTeamType team, bool isFromConsole)
// decrease the bot quota // decrease the bot quota
if (!isFromConsole) 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 #endif
@ -863,10 +876,17 @@ void CCSBotManager::MaintainBotQuota()
int desiredBotCount = int(cv_bot_quota.value); int desiredBotCount = int(cv_bot_quota.value);
int occupiedBotSlots = UTIL_BotsInGame(); 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. // isRoundInProgress is true if the round has progressed far enough that new players will join as dead.
bool isRoundInProgress = CSGameRules()->IsGameStarted() && bool isRoundInProgress = CSGameRules()->IsGameStarted() &&
!TheCSBots()->IsRoundOver() && !TheCSBots()->IsRoundOver() &&
(CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime()); (CSGameRules()->GetRoundRespawnTime() != -1 && CSGameRules()->GetRoundElapsedTime() >= CSGameRules()->GetRoundRespawnTime()) && !isRoundInDeathmatch;
#ifdef REGAMEDLL_ADD #ifdef REGAMEDLL_ADD
if (FStrEq(cv_bot_quota_mode.string, "fill")) if (FStrEq(cv_bot_quota_mode.string, "fill"))
@ -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 // unless the round is already in progress, in which case we play with what we've been dealt
if (!isRoundInProgress) if (!isRoundInProgress)
{ {
desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame + spectatorPlayersInGame); desiredBotCount = Q_max(0, desiredBotCount - humanPlayersInGame);
} }
else else
{ {
@ -922,13 +942,15 @@ void CCSBotManager::MaintainBotQuota()
if (cv_bot_auto_vacate.value > 0.0) if (cv_bot_auto_vacate.value > 0.0)
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - (humanPlayersInGame + 1)); desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - (humanPlayersInGame + 1));
else else
desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame + spectatorPlayersInGame); desiredBotCount = Q_min(desiredBotCount, gpGlobals->maxClients - humanPlayersInGame);
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
// Try to balance teams, if we are in the first specified seconds of a round and bots can join either team. // 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) if (autoteambalance.value > 0.0f)
{ {
@ -1045,7 +1067,8 @@ void CCSBotManager::MaintainBotQuota()
UTIL_KickBotFromTeam(TERRORIST); 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));
} }
} }