net.sf.freecol.common.model
Class TileImprovement

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.TileItem
              extended by net.sf.freecol.common.model.TileImprovement
All Implemented Interfaces:
Locatable, Typed<TileImprovementType>

public class TileImprovement
extends TileItem
implements Typed<TileImprovementType>

Represents a tile improvement, such as a river or road.


Field Summary
static int FJORD_RIVER
           
static int LARGE_RIVER
           
private static java.util.logging.Logger logger
           
private  int magnitude
          Default is type.getMagnitude(), but this will override.
static int NO_RIVER
          River magnitudes
static int SMALL_RIVER
           
private  int style
          To store the style of multi-image TileImprovements (eg.
private  int turnsToComplete
           
private  TileImprovementType type
           
private  boolean virtual
          Whether this is a virtual improvement granted by some structure on the tile (a Colony, for example).
 
Fields inherited from class net.sf.freecol.common.model.TileItem
RESOURCE_ZINDEX, RUMOUR_ZINDEX, tile
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE
 
Constructor Summary
TileImprovement(Game game, org.w3c.dom.Element e)
           
TileImprovement(Game game, java.lang.String id)
          Initiates a new TileImprovement with the given ID.
TileImprovement(Game game, Tile tile, TileImprovementType type)
          Creates a standard TileImprovement-instance.
TileImprovement(Game game, javax.xml.stream.XMLStreamReader in)
           
 
Method Summary
 void compileStyleBreakdown(int[] base, int[] breakdown)
           
 void dispose()
          Disposes this improvement.
 int doWork()
           
 int doWork(int turns)
          Performs work towards completion of this TileImprovement This function allows for a unit to perform more than 1 'turn', perhaps in the event a skilled unit is able to build improvements with a bonus.
static TileImprovementType findBestTileImprovementType(Tile tile, GoodsType goodsType)
          Method for returning the 'most effective' TileImprovementType allowed for a given Tile.
static int[] getBase(Map.Direction[] directions, int baseNumber)
          Returns an int[NUMBER_OF_DIRECTIONS] array based on the baseNumber and the 'active' directions given.
 int getBonus(GoodsType goodsType)
          Returns the bonus (if any).
 TileType getChange(TileType tileType)
          Returns any change of TileType
 int getDeliverAmount()
           
 GoodsType getDeliverGoodsType()
           
 int getExpendedAmount()
           
 EquipmentType getExpendedEquipmentType()
           
 int getMagnitude()
           
 int getMovementCost(int moveCost, Tile fromTile)
          Performs reduction of the movement-cost.
 java.lang.String getOccupationString()
           
 Modifier getProductionModifier(GoodsType goodsType)
          Returns the bonus Modifier (if any).
 int getStyle()
          Returns the Style of this Improvement - used for Rivers
 int[] getStyleBreakdown(int[] base)
          Breaks the Style of this Improvement into 8 directions - used for Rivers (at the moment) Possible TODO: Modify this later should we modify the usage of Style.
 int[] getStyleBreakdown(Map.Direction[] directions, int baseNumber)
          Breaks the Style of this Improvement into 8 directions - used for Rivers (at the moment)
 int getTurnsToComplete()
           
 TileImprovementType getType()
          Gets the type of this object.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 int getZIndex()
          Get the ZIndex value.
 boolean isComplete()
           
 boolean isRiver()
          Is this TileImprovement a river?
 boolean isRoad()
          Is this TileImprovement a road?
 boolean isVirtual()
          Get the Virtual value.
 boolean isWorkerAllowed(Unit unit)
          Checks if a given worker can work at this Improvement
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setMagnitude(int magnitude)
           
 void setStyle(int style)
          Sets the Style of this Improvement - used for Rivers
 void setTurnsToComplete(int turns)
           
 void setVirtual(boolean newVirtual)
          Set the Virtual value.
 java.lang.String toString()
          Returns a textual representation of this object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.model.TileItem
getLocation, getSpaceTaken, getTile, setLocation
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

type

private TileImprovementType type

turnsToComplete

private int turnsToComplete

magnitude

private int magnitude
Default is type.getMagnitude(), but this will override.


NO_RIVER

public static final int NO_RIVER
River magnitudes

See Also:
Constant Field Values

SMALL_RIVER

public static final int SMALL_RIVER
See Also:
Constant Field Values

LARGE_RIVER

public static final int LARGE_RIVER
See Also:
Constant Field Values

FJORD_RIVER

public static final int FJORD_RIVER
See Also:
Constant Field Values

style

private int style
To store the style of multi-image TileImprovements (eg. rivers) Rivers have 4 directions {NE=1, SE=3, SW=9, NW=27}, and 3 levels (see above)

See Also:
Map, River

virtual

private boolean virtual
Whether this is a virtual improvement granted by some structure on the tile (a Colony, for example). Virtual improvements will be removed along with the structure that granted them.

Constructor Detail

TileImprovement

public TileImprovement(Game game,
                       Tile tile,
                       TileImprovementType type)
Creates a standard TileImprovement-instance. This constructor asserts that the game, tile and type are valid.

Parameters:
game - The Game in which this object belongs.
tile - The Tile on which this object sits.
type - The TileImprovementType of this TileImprovement.

TileImprovement

public TileImprovement(Game game,
                       javax.xml.stream.XMLStreamReader in)
                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

TileImprovement

public TileImprovement(Game game,
                       org.w3c.dom.Element e)

TileImprovement

public TileImprovement(Game game,
                       java.lang.String id)
Initiates a new TileImprovement with the given ID. The object should later be initialized by calling either FreeColGameObject.readFromXML(XMLStreamReader) or FreeColObject.readFromXMLElement(Element).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

getType

public TileImprovementType getType()
Description copied from interface: Typed
Gets the type of this object.

Specified by:
getType in interface Typed<TileImprovementType>
Returns:
The type of this object.

getMagnitude

public int getMagnitude()

setMagnitude

public void setMagnitude(int magnitude)

isVirtual

public final boolean isVirtual()
Get the Virtual value.

Returns:
a boolean value

setVirtual

public final void setVirtual(boolean newVirtual)
Set the Virtual value.

Parameters:
newVirtual - The new Virtual value.

isRoad

public boolean isRoad()
Is this TileImprovement a road?

Returns:
a boolean value

isRiver

public boolean isRiver()
Is this TileImprovement a river?

Returns:
a boolean value

toString

public java.lang.String toString()
Returns a textual representation of this object.

Overrides:
toString in class FreeColGameObject
Returns:
A String of either:
  1. NAME (#TURNS turns left) (eg. Road (2 turns left) ) if it is under construction
  2. NAME (eg. Road) if it is complete

getOccupationString

public java.lang.String getOccupationString()

getTurnsToComplete

public int getTurnsToComplete()
Returns:
the current turns to completion.

setTurnsToComplete

public void setTurnsToComplete(int turns)

getZIndex

public final int getZIndex()
Get the ZIndex value.

Specified by:
getZIndex in class TileItem
Returns:
an int value

isComplete

public boolean isComplete()

doWork

public int doWork(int turns)
Performs work towards completion of this TileImprovement This function allows for a unit to perform more than 1 'turn', perhaps in the event a skilled unit is able to build improvements with a bonus. The doWork function without any input params assumes 1 turn of work done.

Returns:
remaining turns to completion

doWork

public int doWork()

getExpendedEquipmentType

public EquipmentType getExpendedEquipmentType()

getExpendedAmount

public int getExpendedAmount()

getDeliverGoodsType

public GoodsType getDeliverGoodsType()

getDeliverAmount

public int getDeliverAmount()

getBonus

public int getBonus(GoodsType goodsType)
Returns the bonus (if any).

Parameters:
goodsType - a GoodsType value
Returns:
an int value

getProductionModifier

public Modifier getProductionModifier(GoodsType goodsType)
Returns the bonus Modifier (if any).

Parameters:
goodsType - a GoodsType value
Returns:
a Modifier value

getMovementCost

public int getMovementCost(int moveCost,
                           Tile fromTile)
Performs reduction of the movement-cost.

Parameters:
moveCost - Original movement cost
Returns:
The movement cost after any change

getChange

public TileType getChange(TileType tileType)
Returns any change of TileType

Returns:
The new TileType.

getStyle

public int getStyle()
Returns the Style of this Improvement - used for Rivers

Returns:
The style

setStyle

public void setStyle(int style)
Sets the Style of this Improvement - used for Rivers

Parameters:
style - The style

getBase

public static int[] getBase(Map.Direction[] directions,
                            int baseNumber)
Returns an int[NUMBER_OF_DIRECTIONS] array based on the baseNumber and the 'active' directions given.

Parameters:
directions - An int[] that gives the active directions eg {Map.N, Map.NE, Map.E, Map.SE, Map.S, Map.SW, Map.W, Map.NW}, or {Map.E, Map.SW};
baseNumber - The base to be used to create the base array.
Returns:
A base array that can create unique identifiers for any combination

getStyleBreakdown

public int[] getStyleBreakdown(Map.Direction[] directions,
                               int baseNumber)
Breaks the Style of this Improvement into 8 directions - used for Rivers (at the moment)

Parameters:
directions - An int[] that gives the active directions eg {Map.N, Map.NE, Map.E, Map.SE, Map.S, Map.SW, Map.W, Map.NW}, or {Map.E, Map.SW};
baseNumber - The base to be used to create the base array.
Returns:
An int[] with the magnitude in each direction.

getStyleBreakdown

public int[] getStyleBreakdown(int[] base)
Breaks the Style of this Improvement into 8 directions - used for Rivers (at the moment) Possible TODO: Modify this later should we modify the usage of Style.

Parameters:
base - Use #getBase(Direction[], int)
Returns:
An int[] with the magnitude in each direction.

compileStyleBreakdown

public void compileStyleBreakdown(int[] base,
                                  int[] breakdown)

findBestTileImprovementType

public static TileImprovementType findBestTileImprovementType(Tile tile,
                                                              GoodsType goodsType)
Method for returning the 'most effective' TileImprovementType allowed for a given Tile. Useful for AI in deciding the Improvements to prioritize.

Parameters:
tile - The Tile that will be improved
goodsType - The GoodsType to be prioritized.
Returns:
The best TileImprovementType available to be done.

isWorkerAllowed

public boolean isWorkerAllowed(Unit unit)
Checks if a given worker can work at this Improvement


dispose

public void dispose()
Disposes this improvement.

Overrides:
dispose in class TileItem

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"tileImprovement".