Search in sources :

Example 1 with PlaceableUnits

use of games.strategy.triplea.delegate.dataObjects.PlaceableUnits in project triplea by triplea-game.

the class PlacePanel method getUnitsToPlace.

private Collection<Unit> getUnitsToPlace(final Territory territory, final int[] maxUnits) {
    getData().acquireReadLock();
    try {
        // not our territory
        if (!territory.isWater() && !territory.getOwner().equals(getCurrentPlayer())) {
            if (GameStepPropertiesHelper.isBid(getData())) {
                final PlayerAttachment pa = PlayerAttachment.get(territory.getOwner());
                if ((pa == null || pa.getGiveUnitControl() == null || !pa.getGiveUnitControl().contains(getCurrentPlayer())) && !territory.getUnits().anyMatch(Matches.unitIsOwnedBy(getCurrentPlayer()))) {
                    return Collections.emptyList();
                }
            } else {
                return Collections.emptyList();
            }
        }
        // get the units that can be placed on this territory.
        Collection<Unit> units = getCurrentPlayer().getUnits().getUnits();
        if (territory.isWater()) {
            if (!(canProduceFightersOnCarriers() || canProduceNewFightersOnOldCarriers() || isLhtrCarrierProductionRules() || GameStepPropertiesHelper.isBid(getData()))) {
                units = CollectionUtils.getMatches(units, Matches.unitIsSea());
            } else {
                final Predicate<Unit> unitIsSeaOrCanLandOnCarrier = Matches.unitIsSea().or(Matches.unitCanLandOnCarrier());
                units = CollectionUtils.getMatches(units, unitIsSeaOrCanLandOnCarrier);
            }
        } else {
            units = CollectionUtils.getMatches(units, Matches.unitIsNotSea());
        }
        if (units.isEmpty()) {
            return Collections.emptyList();
        }
        final IAbstractPlaceDelegate placeDel = (IAbstractPlaceDelegate) getPlayerBridge().getRemoteDelegate();
        final PlaceableUnits production = placeDel.getPlaceableUnits(units, territory);
        if (production.isError()) {
            JOptionPane.showMessageDialog(getTopLevelAncestor(), production.getErrorMessage(), "No units", JOptionPane.INFORMATION_MESSAGE);
            return Collections.emptyList();
        }
        maxUnits[0] = production.getMaxUnits();
        return production.getUnits();
    } finally {
        getData().releaseReadLock();
    }
}
Also used : PlayerAttachment(games.strategy.triplea.attachments.PlayerAttachment) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Unit(games.strategy.engine.data.Unit)

Example 2 with PlaceableUnits

use of games.strategy.triplea.delegate.dataObjects.PlaceableUnits in project triplea by triplea-game.

the class WW2V3Year41Test method testBidPlace.

@Test
public void testBidPlace() {
    final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
    bridge.setStepName("BidPlace");
    bidPlaceDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    bidPlaceDelegate(gameData).start();
    // create 20 british infantry
    addTo(british(gameData), infantry(gameData).create(20, british(gameData)), gameData);
    final Territory uk = territory("United Kingdom", gameData);
    final Collection<Unit> units = british(gameData).getUnits().getUnits();
    final PlaceableUnits placeable = bidPlaceDelegate(gameData).getPlaceableUnits(units, uk);
    assertEquals(20, placeable.getMaxUnits());
    assertNull(placeable.getErrorMessage());
    final String error = bidPlaceDelegate(gameData).placeUnits(units, uk);
    assertNull(error);
}
Also used : Territory(games.strategy.engine.data.Territory) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 3 with PlaceableUnits

use of games.strategy.triplea.delegate.dataObjects.PlaceableUnits in project triplea by triplea-game.

the class PlaceDelegateTest method testCanNotProduceThatManyUnits.

@Test
public void testCanNotProduceThatManyUnits() {
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.add(infantry, 3);
    final PlaceableUnits response = delegate.getPlaceableUnits(GameDataTestUtil.getUnits(map, british), westCanada);
    assertTrue(response.getMaxUnits() == 2);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) UnitType(games.strategy.engine.data.UnitType) Test(org.junit.jupiter.api.Test)

Example 4 with PlaceableUnits

use of games.strategy.triplea.delegate.dataObjects.PlaceableUnits in project triplea by triplea-game.

the class PlaceDelegateTest method testCanProduceInSea.

@Test
public void testCanProduceInSea() {
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.add(transport, 2);
    final PlaceableUnits response = delegate.getPlaceableUnits(GameDataTestUtil.getUnits(map, british), northSea);
    assertFalse(response.isError());
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) UnitType(games.strategy.engine.data.UnitType) Test(org.junit.jupiter.api.Test)

Example 5 with PlaceableUnits

use of games.strategy.triplea.delegate.dataObjects.PlaceableUnits in project triplea by triplea-game.

the class RevisedTest method testBidPlace.

@Test
public void testBidPlace() {
    final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
    bridge.setStepName("BidPlace");
    bidPlaceDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    bidPlaceDelegate(gameData).start();
    // create 20 british infantry
    addTo(british(gameData), infantry(gameData).create(20, british(gameData)), gameData);
    final Territory uk = territory("United Kingdom", gameData);
    final Collection<Unit> units = british(gameData).getUnits().getUnits();
    final PlaceableUnits placeable = bidPlaceDelegate(gameData).getPlaceableUnits(units, uk);
    assertEquals(20, placeable.getMaxUnits());
    assertNull(placeable.getErrorMessage());
    final String error = bidPlaceDelegate(gameData).placeUnits(units, uk);
    assertNull(error);
}
Also used : Territory(games.strategy.engine.data.Territory) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Aggregations

PlaceableUnits (games.strategy.triplea.delegate.dataObjects.PlaceableUnits)10 Territory (games.strategy.engine.data.Territory)6 Unit (games.strategy.engine.data.Unit)6 Test (org.junit.jupiter.api.Test)6 TripleAUnit (games.strategy.triplea.TripleAUnit)5 UnitType (games.strategy.engine.data.UnitType)4 IntegerMap (games.strategy.util.IntegerMap)4 ArrayList (java.util.ArrayList)3 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)2 ProPlaceTerritory (games.strategy.triplea.ai.pro.data.ProPlaceTerritory)2 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)2 Route (games.strategy.engine.data.Route)1 ProBattleResult (games.strategy.triplea.ai.pro.data.ProBattleResult)1 ProOtherMoveOptions (games.strategy.triplea.ai.pro.data.ProOtherMoveOptions)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 IAbstractPlaceDelegate (games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1