Package ch.sahits.game.openpatrician.model.product

Examples of ch.sahits.game.openpatrician.model.product.AmountablePrice


   * @return the effective amount that was moved. The amount may be positive if something was added, negative if
   * the ware was removed from the holding or zero if nothing was moved.
   */
  public int move(IWare ware, int amount, IPlayer player) {
    synchronized (ware) { // There is still a problem with networked solution where the model of the city is replicated.
      AmountablePrice amounted = getWare(ware);
      if (amount<0 && containsWare(ware) && amounted!=null && -amount>amounted.getAmount()){ // remove more than is available
        amount = -amounted.getAmount(); // remove everything
      }
      if (amount<0 && !containsWare(ware)){
        amount = 0;
      }
      if (!containsWare(ware)){ // If the ware does not exist add it with amount 0
        new IllegalStateException("All wares should be initialized, allowed in test").printStackTrace();
      }
      if (amount>0){ // amount was bought
        amounted.add(amount, computeAVGPrice(ware, amount));
      } else { // amount sold
        amounted.remove(amount);
      }
      return amount;
    }
  }
View Full Code Here


    List<IShip> ships = owner.getFleet();
    for (IShip ship : ships) {
      companyValue += ship.getValue();
      Set<IWare> loaded = ship.getLoadedWares();
      for (IWare ware : loaded) {
        AmountablePrice ap = ship.getWare(ware);
        companyValue+=ap.getAVGPrice()*ap.getAmount();
      }
    }
   
    // Add value of all buildings
    for (ECityName cityName : ECityName.values()) {
      ICity city;
      try {
        city = CityFactory.createCityByName(cityName); // TODO refactor this as bean
        List<IBuilding> buildings = owner.findBuildings(city);
        for (IBuilding building : buildings) {
          companyValue += building.getValue();
          if (building instanceof ITradingOffice){
            ITradingOffice office = (ITradingOffice) building;
            for (IWare ware : EWare.values()) {
              AmountablePrice ap = office.getWare(ware);
              companyValue+=ap.getAVGPrice()*ap.getAmount();
            }
          }
        }
      } catch (IOException e) {
        logger.error("Could not retrieve created cities",e);
View Full Code Here

      // Make sure that for wares in other sizes than barrels we only load
      // complete loads.
      if (cap!=amount && sizeInBarrels!=1){
        cap = (cap/sizeInBarrels)*sizeInBarrels;
      }
        AmountablePrice available = getWare((IWare) ware);
        available.add(cap/ware.getSizeAsBarrels(), avgPrice);
  //    }
      return cap/sizeInBarrels;
    }
View Full Code Here

    final int loaded = loadedWare.get(ware).getAmount()*ware.getSizeAsBarrels();
    int unloaded = Math.min(loaded, amount);
    if (unloaded==loaded){ // unloaded completely
      loadedWare.remove(ware);
    } else {
      AmountablePrice available = loadedWare.get(ware);
      available.remove(unloaded/ware.getSizeAsBarrels());
    }
    return unloaded/ware.getSizeAsBarrels();
  }
View Full Code Here

  }

  @Override
  public AmountablePrice getWare(IWare ware) {
    if (!loadedWare.containsKey(ware)){
      loadedWare.put(ware, new AmountablePrice());
    }
    return loadedWare.get(ware);
  }
View Full Code Here

TOP

Related Classes of ch.sahits.game.openpatrician.model.product.AmountablePrice

Copyright © 2018 www.massapicom. 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.