/** * Selects the most desirable goods from the colony. * * @param target The colony. * @return The goods to demand. */ public Goods selectGoods(Colony target) { final Specification spec = getSpecification(); Tension.Level tension = getUnit().getOwner().getTension(target.getOwner()).getLevel(); int dx = spec.getInteger(GameOptions.NATIVE_DEMANDS) + 1; final GoodsType food = spec.getPrimaryFoodType(); Goods goods = null; int amount = capAmount(target.getGoodsCount(food), dx); if (tension.compareTo(Tension.Level.CONTENT) <= 0 && target.getGoodsCount(food) >= amount) { return new Goods(getGame(), target, food, amount); } else if (tension.compareTo(Tension.Level.DISPLEASED) <= 0) { Market market = target.getOwner().getMarket(); int value = 0; for (Goods currentGoods : target.getCompactGoods()) { int goodsValue = market.getSalePrice(currentGoods); if (currentGoods.getType().isFoodType() || currentGoods.getType().isMilitaryGoods()) { continue; } else if (goodsValue > value) { value = goodsValue; goods = currentGoods; } } if (goods != null) { goods.setAmount(capAmount(goods.getAmount(), dx)); return goods; } } else { // Military goods for (GoodsType preferred : spec.getGoodsTypeList()) { if (preferred.isMilitaryGoods()) { amount = target.getGoodsCount(preferred); if (amount > 0) { return new Goods(getGame(), target, preferred, capAmount(amount, dx)); } } } // Storable building materials (what do the natives need tools for?) for (GoodsType preferred : spec.getStorableGoodsTypeList()) { if (preferred.isBuildingMaterial()) { amount = target.getGoodsCount(preferred); if (amount > 0) { return new Goods(getGame(), target, preferred, capAmount(amount, dx)); } } } // Trade goods for (GoodsType preferred : spec.getStorableGoodsTypeList()) { if (preferred.isTradeGoods()) { amount = target.getGoodsCount(preferred); if (amount > 0) { return new Goods(getGame(), target, preferred, capAmount(amount, dx)); } } } // Refined goods for (GoodsType preferred : spec.getStorableGoodsTypeList()) { if (preferred.isRefined()) { amount = target.getGoodsCount(preferred); if (amount > 0) { return new Goods(getGame(), target, preferred, capAmount(amount, dx)); } } } } // Have not found what we want Market market = target.getOwner().getMarket(); int value = 0; for (Goods currentGoods : target.getCompactGoods()) { int goodsValue = market.getSalePrice(currentGoods); if (goodsValue > value) { value = goodsValue; goods = currentGoods; } } if (goods != null) { goods.setAmount(capAmount(goods.getAmount(), dx)); } return goods; }