Skip to content

Commit

Permalink
mgr: fixes to quota managenent
Browse files Browse the repository at this point in the history
  • Loading branch information
jeefo committed Jun 12, 2024
1 parent e50ad2a commit b0da38b
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,16 @@ void BotManager::maintainQuota () {
ctrl.msg ("Can't create bot during map analysis process.");
return;
}
const int maxClients = game.maxClients ();
const int botsInGame = getBotCount ();

// bot's creation update
if (!m_addRequests.empty () && m_maintainTime < game.time ()) {
const BotRequest &request = m_addRequests.popFront ();
const BotCreateResult createResult = create (request.name, request.difficulty, request.personality, request.team, request.skin);
const auto &request = m_addRequests.popFront ();
const auto createResult = create (request.name, request.difficulty, request.personality, request.team, request.skin);

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
Expand All @@ -390,16 +392,16 @@ void BotManager::maintainQuota () {
cv_quota.set (0); // reset quota
}
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
cv_quota.set (getBotCount ());
cv_quota.set (botsInGame);
}
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)");

m_addRequests.clear ();
cv_quota.set (getBotCount ());
cv_quota.set (botsInGame);
}
m_maintainTime = game.time () + cv_quota_adding_interval.as <float> ();
}
Expand All @@ -408,48 +410,48 @@ void BotManager::maintainQuota () {
if (m_quotaMaintainTime > game.time ()) {
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 humanPlayersInGame = getHumansCount (true);

if (!game.isDedicated () && !totalHumansInGame) {
return;
}

int desiredBotCount = cv_quota.as <int> ();
int botsInGame = getBotCount ();

if (cv_quota_mode.as <StringRef> () == "fill") {
botsInGame += humanPlayersInGame;
desiredBotCount = cr::max (0, desiredBotCount - humanPlayersInGame);
}
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) {
desiredBotCount = 0;
}
int maxClients = game.maxClients ();

if (cv_autovacate) {
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 {
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 {
desiredBotCount = cr::min <int> (desiredBotCount, maxClients - humanPlayersInGame);
desiredBotCount = cr::min (desiredBotCount, maxClients - humanPlayersInGame);
}
auto maxSpawnCount = game.getSpawnCount (Team::Terrorist) + game.getSpawnCount (Team::CT) - humanPlayersInGame;

// if has some custom spawn points, max out spawn point counter
if (desiredBotCount >= botsInGame && hasCustomCSDMSpawnEntities ()) {
maxSpawnCount = game.maxClients () + 1;
maxSpawnCount = maxClients + 1;
}

// sent message only to console from here
Expand Down

1 comment on commit b0da38b

@MysticDeathProject
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Приветик jeefo, спасибо тебе за этих ботов очень похожих на людей, ты умничка не слушай всяких ворохов о том что боты должны быть как боты, ты настоящий криейтор и создатель этих ботов, ты создал настоящий шедевр, поэтому как ты понимаешь умные люди не нужны в россии, пожалуйста мой дорогой друг уезжай из рашки, контакты все мои у тебя есть, я искренне желаю тебе мира и счастья и любвьи и побольше умных и добрых проектов, но самое главное я желаю тебе жизни, пожалуйста живи в нормальном и добром и Европейском обществе без зомби вокруг себя.

Please sign in to comment.