use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTransportUtils method getUnusedLocalCarrierCapacity.
public static int getUnusedLocalCarrierCapacity(final PlayerID player, final Territory t, final List<Unit> unitsToPlace) {
final GameData data = ProData.getData();
// Find nearby carrier capacity
final Set<Territory> nearbyTerritories = data.getMap().getNeighbors(t, 2, ProMatches.territoryCanMoveAirUnits(player, data, false));
nearbyTerritories.add(t);
final List<Unit> ownedNearbyUnits = new ArrayList<>();
int capacity = 0;
for (final Territory nearbyTerritory : nearbyTerritories) {
final List<Unit> units = nearbyTerritory.getUnits().getMatches(Matches.unitIsOwnedBy(player));
if (nearbyTerritory.equals(t)) {
units.addAll(unitsToPlace);
}
ownedNearbyUnits.addAll(units);
capacity += AirMovementValidator.carrierCapacity(units, t);
}
// Find nearby air unit carrier cost
final Collection<Unit> airUnits = CollectionUtils.getMatches(ownedNearbyUnits, ProMatches.unitIsOwnedAir(player));
for (final Unit airUnit : airUnits) {
final UnitAttachment ua = UnitAttachment.get(airUnit.getType());
final int cost = ua.getCarrierCost();
if (cost != -1) {
capacity -= cost;
}
}
return capacity;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTransportUtils method getAirThatCantLandOnCarrier.
public static List<Unit> getAirThatCantLandOnCarrier(final PlayerID player, final Territory t, final List<Unit> units) {
final GameData data = ProData.getData();
int capacity = AirMovementValidator.carrierCapacity(units, t);
final Collection<Unit> airUnits = CollectionUtils.getMatches(units, ProMatches.unitIsAlliedAir(player, data));
final List<Unit> airThatCantLand = new ArrayList<>();
for (final Unit airUnit : airUnits) {
final UnitAttachment ua = UnitAttachment.get(airUnit.getType());
final int cost = ua.getCarrierCost();
if (cost != -1) {
if (cost <= capacity) {
capacity -= cost;
} else {
airThatCantLand.add(airUnit);
}
}
}
return airThatCantLand;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProTransportUtils method validateCarrierCapacity.
public static boolean validateCarrierCapacity(final PlayerID player, final Territory t, final List<Unit> existingUnits, final Unit newUnit) {
final GameData data = ProData.getData();
int capacity = AirMovementValidator.carrierCapacity(existingUnits, t);
final Collection<Unit> airUnits = CollectionUtils.getMatches(existingUnits, ProMatches.unitIsAlliedAir(player, data));
airUnits.add(newUnit);
for (final Unit airUnit : airUnits) {
final UnitAttachment ua = UnitAttachment.get(airUnit.getType());
final int cost = ua.getCarrierCost();
if (cost != -1) {
capacity -= cost;
}
}
return capacity >= 0;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProUtils method getEnemyPlayers.
private static List<PlayerID> getEnemyPlayers(final PlayerID player) {
final GameData data = ProData.getData();
final List<PlayerID> enemyPlayers = new ArrayList<>();
for (final PlayerID players : data.getPlayerList().getPlayers()) {
if (!data.getRelationshipTracker().isAllied(player, players)) {
enemyPlayers.add(players);
}
}
return enemyPlayers;
}
use of games.strategy.engine.data.GameData in project triplea by triplea-game.
the class ProUtils method getAlliedPlayers.
private static List<PlayerID> getAlliedPlayers(final PlayerID player) {
final GameData data = ProData.getData();
final List<PlayerID> alliedPlayers = new ArrayList<>();
for (final PlayerID players : data.getPlayerList().getPlayers()) {
if (data.getRelationshipTracker().isAllied(player, players)) {
alliedPlayers.add(players);
}
}
return alliedPlayers;
}
Aggregations