예제 #1
0
 /**
  * @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<RepairRule>(repairRuleComparator);
     repairRules.addAll(rules.keySet());
     for (final RepairRule repairRule : repairRules) {
       final int quantity = rules.getInt(repairRule);
       if (games.strategy.triplea.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,
               data,
               quantity,
               unit.getType(),
               Matches.UnitHasTakenSomeBombingUnitDamage.match(unit),
               Matches.UnitIsDisabled.match(unit));
       }
     }
   }
 }
예제 #2
0
 public int compare(final RepairRule o1, final RepairRule o2) {
   if (o1.getResults().size() == 1 && o2.getResults().size() == 1) {
     final NamedAttachable n1 = o1.getResults().keySet().iterator().next();
     final NamedAttachable n2 = o2.getResults().keySet().iterator().next();
     if (n1 instanceof UnitType) {
       final UnitType u1 = (UnitType) n1;
       if (n2 instanceof UnitType) {
         final UnitType u2 = (UnitType) n2;
         return utc.compare(u1, u2);
       } else if (n2 instanceof Resource) {
         // final Resource r2 = (Resource) n2;
         return -1;
       }
       return n1.getName().compareTo(n2.getName());
     } else if (n1 instanceof Resource) {
       final Resource r1 = (Resource) n1;
       if (n2 instanceof UnitType) {
         // final UnitType u2 = (UnitType) n2;
         return 1;
       } else if (n2 instanceof Resource) {
         final Resource r2 = (Resource) n2;
         return r1.getName().compareTo(r2.getName());
       } else return n1.getName().compareTo(n2.getName());
     }
     return n1.getName().compareTo(n2.getName());
   }
   if (o1.getResults().size() > o2.getResults().size()) return -1;
   else if (o1.getResults().size() < o2.getResults().size()) return 1;
   return o1.getName().compareTo(o2.getName());
 }