/** * Calculates how much of the given goods type this settlement wants and should retain. * * @param type The <code>GoodsType</code>. * @return The amount of goods wanted. */ protected int getWantedGoodsAmount(GoodsType type) { if (getUnitCount() <= 0) return 0; final Specification spec = getSpecification(); final UnitType unitType = getFirstUnit().getType(); final Role militaryRole = Role.getAvailableRoles(getOwner(), unitType, spec.getMilitaryRoles()).get(0); if (type.isMilitaryGoods()) { // Retain enough goods to fully arm. int need = 0; for (Unit u : ownedUnits) { if (u.getRole() == militaryRole) continue; List<AbstractGoods> required = u.getGoodsDifference(militaryRole, 1); need += AbstractGoods.getCount(type, required); } return need; } int consumption = getConsumptionOf(type); if (type == spec.getPrimaryFoodType()) { // Food is perishable, do not try to retain that much return Math.max(40, consumption * 3); } if (type.isTradeGoods() || type.isNewWorldLuxuryType() || type.isRefined()) { // Aim for 10 years supply, resupply is doubtful return Math.max(80, consumption * 20); } // Just keep some around return 2 * getUnitCount(); }
/** {@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; }