net.sf.freecol.common.model
Class WorkLocation

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
All Implemented Interfaces:
Location, Ownable
Direct Known Subclasses:
Building, ColonyTile

public abstract class WorkLocation
extends UnitLocation
implements Ownable

The WorkLocation is a place in a Colony where Units can work. The unit capacity of a WorkLocation is likely to be limited. ColonyTiles can only hold a single worker, and Buildings can hold no more than three workers, for example. WorkLocations do not store any Goods. They take any Goods they consume from the Colony, and put all Goods they produce there, too. Although the WorkLocation implements Ownable, its owner can not be changed directly, as it is always owned by the owner of the Colony.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
private  Colony colony
          Describe colony here.
 
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 WorkLocation()
          Constructor for ServerWorkLocation.
protected WorkLocation(Game game)
          Constructor for ServerWorkLocation.
  WorkLocation(Game game, java.lang.String id)
          Initiates a new WorkLocation with the given ID.
  WorkLocation(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new WorkLocation from an XML representation.
 
Method Summary
 boolean add(Locatable locatable)
          Adds the specified locatable to this building.
abstract  boolean canAutoProduce()
          Can this work location can produce goods without workers?
 boolean canBeWorked()
          Checks if this colony tile can be worked.
 boolean canTeach()
          Returns true if this work location has the Ability to teach skills.
 Colony getColony()
          Returns the Colony this WorkLocation is located in.
 UnitLocation.NoAddReason getNoAddReason(Locatable locatable)
          Gets the reason why a given Locatable can not be added to this Location.
abstract  UnitLocation.NoAddReason getNoWorkReason()
          Checks if this work location is available to the colony to be worked.
 Player getOwner()
          Gets the owner of this Ownable.
abstract  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 work location.
abstract  int getProductionOf(GoodsType goodsType)
          Gets the production of the given type of goods.
abstract  int getProductionOf(Unit unit, GoodsType goodsType)
          Gets the production of the given type of goods produced by a unit.
 Settlement getSettlement()
          Returns the settlement containing this building.
 Tile getTile()
          Gets the Tile where this work location is located.
 void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
 boolean remove(Locatable locatable)
          Removes the specified locatable from this building.
 void setColony(Colony newColony)
          Set the Colony value.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, contains, dispose, disposeList, getGoodsContainer, getLocationName, getLocationNameFor, getSpaceTaken, getUnitCapacity, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, readChild, readChildren, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, getXMLElementTagName, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toString, toXML, toXMLImpl, 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, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

colony

private Colony colony
Describe colony here.

Constructor Detail

WorkLocation

protected WorkLocation()
Constructor for ServerWorkLocation.


WorkLocation

protected WorkLocation(Game game)
Constructor for ServerWorkLocation.

Parameters:
game - The Game this object belongs to.

WorkLocation

public WorkLocation(Game game,
                    javax.xml.stream.XMLStreamReader in)
             throws javax.xml.stream.XMLStreamException
Initiates a new WorkLocation 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 a problem was encountered during parsing.

WorkLocation

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

getProductionOf

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

Parameters:
goodsType - The type of goods to get the production of.
Returns:
The production of the given type of goods.

getProductionOf

public abstract int getProductionOf(Unit unit,
                                    GoodsType goodsType)
Gets the production of the given type of goods produced by a unit.

Parameters:
unit - The unit to do the work.
goodsType - The type of goods to get the production of.
Returns:
The production of the given type of goods.

getPotentialProduction

public abstract 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 work location.

Parameters:
unitType - The UnitType to produce the goods.
goodsType - The GoodsType to produce.
Returns:
The amount of goods potentially produced.

canAutoProduce

public abstract boolean canAutoProduce()
Can this work location can produce goods without workers?

Returns:
True if this work location can produce goods without workers.

getNoWorkReason

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

Returns:
The reason why/not the work location can be worked.

canBeWorked

public boolean canBeWorked()
Checks if this colony tile can be worked.

Returns:
True if the colony tile 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 UnitLocation
Parameters:
locatable - The Locatable to test.
Returns:
The reason why adding would fail.

getColony

public final Colony getColony()
Returns the Colony this WorkLocation is located in. This method always returns a colony != null (in contrast to Location.getColony(), which might return null).

Specified by:
getColony in interface Location
Overrides:
getColony in class UnitLocation
Returns:
The Colony this WorkLocation is located in.
See Also:
Location.getColony()

setColony

public final void setColony(Colony newColony)
Set the Colony value.

Parameters:
newColony - The new Colony value.

getTile

public Tile getTile()
Gets the Tile where this work location is located.

Specified by:
getTile in interface Location
Overrides:
getTile in class UnitLocation
Returns:
The Tile.

getSettlement

public Settlement getSettlement()
Returns the settlement containing this building.

Specified by:
getSettlement in interface Location
Overrides:
getSettlement in class UnitLocation
Returns:
This colony.

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. Do not call this method, ever. Since the owner of this WorkLocation is the owner of the Colony, you must set the owner of the Colony instead.

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.

canTeach

public boolean canTeach()
Returns true if this work location has the Ability to teach skills.

See Also:
Ability.CAN_TEACH

add

public boolean add(Locatable locatable)
Adds the specified locatable to this building.

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

remove

public boolean remove(Locatable locatable)
Removes the specified locatable from this building.

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

readAttributes

public void readAttributes(javax.xml.stream.XMLStreamReader in)
                    throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

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

writeAttributes

public void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                     throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden by any object that uses the toXML(XMLStreamWriter, String) call.

Overrides:
writeAttributes in class UnitLocation
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.