Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ShuffleTeamsNextMatch()
- {
- local Array<Rx_Controller> Team1, Team2, All;
- local int Team1Score, Team2Score;
- local int GDICount, NodCount;
- local Rx_Controller PC, Highest;
- // Gather all Human Players
- foreach WorldInfo.AllControllers(class'Rx_Controller', PC)
- {
- if ( (PC.PlayerReplicationInfo != None) && (PC.PlayerReplicationInfo.Team != None) )
- All.AddItem(PC);
- }
- // Sort them all into 2 teams.
- while (All.Length > 0)
- {
- Highest = None;
- foreach All(PC)
- {
- if (Highest == None)
- Highest = PC;
- else if (Rx_PRI(PC.PlayerReplicationInfo).OldRenScore > Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore)
- Highest = PC;
- }
- All.RemoveItem(Highest);
- if (Team1Score <= Team2Score)
- {
- Team1.AddItem(Highest);
- Team1Score += Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore;
- }
- else
- {
- Team2.AddItem(Highest);
- Team2Score += Rx_PRI(Highest.PlayerReplicationInfo).OldRenScore;
- }
- // If the small team + the rest is less than the larger team, then place all remaining players in the small team.
- if (Team1.Length >= Team2.Length + All.Length)
- {
- // Dump the rest in Team2.
- foreach All(PC)
- Team2.AddItem(PC);
- break;
- }
- else if (Team2.Length >= Team1.Length + All.Length)
- {
- // Dump the rest in Team1.
- foreach All(PC)
- Team1.AddItem(PC);
- break;
- }
- }
- // Figure out which team will be which faction. Just do the one that moves the least.
- foreach Team1(PC)
- {
- if (PC.PlayerReplicationInfo.Team.TeamIndex == 0)
- ++GDICount;
- else
- ++NodCount;
- }
- if (GDICount >= NodCount)
- {
- // Team 1 go GDI, Team 2 go Nod
- foreach Team1(PC)
- if (PC.PlayerReplicationInfo.Team.TeamIndex != 0)
- `RxEngineObject.AddGDIPlayer(PC.PlayerReplicationInfo);
- foreach Team2(PC)
- if (PC.PlayerReplicationInfo.Team.TeamIndex != 1)
- `RxEngineObject.AddNodPlayer(PC.PlayerReplicationInfo);
- }
- else
- {
- // Team 1 go Nod, Team 2 go GDI
- foreach Team1(PC)
- if (PC.PlayerReplicationInfo.Team.TeamIndex != 1)
- `RxEngineObject.AddNodPlayer(PC.PlayerReplicationInfo);
- foreach Team2(PC)
- if (PC.PlayerReplicationInfo.Team.TeamIndex != 0)
- `RxEngineObject.AddGDIPlayer(PC.PlayerReplicationInfo);
- }
- // Terribly unoptimized, but done.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement