use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class TechAbilityAttachment method getAirborneCapacity.
public static int getAirborneCapacity(final Collection<Unit> units, final PlayerID player, final GameData data) {
final IntegerMap<UnitType> capacityMap = getAirborneCapacity(player, data);
int airborneCapacity = 0;
for (final Unit u : units) {
airborneCapacity += Math.max(0, (capacityMap.getInt(u.getType()) - ((TripleAUnit) u).getLaunched()));
}
return airborneCapacity;
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class RevisedTest method testLoadUndoInWrongOrder.
@Test
public void testLoadUndoInWrongOrder() {
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
final PlayerID germans = GameDataTestUtil.germans(gameData);
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final Route eeToSz5 = new Route();
eeToSz5.setStart(eastEurope);
eeToSz5.add(sz5);
// load the transport in the baltic
final List<Unit> infantry = eastEurope.getUnits().getMatches(Matches.unitIsOfType(infantryType));
assertEquals(2, infantry.size());
final TripleAUnit transport = (TripleAUnit) sz5.getUnits().getMatches(Matches.unitIsTransport()).get(0);
// load the transports
// in two moves
String error = moveDelegate.move(infantry.subList(0, 1), eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
error = moveDelegate.move(infantry.subList(1, 2), eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
// make sure the transport was loaded
assertTrue(moveDelegate.getMovesMade().get(0).wasTransportLoaded(transport));
assertTrue(moveDelegate.getMovesMade().get(1).wasTransportLoaded(transport));
// udo the moves in reverse order
moveDelegate.undoMove(0);
moveDelegate.undoMove(0);
// make sure that loaded is not set
assertTrue(transport.getTransporting().isEmpty());
assertFalse(((TripleAUnit) infantry.get(0)).getWasLoadedThisTurn());
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class RevisedTest method testContinuedBattles.
@Test
public void testContinuedBattles() {
final PlayerID russians = GameDataTestUtil.russians(gameData);
final PlayerID germans = germans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
// set up battle
final Territory germany = gameData.getMap().getTerritory("Germany");
final Territory karelia = gameData.getMap().getTerritory("Karelia S.S.R.");
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
gameData.performChange(ChangeFactory.removeUnits(sz5, sz5.getUnits().getUnits()));
final UnitType infantryType = infantry(gameData);
final UnitType subType = submarine(gameData);
final UnitType trnType = transport(gameData);
gameData.performChange(ChangeFactory.addUnits(sz5, subType.create(1, germans)));
gameData.performChange(ChangeFactory.addUnits(sz5, trnType.create(1, germans)));
gameData.performChange(ChangeFactory.addUnits(sz5, subType.create(1, russians)));
// submerge the russian sub
final TripleAUnit sub = (TripleAUnit) CollectionUtils.getMatches(sz5.getUnits().getUnits(), Matches.unitIsOwnedBy(russians)).iterator().next();
sub.setSubmerged(true);
// now move an infantry through the sz
String results = moveDelegate.move(CollectionUtils.getNMatches(germany.getUnits().getUnits(), 1, Matches.unitIsOfType(infantryType)), gameData.getMap().getRoute(germany, sz5), CollectionUtils.getMatches(sz5.getUnits().getUnits(), Matches.unitIsOfType(trnType)));
assertNull(results);
results = moveDelegate.move(CollectionUtils.getNMatches(sz5.getUnits().getUnits(), 1, Matches.unitIsOfType(infantryType)), gameData.getMap().getRoute(sz5, karelia));
assertNull(results);
moveDelegate.end();
final BattleDelegate battle = (BattleDelegate) gameData.getDelegateList().getDelegate("battle");
battle.setDelegateBridgeAndPlayer(bridge);
battle.start();
final BattleTracker tracker = AbstractMoveDelegate.getBattleTracker(gameData);
// The battle should NOT be empty
assertTrue(tracker.hasPendingBattle(sz5, false));
assertFalse(tracker.getPendingBattle(sz5, false, null).isEmpty());
battle.end();
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class RevisedTest method testMoveThroughSubmergedSubs.
@Test
public void testMoveThroughSubmergedSubs() {
final PlayerID british = GameDataTestUtil.british(gameData);
final Territory sz1 = gameData.getMap().getTerritory("1 Sea Zone");
final Territory sz7 = gameData.getMap().getTerritory("7 Sea Zone");
final Territory sz8 = gameData.getMap().getTerritory("8 Sea Zone");
final TripleAUnit sub = (TripleAUnit) sz8.getUnits().iterator().next();
sub.setSubmerged(true);
// now move to attack it
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("NonCombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
// the transport can enter sz 8
// since the sub is submerged
final Route m1 = new Route(sz1, sz8);
assertNull(moveDelegate.move(sz1.getUnits().getUnits(), m1));
// the transport can now leave sz8
final Route m2 = new Route(sz8, sz7);
final String error = moveDelegate.move(sz8.getUnits().getMatches(Matches.unitIsOwnedBy(british)), m2);
assertNull(error, error);
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class RevisedTest method testUnloadInPreviousPhase.
@Test
public void testUnloadInPreviousPhase() {
// a transport may not unload in both combat and non combat
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
final PlayerID germans = GameDataTestUtil.germans(gameData);
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final Route eeToSz5 = new Route();
eeToSz5.setStart(eastEurope);
eeToSz5.add(sz5);
// load the transport in the baltic
final List<Unit> infantry = eastEurope.getUnits().getMatches(Matches.unitIsOfType(infantryType));
assertEquals(2, infantry.size());
final TripleAUnit transport = (TripleAUnit) sz5.getUnits().getMatches(Matches.unitIsTransport()).get(0);
String error = moveDelegate.move(infantry, eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
// unload one infantry to Norway
final Territory norway = gameData.getMap().getTerritory("Norway");
final Route sz5ToNorway = new Route();
sz5ToNorway.setStart(sz5);
sz5ToNorway.add(norway);
error = moveDelegate.move(infantry.subList(0, 1), sz5ToNorway);
assertNull(error, error);
assertTrue(((TripleAUnit) infantry.get(0)).getWasUnloadedInCombatPhase());
// start non combat
moveDelegate.end();
bridge.setStepName("germanNonCombatMove");
// the transport tracker relies on the step name
while (!gameData.getSequence().getStep().getName().equals("germanNonCombatMove")) {
gameData.getSequence().next();
}
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
// try to unload the other infantry somewhere else, an error occurs
error = moveDelegate.move(infantry.subList(1, 2), sz5ToNorway);
assertNotNull(error, error);
assertTrue(error.startsWith(MoveValidator.TRANSPORT_HAS_ALREADY_UNLOADED_UNITS_IN_A_PREVIOUS_PHASE));
}
Aggregations