Search in sources :

Example 11 with RepairRule

use of games.strategy.engine.data.RepairRule in project triplea by triplea-game.

the class ProductionRepairPanel method initRules.

private void initRules(final PlayerID player, final Collection<PlayerID> allowedPlayersToRepair, final GameData data, final HashMap<Unit, IntegerMap<RepairRule>> initialPurchase) {
    if (!Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
        return;
    }
    this.data.acquireReadLock();
    try {
        this.id = player;
        this.allowedPlayersToRepair = allowedPlayersToRepair;
        final Predicate<Unit> myDamagedUnits = Matches.unitIsOwnedByOfAnyOfThesePlayers(this.allowedPlayersToRepair).and(Matches.unitHasTakenSomeBombingUnitDamage());
        final Collection<Territory> terrsWithPotentiallyDamagedUnits = CollectionUtils.getMatches(data.getMap().getTerritories(), Matches.territoryHasUnitsThatMatch(myDamagedUnits));
        for (final RepairRule repairRule : player.getRepairFrontier()) {
            for (final Territory terr : terrsWithPotentiallyDamagedUnits) {
                for (final Unit unit : CollectionUtils.getMatches(terr.getUnits().getUnits(), myDamagedUnits)) {
                    if (!repairRule.getResults().keySet().iterator().next().equals(unit.getType())) {
                        continue;
                    }
                    final TripleAUnit taUnit = (TripleAUnit) unit;
                    final Rule rule = new Rule(repairRule, player, unit, terr);
                    int initialQuantity = 0;
                    if (initialPurchase.get(unit) != null) {
                        initialQuantity = initialPurchase.get(unit).getInt(repairRule);
                    }
                    rule.setQuantity(initialQuantity);
                    rule.setMax(taUnit.getHowMuchCanThisUnitBeRepaired(unit, terr));
                    rule.setName(unit.toString());
                    rules.add(rule);
                }
            }
        }
    } finally {
        this.data.releaseReadLock();
    }
}
Also used : Territory(games.strategy.engine.data.Territory) RepairRule(games.strategy.engine.data.RepairRule) RepairRule(games.strategy.engine.data.RepairRule) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 12 with RepairRule

use of games.strategy.engine.data.RepairRule in project triplea by triplea-game.

the class SimpleUnitPanel method setUnitsFromRepairRuleMap.

/**
 * @param units
 *        a HashMap in the form RepairRule -> number of units
 *        assumes that each repair rule has 1 result, which is simply the number of units.
 */
public void setUnitsFromRepairRuleMap(final HashMap<Unit, IntegerMap<RepairRule>> units, final PlayerID player, final GameData data) {
    removeAll();
    final Set<Unit> entries = units.keySet();
    for (final Unit unit : entries) {
        final IntegerMap<RepairRule> rules = units.get(unit);
        final TreeSet<RepairRule> repairRules = new TreeSet<>(repairRuleComparator);
        repairRules.addAll(rules.keySet());
        for (final RepairRule repairRule : repairRules) {
            final int quantity = rules.getInt(repairRule);
            if (Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(data)) {
                // check to see if the repair rule matches the damaged unit
                if (unit.getType().equals((repairRule.getResults().keySet().iterator().next()))) {
                    addUnits(player, quantity, unit.getType(), Matches.unitHasTakenSomeBombingUnitDamage().test(unit), Matches.unitIsDisabled().test(unit));
                }
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) RepairRule(games.strategy.engine.data.RepairRule) Unit(games.strategy.engine.data.Unit)

Aggregations

RepairRule (games.strategy.engine.data.RepairRule)12 Unit (games.strategy.engine.data.Unit)8 TripleAUnit (games.strategy.triplea.TripleAUnit)7 IntegerMap (games.strategy.util.IntegerMap)7 Territory (games.strategy.engine.data.Territory)5 Resource (games.strategy.engine.data.Resource)3 HashMap (java.util.HashMap)3 NamedAttachable (games.strategy.engine.data.NamedAttachable)2 ProductionRule (games.strategy.engine.data.ProductionRule)2 TreeSet (java.util.TreeSet)2 Test (org.junit.jupiter.api.Test)2 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)1 PlayerID (games.strategy.engine.data.PlayerID)1 RepairFrontier (games.strategy.engine.data.RepairFrontier)1 ResourceCollection (games.strategy.engine.data.ResourceCollection)1 Route (games.strategy.engine.data.Route)1 UnitType (games.strategy.engine.data.UnitType)1 ProPlaceTerritory (games.strategy.triplea.ai.pro.data.ProPlaceTerritory)1 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)1