private void RestoreSquads(List<PlayerModel> allCopy, Dictionary<int,int> allocated, bool logOnly)
{
// Try to restore to original squad
foreach (PlayerModel clone in allCopy) {
try {
// Check to make sure original team and squad are available
if (clone.Team < 1 || clone.Team > 2 || clone.OriginalSquad < 1 || clone.OriginalSquad >= SQUAD_NAMES.Length) continue;
int toSquad = clone.OriginalSquad;
// If the original squad is full, pick one that isn't
if (allocated != null) {
int key = (1000 * clone.Team) + toSquad;
while (allocated.ContainsKey(key) && allocated[key] >= fMaxSquadSize) {
++toSquad;
if (toSquad >= SQUAD_NAMES.Length) {
break;
}
key = (1000 * clone.Team) + toSquad;
}
if (toSquad >= SQUAD_NAMES.Length) {
DebugScrambler("UNABLE to restore ^b" + clone.FullName + "^n to a squad, skipping");
continue;
}
}
// Do the move
if (!EnableLoggingOnlyMode && !logOnly) {
DebugScrambler("^1^bMOVE^n^0 ^b" + clone.FullName + "^n to " + GetTeamName(clone.Team) + " team, restore squad " + GetSquadName(toSquad));
ServerCommand("admin.movePlayer", clone.Name, clone.Team.ToString(), toSquad.ToString(), "false");
Thread.Sleep(60);
} else {
DebugScrambler("^9(SIMULATED) ^1^bMOVE^n^0 ^b" + clone.FullName + "^n to " + GetTeamName(clone.Team) + " team, restore squad " + GetSquadName(toSquad));
}
} catch (Exception e) {
ConsoleException(e);
}
}
}