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.ColonyTile
All Implemented Interfaces:
Location, Ownable, WorkLocation

public class ColonyTile
extends FreeColGameObject
implements WorkLocation, Ownable

Represents a work location on a tile.


Field Summary
static java.lang.String UNIT_CHANGE
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
ColonyTile(Game game, Colony colony, Tile workTile)
          Creates a new ColonyTile.
ColonyTile(Game game, org.w3c.dom.Element e)
          Initiates a new Building 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 Building from an XML representation.
 
Method Summary
 void add(Locatable locatable)
          Add the specified Locatable to this WorkLocation.
 boolean canAdd(Locatable locatable)
          Checks if the specified Locatable may be added to this WorkLocation.
 boolean canBeWorked()
          Check if this WorkLocation is available to the colony.
 boolean contains(Locatable locatable)
          Checks if this ColonyTile contains the given Locatable.
 void dispose()
          Removes all references to this object.
 Colony getColony()
          Gets a pointer to the colony containing this tile.
 Unit getFirstUnit()
          Gets the Unit currently working on this ColonyTile.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods.
 Unit getLastUnit()
          Gets the Unit currently working on this ColonyTile.
 Unit getOccupyingUnit()
          Returns the unit who is occupying the tile
 Player getOwner()
          Gets the owner of this Ownable.
 java.util.Set<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
          Returns the production of the given type of goods.
 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
 Tile getTile()
          Gets the tile where the colony is located.
 Unit getUnit()
          Gets the Unit currently working on this ColonyTile.
 int getUnitCount()
          Gets the amount of Units at this ColonyTile.
 java.util.Iterator<Unit> getUnitIterator()
          Gets a Iterator of every Unit directly located on this Location.
 java.util.List<Unit> getUnitList()
          Returns a list containing all the Units present at this Location.
 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.
 void newTurn()
          Prepares this ColonyTile for a new turn.
 void relocateWorkers()
          Relocates any worker on this ColonyTile.
 void remove(Locatable locatable)
          Remove the specified Locatable from this WorkLocation.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 void setUnit(Unit unit)
          Sets a Unit to this ColonyTile.
 java.lang.String toString()
          Will return the position of the tile and the name of the colony in addition to the FreeColObject.toString().
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toXML, 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, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

UNIT_CHANGE

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

ColonyTile

public ColonyTile(Game game,
                  Colony colony,
                  Tile workTile)
Creates a new ColonyTile.

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 Building 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 Building 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

getOwner

public Player getOwner()
Gets the owner of this Ownable.

Specified by:
getOwner in interface Ownable
Returns:
The Player controlling this Ownable.

setOwner

public void setOwner(Player p)
Sets the owner of this Ownable.

Specified by:
setOwner in interface Ownable
Parameters:
p - The Player that should take ownership of this Ownable.
Throws:
java.lang.UnsupportedOperationException - is always thrown by this method.

isColonyCenterTile

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

Returns:
The result.

getWorkTile

public Tile getWorkTile()
Gets the work tile.

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

getTile

public Tile getTile()
Gets the tile where the colony is located.

Specified by:
getTile in interface Location
Returns:
The Tile.

getGoodsContainer

public GoodsContainer getGoodsContainer()
Description copied from interface: Location
Gets the GoodsContainer this Location use for storing it's goods.

Specified by:
getGoodsContainer in interface Location
Returns:
The GoodsContainer or null if the Location cannot store any goods.

getUnit

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

Returns:
The Unit or null if no unit is present.
See Also:
setUnit(net.sf.freecol.common.model.Unit)

getColony

public Colony getColony()
Gets a pointer to the colony containing this tile.

Specified by:
getColony in interface Location
Specified by:
getColony in interface WorkLocation
Returns:
The Colony.
See Also:
Location.getColony()

setUnit

public void setUnit(Unit unit)
Sets a Unit to this ColonyTile.

Parameters:
unit - The Unit.
See Also:
getUnit()

getUnitCount

public int getUnitCount()
Gets the amount of Units at this ColonyTile.

Specified by:
getUnitCount in interface Location
Returns:
The amount of Units at this ColonyTile.

relocateWorkers

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


canBeWorked

public boolean canBeWorked()
Check if this WorkLocation is available to the colony. Used by canAdd() and the gui to decide whether to draw a border on this tile in the colony panel.

Returns:
True if the location can be worked.

canAdd

public boolean canAdd(Locatable locatable)
Checks if the specified Locatable may be added to this WorkLocation.

Specified by:
canAdd in interface Location
Parameters:
locatable - the Locatable.
Returns:
true if the Unit may be added and false otherwise.

add

public void add(Locatable locatable)
Add the specified Locatable to this WorkLocation.

Specified by:
add in interface Location
Parameters:
locatable - The Locatable that shall be added to this WorkLocation.

remove

public void remove(Locatable locatable)
Remove the specified Locatable from this WorkLocation.

Specified by:
remove in interface Location
Parameters:
locatable - The Locatable that shall be removed from this WorkLocation.

getUnitList

public java.util.List<Unit> getUnitList()
Description copied from interface: Location
Returns a list containing all the Units present at this Location.

Specified by:
getUnitList in interface Location
Returns:
a list containing the Units present at this location.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Description copied from interface: Location
Gets a Iterator of every Unit directly located on this Location.

Specified by:
getUnitIterator in interface Location
Returns:
The Iterator.

contains

public boolean contains(Locatable locatable)
Checks if this ColonyTile contains the given Locatable.

Specified by:
contains in interface Location
Parameters:
locatable - The Locatable.
Returns:
The result.

getFirstUnit

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

Returns:
The Unit or null if no unit is present.
See Also:
setUnit(net.sf.freecol.common.model.Unit)

getLastUnit

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

Returns:
The Unit or null if no unit is present.
See Also:
setUnit(net.sf.freecol.common.model.Unit)

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

newTurn

public void newTurn()
Prepares this ColonyTile for a new turn.

Specified by:
newTurn in interface WorkLocation

getWorkType

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

Parameters:
unit - a Unit value
Returns:
a workType

getProductionOf

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

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

getProductionModifiers

public java.util.Set<Modifier> getProductionModifiers(GoodsType goodsType,
                                                      UnitType unitType)
Returns the production of the given type of goods.

Parameters:
goodsType - a GoodsType value
unitType - a unitType 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

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

dispose

public void dispose()
Description copied from class: FreeColGameObject
Removes all references to this object.

Overrides:
dispose in class FreeColGameObject

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".