ch.sahits.game.openpatrician.model.ship.impl
Class Ship

java.lang.Object
  extended by ch.sahits.game.openpatrician.model.ship.impl.Ship
All Implemented Interfaces:
IShip
Direct Known Subclasses:
Cog, Crayer, Holk, Snaikka

abstract class Ship
extends Object
implements IShip


Field Summary
protected  int fitness
          Fitness of the ship.
private  int initialValue
          Initial value of the ship
private  Map<IWare,AmountablePrice> loadedWare
          Store the wares loaded on the ship together with their amount.
protected  String name
          Name of the ship
protected  EShipUpgrade upgradeLevel
          State of the design standard level
private  ArrayList<WeaponsLocation> weapons
          List of the weapons on board together with their location
 
Constructor Summary
Ship(int value)
           
 
Method Summary
protected  void clearLoadedWares()
          Clear all loaded wares.
private  int ensureCapacity(int amount)
          Check if the amount can be loaded
 int getLoad()
          Retrieve the amount of load in barrels that is loaded in actual wares (no wappen or crew)
 Set<IWare> getLoadedWares()
          Retrieve a list of all loaded wares
 String getName()
          Retrieve the name of the of the ship
private  EShipSide getNextFreeSide(IWeapon weapon)
          Retrieve the side of the next free slot where the weapon can be placed.
private  int getNextFreeSlot(IWeapon weapon, EShipSide side)
          Retrieve the next free slot for the weapon on the side.
 int getValue()
          Retrieve the current value of the ship without its cargo
 AmountablePrice getWare(IWare ware)
          Retrieve the amount of ware loaded
 boolean hasWeapons()
          check if weapons are on board
 boolean isUpgradable()
          Check if the ship can be upgraded
 int load(IWare ware, int amount, int avgPrice)
          Load the ware in the specified amount onto the ship.
 void setName(String name)
          Set the ships name
 int unload(IWare ware, int amount)
          Unload the specified quantity of the ware.
 void upgrade()
          Upgrade the ship if it is upgradable
 
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.ship.IShip
damage, getCapacity, getDamage, getSize, getUpgradeSpaceReduction, repair
 

Field Detail

upgradeLevel

protected EShipUpgrade upgradeLevel
State of the design standard level


name

protected String name
Name of the ship


loadedWare

private Map<IWare,AmountablePrice> loadedWare
Store the wares loaded on the ship together with their amount. The amount is ware specific


weapons

private final ArrayList<WeaponsLocation> weapons
List of the weapons on board together with their location


fitness

protected int fitness
Fitness of the ship. This is reduced as it is damaged


initialValue

private final int initialValue
Initial value of the ship

Constructor Detail

Ship

public Ship(int value)
Method Detail

isUpgradable

public boolean isUpgradable()
Description copied from interface: IShip
Check if the ship can be upgraded

Specified by:
isUpgradable in interface IShip
Returns:

upgrade

public void upgrade()
Description copied from interface: IShip
Upgrade the ship if it is upgradable

Specified by:
upgrade in interface IShip

getName

public String getName()
Description copied from interface: IShip
Retrieve the name of the of the ship

Specified by:
getName in interface IShip
Returns:

getLoadedWares

public Set<IWare> getLoadedWares()
Description copied from interface: IShip
Retrieve a list of all loaded wares

Specified by:
getLoadedWares in interface IShip
Returns:

load

public int load(IWare ware,
                int amount,
                int avgPrice)
Load the ware in the specified amount onto the ship. The amount uses the size specified by the ware This method is not thread safe as it is only intended to be accessed by one thread at a time

Specified by:
load in interface IShip
Parameters:
ware - to be loaded
amount - of items the ware
avgPrice - average price of one item of the ware
Returns:
amount actually loaded

ensureCapacity

private int ensureCapacity(int amount)
Check if the amount can be loaded

Parameters:
amount -
Returns:

unload

public int unload(IWare ware,
                  int amount)
Unload the specified quantity of the ware. The amount uses the size specified by the ware This method is not thread safe as it is only intended to be accessed by one thread at a time

Specified by:
unload in interface IShip
Parameters:
ware - to be unloaded
amount - amount of items of ware to unload
Returns:
amount of the ware unloaded

setName

public void setName(String name)
Description copied from interface: IShip
Set the ships name

Specified by:
setName in interface IShip

getLoad

public int getLoad()
Description copied from interface: IShip
Retrieve the amount of load in barrels that is loaded in actual wares (no wappen or crew)

Specified by:
getLoad in interface IShip
Returns:
amount of loaded wares in barrels

clearLoadedWares

protected void clearLoadedWares()
Clear all loaded wares. This method is only intended for testing


getWare

public AmountablePrice getWare(IWare ware)
Description copied from interface: IShip
Retrieve the amount of ware loaded

Specified by:
getWare in interface IShip
Returns:

getNextFreeSide

private EShipSide getNextFreeSide(IWeapon weapon)
Retrieve the side of the next free slot where the weapon can be placed. check first port and then starboard. There is no free solt on either side, null will be returned.

Parameters:
weapon - to be placed
Returns:
EShipSide.PORT, EShipSide.STARBOARD or null

getNextFreeSlot

private int getNextFreeSlot(IWeapon weapon,
                            EShipSide side)
Retrieve the next free slot for the weapon on the side. The slots are checked from stern to bow. If there is no free slot a negative number will be returned

Parameters:
weapon - to be placed
side - to be checked EShipSide.PORT or EShipSide.STARBOARD
Returns:
slot index or negative number

hasWeapons

public boolean hasWeapons()
Description copied from interface: IShip
check if weapons are on board

Specified by:
hasWeapons in interface IShip
Returns:

getValue

public int getValue()
Description copied from interface: IShip
Retrieve the current value of the ship without its cargo

Specified by:
getValue in interface IShip
Returns:


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