mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Avoid unbalancing teams when removing bots
This commit is contained in:
parent
d3d85fded0
commit
9119319429
1 changed files with 33 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue