use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.
the class ProPurchaseUtils method findPurchaseTerritories.
public static Map<Territory, ProPurchaseTerritory> findPurchaseTerritories(final PlayerID player) {
ProLogger.info("Find all purchase territories");
final GameData data = ProData.getData();
// Find all territories that I can place units on
final RulesAttachment ra = player.getRulesAttachment();
List<Territory> ownedAndNotConqueredFactoryTerritories;
if (ra != null && ra.getPlacementAnyTerritory()) {
ownedAndNotConqueredFactoryTerritories = data.getMap().getTerritoriesOwnedBy(player);
} else {
ownedAndNotConqueredFactoryTerritories = CollectionUtils.getMatches(data.getMap().getTerritories(), ProMatches.territoryHasInfraFactoryAndIsNotConqueredOwnedLand(player, data));
}
ownedAndNotConqueredFactoryTerritories = CollectionUtils.getMatches(ownedAndNotConqueredFactoryTerritories, ProMatches.territoryCanMoveLandUnits(player, data, false));
// Create purchase territory holder for each factory territory
final Map<Territory, ProPurchaseTerritory> purchaseTerritories = new HashMap<>();
for (final Territory t : ownedAndNotConqueredFactoryTerritories) {
final int unitProduction = getUnitProduction(t, data, player);
final ProPurchaseTerritory ppt = new ProPurchaseTerritory(t, data, player, unitProduction);
purchaseTerritories.put(t, ppt);
ProLogger.debug(ppt.toString());
}
return purchaseTerritories;
}
use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.
the class ProPurchaseUtils method getUnitProduction.
private static int getUnitProduction(final Territory territory, final GameData data, final PlayerID player) {
final Predicate<Unit> factoryMatch = Matches.unitIsOwnedAndIsFactoryOrCanProduceUnits(player).and(Matches.unitIsBeingTransported().negate()).and((territory.isWater() ? Matches.unitIsLand() : Matches.unitIsSea()).negate());
final Collection<Unit> factoryUnits = territory.getUnits().getMatches(factoryMatch);
final TerritoryAttachment ta = TerritoryAttachment.get(territory);
final boolean originalFactory = (ta != null && ta.getOriginalFactory());
final boolean playerIsOriginalOwner = factoryUnits.size() > 0 && player.equals(getOriginalFactoryOwner(territory, player));
final RulesAttachment ra = player.getRulesAttachment();
if (originalFactory && playerIsOriginalOwner) {
if (ra != null && ra.getMaxPlacePerTerritory() != -1) {
return Math.max(0, ra.getMaxPlacePerTerritory());
}
return Integer.MAX_VALUE;
}
if (ra != null && ra.getPlacementAnyTerritory()) {
return Integer.MAX_VALUE;
}
return TripleAUnit.getProductionPotentialOfTerritory(territory.getUnits().getUnits(), territory, player, data, true, true);
}
use of games.strategy.triplea.attachments.RulesAttachment in project triplea by triplea-game.
the class PactOfSteel2Test method testDirectOwnershipTerritories.
@Test
public void testDirectOwnershipTerritories() {
final Territory norway = gameData.getMap().getTerritory("Norway");
final Territory easternEurope = gameData.getMap().getTerritory("Eastern Europe");
final Territory eastBalkans = gameData.getMap().getTerritory("East Balkans");
final Territory ukraineSsr = gameData.getMap().getTerritory("Ukraine S.S.R.");
final Territory belorussia = gameData.getMap().getTerritory("Belorussia");
final PlayerID british = GameDataTestUtil.british(gameData);
final PlayerID germans = GameDataTestUtil.germans(gameData);
final PlayerID russians = GameDataTestUtil.russians(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(russians);
// this National Objective russia has to own at least 3 of the 5 territories by itself
final RulesAttachment russianEasternEurope = RulesAttachment.get(russians, "objectiveAttachmentRussians1_EasternEurope");
final Collection<Territory> terrs = new ArrayList<>();
terrs.add(norway);
terrs.add(easternEurope);
terrs.add(eastBalkans);
terrs.add(ukraineSsr);
terrs.add(belorussia);
assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertFalse(russianEasternEurope.isSatisfied(null, bridge));
norway.setOwner(british);
easternEurope.setOwner(russians);
eastBalkans.setOwner(russians);
ukraineSsr.setOwner(germans);
belorussia.setOwner(germans);
assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertFalse(russianEasternEurope.isSatisfied(null, bridge));
ukraineSsr.setOwner(british);
belorussia.setOwner(british);
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertFalse(russianEasternEurope.isSatisfied(null, bridge));
norway.setOwner(russians);
ukraineSsr.setOwner(germans);
belorussia.setOwner(germans);
assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertTrue(russianEasternEurope.isSatisfied(null, bridge));
ukraineSsr.setOwner(russians);
assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(4, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertTrue(russianEasternEurope.isSatisfied(null, bridge));
belorussia.setOwner(russians);
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
assertTrue(russianEasternEurope.isSatisfied(null, bridge));
}
Aggregations