/** * Price some goods according to the amount present in the settlement. * * @param type The type of goods for sale. * @param amount The amount of goods for sale. * @return A price for the goods. */ private int getNormalGoodsPriceToBuy(GoodsType type, int amount) { final int tradeGoodsAdd = 20; // Fake additional trade goods present final int capacity = getGoodsCapacity(); int current = getGoodsCount(type); // Increase effective stock if its raw material is produced here. GoodsType rawType = type.getInputType(); if (rawType != null) { int rawProduction = getMaximumProduction(rawType); int add = (rawProduction < 5) ? 10 * rawProduction : (rawProduction < 10) ? 5 * rawProduction + 25 : (rawProduction < 20) ? 2 * rawProduction + 55 : 100; // Decrease bonus in proportion to current stock, up to capacity. add = add * Math.max(0, capacity - current) / capacity; current += add; } else if (type.isTradeGoods()) { // Small artificial increase of the trade goods stored. current += tradeGoodsAdd; } // Only interested in the amount of goods that keeps the // total under the threshold. int retain = Math.min(getWantedGoodsAmount(type), capacity); int valued = (retain <= current) ? 0 : Math.min(amount, retain - current); // Unit price then is maximum price plus the bonus for the // settlement type, reduced by the proportion of goods present. int unitPrice = (GOODS_BASE_PRICE + getType().getTradeBonus()) * Math.max(0, capacity - current) / capacity; // But farmed goods are always less interesting. // and small settlements are not interested in building. if (type.isFarmed() || type.isRawBuildingMaterial()) unitPrice /= 2; // Only pay for the portion that is valued. return (unitPrice < 0) ? 0 : valued * unitPrice; }