PRoConEvents.MULTIbalancer.AssignFillerToTeam C# (CSharp) Method

AssignFillerToTeam() private method

private AssignFillerToTeam ( PlayerModel filler, int toTeamId, List target, SquadRoster>.Dictionary targetSquadTable ) : void
filler PlayerModel
toTeamId int
target List
targetSquadTable SquadRoster>.Dictionary
return void
        private void AssignFillerToTeam(PlayerModel filler, int toTeamId, List<PlayerModel> target, Dictionary<int,SquadRoster> targetSquadTable)
        {
            String who = GetTeamName(toTeamId);
            if ((target.Count + 1) > (MaximumServerSize/2)) {
            DebugScrambler("Team " + who + " is full, skipping filler assignment of ^b" + filler.FullName);
            return;
            }
            if (!IsKnownPlayer(filler.Name)) return; // might have left

            // Find a squad with room to add this player, otherwise create a squad
            int toSquadId = 0;
            int emptyId = 1;
            SquadRoster toSquad = null;
            foreach (int key in targetSquadTable.Keys) {
            toSquad = targetSquadTable[key];
            if (toSquad.Roster.Count == fMaxSquadSize) continue;
            toSquadId = key;
            break;
            }
            if (toSquadId == 0) {
            // Create a new squad
            while (targetSquadTable.ContainsKey(emptyId)) {
            ++emptyId;
            if (emptyId >= SQUAD_NAMES.Length) {
                emptyId = 0;
                break;
            }
            }
            toSquadId = emptyId;
            ConsoleDebug("AssignFillerToTeam: created new squad " + GetSquadName(toSquadId));
            } else {
            ConsoleDebug("AssignFillerToTeam: using existing squad " + GetSquadName(toSquadId));
            }
            DebugScrambler("Filling in " + who + " team with player ^b" + filler.FullName + "^n to squad " + GetSquadName(toSquadId));
            filler.ScrambledSquad = toSquadId;
            filler.Team = toTeamId;
            target.Add(filler);
            toSquad = null;
            if (!targetSquadTable.ContainsKey(toSquadId)) {
            toSquad = new SquadRoster(toSquadId);
            targetSquadTable[toSquadId] = toSquad;
            } else {
            toSquad = targetSquadTable[toSquadId];
            }
            toSquad.Roster.Add(filler);
        }
MULTIbalancer