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.UnitLocation
              extended by net.sf.freecol.common.model.GoodsLocation
                  extended by net.sf.freecol.common.model.Settlement
All Implemented Interfaces:
Location, Named, Ownable
Direct Known Subclasses:
Colony, IndianSettlement

public abstract class Settlement
extends GoodsLocation
implements Named, Ownable

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


Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
private  FeatureContainer featureContainer
          Contains the abilities and modifiers of this Settlement.
static int FOOD_PER_COLONIST
           
private static java.util.logging.Logger logger
           
private  java.lang.String name
          The name of the Settlement.
private  java.util.List<Tile> ownedTiles
          The tiles this settlement owns.
protected  Player owner
          The Player owning this Settlement.
protected  Tile tile
          The Tile where this Settlement is located.
private  SettlementType type
          Describe type 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 Settlement()
          Empty constructor needed for Colony -> ServerColony.
  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
 void addTile(Tile tile)
          Adds a tile to this settlement.
 boolean canBuildEquipment(EquipmentType equipmentType)
          Return true if this Colony could build at least one item of the given EquipmentType.
 boolean canProvideEquipment(EquipmentType equipmentType)
          Determines if this settlement can build the given type of equipment.
 boolean canProvideEquipment(java.util.List<EquipmentType> equipment)
          Return true if this Settlement could provide at least one item of all the given EquipmentTypes.
 void changeOwner(Player newOwner)
          Change the owner of this Settlement.
 java.util.List<FreeColGameObject> disposeList()
          Dispose of this settlement.
 int getConsumptionOf(GoodsType goodsType)
          Returns the number of goods of a given type used by the settlement each turn.
 int getConsumptionOf(java.util.List<GoodsType> goodsTypes)
          Returns the number of goods of all given types used by the settlement each turn.
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.
abstract  java.lang.String getImageKey()
          Gets an image key for this settlement.
 int getLineOfSight()
          Gets this colony's line of sight.
 java.util.Set<Modifier> getModifierSet(java.lang.String key)
           
 java.lang.String getName()
          Gets the name of this Settlement.
abstract  java.lang.String getNameFor(Player player)
          Gets the name of this Settlement for a particular player.
 java.lang.String getNameKey()
          Gets the name of this Named.
 java.util.List<Tile> getOwnedTiles()
          Get the tiles this settlement owns.
 Player getOwner()
          Gets the owner of this Settlement.
 int getPlunder(Unit attacker, java.util.Random random)
          Gets an amount of plunder when this settlement is taken.
abstract  RandomRange getPlunderRange(Unit attacker)
          Gets the range of gold plunderable when this settlement is captured.
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.
 Settlement getSettlement()
          Returns this Settlement.
abstract  int getSoL()
          Gets the current Sons of Liberty in this settlement.
 Tile getTile()
          Gets the Tile where this Settlement is located.
 SettlementType getType()
          Get the Type value.
 boolean isCapital()
          Returns true if this is the Nation's capital.
 boolean isConnected()
          Returns whether this settlement is connected by water to Europe.
 void placeSettlement(boolean maximal)
          Put a prepared settlement onto the map.
abstract  boolean propagateAlarm(Player player, int addToAlarm)
          Propagates a global change in tension down to a settlement.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
 void removeTile(Tile tile)
          Removes a tile from this settlement.
 void setCapital(boolean isCapital)
          Sets the capital value.
protected  void setFeatureContainer(FeatureContainer container)
          Describe setFeatureContainer method here.
 void setName(java.lang.String newName)
          Sets the name of this Settlement.
 void setOwner(Player player)
          Sets the owner of this Settlement.
 void setType(SettlementType newType)
          Set the Type value.
protected  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.GoodsLocation
add, addGoods, addGoods, contains, dispose, getCompactGoods, getGoodsCapacity, getGoodsContainer, getGoodsCount, getGoodsIterator, getNoAddReason, getWarehouseCapacity, readChild, remove, removeGoods, removeGoods, removeGoods, setGoodsContainer, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, getColony, getLocationName, getLocationNameFor, getSpaceTaken, getUnitCapacity, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, readChildren
 
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

logger

private static final java.util.logging.Logger logger

FOOD_PER_COLONIST

public static final int FOOD_PER_COLONIST
See Also:
Constant Field Values

owner

protected Player owner
The Player owning this Settlement.


name

private java.lang.String name
The name of the Settlement.


tile

protected Tile tile
The Tile where this Settlement is located.


featureContainer

private FeatureContainer featureContainer
Contains the abilities and modifiers of this Settlement.


ownedTiles

private java.util.List<Tile> ownedTiles
The tiles this settlement owns.


type

private SettlementType type
Describe type here.

Constructor Detail

Settlement

protected Settlement()
Empty constructor needed for Colony -> ServerColony.


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

getType

public final SettlementType getType()
Get the Type value.

Returns:
a SettlementType value

setType

public final void setType(SettlementType newType)
Set the Type value.

Parameters:
newType - The new Type value.

getModifierSet

public java.util.Set<Modifier> getModifierSet(java.lang.String key)

getNameKey

public java.lang.String getNameKey()
Description copied from interface: Named
Gets the name of this Named.

Specified by:
getNameKey in interface Named
Returns:
The name of the Named.

getName

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

Returns:
The name as a String.

getNameFor

public abstract java.lang.String getNameFor(Player player)
Gets the name of this Settlement for a particular player.

Parameters:
player - A Player to return the name for.
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.

getImageKey

public abstract java.lang.String getImageKey()
Gets an image key for this settlement.


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

setFeatureContainer

protected void setFeatureContainer(FeatureContainer container)
Describe setFeatureContainer method here.

Parameters:
container - 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 unit be attacking this Settlement.
Returns:
The Unit that has been chosen to defend this Settlement.

getPlunderRange

public abstract RandomRange getPlunderRange(Unit attacker)
Gets the range of gold plunderable when this settlement is captured.

Parameters:
attacker - The Unit that takes the settlement.
Returns:
A RandomRange encapsulating the range of plunder available.

getPlunder

public int getPlunder(Unit attacker,
                      java.util.Random random)
Gets an amount of plunder when this settlement is taken.

Parameters:
attacker - The Unit that takes the settlement.
random - A pseudo-random number source.
Returns:
An amount of gold plundered.

getTile

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

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

getSettlement

public Settlement getSettlement()
Returns this Settlement.

Specified by:
getSettlement in interface Location
Overrides:
getSettlement in class UnitLocation
Returns:
this Settlement

placeSettlement

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

Parameters:
maximal - If true, also claim all the tiles possible.

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 player)
Sets the owner of this Settlement.

Specified by:
setOwner in interface Ownable
Parameters:
player - The new owner of this Settlement.

changeOwner

public void changeOwner(Player newOwner)
Change the owner of this Settlement.

Parameters:
newOwner - The Player that shall own this Settlement.
See Also:
getOwner()

getOwnedTiles

public java.util.List<Tile> getOwnedTiles()
Get the tiles this settlement owns.

Returns:
A list of tiles.

addTile

public void addTile(Tile tile)
Adds a tile to this settlement.

Parameters:
tile - The Tile to add.

removeTile

public void removeTile(Tile tile)
Removes a tile from this settlement.

Parameters:
tile - The Tile to remove.

disposeList

public java.util.List<FreeColGameObject> disposeList()
Dispose of this settlement.

Overrides:
disposeList in class GoodsLocation
Returns:
A list of disposed objects.

getRadius

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

Returns:
Settlement radius

isConnected

public boolean isConnected()
Returns whether this settlement is connected by water to Europe.

Returns:
true if this Settlement is connected to Europe.

getSoL

public abstract int getSoL()
Gets the current Sons of Liberty in this settlement.


propagateAlarm

public abstract boolean propagateAlarm(Player player,
                                       int addToAlarm)
Propagates a global change in tension down to a settlement. Only apply the change if the settlement is aware of the player causing alarm.

Parameters:
player - The Player towards whom the alarm is felt.
addToAlarm - The amount to add to the current alarm level.
Returns:
True if the settlement alarm level changes as a result of this change.

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

getConsumptionOf

public int getConsumptionOf(GoodsType goodsType)
Returns the number of goods of a given type used by the settlement each turn.

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

getConsumptionOf

public int getConsumptionOf(java.util.List<GoodsType> goodsTypes)
Returns the number of goods of all given types used by the settlement each turn.

Parameters:
goodsTypes - GoodsType values
Returns:
an int value

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.

canBuildEquipment

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

Parameters:
equipmentType - The EquipmentType to build.
Returns:
True if the equipment can be built.

canProvideEquipment

public boolean canProvideEquipment(EquipmentType equipmentType)
Determines if this settlement can build the given type of equipment. Unlike canBuildEquipment, this takes goods "reserved" for other purposes into account (e.g. breeding).

Parameters:
equipmentType - an EquipmentType value
Returns:
True if the settlement can provide the equipment.
See Also:
canBuildEquipment(EquipmentType equipmentType)

canProvideEquipment

public boolean canProvideEquipment(java.util.List<EquipmentType> equipment)
Return true if this Settlement could provide at least one item of all the given EquipmentTypes. This is designed specifically to mesh with getRoleEquipment().

Parameters:
equipment - A list of EquipmentTypes to build.
Returns:
True if the settlement can provide all the equipment.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

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

readAttributes

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