Esempio n. 1
0
  /**
   * Gets the maximum possible production of the given type of goods.
   *
   * @param goodsType The type of goods to check.
   * @return The maximum amount, of the given type of goods, that can be produced in one turn.
   */
  public int getMaximumProduction(GoodsType goodsType) {
    int amount = 0;
    for (Tile workTile : getTile().getSurroundingTiles(getRadius())) {
      if (workTile.getOwningSettlement() == null || workTile.getOwningSettlement() == this) {
        // FIXME: make unitType brave
        amount += workTile.getPotentialProduction(goodsType, null);
      }
    }

    return amount;
  }
Esempio n. 2
0
 /**
  * Add some initial goods to a newly generated settlement. After all, they have been here for some
  * time.
  *
  * @param random A pseudo-random number source.
  */
 public void addRandomGoods(Random random) {
   HashMap<GoodsType, Integer> goodsMap = new HashMap<>();
   for (Tile t : getOwnedTiles()) {
     for (AbstractGoods ag : t.getSortedPotential()) {
       GoodsType type = ag.getType().getStoredAs();
       Integer i = goodsMap.get(type);
       int value = (i == null) ? 0 : i;
       goodsMap.put(type, value + ag.getAmount());
     }
   }
   double d = randomInt(logger, "Goods at " + getName(), random, 10) * 0.1 + 1.0;
   for (Entry<GoodsType, Integer> e : goodsMap.entrySet()) {
     int i = e.getValue();
     if (!e.getKey().isFoodType()) i = (int) Math.round(d * e.getValue());
     i = Math.min(i, GoodsContainer.CARGO_SIZE);
     if (i > 0) addGoods(e.getKey(), i);
   }
 }
Esempio n. 3
0
  /** {@inheritDoc} */
  @Override
  public int getTotalProductionOf(GoodsType type) {
    if (type.isRefined()) {
      if (type != goodsToMake()) return 0;
      // Pretend 1/3 of the units present make the item with
      // basic production of 3.
      return getUnitCount();
    }

    int potential = 0;
    int tiles = 0;

    for (Tile workTile : getOwnedTiles()) {
      if (workTile != getTile() && !workTile.isOccupied()) {
        // FIXME: make unitType brave
        potential += workTile.getPotentialProduction(type, null);
        tiles++;
      }
    }

    // When a native settlement has more tiles than units, pretend
    // that they produce from their entire area at reduced
    // efficiency.
    if (tiles > getUnitCount()) {
      potential *= (float) getUnitCount() / tiles;
    }

    // Raw production is too generous, apply a fudge factor to reduce it
    // a bit for the non-food cases.
    if (!type.isFoodType()) {
      potential = (int) Math.round(potential * NATIVE_PRODUCTION_EFFICIENCY);
    }

    // But always add full potential of the center tile.
    potential += getTile().getPotentialProduction(type, null);
    return potential;
  }