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();
}
}
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));
}
}
}
}
}
Aggregations