use of games.strategy.engine.data.Unit 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.Unit in project triplea by triplea-game.
the class ProTransportUtils method getUnusedCarrierCapacity.
public static int getUnusedCarrierCapacity(final PlayerID player, final Territory t, final List<Unit> unitsToPlace) {
final List<Unit> units = new ArrayList<>(unitsToPlace);
units.addAll(t.getUnits().getUnits());
int capacity = AirMovementValidator.carrierCapacity(units, t);
final Collection<Unit> airUnits = CollectionUtils.getMatches(units, 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.Unit in project triplea by triplea-game.
the class ProTransportUtils method getUnitsToTransportFromTerritories.
// TODO: this needs fixed to consider whether a valid route exists to load all units
public static List<Unit> getUnitsToTransportFromTerritories(final PlayerID player, final Unit transport, final Set<Territory> territoriesToLoadFrom, final List<Unit> unitsToIgnore, final Predicate<Unit> validUnitMatch) {
final List<Unit> selectedUnits = new ArrayList<>();
// Get units if transport already loaded
if (TransportTracker.isTransporting(transport)) {
selectedUnits.addAll(TransportTracker.transporting(transport));
} else {
// Get all units that can be transported
final List<Unit> units = new ArrayList<>();
for (final Territory loadFrom : territoriesToLoadFrom) {
units.addAll(loadFrom.getUnits().getMatches(validUnitMatch));
}
units.removeAll(unitsToIgnore);
// Sort units by attack
units.sort((o1, o2) -> {
// Very rough way to add support power
final Set<UnitSupportAttachment> supportAttachments1 = UnitSupportAttachment.get(o1.getType());
int maxSupport1 = 0;
for (final UnitSupportAttachment usa : supportAttachments1) {
if (usa.getAllied() && usa.getOffence() && usa.getBonus() > maxSupport1) {
maxSupport1 = usa.getBonus();
}
}
final int attack1 = UnitAttachment.get(o1.getType()).getAttack(player) + maxSupport1;
final Set<UnitSupportAttachment> supportAttachments2 = UnitSupportAttachment.get(o2.getType());
int maxSupport2 = 0;
for (final UnitSupportAttachment usa : supportAttachments2) {
if (usa.getAllied() && usa.getOffence() && usa.getBonus() > maxSupport2) {
maxSupport2 = usa.getBonus();
}
}
final int attack2 = UnitAttachment.get(o2.getType()).getAttack(player) + maxSupport2;
return attack2 - attack1;
});
// Get best units that can be loaded
selectedUnits.addAll(selectUnitsToTransportFromList(transport, units));
}
return selectedUnits;
}
use of games.strategy.engine.data.Unit 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.Unit in project triplea by triplea-game.
the class WeakAi method populateTransportUnloadNonCom.
private static void populateTransportUnloadNonCom(final GameData data, final List<Collection<Unit>> moveUnits, final List<Route> moveRoutes, final PlayerID player) {
final Route amphibRoute = getAmphibRoute(player, data);
if (amphibRoute == null) {
return;
}
final Territory lastSeaZoneOnAmphib = amphibRoute.getAllTerritories().get(amphibRoute.numberOfSteps() - 1);
final Territory landOn = amphibRoute.getEnd();
final Predicate<Unit> landAndOwned = Matches.unitIsLand().and(Matches.unitIsOwnedBy(player));
final List<Unit> units = lastSeaZoneOnAmphib.getUnits().getMatches(landAndOwned);
if (units.size() > 0) {
// just try to make the move, the engine will stop us if it doesnt work
final Route route = new Route();
route.setStart(lastSeaZoneOnAmphib);
route.add(landOn);
moveUnits.add(units);
moveRoutes.add(route);
}
}
Aggregations