diff --git a/src/control/C4Teams.cpp b/src/control/C4Teams.cpp index d43dc8085..05e7d73d2 100644 --- a/src/control/C4Teams.cpp +++ b/src/control/C4Teams.cpp @@ -671,7 +671,13 @@ void C4TeamList::RecheckTeams() // automatic team distributions only if (!IsRandomTeam()) return; // host decides random teams - if (!::Control.isCtrlHost()) return; + if (!::Control.isCtrlHost()) + { + // Still make sure that we have the right number of teams on the clients as well so that + // GetTeamCount() does not report inconsistent values. + EnsureTeamCount(); + return; + } // random teams in auto generate mode? Make sure there are exactly two teams if (IsAutoGenerateTeams() && GetTeamCount() != 2) { @@ -710,6 +716,19 @@ void C4TeamList::RecheckTeams() } } +void C4TeamList::EnsureTeamCount() +{ + // in random autogenerate mode, there must be exactly two teams + if (IsRandomTeam()) + { + if (IsAutoGenerateTeams() && GetTeamCount() != 2) + { + ClearTeams(); + GenerateDefaultTeams(2); + } + } +} + void C4TeamList::ReassignAllTeams() { assert(::Control.isCtrlHost()); @@ -731,13 +750,7 @@ void C4TeamList::ReassignAllTeams() } // clear players from team lists RecheckPlayers(); - // in random autogenerate mode, there must be exactly two teams - if (IsRandomTeam()) - if (IsAutoGenerateTeams() && GetTeamCount() != 2) - { - ClearTeams(); - GenerateDefaultTeams(2); - } + EnsureTeamCount(); // reassign them idStart = -1; while ((pNfo = Game.PlayerInfos.GetNextPlayerInfoByID(idStart))) diff --git a/src/control/C4Teams.h b/src/control/C4Teams.h index 1662455d3..91f6f6f85 100644 --- a/src/control/C4Teams.h +++ b/src/control/C4Teams.h @@ -195,6 +195,9 @@ public: // any changed players will be flagged "updated" void RecheckTeams(); + // Makes sure that there's the right amount of teams when switching to random teams. + void EnsureTeamCount(); + // marks all unjoined players as not-in-team and reassigns a team for them // also automatically flags all affected player infos as updated void ReassignAllTeams();