Fix team count inconsistency with random teams (#2051)

Switching to random teams would remove all teams but the first two on
the host, but not on the clients. With this fix, the extra teams are
removed on the clients as well. This fixes a desync when using
GetTeamCount() in a sync-relevant way.
master
Lukas Werling 2019-02-02 00:20:50 +01:00
parent f6fba582f3
commit 75d4ac2512
2 changed files with 24 additions and 8 deletions

View File

@ -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)))

View File

@ -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();