Avoid unbalancing teams when removing bots

This commit is contained in:
smallmodel 2024-10-06 18:46:02 +02:00
parent d3d85fded0
commit 9119319429
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -256,9 +256,42 @@ void G_RemoveBot(unsigned int num)
{
unsigned int removed = 0;
unsigned int n;
unsigned int teamCount[2]{ 0 };
bool bNoMoreToRemove = false;
num = Q_min(num, sv_maxbots->integer);
teamCount[0] = dmManager.GetTeamAllies()->m_players.NumObjects();
teamCount[1] = dmManager.GetTeamAxis()->m_players.NumObjects();
while (!bNoMoreToRemove) {
bNoMoreToRemove = true;
for (n = 0; n < game.maxclients && removed < num; n++) {
gentity_t *e = &g_entities[game.maxclients - sv_maxbots->integer + n];
if (e->inuse && e->client) {
Player* player = static_cast<Player*>(e->entity);
if (player->GetTeam() == TEAM_ALLIES || player->GetTeam() == TEAM_AXIS) {
unsigned int teamIndex = (player->GetTeam() - TEAM_ALLIES);
if (teamCount[teamIndex] < teamCount[1 - teamIndex]) {
// Skip bots in the lowest team
continue;
}
teamCount[teamIndex]--;
bNoMoreToRemove = false;
}
G_ClientDisconnect(e);
current_bot_count--;
removed++;
}
}
}
//
// Remove all bots regardless
//
for (n = 0; n < game.maxclients && removed < num; n++) {
gentity_t *e = &g_entities[game.maxclients - sv_maxbots->integer + n];
if (e->inuse && e->client) {