Examples of ICityPlayerProxy


Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    int availableAmountCity = city.getCity().getWare(ware).getAmount();
    ITradingOffice office = city.getPlayer().findTradingOffice(city.getCity());
    if (availableAmountCity>0 && office!=null){
      int amount2Move = dialog.getAmount(availableAmountCity); // This is ware specific size
      int avgPrice = ware.computeBuyPrice(availableAmountCity, amount2Move);
      // check if this is afforable
      final long cash = city.getPlayer().getCompany().getCash();
      if (cash<(long)avgPrice*amount2Move){
        int amountAprox = (int) (cash/avgPrice); // approx amount we can afford
        if (amountAprox>0){
          int tempPrice = ware.computeBuyPrice(availableAmountCity, amountAprox);
          while (amountAprox*tempPrice+tempPrice<cash){
            int newTempPrice = ware.computeBuyPrice(availableAmountCity, amountAprox++);
            if (amountAprox*newTempPrice>cash){
              // we cannot afford another item
              break;
            }
            tempPrice=newTempPrice;
          }
          avgPrice=tempPrice;
          amount2Move=amountAprox;
        } else {
          return; // cannot buy anything
        }
      }
      int movedAmount = city.getCity().move(ware, -amount2Move,city.getPlayer());
      if (amount2Move!=-movedAmount){
        avgPrice = ware.computeBuyPrice(city.getCity().getWare(ware).getAmount()+movedAmount, movedAmount);
        amount2Move=movedAmount;
      }
      int loaded = office.move(ware, amount2Move,avgPrice);
      city.getPlayer().updateCash(-avgPrice*loaded);
    }
  }
 
View Full Code Here

Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    int availableAmountCity = city.getCity().getWare(ware).getAmount();
    if (availableAmountCity>0){
      int amount2Move = dialog.getAmount(availableAmountCity); // This is ware specific size
      // consider available capacity
      final short sizeAsBarrels = ware.getSizeAsBarrels();
      if (sizeAsBarrels==1){
        amount2Move = Math.min(amount2Move, city.getActiveShip().getCapacity());
      } else {
        int temp = Math.min(amount2Move*sizeAsBarrels, city.getActiveShip().getCapacity());
        amount2Move = temp/sizeAsBarrels;
      }
      int avgPrice = ware.computeBuyPrice(availableAmountCity, amount2Move);
      // check if this is afforable
      final long cash = city.getPlayer().getCompany().getCash();
      if (cash<(long)avgPrice*amount2Move){
        int amountAprox = (int) (cash/avgPrice); // approx amount we can afford
        if (amountAprox>0){
          int tempPrice = ware.computeBuyPrice(availableAmountCity, amountAprox);
          while (amountAprox*tempPrice+tempPrice<cash){
            int newTempPrice = ware.computeBuyPrice(availableAmountCity, amountAprox++);
            if (amountAprox*newTempPrice>cash){
              // we cannot afford another item
              break;
            }
            tempPrice=newTempPrice;
          }
          avgPrice=tempPrice;
          amount2Move=amountAprox;
        } else {
          return; // cannot buy anything
        }
      }
      int movedAmount = city.getCity().move(ware, -amount2Move,city.getPlayer());
      if (amount2Move!=-movedAmount){
        avgPrice = ware.computeBuyPrice(city.getCity().getWare(ware).getAmount()+movedAmount, movedAmount);
        amount2Move=movedAmount;
      }
      int loaded = city.getActiveShip().load(ware, amount2Move, avgPrice);
      city.getPlayer().updateCash(-avgPrice*loaded);
    }
  }
 
View Full Code Here

Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    ITradingOffice office = city.getPlayer().findTradingOffice(city.getCity());
    if (office!=null) {
      int amountInStorage = office.getWare(ware).getAmount();
      if (amountInStorage > 0) {
        int availableAmountCity = city.getCity().getWare(ware).getAmount();
        int amount2Move = dialog.getAmount(amountInStorage);
        final int avgPrice;
        if (dialog.getMovableAmount() == ETransferAmount.MAX) {
          avgPrice = ware.getMaxValueSell();
        } else {
          avgPrice = ware.computeSellPrice(availableAmountCity,amount2Move);
        }
        city.getCity().move(ware, amount2Move,city.getPlayer()); // The price here is irrelevant
        int sold = office.move(ware, -amount2Move);
        city.getPlayer().updateCash(avgPrice * sold);
      } // end stored amount
    } // end office
  }
View Full Code Here

Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    int amountOnShip = city.getActiveShip().getWare(ware).getAmount();
    if (amountOnShip>0){
      int availableAmountCity = city.getCity().getWare(ware).getAmount();
      int amount2Move = dialog.getAmount(amountOnShip);
      final int avgPrice;
      if (dialog.getMovableAmount()==ETransferAmount.MAX){
        avgPrice = ware.getMaxValueSell();
      } else {
        avgPrice = ware.computeSellPrice(availableAmountCity, amount2Move);
      }
      city.getCity().move(ware, amount2Move,city.getPlayer()); // The price here is irrelevant
      int sold = city.getActiveShip().unload(ware, -amount2Move);
      city.getPlayer().updateCash(avgPrice*sold);
    }
  }
 
View Full Code Here

Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    IShip ship = city.getActiveShip();
    ITradingOffice office = city.getPlayer().findTradingOffice(city.getCity());
    int availableAmountStorage = office.getWare(ware).getAmount();
    if (availableAmountStorage>0 && office!=null){
      int amount2Move = dialog.getAmount(availableAmountStorage); // This is ware specific size
      int avgPrice = office.getWare(ware).getAVGPrice();
      int moved = office.move(ware, -amount2Move,avgPrice);
View Full Code Here

Examples of ch.sahits.game.graphic.display.model.ICityPlayerProxy

    this.dialog=dialog;
  }

  @Override
  public void run() {
    ICityPlayerProxy city = dialog.getCityPlayerProxy();
    IShip ship = city.getActiveShip();
    int availableAmountShip = ship.getWare(ware).getAmount();
    ITradingOffice office = city.getPlayer().findTradingOffice(city.getCity());
    if (availableAmountShip>0 && office!=null){
      int amount2Move = dialog.getAmount(availableAmountShip); // This is ware specific size
      int avgPrice = ship.getWare(ware).getAVGPrice();
      int moved = ship.unload(ware, amount2Move);
      office.move(ware, moved,avgPrice);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.