int nTeams = game.getNoOfTeams();
Hashtable<Team, TurnVectors> allTeamTurns = new Hashtable<Team, TurnVectors>(nTeams);
Hashtable<Team, int[]> evenTrackers = new Hashtable<Team, int[]>(nTeams);
int numTeamsMoving = 0;
for (Enumeration<Team> loop = game.getTeams(); loop.hasMoreElements();) {
final Team team = loop.nextElement();
allTeamTurns.put(team, team.determineTeamOrder(game));
// Track both the number of times we've checked the team for
// "leftover" turns, and the number of "leftover" turns placed.
int[] evenTracker = new int[2];
evenTracker[0] = 0;
evenTracker[1] = 0;
evenTrackers.put(team, evenTracker);
// Count this team if it has any "normal" moves.
if (team.getNormalTurns(game) > 0) {
numTeamsMoving++;
}
}
// Now, generate the global order of all teams' turns.
TurnVectors team_order = TurnOrdered.generateTurnOrder(game.getTeamsVector(), game);
// See if there are any loaded units stranded on immobile transports.
Enumeration<Entity> strandedUnits = game.getSelectedEntities(new EntitySelector() {
public boolean accept(Entity entity) {
if (game.isEntityStranded(entity)) {
return true;
}
return false;
}
});
// Now, we collect everything into a single vector.
Vector<GameTurn> turns;
if (strandedUnits.hasMoreElements() && (game.getPhase() == IGame.Phase.PHASE_MOVEMENT)) {
// Add a game turn to unload stranded units, if this
// is the movement phase.
turns = new Vector<GameTurn>(team_order.getTotalTurns() + team_order.getEvenTurns() + 1);
turns.addElement(new GameTurn.UnloadStrandedTurn(strandedUnits));
} else {
// No stranded units.
turns = new Vector<GameTurn>(team_order.getTotalTurns() + team_order.getEvenTurns());
}
// Walk through the global order, assigning turns
// for individual players to the single vector.
// Keep track of how many turns we've added to the vector.
Team prevTeam = null;
int min = team_order.getMin();
for (int numTurn = 0; team_order.hasMoreElements(); numTurn++) {
Team team = (Team) team_order.nextElement();
TurnVectors withinTeamTurns = allTeamTurns.get(team);
int[] evenTracker = evenTrackers.get(team);
float teamEvenTurns = team.getEvenTurns();
// Calculate the number of "even" turns to add for this team.
int numEven = 0;
if (1 == numTeamsMoving) {
// The only team moving should move all "even" units.
numEven += teamEvenTurns;
} else if (prevTeam == null) {
// Increment the number of times we've checked for "leftovers".
evenTracker[0]++;
// The first team to move just adds the "baseline" turns.
numEven += teamEvenTurns / min;
} else if (!team.equals(prevTeam)) {
// Increment the number of times we've checked for "leftovers".
evenTracker[0]++;
// This wierd equation attempts to spread the "leftover"
// turns accross the turn's moves in a "fair" manner.