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();
}
}
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);
}
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);
}
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());
}
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);
}
Aggregations