コード例 #1
0
ファイル: IndianSettlement.java プロジェクト: vardars/FreeCol
  /**
   * Gets the goods this settlement is willing to sell.
   *
   * @param limit The maximum number of goods required.
   * @param unit The <code>Unit</code> that is trading.
   * @return A list of goods to sell.
   */
  public List<Goods> getSellGoods(int limit, Unit unit) {
    List<Goods> result = new ArrayList<>();
    List<Goods> settlementGoods = getCompactGoods();
    Collections.sort(settlementGoods, exportGoodsComparator);

    int count = 0;
    for (Goods goods : settlementGoods) {
      if (!willSell(goods.getType())) continue;
      int amount = goods.getAmount();
      int retain = getWantedGoodsAmount(goods.getType());
      if (retain >= amount) continue;
      amount -= retain;
      if (amount > GoodsContainer.CARGO_SIZE) {
        amount = GoodsContainer.CARGO_SIZE;
      }
      if (unit != null) {
        amount =
            Math.round(
                applyModifiers(
                    (float) amount,
                    getGame().getTurn(),
                    unit.getModifiers(Modifier.TRADE_VOLUME_PENALTY)));
      }
      if (amount < TRADE_MINIMUM_SIZE) continue;
      result.add(new Goods(getGame(), this, goods.getType(), amount));
      count++;
      if (count >= limit) break;
    }
    return result;
  }
コード例 #2
0
ファイル: IndianSettlement.java プロジェクト: vardars/FreeCol
 @Override
 public int compare(Goods goods1, Goods goods2) {
   int cmp;
   GoodsType t1 = goods1.getType();
   GoodsType t2 = goods2.getType();
   cmp = (((t2.isNewWorldGoodsType()) ? 1 : 0) - ((t1.isNewWorldGoodsType()) ? 1 : 0));
   if (cmp == 0) {
     int a1 = Math.min(goods2.getAmount(), GoodsContainer.CARGO_SIZE);
     int a2 = Math.min(goods1.getAmount(), GoodsContainer.CARGO_SIZE);
     cmp = getPriceToSell(t2, a2) - getPriceToSell(t1, a1);
     if (cmp == 0) {
       cmp = a2 - a1;
     }
   }
   return cmp;
 }
コード例 #3
0
ファイル: IndianSettlement.java プロジェクト: vardars/FreeCol
 /**
  * Gets the amount of gold this <code>IndianSettlment</code> is willing to sell the given <code>
  * Goods</code> for.
  *
  * <p>It is only meaningful to call this method from the server, since the settlement's {@link
  * GoodsContainer} is hidden from the clients.
  *
  * @param goods The <code>Goods</code> to price.
  * @return The price.
  */
 public int getPriceToSell(Goods goods) {
   return getPriceToSell(goods.getType(), goods.getAmount());
 }