net.sf.freecol.common.model
Class Building

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

public final class Building
extends FreeColGameObject
implements WorkLocation, Ownable, Typed<BuildingType>

Represents a building in a colony.


Field Summary
static java.lang.String UNIT_CHANGE
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Building(Game game, Colony colony, BuildingType type)
          Creates a new Building.
Building(Game game, org.w3c.dom.Element e)
          Initiates a new Building from an XML representation.
Building(Game game, java.lang.String id)
          Initiates a new Building with the given ID.
Building(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Building from an XML representation.
 
Method Summary
 void add(Locatable locatable)
          Adds the specified Locatable to this WorkLocation.
 int applyModifiers(int productivity)
          Returns the Production from this building applying the production bonus of the colony to the given productivity of the worker(s).
 boolean canAdd(Locatable locatable)
          Checks if the specified Locatable may be added to this WorkLocation.
 boolean canAdd(UnitType unitType)
          Checks if the specified UnitType may be added to this WorkLocation.
 boolean canAutoProduce()
          Returns true if this building can produce goods without workers.
 boolean canBeDamaged()
          Returns whether this building can be damaged
 boolean canBuildNext()
          Checks if this building can have a higher level.
 boolean contains(Locatable locatable)
          Checks if this Building contains the specified Locatable.
 void damage()
          Reduces this building to previous level (is set to UpgradesFrom attribute in BuildingType) or is destroyed if it's the first level
 void dispose()
          Disposes this building.
 Unit findStudent(Unit teacher)
           
 int getAdditionalProduction(Unit addUnit)
          Returns the maximum production of a given unit to be added to this building.
 int getAdditionalProductionNextTurn(Unit addUnit)
          Returns the additional production of new Unit at this building for next turn.
static java.util.Comparator<Building> getBuildingComparator()
           
 Colony getColony()
          Gets a pointer to the colony containing this building.
 UnitType getExpertUnitType()
          Returns the unit type being an expert in this Building.
 Unit getFirstUnit()
          Gets the first unit in this building.
 GoodsContainer getGoodsContainer()
          Gets this Location's GoodsContainer.
 int getGoodsInput()
          Returns the amount of goods being used to get the current production.
 int getGoodsInputNextTurn()
          Returns the amount of goods being used to get the current production at the next turn.
 GoodsType getGoodsInputType()
          Returns the type of goods this building needs for input.
 GoodsType getGoodsOutputType()
          Returns the type of goods this Building produces.
 Unit getLastUnit()
          Gets the last unit in this building.
 int getLevel()
          Returns the level of this building.
 int getMaximumGoodsInput()
          Returns the amount of goods needed to have a full production.
 int getMaximumProduction()
          Returns the maximum production of this building.
 int getMaxUnits()
          Gets the maximum number of units allowed in this Building.
 java.lang.String getNextName()
          Gets the name of the improved building of the same type.
 Player getOwner()
          Gets the owner of this Ownable.
 int getProduction()
          Returns the actual production of this building.
 int getProductionNextTurn()
          Returns the actual production of this building for next turn.
 int getProductionOf(GoodsType goodsType)
          Returns the production of the given type of goods.
 Tile getTile()
          Gets the Tile where this Building is located.
 BuildingType getType()
          Gets the type of this building.
 int getUnitCount()
          Gets the amount of units at this WorkLocation.
 java.util.Iterator<Unit> getUnitIterator()
          Gets an Iterator of every Unit directly located on this Building.
 java.util.List<Unit> getUnitList()
          Returns a list containing all the Units present at this Location.
 int getUnitProductivity(Unit prodUnit)
          Returns the maximum productivity of a unit working in this building.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 void newTurn()
          Prepares this Building for a new turn.
 void remove(Locatable locatable)
          Removes the specified Locatable from this WorkLocation.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 java.lang.String toString()
          Returns a string representation of the object.
 void upgrade()
          Upgrades this building to next level (is set to UpgradesTo attribute in BuildingType)
 
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

Building

public Building(Game game,
                Colony colony,
                BuildingType type)
Creates a new Building.

Parameters:
game - The Game this object belongs to.
colony - The colony in which this building is located.
type - The type of building.

Building

public Building(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 a problem was encountered during parsing.

Building

public Building(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.

Building

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

getTile

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

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

getLevel

public int getLevel()
Returns the level of this building.

Returns:
an int value

getNextName

public java.lang.String getNextName()
Gets the name of the improved building of the same type. An improved building is a building of a higher level.

Returns:
The name of the improved building or null if the improvement does not exist.

canBuildNext

public boolean canBuildNext()
Checks if this building can have a higher level.

Returns:
If this Building can have a higher level, that Adam Smith is present for manufactoring factory level buildings and that the Colony containing this Building has a sufficiently high population.

getColony

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

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

getType

public BuildingType getType()
Gets the type of this building.

Specified by:
getType in interface Typed<BuildingType>
Returns:
The type.

canBeDamaged

public boolean canBeDamaged()
Returns whether this building can be damaged

Returns:
true if can be damaged
See Also:
damage()

damage

public void damage()
Reduces this building to previous level (is set to UpgradesFrom attribute in BuildingType) or is destroyed if it's the first level


upgrade

public void upgrade()
Upgrades this building to next level (is set to UpgradesTo attribute in BuildingType)


getMaxUnits

public int getMaxUnits()
Gets the maximum number of units allowed in this Building.

Returns:
The number.

getUnitCount

public int getUnitCount()
Gets the amount of units at this WorkLocation.

Specified by:
getUnitCount in interface Location
Returns:
The amount of units at this WorkLocation.

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.

canAdd

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

Parameters:
unitType - the UnitTYpe.
Returns:
true if the UnitType may be added and false otherwise.

add

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

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

getExpertUnitType

public UnitType getExpertUnitType()
Returns the unit type being an expert in this Building.

Returns:
The UnitType.

remove

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

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

contains

public boolean contains(Locatable locatable)
Checks if this Building contains the specified Locatable.

Specified by:
contains in interface Location
Parameters:
locatable - The Locatable to test the presence of.
Returns:
  • >trueif the specified Locatable is in this Building and
  • false otherwise.

getFirstUnit

public Unit getFirstUnit()
Gets the first unit in this building.

Returns:
The Unit.

getLastUnit

public Unit getLastUnit()
Gets the last unit in this building.

Returns:
The Unit.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Gets an Iterator of every Unit directly located on this Building.

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

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.

getGoodsContainer

public GoodsContainer getGoodsContainer()
Gets this Location's GoodsContainer.

Specified by:
getGoodsContainer in interface Location
Returns:
null.

newTurn

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

Specified by:
newTurn in interface WorkLocation

findStudent

public Unit findStudent(Unit teacher)

getGoodsOutputType

public GoodsType getGoodsOutputType()
Returns the type of goods this Building produces.

Returns:
The type of goods this Building produces or -1 if there is no goods production by this Building.

getGoodsInputType

public GoodsType getGoodsInputType()
Returns the type of goods this building needs for input.

Returns:
The type of goods this Building requires as input in order to produce it's output.

getMaximumGoodsInput

public int getMaximumGoodsInput()
Returns the amount of goods needed to have a full production.

Returns:
The maximum level of goods needed in order to have the maximum possible production with the current configuration of workers and improvements. This is actually the input being used this turn, provided that the amount of goods in the Colony is either larger or the same as the value returned by this method.
See Also:
getGoodsInput(), getProduction()

getGoodsInput

public int getGoodsInput()
Returns the amount of goods being used to get the current production.

Returns:
The actual amount of goods that is being used to support the current production.
See Also:
getMaximumGoodsInput(), getProduction()

getGoodsInputNextTurn

public int getGoodsInputNextTurn()
Returns the amount of goods being used to get the current production at the next turn.

Returns:
The actual amount of goods that will be used to support the production at the next turn.
See Also:
getMaximumGoodsInput(), getProduction()

getProduction

public int getProduction()
Returns the actual production of this building.

Returns:
The amount of goods being produced by this Building the current turn. The type of goods being produced is given by getGoodsOutputType().
See Also:
getProductionNextTurn(), getMaximumProduction()

getProductionNextTurn

public int getProductionNextTurn()
Returns the actual production of this building for next turn.

Returns:
The production of this building the next turn.
See Also:
getProduction()

canAutoProduce

public boolean canAutoProduce()
Returns true if this building can produce goods without workers.

Returns:
a boolean value

getAdditionalProductionNextTurn

public int getAdditionalProductionNextTurn(Unit addUnit)
Returns the additional production of new Unit at this building for next turn.

Returns:
The production of this building the next turn.
See Also:
getProduction()

getProductionOf

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

Specified by:
getProductionOf in interface WorkLocation
Parameters:
goodsType - The type of goods to get the production for.
Returns:
the production og the given goods this turn. This method will return the same as getProduction() if the given type of goods is the same as getGoodsOutputType() and 0 otherwise.

getUnitProductivity

public int getUnitProductivity(Unit prodUnit)
Returns the maximum productivity of a unit working in this building.

Returns:
The maximum returns from this unit if in this Building, assuming enough "input goods".

getMaximumProduction

public int getMaximumProduction()
Returns the maximum production of this building.

Returns:
The production of this building, with the current amount of workers, when there is enough "input goods".

getAdditionalProduction

public int getAdditionalProduction(Unit addUnit)
Returns the maximum production of a given unit to be added to this building.

Returns:
If unit can be added, will return the maximum production potential if it cannot be added, will return 0.

applyModifiers

public int applyModifiers(int productivity)
Returns the Production from this building applying the production bonus of the colony to the given productivity of the worker(s).

Parameters:
productivity - From getProductivity(net.sf.freecol.common.model.Unit...)
Returns:
Production based on Productivity

getBuildingComparator

public static java.util.Comparator<Building> getBuildingComparator()

dispose

public void dispose()
Disposes this building. All units that currently has this Building as it's location will be disposed.

Overrides:
dispose in class FreeColGameObject

getXMLElementTagName

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

Returns:
the tag name.

toString

public java.lang.String toString()
Description copied from class: FreeColGameObject
Returns a string representation of the object.

Overrides:
toString in class FreeColGameObject
Returns:
The String