net.sf.freecol.common.model
Class Building

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColGameObject
      extended by net.sf.freecol.common.model.Building
All Implemented Interfaces:
Location, Nameable, Ownable, WorkLocation

public final class Building
extends FreeColGameObject
implements WorkLocation, Ownable, Nameable

Represents a building in a colony.

Each Building has a type and a level. The levels are NOT_BUILT, HOUSE, SHOP and FACTORY. The name of a Building depends on both the type and the level:

Type STOCKADE
Level NOT_BUILT: null
Level HOUSE: "Stockade"
Level SHOP: "Fort"
Level FACTORY: "Fortress"


Field Summary
static int ARMORY
          The type of a building.
static int BLACKSMITH
          The type of a building.
static int CARPENTER
          The type of a building.
static int CHURCH
          The type of a building.
static java.lang.String COPYRIGHT
           
static int CUSTOM_HOUSE
          The type of a building.
static int DISTILLER
          The type of a building.
static int DOCK
          The type of a building.
static int FACTORY
          The level of a building.
static int FUR_TRADER
          The type of a building.
static int HOUSE
          The level of a building.
static java.lang.String LICENSE
           
static int MAX_LEVEL
          The maximum level.
static int NONE
          The type of a building.
static int NOT_BUILT
          The level of a building.
static int NUMBER_OF_TYPES
          The maximum number of building types.
static int PRINTING_PRESS
          The type of a building.
static java.lang.String REVISION
           
static int SCHOOLHOUSE
          The type of a building.
static int SHOP
          The level of a building.
static int STABLES
          The type of a building.
static int STOCKADE
          The type of a building.
static int TOBACCONIST
          The type of a building.
static int TOWN_HALL
          The type of a building.
static int WAREHOUSE
          The type of a building.
static int WEAVER
          The type of a building.
 
Constructor Summary
Building(Game game, Colony colony, int type, int level)
          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 calculateOutput(int goodsInput)
          Calculates and returns the output of this building from the input.
 boolean canAdd(Locatable locatable)
          Checks if the specified Locatable may be added to this WorkLocation.
 boolean canBuildNext()
          Checks if this building can have a higher level.
 boolean contains(Locatable locatable)
          Checks if this Building contains the specified Locatable.
 void dispose()
          Disposes this building.
 Colony getColony()
          Gets a pointer to the colony containing this building.
 int getExpertUnitType()
          Returns the unit type being an expert in this Building.
static int getExpertUnitType(int type)
          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 beeing used to get the current production.
 int getGoodsInputType()
          Returns the type of goods this building needs for input.
static int getGoodsInputType(int type)
          Returns the type of goods this building needs for input.
 int getGoodsOutputType()
          Returns the type of goods this Building produces.
static int getGoodsOutputType(int type)
          Returns the type of goods this Building produces.
 Unit getLastUnit()
          Gets the last unit in this building.
 int getLevel()
          Gets the level of the building.
 java.lang.String getLocationName()
          Returns the name of this location.
 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 getName()
          Gets the name of a building.
 int getNextHammers()
          Gets the number of hammers required for the improved building of the same type.
 java.lang.String getNextName()
          Gets the name of the improved building of the same type.
 int getNextPop()
          Gets the colony population required for the improved building of the same type.
 int getNextTools()
          Gets the number of tools required for 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(int goodsType)
          Returns the production of the given type of goods.
 Tile getTile()
          Gets the Tile where this Building is located.
 int 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.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean isBuilt()
          Checks if the building has been built.
 void newTurn()
          Prepares this Building for a new turn.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void remove(Locatable locatable)
          Removes the specified Locatable from this WorkLocation.
 void setLevel(int level)
          Sets the level of the building.
 void setName(java.lang.String newName)
          Set the Name value.
 void setOwner(Player p)
          Sets the owner of this Ownable.
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.FreeColGameObject
addModelMessage, addModelMessage, equals, equals, getGame, getGameOptions, getID, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromXML, readFromXMLElement, setFakeID, setGame, setID, toArrayElement, toArrayElement, toArrayElement, toArrayElement, toSavedXML, toString, toXML, toXML, toXML, toXMLElement, toXMLElement, updateID
 
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

COPYRIGHT

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

LICENSE

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

REVISION

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

MAX_LEVEL

public static final int MAX_LEVEL
The maximum level.

See Also:
Constant Field Values

NONE

public static final int NONE
The type of a building.

See Also:
Constant Field Values

TOWN_HALL

public static final int TOWN_HALL
The type of a building.

See Also:
Constant Field Values

CARPENTER

public static final int CARPENTER
The type of a building.

See Also:
Constant Field Values

BLACKSMITH

public static final int BLACKSMITH
The type of a building.

See Also:
Constant Field Values

TOBACCONIST

public static final int TOBACCONIST
The type of a building.

See Also:
Constant Field Values

WEAVER

public static final int WEAVER
The type of a building.

See Also:
Constant Field Values

DISTILLER

public static final int DISTILLER
The type of a building.

See Also:
Constant Field Values

FUR_TRADER

public static final int FUR_TRADER
The type of a building.

See Also:
Constant Field Values

SCHOOLHOUSE

public static final int SCHOOLHOUSE
The type of a building.

See Also:
Constant Field Values

ARMORY

public static final int ARMORY
The type of a building.

See Also:
Constant Field Values

CHURCH

public static final int CHURCH
The type of a building.

See Also:
Constant Field Values

STOCKADE

public static final int STOCKADE
The type of a building.

See Also:
Constant Field Values

WAREHOUSE

public static final int WAREHOUSE
The type of a building.

See Also:
Constant Field Values

STABLES

public static final int STABLES
The type of a building.

See Also:
Constant Field Values

DOCK

public static final int DOCK
The type of a building.

See Also:
Constant Field Values

PRINTING_PRESS

public static final int PRINTING_PRESS
The type of a building.

See Also:
Constant Field Values

CUSTOM_HOUSE

public static final int CUSTOM_HOUSE
The type of a building.

See Also:
Constant Field Values

NUMBER_OF_TYPES

public static final int NUMBER_OF_TYPES
The maximum number of building types.


NOT_BUILT

public static final int NOT_BUILT
The level of a building.

See Also:
Constant Field Values

HOUSE

public static final int HOUSE
The level of a building.

See Also:
Constant Field Values

SHOP

public static final int SHOP
The level of a building.

See Also:
Constant Field Values

FACTORY

public static final int FACTORY
The level of a building.

See Also:
Constant Field Values
Constructor Detail

Building

public Building(Game game,
                Colony colony,
                int type,
                int level)
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.
level - The level of the building: NOT_BUILT, HOUSE, SHOP or FACTORY.

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 FreeColGameObject.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()
Gets the level of the building. One of NOT_BUILT, HOUSE, SHOP and FACTORY.

Returns:
The current level.

setLevel

public void setLevel(int level)
Sets the level of the building.

Parameters:
level - The new level of the building. This should be one of NOT_BUILT, HOUSE, SHOP and FACTORY.

getName

public java.lang.String getName()
Gets the name of a building.

Specified by:
getName in interface Nameable
Returns:
The name of the Building or null if the building has not been built.

setName

public void setName(java.lang.String newName)
Set the Name value.

Specified by:
setName in interface Nameable
Parameters:
newName - The new Name value.

getLocationName

public java.lang.String getLocationName()
Returns the name of this location.

Specified by:
getLocationName in interface Location
Returns:
The name of this location.

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.

getNextHammers

public int getNextHammers()
Gets the number of hammers required for the improved building of the same type.

Returns:
The number of hammers required for the improved building of the same type, or -1 if the building does not exist.

getNextTools

public int getNextTools()
Gets the number of tools required for the improved building of the same type.

Returns:
The number of tools required for the improved building of the same type, or -1 if the building does not exist.

getNextPop

public int getNextPop()
Gets the colony population required for the improved building of the same type.

Returns:
The colony population required for the improved building of the same type, or -1 if the building 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.

isBuilt

public boolean isBuilt()
Checks if the building has been built.

Returns:
The result.

getColony

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

Specified by:
getColony in interface WorkLocation
Returns:
The Colony.

getType

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

Returns:
The type.

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.

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 int getExpertUnitType()
Returns the unit type being an expert in this Building.

Returns:
The unit type.
See Also:
Unit.getExpertWorkType(), ColonyTile.getExpertForProducing(int)

getExpertUnitType

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

Parameters:
type - The type of building.
Returns:
The unit type.
See Also:
Unit.getExpertWorkType(), ColonyTile.getExpertForProducing(int)

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. The list is a cloned list, so no risk.

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.


getGoodsOutputType

public int 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.

getGoodsOutputType

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

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

getGoodsInputType

public int 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.

getGoodsInputType

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

Parameters:
type - The type of building.
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 beeing 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()

calculateOutput

public int calculateOutput(int goodsInput)
Calculates and returns the output of this building from the input.

Returns:
The production of this building from the input.
See Also:
getProduction, getProductionNextTurn

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()

getProductionOf

public int getProductionOf(int 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.

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

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

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.

Specified by:
readFromXMLImpl in class FreeColGameObject
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:
the tag name.