Exemplo n.º 1
0
 /**
  * Convenience function to check if there is an output for a given goods type in a collection of
  * production types.
  *
  * @param goodsType The <code>GoodsType</code> to use.
  * @param types A list of <code>ProductionType</code>s to consider.
  * @return The most productive output that produces the goods type, or null if none found.
  */
 public static boolean canProduce(GoodsType goodsType, Collection<ProductionType> types) {
   for (ProductionType productionType : types) {
     AbstractGoods output = AbstractGoods.findByType(goodsType, productionType.getOutputs());
     if (output != null) return true;
   }
   return false;
 }
Exemplo n.º 2
0
 /**
  * Convenience function to get the best output for a given goods type from a collection of
  * production types.
  *
  * @param goodsType The <code>GoodsType</code> to use.
  * @param types A collection of <code>ProductionType</code>s to consider.
  * @return The most productive output that produces the goods type, or null if none found.
  */
 public static AbstractGoods getBestOutputFor(
     GoodsType goodsType, Collection<ProductionType> types) {
   AbstractGoods best = null;
   for (ProductionType productionType : types) {
     for (AbstractGoods output : productionType.getOutputs()) {
       if (output.getType() == goodsType
           && (best == null || output.getAmount() > best.getAmount())) {
         best = output;
       }
     }
   }
   return best;
 }
Exemplo n.º 3
0
 /**
  * Get the production type with the greatest total output of an optional goods type from a
  * collection of production types
  *
  * @param goodsType An optional <code>GoodsType</code> to restrict the choice of outputs with.
  * @param types A collection of <code>ProductionType</code>s to consider.
  * @return The most productive <code>ProductionType</code>.
  */
 public static ProductionType getBestProductionType(
     GoodsType goodsType, Collection<ProductionType> types) {
   ProductionType best = null;
   int bestSum = 0;
   for (ProductionType pt : types) {
     int sum = 0;
     for (AbstractGoods output : pt.getOutputs()) {
       if (goodsType == null || goodsType == output.getType()) {
         sum += output.getAmount();
       }
     }
     if (bestSum < sum) {
       bestSum = sum;
       best = pt;
     }
   }
   return best;
 }