ch.sahits.game.openpatrician.model.building
Class TradingOffice

java.lang.Object
  extended by ch.sahits.game.openpatrician.model.impl.WareHolding
      extended by ch.sahits.game.openpatrician.model.building.TradingOffice
All Implemented Interfaces:
IBuilding, ITradingOffice, IPeriodicalUpdate

 class TradingOffice
extends WareHolding
implements ITradingOffice, IPeriodicalUpdate

Implementation of the trading office

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on Dec 17, 2011

Field Summary
private  int baseValue
          Value of the building (building costs
private  ICity city
          Reference to the city the trading office is located in
private  IBalanceSheet currentWeek
           
private  IBalanceSheet lastWeek
           
private static int MAX_CAPACITY
          Maximal capacity of the trading office in barrels
private  IPlayer player
          Reference to the player
private  IStorage storage
           
private  IWeaponStorage weapons
          Weapons storage
 
Constructor Summary
TradingOffice(IPlayer player, ICity city, int value)
           
 
Method Summary
protected  int computeAVGPrice(IWare ware, int amount)
          Compute the average price for ware that is to be purchased in the specified amount.
 IBalanceSheet getBalanceLastWeek()
          Retrieve the balance sheet for last completed week.
 int getCapacity()
          Retrieve the storage capacity of the trading office and all other storages in the same city
 IBalanceSheet getCurrentWeek()
          Retrieve the balance sheet for the current week
 IAutomatedTrading getOfficeTrading()
          Get the trading object of the office
 IPlayer getOwner()
          Retrieve the owner of the trading office
 int getPropertyTax()
          Retrieve the amount of property taxes per week
 ISteward getSteward()
          Retrieve the steward of the trading office (manager).
 IStorage getStorage()
          Retrieve an overview over the storage
 int getStored()
          Retrieve the total amount of the stored goods
 int getValue()
          Retrieve the value of the building
 IWeaponStorage getWeaponStorage()
          Retrieve the weapon storage for this trading office
 boolean hasWeapons()
          check if there are any weapons in storage
 int move(IWare ware, int amount)
          Add or remove ware from the storage.
 int move(IWare ware, int amount, int avgPrice)
          Move the ware into/from the storage with a price attached.
 int move(IWeapon weapon, int amount)
          /** Add or remove weapon from the storage. This method is thread save.
 void notify(DateObject date)
          The time defined as period has passed and it is now date
 
Methods inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
addNewWare, containsWare, getWare, move
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.sahits.game.openpatrician.model.building.ITradingOffice
getWare
 

Field Detail

MAX_CAPACITY

private static final int MAX_CAPACITY
Maximal capacity of the trading office in barrels

See Also:
Constant Field Values

player

private final IPlayer player
Reference to the player


city

private final ICity city
Reference to the city the trading office is located in


baseValue

private final int baseValue
Value of the building (building costs


weapons

private final IWeaponStorage weapons
Weapons storage


storage

private final IStorage storage

lastWeek

private IBalanceSheet lastWeek

currentWeek

private IBalanceSheet currentWeek
Constructor Detail

TradingOffice

public TradingOffice(IPlayer player,
                     ICity city,
                     int value)
Method Detail

getOwner

public IPlayer getOwner()
Description copied from interface: IBuilding
Retrieve the owner of the trading office

Specified by:
getOwner in interface IBuilding
Returns:

getCapacity

public int getCapacity()
Description copied from interface: ITradingOffice
Retrieve the storage capacity of the trading office and all other storages in the same city

Specified by:
getCapacity in interface ITradingOffice
Returns:
storage capacity in barrels

getStored

public int getStored()
Description copied from interface: ITradingOffice
Retrieve the total amount of the stored goods

Specified by:
getStored in interface ITradingOffice
Returns:
number of stored barrels

hasWeapons

public boolean hasWeapons()
Description copied from interface: ITradingOffice
check if there are any weapons in storage

Specified by:
hasWeapons in interface ITradingOffice
Returns:

move

public int move(IWeapon weapon,
                int amount)
/** Add or remove weapon from the storage. If the amount is negative it will be removed. If the full amount is not available only the available will be moved and returned. The amount is in the ware specific size. This method is thread save.

Specified by:
move in interface ITradingOffice
Returns:
amount moved

computeAVGPrice

protected int computeAVGPrice(IWare ware,
                              int amount)
Compute the average price for ware that is to be purchased in the specified amount. The price is computed based on the amount that is available in the city.

Overrides:
computeAVGPrice in class WareHolding
Parameters:
ware - for which the average price is to be computed
amount - amount that is bought
Returns:

move

public int move(IWare ware,
                int amount,
                int avgPrice)
Move the ware into/from the storage with a price attached.

Specified by:
move in interface ITradingOffice
Parameters:
ware - to be moved
amount - amount to be moved
avgPrice - average price to use on the amount of ware

getBalanceLastWeek

public IBalanceSheet getBalanceLastWeek()
Description copied from interface: ITradingOffice
Retrieve the balance sheet for last completed week.

Specified by:
getBalanceLastWeek in interface ITradingOffice
Returns:

getCurrentWeek

public IBalanceSheet getCurrentWeek()
Description copied from interface: ITradingOffice
Retrieve the balance sheet for the current week

Specified by:
getCurrentWeek in interface ITradingOffice
Returns:

getSteward

public ISteward getSteward()
Description copied from interface: ITradingOffice
Retrieve the steward of the trading office (manager). May be null if no manager is employed

Specified by:
getSteward in interface ITradingOffice
Returns:

getPropertyTax

public int getPropertyTax()
Description copied from interface: IBuilding
Retrieve the amount of property taxes per week

Specified by:
getPropertyTax in interface IBuilding
Returns:

getOfficeTrading

public IAutomatedTrading getOfficeTrading()
Description copied from interface: ITradingOffice
Get the trading object of the office

Specified by:
getOfficeTrading in interface ITradingOffice
Returns:

notify

public void notify(DateObject date)
Description copied from interface: IPeriodicalUpdate
The time defined as period has passed and it is now date

Specified by:
notify in interface IPeriodicalUpdate
Parameters:
date - current date time

move

public int move(IWare ware,
                int amount)
Description copied from interface: ITradingOffice
Add or remove ware from the storage. If the amount is negative it will be removed. If the full amount is not available only the available will be moved and returned. The amount is in the ware specific size. The price of the wares is computed based on the amount

Specified by:
move in interface ITradingOffice
Returns:
amount moved

getValue

public int getValue()
Description copied from interface: IBuilding
Retrieve the value of the building

Specified by:
getValue in interface IBuilding
Returns:

getWeaponStorage

public IWeaponStorage getWeaponStorage()
Description copied from interface: ITradingOffice
Retrieve the weapon storage for this trading office

Specified by:
getWeaponStorage in interface ITradingOffice
Returns:

getStorage

public IStorage getStorage()
Description copied from interface: ITradingOffice
Retrieve an overview over the storage

Specified by:
getStorage in interface ITradingOffice
Returns:


Copyright © 2011-2012 Sahits GmbH. All Rights Reserved.