private void AnalyzeSquadLists(int beforeTeam, int beforeSquad, List<String> beforeSquadList, int afterTeam, Dictionary<int, List<String>> afterTable, int otherTeam, Dictionary<int, List<String>> otherTable, bool finalCheck)
{
// Analyze the disposition of one squad (beforeSquad)
if (beforeTeam < 1 || beforeTeam > 2 || beforeSquad < 0 || beforeSquad >= SQUAD_NAMES.Length) return;
Dictionary<String,int> endedUpIn = new Dictionary<string,int>();
String teamName = GetTeamName(beforeTeam);
String squadName = GetSquadName(beforeSquad);
String ts = teamName + "/" + squadName;
// Find which squad each expected player ended up in
foreach (String x in beforeSquadList) {
// anyone leave?
if (finalCheck && !IsKnownPlayer(x)) {
ConsoleDump("Player must have left, since " + ts + " is missing ^b" + x);
continue;
}
// where did player x end up?
foreach (int afterSquad in afterTable.Keys) {
if (afterTable[afterSquad].Contains(x)) {
endedUpIn[x] = (1000 * afterTeam) + afterSquad; // remember combined team+squad this name ended up
}
}
foreach (int otherSquad in otherTable.Keys) {
if (otherTable[otherSquad].Contains(x)) {
endedUpIn[x] = (1000 * otherTeam) + otherSquad; // remember combined team+squad this name ended up
}
}
}
// build a table of where every player actually ended up (invert endedUpIn table)
String split = " ";
int different = -1;
Dictionary<int, List<String>> movedSquadTable = new Dictionary<int,List<string>>(); // key is combined team + squad
foreach (String name in endedUpIn.Keys) {
int eui = endedUpIn[name];
int endedUpInTeam = eui / 1000;
int endedUpInSquad = eui - (1000 * endedUpInTeam);
if (endedUpInSquad != beforeSquad) different = eui; // only remember the latest
List<String> endedUpInSquadList = null;
if (movedSquadTable.TryGetValue(eui, out endedUpInSquadList) && endedUpInSquadList != null) {
endedUpInSquadList.Add(name);
} else {
endedUpInSquadList = new List<String>();
endedUpInSquadList.Add(name);
movedSquadTable[eui] = endedUpInSquadList;
}
}
// A split squad will have more than one entry in the squad id -> player list table
if (movedSquadTable.Keys.Count > 1) {
// Decide which players are the outliers, in the smallest lists
int max = -1;
int big = -1;
foreach (int si in movedSquadTable.Keys) {
if (movedSquadTable[si].Count > max) {
big = si;
max = movedSquadTable[si].Count;
}
}
// every list except max
String notice = "Player(s) removed from " + ts + " to balance teams:";
foreach (int si in movedSquadTable.Keys) {
if (si == big) continue;
int siTeam = si / 1000;
int siSquad = si - (1000 * siTeam);
if (!finalCheck) {
foreach (String outlier in movedSquadTable[si]) {
split = split + "^b" + outlier + "^n to " + GetSquadName(siSquad) + ", ";
}
split = split + "end.";
ConsoleDump(notice + split);
split = " ";
} else {
foreach (String finalOutlier in movedSquadTable[si]) {
String fm = null;
try {
lock (fExtrasLock) {
fDebugScramblerSuspects.TryGetValue(finalOutlier, out fm);
}
if (fm == null) {
fm = "^4UNEXPECTED: split of " + ts + " due to player ^b{0}^n being found in " + GetSquadName(siSquad);
}
PlayerModel outp = GetPlayer(finalOutlier);
String fullName = (outp == null) ? finalOutlier : outp.FullName;
ConsoleDump(String.Format(fm, fullName));
} catch (Exception e) {
ConsoleException(e);
}
}
}
}
} else if (different != -1) {
int differentTeam = different / 1000;
if (differentTeam < 1 || differentTeam > 2) differentTeam = 0;
int differentSquad = different - (1000 * differentTeam);
if (differentSquad < 0 || differentSquad >= SQUAD_NAMES.Length) differentSquad = 0;
ConsoleDump(ts + " is intact and is now a different squad: " + GetTeamName(differentTeam) + "/" + GetSquadName(differentSquad));
}
// Dump nothing if everything is as expected
}