From 87cbd144c22f676d83c265c9241e79055ccfcba6 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 1 Jun 2024 13:58:48 +0300 Subject: [PATCH] mgr: random bot kick is now more even across teams --- inc/manager.h | 1 + src/control.cpp | 2 +- src/manager.cpp | 39 ++++++++++++++++++++++----------------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/inc/manager.h b/inc/manager.h index abcde90..183bcab 100644 --- a/inc/manager.h +++ b/inc/manager.h @@ -126,6 +126,7 @@ public: bool isTeamStacked (int team); bool kickRandom (bool decQuota = true, Team fromTeam = Team::Unassigned); + bool balancedKickRandom (bool decQuota); bool hasCustomCSDMSpawnEntities (); bool isLineBlockedBySmoke (const Vector &from, const Vector &to, float grenadeBloat = 1.0f); diff --git a/src/control.cpp b/src/control.cpp index a32b8eb..b21f48e 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -53,7 +53,7 @@ int BotControl::cmdKickBot () { bots.kickFromTeam (Team::Terrorist); } else { - bots.kickRandom (); + bots.balancedKickRandom (true); } return BotCommandResult::Handled; } diff --git a/src/manager.cpp b/src/manager.cpp index a1574b9..68fb7e3 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -460,23 +460,7 @@ void BotManager::maintainQuota () { createRandom (); } else if (desiredBotCount < botsInGame) { - const auto &tp = countTeamPlayers (); - bool isKicked = false; - - if (tp.first > tp.second) { - isKicked = kickRandom (false, Team::Terrorist); - } - else if (tp.first < tp.second) { - isKicked = kickRandom (false, Team::CT); - } - else { - isKicked = kickRandom (false, Team::Unassigned); - } - - // if we can't kick player from correct team, just kick any random to keep quota control work - if (!isKicked) { - kickRandom (false, Team::Unassigned); - } + balancedKickRandom (false); } else { // clear the saved names when quota balancing ended @@ -796,6 +780,27 @@ bool BotManager::kickRandom (bool decQuota, Team fromTeam) { return false; } +bool BotManager::balancedKickRandom (bool decQuota) { + const auto &tp = countTeamPlayers (); + bool isKicked = false; + + if (tp.first > tp.second) { + isKicked = kickRandom (decQuota, Team::Terrorist); + } + else if (tp.first < tp.second) { + isKicked = kickRandom (decQuota, Team::CT); + } + else { + isKicked = kickRandom (decQuota, Team::Unassigned); + } + + // if we can't kick player from correct team, just kick any random to keep quota control work + if (!isKicked) { + isKicked = kickRandom (decQuota, Team::Unassigned); + } + return isKicked; +} + bool BotManager::hasCustomCSDMSpawnEntities () { if (!game.is (GameFlags::CSDM | GameFlags::FreeForAll)) { return false;