Search in sources :

Example 36 with TripleAUnit

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;
}
Also used : UnitType(games.strategy.engine.data.UnitType) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 37 with TripleAUnit

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());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 38 with TripleAUnit

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();
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Example 39 with TripleAUnit

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);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 40 with TripleAUnit

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));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

TripleAUnit (games.strategy.triplea.TripleAUnit)47 Unit (games.strategy.engine.data.Unit)42 Territory (games.strategy.engine.data.Territory)25 PlayerID (games.strategy.engine.data.PlayerID)19 UnitType (games.strategy.engine.data.UnitType)16 CompositeChange (games.strategy.engine.data.CompositeChange)15 Test (org.junit.jupiter.api.Test)14 Route (games.strategy.engine.data.Route)13 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)12 ArrayList (java.util.ArrayList)11 GameData (games.strategy.engine.data.GameData)10 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)8 IntegerMap (games.strategy.util.IntegerMap)8 Change (games.strategy.engine.data.Change)7 RepairRule (games.strategy.engine.data.RepairRule)5 HashSet (java.util.HashSet)4 Resource (games.strategy.engine.data.Resource)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 ResourceCollection (games.strategy.engine.data.ResourceCollection)2