// Enforce "inf_move_multi" and "protos_move_multi" options.
// The "isNormalTurn" flag is checking to see if any non-Infantry
// or non-Protomech units can move during the current turn.
boolean turnsChanged = false;
boolean outOfOrder = false;
GameTurn turn = game.getTurn();
if(game.isPhaseSimultaneous() && !turn.isValid(entityUsed.getOwnerId(), game)) {
//turn played out of order
outOfOrder = true;
entityUsed.setDone(false);
GameTurn removed = game.removeFirstTurnFor(entityUsed);
entityUsed.setDone(true);
turnsChanged = true;
if(removed != null) {
turn = removed;
}
}
final int playerId = null == entityUsed ? Player.PLAYER_NONE : entityUsed.getOwnerId();
boolean infMoved = entityUsed instanceof Infantry;
boolean infMoveMulti = game.getOptions().booleanOption("inf_move_multi") && ((game.getPhase() == IGame.Phase.PHASE_MOVEMENT) || (game.getPhase() == IGame.Phase.PHASE_INITIATIVE));
boolean protosMoved = entityUsed instanceof Protomech;
boolean protosMoveMulti = game.getOptions().booleanOption("protos_move_multi");
boolean tanksMoved = entityUsed instanceof Tank;
boolean tanksMoveMulti = game.getOptions().booleanOption("vehicle_lance_movement") && ((game.getPhase() == IGame.Phase.PHASE_MOVEMENT) || (game.getPhase() == IGame.Phase.PHASE_INITIATIVE));
// If infantry or protos move multi see if any
// other unit types can move in the current turn.
int multiMask = 0;
if (infMoveMulti) {
multiMask += GameTurn.CLASS_INFANTRY;
}
if (protosMoveMulti) {
multiMask += GameTurn.CLASS_PROTOMECH;
}
// If a proto declared fire and protos don't move
// multi, ignore whether infantry move or not.
else if (protosMoved && (game.getPhase() == IGame.Phase.PHASE_FIRING)) {
multiMask = 0;
}
if (tanksMoveMulti) {
multiMask += GameTurn.CLASS_TANK;
}
// Is this a general move turn?
boolean isGeneralMoveTurn = !(turn instanceof GameTurn.SpecificEntityTurn) && !(turn instanceof GameTurn.UnitNumberTurn) && !(turn instanceof GameTurn.UnloadStrandedTurn) && (!(turn instanceof GameTurn.EntityClassTurn) || ((turn instanceof GameTurn.EntityClassTurn) && ((GameTurn.EntityClassTurn) turn).isValidClass(~multiMask)));
// Unless overridden by the "protos_move_multi" option, all Protomechs
// in a unit declare fire, and they don't mix with infantry.
if (protosMoved && !protosMoveMulti && isGeneralMoveTurn && (entityUsed != null)) {
// What's the unit number and ID of the entity used?
final char movingUnit = entityUsed.getUnitNumber();
final int movingId = entityUsed.getId();
// How many other Protomechs are in the unit that can fire?
int protoTurns = game.getSelectedEntityCount(new EntitySelector() {
private final int ownerId = playerId;
private final int entityId = movingId;
private final char unitNum = movingUnit;
public boolean accept(Entity entity) {
if ((entity instanceof Protomech) && entity.isSelectableThisTurn() && (ownerId == entity.getOwnerId()) && (entityId != entity.getId()) && (unitNum == entity.getUnitNumber())) {
return true;
}
return false;
}
});
// Add the correct number of turns for the Protomech unit number.
for (int i = 0; i < protoTurns; i++) {
GameTurn newTurn = new GameTurn.UnitNumberTurn(playerId, movingUnit);
game.insertNextTurn(newTurn);
turnsChanged = true;
}
}
// Otherwise, we may need to add turns for the "*_move_multi" options.
else if (((infMoved && infMoveMulti) || (protosMoved && protosMoveMulti)) && isGeneralMoveTurn) {
int remaining = 0;
// Calculate the number of EntityClassTurns need to be added.
if (infMoveMulti) {
remaining += game.getInfantryLeft(playerId);
}
if (protosMoveMulti) {
remaining += game.getProtomechsLeft(playerId);
}
int moreInfAndProtoTurns = Math.min(game.getOptions().intOption("inf_proto_move_multi") - 1, remaining);
// Add the correct number of turns for the right unit classes.
for (int i = 0; i < moreInfAndProtoTurns; i++) {
GameTurn newTurn = new GameTurn.EntityClassTurn(playerId, multiMask);
game.insertNextTurn(newTurn);
turnsChanged = true;
}
}
if (tanksMoved && tanksMoveMulti && isGeneralMoveTurn) {
int remaining = game.getVehiclesLeft(playerId);
int moreVeeTurns = Math.min(game.getOptions().intOption("vehicle_lance_movement_number") - 1, remaining);
// Add the correct number of turns for the right unit classes.
for (int i = 0; i < moreVeeTurns; i++) {
GameTurn newTurn = new GameTurn.EntityClassTurn(playerId, multiMask);
game.insertNextTurn(newTurn);
turnsChanged = true;
}
}