コード例 #1
0
ファイル: UnitWas.java プロジェクト: amrecio/mymom
 public String toString() {
   Tile tile = colony.getTile();
   String eqStr = "/";
   for (EquipmentType e : equipment.keySet()) {
     eqStr += e.toString().substring(16, 17);
   }
   String locStr =
       (loc == null)
           ? ""
           : (loc instanceof Building)
               ? Utils.lastPart(((Building) loc).getType().toString(), ".")
               : (loc instanceof ColonyTile)
                   ? tile.getDirection(((ColonyTile) loc).getWorkTile()).toString()
                   : (loc instanceof Tile) ? (loc.getId() + eqStr) : loc.getId();
   Location newLoc = unit.getLocation();
   String newEqStr = "/";
   for (EquipmentType e : unit.getEquipment().keySet()) {
     newEqStr += e.toString().substring(16, 17);
   }
   String newLocStr =
       (newLoc == null)
           ? ""
           : (newLoc instanceof Building)
               ? Utils.lastPart(((Building) newLoc).getType().toString(), ".")
               : (newLoc instanceof ColonyTile)
                   ? tile.getDirection(((ColonyTile) newLoc).getWorkTile()).toString()
                   : (newLoc instanceof Tile) ? (newLoc.getId() + newEqStr) : newLoc.getId();
   GoodsType newWork = unit.getWorkType();
   int newWorkAmount = (newWork == null) ? 0 : getAmount(newLoc, newWork);
   return String.format(
           "%-30s %-25s -> %-25s",
           unit.getId() + ":" + Utils.lastPart(unit.getType().toString(), "."),
           locStr
               + ((work == null || workAmount <= 0)
                   ? ""
                   : "("
                       + Integer.toString(workAmount)
                       + " "
                       + Utils.lastPart(work.toString(), ".")
                       + ")"),
           newLocStr
               + ((newWork == null || newWorkAmount <= 0)
                   ? ""
                   : "("
                       + Integer.toString(newWorkAmount)
                       + " "
                       + Utils.lastPart(newWork.toString(), ".")
                       + ")"))
       .trim();
 }
コード例 #2
0
ファイル: ProductionType.java プロジェクト: vardars/FreeCol
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int hash = super.hashCode();
   hash = 31 * hash + ((this.unattended) ? 1 : 0);
   hash = 31 * hash + Utils.hashCode(this.productionLevel);
   if (this.outputs != null) {
     for (AbstractGoods ag : this.outputs) {
       hash = 31 * hash + Utils.hashCode(ag);
     }
   }
   if (this.inputs != null) {
     for (AbstractGoods ag : this.inputs) {
       hash = 31 * hash + Utils.hashCode(ag);
     }
   }
   return hash;
 }
コード例 #3
0
ファイル: ProductionType.java プロジェクト: vardars/FreeCol
 /** {@inheritDoc} */
 @Override
 public boolean equals(Object o) {
   if (this == o) return true;
   if (o instanceof ProductionType) {
     ProductionType pt = (ProductionType) o;
     return super.equals(o)
         && this.unattended == pt.unattended
         && Utils.equals(this.productionLevel, pt.productionLevel)
         && listEquals(this.outputs, pt.outputs)
         && listEquals(this.inputs, pt.inputs);
   }
   return false;
 }
コード例 #4
0
ファイル: BuildQueuePanel.java プロジェクト: nav18/freecool
  @SuppressWarnings("unchecked") // FIXME in Java7
  private void updateBuildingList() {
    DefaultListModel buildings = (DefaultListModel) buildingList.getModel();
    DefaultListModel current = (DefaultListModel) buildQueueList.getModel();
    buildings.clear();
    loop:
    for (BuildingType buildingType : getSpecification().getBuildingTypeList()) {
      // compare colony.getNoBuildReason()
      List<String> lockReason = new ArrayList<String>();
      Building colonyBuilding = colony.getBuilding(buildingType);
      if (current.contains(buildingType) || hasBuildingType(buildingType)) {
        // only one building of any kind
        continue;
      } else if (unbuildableTypes.contains(buildingType)) {
        continue;
      } else if (!buildingType.needsGoodsToBuild()) {
        // pre-built
        continue;
      } else if (unbuildableTypes.contains(buildingType.getUpgradesFrom())) {
        // impossible upgrade path
        unbuildableTypes.add(buildingType);
        continue;
      }

      if (buildingType.getRequiredPopulation() > unitCount) {
        lockReason.add(
            Messages.message(
                StringTemplate.template("colonyPanel.populationTooSmall")
                    .addAmount("%number%", buildingType.getRequiredPopulation())));
      }

      for (Entry<String, Boolean> entry : buildingType.getRequiredAbilities().entrySet()) {
        if (colony.hasAbility(entry.getKey()) != entry.getValue()
            && FeatureContainer.hasAbility(featureContainer, entry.getKey(), null, null)
                != entry.getValue()) {
          List<FreeColGameObjectType> sources =
              getSpecification().getTypesProviding(entry.getKey(), entry.getValue());
          if (sources.isEmpty()) {
            // no type provides the required ability
            unbuildableTypes.add(buildingType);
            continue loop;
          } else {
            lockReason.add(Messages.message(sources.get(0).getNameKey()));
          }
        }
      }

      if (buildingType.getLimits() != null) {
        for (Limit limit : buildingType.getLimits()) {
          if (!limit.evaluate(colony)) {
            lockReason.add(Messages.message(limit.getDescriptionKey()));
          }
        }
      }

      if (buildingType.getUpgradesFrom() != null
          && !current.contains(buildingType.getUpgradesFrom())) {
        if (colonyBuilding == null || colonyBuilding.getType() != buildingType.getUpgradesFrom()) {
          lockReason.add(Messages.message(buildingType.getUpgradesFrom().getNameKey()));
        }
      }
      if (lockReason.isEmpty()) {
        lockReasons.put(buildingType, null);
      } else {
        lockReasons.put(
            buildingType,
            Messages.message(
                StringTemplate.template("colonyPanel.requires")
                    .addName("%string%", Utils.join("/", lockReason))));
      }
      if (lockReason.isEmpty() || showAll.isSelected()) {
        buildings.addElement(buildingType);
      }
    }
  }
コード例 #5
0
ファイル: BuildQueuePanel.java プロジェクト: nav18/freecool
  @SuppressWarnings("unchecked") // FIXME in Java7
  private void updateUnitList() {
    final Specification spec = getSpecification();
    DefaultListModel units = (DefaultListModel) unitList.getModel();
    units.clear();
    loop:
    for (UnitType unitType : buildableUnits) {
      // compare colony.getNoBuildReason()
      List<String> lockReason = new ArrayList<String>();
      if (unbuildableTypes.contains(unitType)) {
        continue;
      }

      if (unitType.getRequiredPopulation() > unitCount) {
        lockReason.add(
            Messages.message(
                StringTemplate.template("colonyPanel.populationTooSmall")
                    .addAmount("%number%", unitType.getRequiredPopulation())));
      }

      if (unitType.getLimits() != null) {
        for (Limit limit : unitType.getLimits()) {
          if (!limit.evaluate(colony)) {
            lockReason.add(Messages.message(limit.getDescriptionKey()));
          }
        }
      }

      if (!(colony.hasAbility(Ability.BUILD, unitType, getGame().getTurn())
          || FeatureContainer.hasAbility(featureContainer, Ability.BUILD, unitType, null))) {
        boolean builderFound = false;
        for (Ability ability : spec.getAbilities(Ability.BUILD)) {
          if (ability.appliesTo(unitType)
              && ability.getValue()
              && ability.getSource() != null
              && !unbuildableTypes.contains(ability.getSource())) {
            builderFound = true;
            lockReason.add(Messages.getName(ability.getSource()));
            break;
          }
        }
        if (!builderFound) {
          unbuildableTypes.add(unitType);
          continue;
        }
      }

      for (Entry<String, Boolean> entry : unitType.getRequiredAbilities().entrySet()) {
        if (colony.hasAbility(entry.getKey()) != entry.getValue()
            && FeatureContainer.hasAbility(featureContainer, entry.getKey(), null, null)
                != entry.getValue()) {
          List<FreeColGameObjectType> sources =
              spec.getTypesProviding(entry.getKey(), entry.getValue());
          if (sources.isEmpty()) {
            // no type provides the required ability
            unbuildableTypes.add(unitType);
            continue loop;
          } else {
            lockReason.add(Messages.message(sources.get(0).getNameKey()));
          }
        }
      }
      if (lockReason.isEmpty()) {
        lockReasons.put(unitType, null);
      } else {
        lockReasons.put(
            unitType,
            Messages.message(
                StringTemplate.template("colonyPanel.requires")
                    .addName("%string%", Utils.join("/", lockReason))));
      }
      if (lockReason.isEmpty() || showAll.isSelected()) {
        units.addElement(unitType);
      }
    }
  }