net.sf.freecol.common.model
Class Settlement

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.Settlement
All Implemented Interfaces:
Location, Named, Ownable
Direct Known Subclasses:
Colony, IndianSettlement

public abstract class Settlement
extends FreeColGameObject
implements Location, Named, Ownable

The super class of all settlements on the map (that is colonies and indian settlements).


Nested Class Summary
static class Settlement.SettlementType
           
 
Field Summary
static int FOOD_CONSUMPTION
           
static int RADIUS
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Settlement(Game game, org.w3c.dom.Element e)
          Initiates a new Settlement from an Element.
Settlement(Game game, Player owner, java.lang.String name, Tile tile)
          Creates a new Settlement.
Settlement(Game game, java.lang.String id)
          Initiates a new Settlement with the given ID.
Settlement(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Settlement from an Element.
 
Method Summary
abstract  void add(Locatable locatable)
          Adds a Locatable to this Location.
 void addGoods(AbstractGoods goods)
           
 void addGoods(GoodsType type, int amount)
          Describe addGoods method here.
abstract  boolean canAdd(Locatable locatable)
          Checks whether or not the specified locatable may be added to this Location.
 boolean canBuildEquipment(EquipmentType equipmentType)
          Return true if this Colony could build at least one item of the given EquipmentType.
 void claimTile(Tile tile)
          Claim a single Tile for this Settlement.
abstract  boolean contains(Locatable locatable)
          Checks if this Location contains the specified Locatable.
 void dispose()
          Dispose of this Settlement.
 java.util.List<Goods> getCompactGoods()
          Gets an List with every Goods in this Colony.
abstract  Unit getDefendingUnit(Unit attacker)
          Gets the Unit that is currently defending this Settlement.
 FeatureContainer getFeatureContainer()
          Describe getFeatureContainer method here.
 int getFoodConsumption()
          Gives the food needed to keep all units alive in this Settlement.
 int getFoodConsumptionByType(GoodsType type)
          Gets food consumption by type
 int getFoodCount()
          Returns the total amount of food present.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods.
 int getGoodsCount(GoodsType type)
          Gets the amount of one type of Goods at this Settlement.
 java.util.Iterator<Goods> getGoodsIterator()
          Gets an Iterator of every Goods in this GoodsContainer.
 int getLineOfSight()
          Gets this colony's line of sight.
 java.lang.String getName()
          Gets the name of this Settlement.
 Player getOwner()
          Gets the owner of this Settlement.
abstract  int getProductionOf(GoodsType goodsType)
          Returns the production of the given type of goods.
 int getRadius()
          Gets the radius of what the Settlement considers as it's own land.
 Tile getTile()
          Gets the Tile where this Settlement is located.
 Tile getTile(int x, int y)
          Gets a Tile from the neighbourhood of this Colony.
abstract  int getUnitCount()
          Returns the number of units in this settlement.
 boolean isCapital()
          Returns true if this is the Nation's capital.
abstract  void newTurn()
           
 void placeSettlement()
          Put a prepared settlement onto the map.
abstract  void remove(Locatable locatable)
          Removes a Locatable from this Location.
 void removeGoods(AbstractGoods goods)
          Removes the given Goods from the Settlement.
 void removeGoods(GoodsType type)
          Removes all Goods of the given type from the Settlement.
 void removeGoods(GoodsType type, int amount)
          Removes a specified amount of a type of Goods from this Settlement.
 void setCapital(boolean isCapital)
          Sets the capital value.
 void setName(java.lang.String newName)
          Sets the name of this Settlement.
 void setOwner(Player owner)
          Sets the owner of this Settlement.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, getXMLElementTagName, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toString, 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
getColony, getId, getUnitIterator, getUnitList
 

Field Detail

RADIUS

public static final int RADIUS
See Also:
Constant Field Values

FOOD_CONSUMPTION

public static final int FOOD_CONSUMPTION
See Also:
Constant Field Values
Constructor Detail

Settlement

public Settlement(Game game,
                  Player owner,
                  java.lang.String name,
                  Tile tile)
Creates a new Settlement.

Parameters:
game - The Game in which this object belong.
owner - The owner of this Settlement.
name - The name for this Settlement.
tile - The location of the Settlement.

Settlement

public Settlement(Game game,
                  javax.xml.stream.XMLStreamReader in)
           throws javax.xml.stream.XMLStreamException
Initiates a new Settlement from an Element.

Parameters:
game - The Game in which this object belong.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

Settlement

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

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

Settlement

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

getName

public java.lang.String getName()
Gets the name of this Settlement.

Specified by:
getName in interface Named
Returns:
The name as a String.

setName

public void setName(java.lang.String newName)
Sets the name of this Settlement.

Parameters:
newName - The new name.

isCapital

public boolean isCapital()
Returns true if this is the Nation's capital.

Returns:
true if this is the Nation's capital.

setCapital

public void setCapital(boolean isCapital)
Sets the capital value.

Parameters:
isCapital - a boolean value

getFeatureContainer

public FeatureContainer getFeatureContainer()
Describe getFeatureContainer method here.

Returns:
a FeatureContainer value

getLineOfSight

public int getLineOfSight()
Gets this colony's line of sight.

Returns:
The line of sight offered by this Colony.
See Also:
Player.canSee(Tile)

getDefendingUnit

public abstract Unit getDefendingUnit(Unit attacker)
Gets the Unit that is currently defending this Settlement.

Parameters:
attacker - The target that would be attacking this Settlement.
Returns:
The Unit that has been chosen to defend this Settlement.

getTile

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

Specified by:
getTile in interface Location
Returns:
The Tile where this Settlement is located.

getTile

public Tile getTile(int x,
                    int y)
Gets a Tile from the neighbourhood of this Colony.

Parameters:
x - The x-coordinate of the Tile.
y - The y-coordinate of the Tile.
Returns:
The Tile.

claimTile

public void claimTile(Tile tile)
Claim a single Tile for this Settlement.

Parameters:
tile - a Tile value

placeSettlement

public void placeSettlement()
Put a prepared settlement onto the map.


getOwner

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

Specified by:
getOwner in interface Ownable
Returns:
The owner of this Settlement.
See Also:
setOwner(net.sf.freecol.common.model.Player)

setOwner

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

Specified by:
setOwner in interface Ownable
Parameters:
owner - The Player that shall own this Settlement.
See Also:
getOwner()

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.

getGoodsIterator

public java.util.Iterator<Goods> getGoodsIterator()
Gets an Iterator of every Goods in this GoodsContainer. Each Goods have a maximum amount of 100.

Returns:
The Iterator.

getCompactGoods

public java.util.List<Goods> getCompactGoods()
Gets an List with every Goods in this Colony. There is only one Goods for each type of goods.

Returns:
The Iterator.

add

public abstract void add(Locatable locatable)
Adds a Locatable to this Location.

Specified by:
add in interface Location
Parameters:
locatable - The Locatable to add to this Location.

remove

public abstract void remove(Locatable locatable)
Removes a Locatable from this Location.

Specified by:
remove in interface Location
Parameters:
locatable - The Locatable to remove from this Location.

canAdd

public abstract boolean canAdd(Locatable locatable)
Description copied from interface: Location
Checks whether or not the specified locatable may be added to this Location.

Specified by:
canAdd in interface Location
Parameters:
locatable - The Locatable to add.
Returns:
The result.

getUnitCount

public abstract int getUnitCount()
Returns the number of units in this settlement.

Specified by:
getUnitCount in interface Location
Returns:
The number of units in this settlement.

contains

public abstract boolean contains(Locatable locatable)
Description copied from interface: Location
Checks if this Location contains the specified Locatable.

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

dispose

public void dispose()
Dispose of this Settlement.

Overrides:
dispose in class FreeColGameObject

getRadius

public int getRadius()
Gets the radius of what the Settlement considers as it's own land.

Returns:
Settlement radius

newTurn

public abstract void newTurn()

removeGoods

public void removeGoods(GoodsType type,
                        int amount)
Removes a specified amount of a type of Goods from this Settlement.

Parameters:
type - The type of Goods to remove from this settlement.
amount - The amount of Goods to remove from this settlement.

removeGoods

public void removeGoods(AbstractGoods goods)
Removes the given Goods from the Settlement.

Parameters:
goods - a Goods value

removeGoods

public void removeGoods(GoodsType type)
Removes all Goods of the given type from the Settlement.

Parameters:
type - a GoodsType value

addGoods

public void addGoods(GoodsType type,
                     int amount)
Describe addGoods method here.

Parameters:
type - a GoodsType value
amount - an int value

addGoods

public void addGoods(AbstractGoods goods)

getGoodsCount

public int getGoodsCount(GoodsType type)
Gets the amount of one type of Goods at this Settlement.

Parameters:
type - The type of goods to look for.
Returns:
The amount of this type of Goods at this Location.

getProductionOf

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

Parameters:
goodsType - The type of goods to get the production for.
Returns:
The production of the given type of goods the current turn by the Settlement

getFoodConsumption

public int getFoodConsumption()
Gives the food needed to keep all units alive in this Settlement.

Returns:
The amount of food eaten in this colony each this turn.

getFoodConsumptionByType

public int getFoodConsumptionByType(GoodsType type)
Gets food consumption by type


getFoodCount

public int getFoodCount()
Returns the total amount of food present.

Returns:
an int value

canBuildEquipment

public boolean canBuildEquipment(EquipmentType equipmentType)
Return true if this Colony could build at least one item of the given EquipmentType.

Parameters:
equipmentType - an EquipmentType value
Returns:
a boolean value