forked from Mirrors/openclonk
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
parent
f6fba582f3
commit
75d4ac2512
|
@ -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)))
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue