mgr: fixes to quota managenent

This commit is contained in:
jeefo 2024-06-12 23:04:53 +03:00
commit b0da38b2ab
No known key found for this signature in database
GPG key ID: D696786B81B667C8

View file

@ -374,14 +374,16 @@ void BotManager::maintainQuota () {
ctrl.msg ("Can't create bot during map analysis process."); ctrl.msg ("Can't create bot during map analysis process.");
return; return;
} }
const int maxClients = game.maxClients ();
const int botsInGame = getBotCount ();
// bot's creation update // bot's creation update
if (!m_addRequests.empty () && m_maintainTime < game.time ()) { if (!m_addRequests.empty () && m_maintainTime < game.time ()) {
const BotRequest &request = m_addRequests.popFront (); const auto &request = m_addRequests.popFront ();
const BotCreateResult createResult = create (request.name, request.difficulty, request.personality, request.team, request.skin); const auto createResult = create (request.name, request.difficulty, request.personality, request.team, request.skin);
if (request.manual) { if (request.manual) {
cv_quota.set (cr::min (cv_quota.as <int> () + 1, game.maxClients ())); cv_quota.set (cr::min (cv_quota.as <int> () + 1, maxClients));
} }
// check the result of creation // check the result of creation
@ -390,16 +392,16 @@ void BotManager::maintainQuota () {
cv_quota.set (0); // reset quota cv_quota.set (0); // reset quota
} }
else if (createResult == BotCreateResult::MaxPlayersReached) { else if (createResult == BotCreateResult::MaxPlayersReached) {
ctrl.msg ("Maximum players reached (%d/%d). Unable to create Bot.", game.maxClients (), game.maxClients ()); ctrl.msg ("Maximum players reached (%d/%d). Unable to create Bot.", maxClients, maxClients);
m_addRequests.clear (); // maximum players reached, so set quota to maximum players m_addRequests.clear (); // maximum players reached, so set quota to maximum players
cv_quota.set (getBotCount ()); cv_quota.set (botsInGame);
} }
else if (createResult == BotCreateResult::TeamStacked) { else if (createResult == BotCreateResult::TeamStacked) {
ctrl.msg ("Could not add bot to the game: Team is stacked (to disable this check, set mp_limitteams and mp_autoteambalance to zero and restart the round)"); ctrl.msg ("Could not add bot to the game: Team is stacked (to disable this check, set mp_limitteams and mp_autoteambalance to zero and restart the round)");
m_addRequests.clear (); m_addRequests.clear ();
cv_quota.set (getBotCount ()); cv_quota.set (botsInGame);
} }
m_maintainTime = game.time () + cv_quota_adding_interval.as <float> (); m_maintainTime = game.time () + cv_quota_adding_interval.as <float> ();
} }
@ -408,8 +410,12 @@ void BotManager::maintainQuota () {
if (m_quotaMaintainTime > game.time ()) { if (m_quotaMaintainTime > game.time ()) {
return; return;
} }
cv_quota.set (cr::clamp <int> (cv_quota.as <int> (), 0, game.maxClients ())); int desiredBotCount = cv_quota.as <int> ();
// only assign if out of range
if (desiredBotCount < 0 || desiredBotCount > maxClients) {
cv_quota.set (cr::clamp (desiredBotCount, 0, maxClients));
}
const int totalHumansInGame = getHumansCount (); const int totalHumansInGame = getHumansCount ();
const int humanPlayersInGame = getHumansCount (true); const int humanPlayersInGame = getHumansCount (true);
@ -417,39 +423,35 @@ void BotManager::maintainQuota () {
return; return;
} }
int desiredBotCount = cv_quota.as <int> ();
int botsInGame = getBotCount ();
if (cv_quota_mode.as <StringRef> () == "fill") { if (cv_quota_mode.as <StringRef> () == "fill") {
botsInGame += humanPlayersInGame; desiredBotCount = cr::max (0, desiredBotCount - humanPlayersInGame);
} }
else if (cv_quota_mode.as <StringRef> () == "match") { else if (cv_quota_mode.as <StringRef> () == "match") {
int detectQuotaMatch = cv_quota_match.as <int> () == 0 ? cv_quota.as <int> () : cv_quota_match.as <int> (); const int detectQuotaMatch = cv_quota_match.as <int> () == 0 ? cv_quota.as <int> () : cv_quota_match.as <int> ();
desiredBotCount = cr::max <int> (0, detectQuotaMatch * humanPlayersInGame); desiredBotCount = cr::max (0, detectQuotaMatch * humanPlayersInGame);
} }
if (cv_join_after_player && humanPlayersInGame == 0) { if (cv_join_after_player && humanPlayersInGame == 0) {
desiredBotCount = 0; desiredBotCount = 0;
} }
int maxClients = game.maxClients ();
if (cv_autovacate) { if (cv_autovacate) {
if (cv_kick_after_player_connect) { if (cv_kick_after_player_connect) {
desiredBotCount = cr::min <int> (desiredBotCount, maxClients - (totalHumansInGame + cv_autovacate_keep_slots.as <int> ())); desiredBotCount = cr::min (desiredBotCount, maxClients - (totalHumansInGame + cv_autovacate_keep_slots.as <int> ()));
} }
else { else {
desiredBotCount = cr::min <int> (desiredBotCount, maxClients - (humanPlayersInGame + cv_autovacate_keep_slots.as <int> ())); desiredBotCount = cr::min (desiredBotCount, maxClients - (humanPlayersInGame + cv_autovacate_keep_slots.as <int> ()));
} }
} }
else { else {
desiredBotCount = cr::min <int> (desiredBotCount, maxClients - humanPlayersInGame); desiredBotCount = cr::min (desiredBotCount, maxClients - humanPlayersInGame);
} }
auto maxSpawnCount = game.getSpawnCount (Team::Terrorist) + game.getSpawnCount (Team::CT) - humanPlayersInGame; auto maxSpawnCount = game.getSpawnCount (Team::Terrorist) + game.getSpawnCount (Team::CT) - humanPlayersInGame;
// if has some custom spawn points, max out spawn point counter // if has some custom spawn points, max out spawn point counter
if (desiredBotCount >= botsInGame && hasCustomCSDMSpawnEntities ()) { if (desiredBotCount >= botsInGame && hasCustomCSDMSpawnEntities ()) {
maxSpawnCount = game.maxClients () + 1; maxSpawnCount = maxClients + 1;
} }
// sent message only to console from here // sent message only to console from here