Search in sources :

Example 36 with GameData

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) Territory(games.strategy.engine.data.Territory) ProTerritory(games.strategy.triplea.ai.pro.data.ProTerritory) GameData(games.strategy.engine.data.GameData) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit)

Example 37 with GameData

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameData(games.strategy.engine.data.GameData) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit)

Example 38 with GameData

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;
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameData(games.strategy.engine.data.GameData) Unit(games.strategy.engine.data.Unit)

Example 39 with GameData

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) ArrayList(java.util.ArrayList)

Example 40 with GameData

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) ArrayList(java.util.ArrayList)

Aggregations

GameData (games.strategy.engine.data.GameData)204 Unit (games.strategy.engine.data.Unit)100 PlayerID (games.strategy.engine.data.PlayerID)92 Territory (games.strategy.engine.data.Territory)92 ArrayList (java.util.ArrayList)83 TripleAUnit (games.strategy.triplea.TripleAUnit)64 HashSet (java.util.HashSet)50 CompositeChange (games.strategy.engine.data.CompositeChange)40 List (java.util.List)36 HashMap (java.util.HashMap)32 Set (java.util.Set)32 Route (games.strategy.engine.data.Route)31 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)30 Collection (java.util.Collection)29 UnitType (games.strategy.engine.data.UnitType)26 Change (games.strategy.engine.data.Change)24 Test (org.junit.jupiter.api.Test)23 Resource (games.strategy.engine.data.Resource)22 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)22 Map (java.util.Map)21