net.sf.freecol.common.model
Class ColonyTile

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.UnitLocation
              extended by net.sf.freecol.common.model.WorkLocation
                  extended by net.sf.freecol.common.model.ColonyTile
All Implemented Interfaces:
Location, Ownable
Direct Known Subclasses:
ServerColonyTile

public class ColonyTile
extends WorkLocation
implements Ownable

Represents a work location on a tile. Each ColonyTile except the colony center tile provides a work place for a single unit and produces a single type of goods. The colony center tile generally produces two different of goods, one food type and one new world raw material.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
protected  boolean colonyCenterTile
          Is this colony tile at the center of the colony.
private static java.util.logging.Logger logger
           
static int UNIT_CAPACITY
          The maximum number of units a ColonyTile can hold.
static java.lang.String UNIT_CHANGE
           
protected  Tile workTile
          The tile to work.
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
protected ColonyTile()
          Constructor for ServerColonyTile.
protected ColonyTile(Game game, Colony colony, Tile workTile)
          Constructor for ServerColonyTile.
  ColonyTile(Game game, org.w3c.dom.Element e)
          Initiates a new ColonyTile from an XML representation.
  ColonyTile(Game game, java.lang.String id)
          Initiates a new ColonyTile with the given ID.
  ColonyTile(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new ColonyTile from an XML representation.
 
Method Summary
 boolean add(Locatable locatable)
          Add the specified locatable to this colony tile.
 StringTemplate getLabel()
          Returns a description of the tile, with the name of the tile and any improvements made to it (road/plow).
 StringTemplate getLocationName()
          Returns the (non-unique) name of this ColonyTile.
 UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
          Gets the reason why a given Locatable can not be added to this Location.
 UnitLocation.NoAddReason getNoWorkReason()
          Checks if this work location is available to the colony to be worked.
 Unit getOccupyingUnit()
          Returns the unit who is occupying the tile
 int getPotentialProduction(UnitType unitType, GoodsType goodsType)
          Gets the potential production of a given goods type from using a unit of a given type in this building.
private  AbstractGoods getPrimaryProduction()
          Returns the primary production of a colony center tile.
 java.util.List<AbstractGoods> getProduction()
           
 java.util.Set<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
          Gets the production modifiers for the given type of goods and unit.
 int getProductionOf(GoodsType goodsType)
          Returns the production of the given type of goods.
 int getProductionOf(Unit unit, GoodsType goodsType)
          Returns the production of the given type of goods which would be produced by the given unit
private  AbstractGoods getSecondaryProduction()
          Returns the secondary production of a colony center tile.
 Unit getUnit()
          Gets the Unit currently working on this ColonyTile.
 int getUnitCapacity()
          Gets the maximum number of Units this Location can hold.
 Tile getWorkTile()
          Gets the work tile.
 GoodsType getWorkType(Unit unit)
          Returns a worktype for a unit.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean isColonyCenterTile()
          Checks if this is the tile where the Colony is located.
 boolean isOccupied()
          Checks whether there is a fortified enemy unit in the tile.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
          Partial reader, so that "remove" messages can be brief.
 void relocateWorkers()
          Relocates any worker on this ColonyTile.
 boolean remove(Locatable locatable)
          Remove the specified locatable from this colony tile.
 java.lang.String toString()
          Will return the position of the tile and the name of the colony in addition to the FreeColObject.toString().
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.
protected  void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out, java.lang.String[] fields)
          Partial writer, so that "remove" messages can be brief.
 
Methods inherited from class net.sf.freecol.common.model.WorkLocation
canBeWorked, canTeach, getColony, getOwner, getSettlement, getTile, readAttributes, setColony, setOwner, writeAttributes
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, contains, dispose, disposeList, getGoodsContainer, getLocationNameFor, getSpaceTaken, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, readChild, readChildren, writeChildren, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Ownable
getOwner, setOwner
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

logger

private static final java.util.logging.Logger logger

UNIT_CHANGE

public static final java.lang.String UNIT_CHANGE
See Also:
Constant Field Values

UNIT_CAPACITY

public static final int UNIT_CAPACITY
The maximum number of units a ColonyTile can hold.

See Also:
Constant Field Values

workTile

protected Tile workTile
The tile to work.


colonyCenterTile

protected boolean colonyCenterTile
Is this colony tile at the center of the colony.

Constructor Detail

ColonyTile

protected ColonyTile()
Constructor for ServerColonyTile.


ColonyTile

protected ColonyTile(Game game,
                     Colony colony,
                     Tile workTile)
Constructor for ServerColonyTile.

Parameters:
game - The Game this object belongs to.
colony - The Colony this object belongs to.
workTile - The tile in which this ColonyTile represents a WorkLocation for.

ColonyTile

public ColonyTile(Game game,
                  javax.xml.stream.XMLStreamReader in)
           throws javax.xml.stream.XMLStreamException
Initiates a new ColonyTile from an XML representation.

Parameters:
game - The Game this object belongs to.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if an error occured during parsing.

ColonyTile

public ColonyTile(Game game,
                  org.w3c.dom.Element e)
Initiates a new ColonyTile from an XML representation.

Parameters:
game - The Game this object belongs to.
e - An XML-element that will be used to initialize this object.

ColonyTile

public ColonyTile(Game game,
                  java.lang.String id)
Initiates a new ColonyTile 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

getLocationName

public StringTemplate getLocationName()
Returns the (non-unique) name of this ColonyTile.

Specified by:
getLocationName in interface Location
Overrides:
getLocationName in class UnitLocation
Returns:
The name of this ColonyTile.

getLabel

public StringTemplate getLabel()
Returns a description of the tile, with the name of the tile and any improvements made to it (road/plow).

Returns:
The description label for this tile

isColonyCenterTile

public boolean isColonyCenterTile()
Checks if this is the tile where the Colony is located.

Returns:
True if this is the colony center tile.

getWorkTile

public Tile getWorkTile()
Gets the work tile.

Returns:
The tile in which this ColonyTile represents a WorkLocation for.

getUnit

public Unit getUnit()
Gets the Unit currently working on this ColonyTile.

Returns:
The Unit or null if no unit is present. TODO: deprecate this in favour of using the unit list, as we are unnecessarily encoding the assumption that there can only be one unit.

getUnitCapacity

public int getUnitCapacity()
Gets the maximum number of Units this Location can hold. To be overridden by subclasses.

Overrides:
getUnitCapacity in class UnitLocation
Returns:
Integer.MAX_VALUE, denoting no effective limit.

getNoWorkReason

public UnitLocation.NoAddReason getNoWorkReason()
Checks if this work location is available to the colony to be worked.

Specified by:
getNoWorkReason in class WorkLocation
Returns:
The reason why/not the work location can be worked.

getNoAddReason

public UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
Gets the reason why a given Locatable can not be added to this Location.

Overrides:
getNoAddReason in class WorkLocation
Parameters:
locatable - The Locatable to test.
Returns:
The reason why adding would fail.

add

public boolean add(Locatable locatable)
Add the specified locatable to this colony tile.

Specified by:
add in interface Location
Overrides:
add in class WorkLocation
Parameters:
locatable - The Locatable to add.

remove

public boolean remove(Locatable locatable)
Remove the specified locatable from this colony tile.

Specified by:
remove in interface Location
Overrides:
remove in class WorkLocation
Parameters:
locatable - The Locatable to be removed.

relocateWorkers

public void relocateWorkers()
Relocates any worker on this ColonyTile. The workers are added to another WorkLocation within the Colony.


getOccupyingUnit

public Unit getOccupyingUnit()
Returns the unit who is occupying the tile

Returns:
the unit who is occupying the tile
See Also:
isOccupied()

isOccupied

public boolean isOccupied()
Checks whether there is a fortified enemy unit in the tile. Units can't produce in occupied tiles

Returns:
true if an fortified enemy unit is in the tile

getWorkType

public GoodsType getWorkType(Unit unit)
Returns a worktype for a unit.

Parameters:
unit - a Unit value
Returns:
a workType

getPrimaryProduction

private AbstractGoods getPrimaryProduction()
Returns the primary production of a colony center tile. In the standard rule sets, this is always some kind of food and all tile improvements contribute to the production.

Returns:
an AbstractGoods value

getSecondaryProduction

private AbstractGoods getSecondaryProduction()
Returns the secondary production of a colony center tile. Only natural tile improvements, such as rivers, contribute to the production. Artificial tile improvements, such as plowing, are ignored.

Returns:
an int value

getProduction

public java.util.List<AbstractGoods> getProduction()

getProductionModifiers

public java.util.Set<Modifier> getProductionModifiers(GoodsType goodsType,
                                                      UnitType unitType)
Gets the production modifiers for the given type of goods and unit.

Parameters:
goodsType - The GoodsType to produce.
unitType - The unitType to produce them.
Returns:
A set of the applicable modifiers.

getProductionOf

public int getProductionOf(GoodsType goodsType)
Returns the production of the given type of goods.

Specified by:
getProductionOf in class WorkLocation
Parameters:
goodsType - a GoodsType value
Returns:
an int value

getProductionOf

public int getProductionOf(Unit unit,
                           GoodsType goodsType)
Returns the production of the given type of goods which would be produced by the given unit

Specified by:
getProductionOf in class WorkLocation
Parameters:
unit - an Unit value
goodsType - a GoodsType value
Returns:
an int value

getPotentialProduction

public int getPotentialProduction(UnitType unitType,
                                  GoodsType goodsType)
Gets the potential production of a given goods type from using a unit of a given type in this building.

Specified by:
getPotentialProduction in class WorkLocation
Parameters:
unitType - The UnitType to check.
goodsType - The GoodsType to check.
Returns:
The amount of goods potentially produced.

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.

toXMLPartialImpl

protected void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
                                java.lang.String[] fields)
                         throws javax.xml.stream.XMLStreamException
Partial writer, so that "remove" messages can be brief.

Overrides:
toXMLPartialImpl in class FreeColObject
Parameters:
out - The target stream.
fields - The fields to write.
Throws:
javax.xml.stream.XMLStreamException - If there are problems writing the stream.

readFromXMLPartialImpl

protected void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
                               throws javax.xml.stream.XMLStreamException
Partial reader, so that "remove" messages can be brief.

Overrides:
readFromXMLPartialImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - If there are problems reading the stream.

toString

public java.lang.String toString()
Will return the position of the tile and the name of the colony in addition to the FreeColObject.toString().

Overrides:
toString in class FreeColGameObject
Returns:
A representation of a colony-tile that can be used for debugging.

getXMLElementTagName

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

Returns:
"colonyTile".