net.sf.freecol.common.model
Class Colony

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
              extended by net.sf.freecol.common.model.Colony
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, Location, Nameable, Named, Ownable

public final class Colony
extends Settlement
implements Nameable, java.beans.PropertyChangeListener

Represents a colony. A colony contains Buildings and ColonyTiles. The latter represents the tiles around the Colony where working is possible.


Nested Class Summary
static class Colony.ColonyChangeEvent
           
static class Colony.NoBuildReason
           
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.Settlement
Settlement.SettlementType
 
Field Summary
static int FOOD_PER_COLONIST
           
static Ability HAS_PORT
           
static int LIBERTY_PER_REBEL
           
static FreeColGameObjectType SOL_MODIFIER_SOURCE
           
 
Fields inherited from class net.sf.freecol.common.model.Settlement
FOOD_CONSUMPTION, RADIUS
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Colony(Game game, org.w3c.dom.Element e)
          Initiates a new Colony from an XML representation.
Colony(Game game, Player owner, java.lang.String name, Tile tile)
          Creates a new Colony.
Colony(Game game, java.lang.String id)
          Initiates a new Colony with the given ID.
Colony(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Colony from an XML representation.
 
Method Summary
 void add(Locatable locatable)
          Adds a Locatable to this Location.
 void addBuilding(Building building)
          Add a Building to this Colony.
 void addGoods(AbstractGoods goods)
           
 void addGoods(GoodsType type, int amount)
          Describe addGoods method here.
 void addLiberty(int amount)
          Adds to the liberty points of the colony.
 int calculateMembership(int units)
          Returns the SoL membership of the colony based on the liberty value and the number of colonists given.
 boolean canAdd(Locatable locatable)
          Checks whether or not the specified locatable may be added to this Location.
 boolean canBombardEnemyShip()
          Verify if colony has the conditions to bombard an enemy ship adjacent to it
 boolean canBreed(GoodsType goodsType)
          Returns true if this Colony can breed the given type of Goods.
 boolean canBuild()
          Describe canBuild method here.
 boolean canBuild(BuildableType buildableType)
          Returns true if this Colony can build the given BuildableType.
 boolean canPayToFinishBuilding()
          Check if the owner can buy the remaining hammers and tools for the Building that is currently being built.
 boolean canPayToFinishBuilding(BuildableType buildableType)
          Check if the owner can buy the remaining hammers and tools for the Building given.
 boolean canReducePopulation()
          Returns true if the colony can reduce its population voluntarily.
 boolean canTrain(Unit unit)
          Returns true if this colony has a schoolhouse and the unit type is a skilled unit type with a skill level not exceeding the level of the schoolhouse.
 boolean canTrain(UnitType unitType)
          Returns true if this colony has a schoolhouse and the unit type is a skilled unit type with a skill level not exceeding the level of the schoolhouse.
 ModelMessage checkForGovMgtChangeMessage()
           
 boolean contains(Locatable locatable)
          Checks if this Location contains the specified Locatable.
 Building createBuilding(BuildingType buildingType)
          Ask the server to create a building for us.
 Building createFreeBuilding(BuildingType buildingType)
          Ask the server to create a free building for us.
 void dispose()
          Disposes this Colony.
 Unit findTeacher(Unit unit)
           
 java.util.List<UnitType> getBuildableUnits()
          Returns a List with every unit type this colony may build.
 Building getBuilding(BuildingType type)
          Gets a Building of the specified type.
 Building getBuildingFor(Unit unit)
          Return the Building best suited for the given Unit.
 Building getBuildingForConsuming(GoodsType goodsType)
          Find a building for consuming the given type of goods.
 Building getBuildingForProducing(GoodsType goodsType)
          Find a building for producing the given type of goods.
 java.util.List<Building> getBuildings()
          Gets a List of every Building in this Colony.
 java.util.List<Building> getBuildingsForConsuming(GoodsType goodsType)
          Collect the buildings for consuming the given type of goods.
 java.util.List<Building> getBuildingsForProducing(GoodsType goodsType)
          Collect the buildings for producing the given type of goods.
 Building getBuildingWithAbility(java.lang.String ability)
          Returns a Building with the given Ability, or null, if none exists.
 java.util.List<BuildableType> getBuildQueue()
          Get the BuildQueue value.
 Colony getColony()
          Returns just this Colony itself.
 ColonyTile getColonyTile(int x, int y)
          Gets the specified ColonyTile.
 ColonyTile getColonyTile(Tile t)
          Returns the ColonyTile matching the given Tile.
 java.util.List<ColonyTile> getColonyTiles()
          Gets a List of every ColonyTile in this Colony.
 int getConsumption(GoodsType goodsType)
          Returns the number of goods of a given type used by the colony each turn.
 BuildableType getCurrentlyBuilding()
          Returns the type of building currently being built.
 Unit getDefendingUnit(Unit attacker)
          Gets the Unit that is currently defending this Colony.
 ExportData getExportData(GoodsType goodsType)
          Describe getExportData method here.
 FeatureContainer getFeatureContainer()
          Describe getFeatureContainer method here.
 int getFoodProduction()
          Gets the combined production of all food types.
 int getImmigration()
          Describe getImmigration method here.
 int getLiberty()
          Describe getLiberty method here.
 int getMembers()
          Return the number of sons of liberty
 java.util.Set<Modifier> getModifierSet(java.lang.String id)
          Get the Modifier value.
 Colony.NoBuildReason getNoBuildReason(BuildableType buildableType)
          Return the reason why the give BuildableType can not be built.
 int getPriceForBuilding()
          Returns the price for the remaining hammers and tools for the Building that is currently being built.
 int getPriceForBuilding(BuildableType buildableType)
          Returns the price for the remaining hammers and tools for the Building given.
 int getProductionBonus()
          Returns the production bonus, if any, of the colony.
 Modifier getProductionModifier(GoodsType goodsType)
           
 int getProductionNetOf(GoodsType goodsType)
          Returns how much of a Good will be produced by this colony this turn, taking into account how much is consumed - by workers, horses, etc.
 int getProductionNextTurn(GoodsType goodsType)
          Returns how much of a Good will be produced by this colony this turn
 int getProductionOf(GoodsType goodsType)
          Returns the production of the given type of goods.
 Unit getRandomUnit()
          Returns a random unit from this colony.
 int getSoL()
          Returns the current SoL membership of the colony.
 Building getStockade()
          Returns the stockade building
 java.util.List<Unit> getTeachers()
           
 int getTory()
          Returns the Tory membership of the colony.
 int getTurnsToComplete(BuildableType buildable)
          Returns how many turns it would take to build the given BuildableType.
 int getUnitCount()
          Gets the amount of Units at this Location.
 java.util.Iterator<Unit> getUnitIterator()
          Gets a Iterator of every Unit directly located on this Location.
 java.util.List<Unit> getUnitList()
          Returns a list containing all the Units present at this Location.
 ColonyTile getVacantColonyTileFor(Unit unit, boolean allowClaim, GoodsType... goodsTypes)
          Returns a vacant ColonyTile where the given unit produces the maximum output of the given goodsType.
 WorkLocation getVacantWorkLocationFor(Unit unit)
          Gets a vacant WorkLocation for the given Unit.
 Building getWarehouse()
           
 int getWarehouseCapacity()
          Returns the capacity of this colony's warehouse.
 java.util.Collection<java.lang.String> getWarnings(GoodsType goodsType, int amount, int production)
          determine if there is a problem with the production of the specified good
 java.util.List<WorkLocation> getWorkLocations()
          Gets a List of every WorkLocation in this Colony.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 int governmentChange(int units)
          Returns 1, 0, or -1 to indicate that government would improve, remain the same, or deteriorate if the colony had the given population.
 boolean hasAbility(java.lang.String id)
          Returns true if the Colony, or its owner has the ability identified by id.
 boolean hasAbility(java.lang.String id, FreeColGameObjectType type)
          Returns true if the Colony, or its owner has the ability identified by id.
 boolean hasStockade()
          Returns true when colony has a stockade
 void incrementImmigration(int amount)
           
 void incrementLiberty(int amount)
           
 boolean isConnected()
          Returns whether this colony is connected by water to Europe.
 boolean isLandLocked()
          Returns whether this colony is landlocked, or has access to water.
 boolean isUndead()
          Returns whether this colony has undead units.
 void newTurn()
          Prepares this Colony for a new turn.
 void payForBuilding()
          Buys the remaining hammers and tools for the Building that is currently being built.
 void propertyChange(java.beans.PropertyChangeEvent event)
           
 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 setBuildQueue(java.util.List<BuildableType> newBuildQueue)
          Set the BuildQueue value.
 void setCurrentlyBuilding(BuildableType buildable)
          Sets the type of building to be built.
 void setExportData(ExportData newExportData)
          Describe setExportData method here.
 void setOwner(Player owner)
          Sets the owner of this Colony, including all units within, and change main tile nation ownership.
 void setUnitCount(int unitCount)
          Sets the number of units inside the colony, used in enemy colonies
 java.lang.String toString()
          Gets a string representation of the Colony.
 void updatePopulation(int difference)
          Updates SoL and builds Buildings that are free if possible.
 void updateSoL()
          Calculates the current SoL membership of the colony based on the liberty value and colonists.
 
Methods inherited from class net.sf.freecol.common.model.Settlement
canBuildEquipment, claimTile, getCompactGoods, getFoodConsumption, getFoodConsumptionByType, getFoodCount, getGoodsContainer, getGoodsCount, getGoodsIterator, getLineOfSight, getName, getOwner, getRadius, getTile, getTile, isCapital, placeSettlement, setCapital, setName
 
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, 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.Nameable
setName
 
Methods inherited from interface net.sf.freecol.common.model.Named
getName
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

LIBERTY_PER_REBEL

public static final int LIBERTY_PER_REBEL
See Also:
Constant Field Values

FOOD_PER_COLONIST

public static final int FOOD_PER_COLONIST
See Also:
Constant Field Values

HAS_PORT

public static final Ability HAS_PORT

SOL_MODIFIER_SOURCE

public static final FreeColGameObjectType SOL_MODIFIER_SOURCE
Constructor Detail

Colony

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

Parameters:
game - The Game in which this object belongs.
owner - The Player owning this Colony.
name - The name of the new Colony.
tile - The location of the Colony.

Colony

public Colony(Game game,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Initiates a new Colony 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 an error occurred during parsing.

Colony

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

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

Colony

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

addBuilding

public void addBuilding(Building building)
Add a Building to this Colony.

Parameters:
building - a Building value

canReducePopulation

public boolean canReducePopulation()
Returns true if the colony can reduce its population voluntarily. This is generally the case, but can be prevented by buildings such as the stockade.

Returns:
a boolean value

updatePopulation

public void updatePopulation(int difference)
Updates SoL and builds Buildings that are free if possible.

Parameters:
difference - an int value

getExportData

public ExportData getExportData(GoodsType goodsType)
Describe getExportData method here.

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

setExportData

public final void setExportData(ExportData newExportData)
Describe setExportData method here.

Parameters:
newExportData - an ExportData value

isLandLocked

public boolean isLandLocked()
Returns whether this colony is landlocked, or has access to water.

Returns:
true if there are no adjacent tiles to this Colony's tile being water tiles.

isConnected

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

Returns:
true if this Colony is connected to Europe.

isUndead

public boolean isUndead()
Returns whether this colony has undead units.

Returns:
whether this colony has undead units.

setOwner

public void setOwner(Player owner)
Sets the owner of this Colony, including all units within, and change main tile nation ownership.

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

setUnitCount

public void setUnitCount(int unitCount)
Sets the number of units inside the colony, used in enemy colonies

Parameters:
unitCount - The units inside the colony
See Also:
getUnitCount()

getBuildingsForProducing

public java.util.List<Building> getBuildingsForProducing(GoodsType goodsType)
Collect the buildings for producing the given type of goods.

Parameters:
goodsType - The type of goods.
Returns:
A List of Buildings which produce the given type of goods.

getBuildingsForConsuming

public java.util.List<Building> getBuildingsForConsuming(GoodsType goodsType)
Collect the buildings for consuming the given type of goods.

Parameters:
goodsType - The type of goods.
Returns:
A List of Buildings which consume the given type of goods.
See Also:
Goods

getBuildingForProducing

public Building getBuildingForProducing(GoodsType goodsType)
Find a building for producing the given type of goods.

Parameters:
goodsType - The type of goods.
Returns:
A Building which produces the given type of goods, or null if such a building can not be found.

getBuildingForConsuming

public Building getBuildingForConsuming(GoodsType goodsType)
Find a building for consuming the given type of goods.

Parameters:
goodsType - The type of goods.
Returns:
A Building which consumes the given type of goods, or null if such a building can not be found.

getWorkLocations

public java.util.List<WorkLocation> getWorkLocations()
Gets a List of every WorkLocation in this Colony.

Returns:
The List.
See Also:
WorkLocation

getBuildings

public java.util.List<Building> getBuildings()
Gets a List of every Building in this Colony.

Returns:
The List.
See Also:
Building

getColonyTiles

public java.util.List<ColonyTile> getColonyTiles()
Gets a List of every ColonyTile in this Colony.

Returns:
The List.
See Also:
ColonyTile

getBuilding

public Building getBuilding(BuildingType type)
Gets a Building of the specified type.

Parameters:
type - The type of the building to get.
Returns:
The Building.

getBuildingWithAbility

public Building getBuildingWithAbility(java.lang.String ability)
Returns a Building with the given Ability, or null, if none exists.

Parameters:
ability - a String value
Returns:
a Building value

getColonyTile

public ColonyTile getColonyTile(int x,
                                int y)
Gets the specified ColonyTile.

Parameters:
x - The x-coordinate of the Tile.
y - The y-coordinate of the Tile.
Returns:
The ColonyTile for the Tile returned by Settlement.getTile(int, int).

getColonyTile

public ColonyTile getColonyTile(Tile t)
Returns the ColonyTile matching the given Tile.

Parameters:
t - The Tile to get the ColonyTile for.
Returns:
The ColonyTile

incrementLiberty

public void incrementLiberty(int amount)

incrementImmigration

public void incrementImmigration(int amount)

add

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

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

removeGoods

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

Overrides:
removeGoods in class 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.

Overrides:
removeGoods in class Settlement
Parameters:
goods - a Goods value

removeGoods

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

Overrides:
removeGoods in class Settlement
Parameters:
type - a GoodsType value

addGoods

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

Overrides:
addGoods in class Settlement
Parameters:
type - a GoodsType value
amount - an int value

addGoods

public void addGoods(AbstractGoods goods)
Overrides:
addGoods in class Settlement

remove

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

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

getUnitCount

public int getUnitCount()
Gets the amount of Units at this Location. These units are located in a WorkLocation in this Colony.

Specified by:
getUnitCount in interface Location
Specified by:
getUnitCount in class Settlement
Returns:
The amount of Units at this Location.

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.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Description copied from interface: Location
Gets a Iterator of every Unit directly located on this Location.

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

contains

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

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

canAdd

public 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
Specified by:
canAdd in class Settlement
Parameters:
locatable - The Locatable to add.
Returns:
The result.

canTrain

public boolean canTrain(Unit unit)
Returns true if this colony has a schoolhouse and the unit type is a skilled unit type with a skill level not exceeding the level of the schoolhouse. @see Building#canAdd

Parameters:
unit - The unit to add as a teacher.
Returns:
true if this unit type could be added.

canTrain

public boolean canTrain(UnitType unitType)
Returns true if this colony has a schoolhouse and the unit type is a skilled unit type with a skill level not exceeding the level of the schoolhouse. The number of units already in the schoolhouse and the availability of pupils are not taken into account. @see Building#canAdd

Parameters:
unitType - The unit type to add as a teacher.
Returns:
true if this unit type could be added.

getTeachers

public java.util.List<Unit> getTeachers()

getDefendingUnit

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

Note that this function will only return a unit working inside the colony. Typically, colonies are also defended by units outside the colony on the same tile. To consider units outside the colony as well, use (@see Tile#getDefendingUnit) instead.

Returns an arbitrary unarmed land unit unless Paul Revere is present as founding father, in which case the unit can be armed as well.

Specified by:
getDefendingUnit in class Settlement
Parameters:
attacker - The unit that would be attacking this colony.
Returns:
The Unit that has been chosen to defend this colony, or null if the colony belongs to another player and client is not permitted to view contents.
Throws:
java.lang.IllegalStateException - if there are units in the colony
See Also:
Tile.getDefendingUnit(Unit)

getBuildableUnits

public java.util.List<UnitType> getBuildableUnits()
Returns a List with every unit type this colony may build.

Returns:
A List with UnitType

getCurrentlyBuilding

public BuildableType getCurrentlyBuilding()
Returns the type of building currently being built.

Returns:
The type of building currently being built.

setCurrentlyBuilding

public void setCurrentlyBuilding(BuildableType buildable)
Sets the type of building to be built.

Parameters:
buildable - The type of building to be built.

getTurnsToComplete

public int getTurnsToComplete(BuildableType buildable)
Returns how many turns it would take to build the given BuildableType. Returns a negative number if any of the production goods isnt being built, Integer.MIN_VAL if none is, and there are no goods available

Parameters:
buildable - a BuildableType value
Returns:
an int value

getBuildQueue

public java.util.List<BuildableType> getBuildQueue()
Get the BuildQueue value.

Returns:
a List value

setBuildQueue

public void setBuildQueue(java.util.List<BuildableType> newBuildQueue)
Set the BuildQueue value.

Parameters:
newBuildQueue - The new BuildQueue value.

getLiberty

public int getLiberty()
Describe getLiberty method here.

Returns:
an int value

addLiberty

public void addLiberty(int amount)
Adds to the liberty points of the colony. Used only by DebugMenu.

Parameters:
amount - The number of liberty to add.

getImmigration

public int getImmigration()
Describe getImmigration method here.

Returns:
an int value

getConsumption

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

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

getSoL

public int getSoL()
Returns the current SoL membership of the colony.

Returns:
The current SoL membership of the colony.

updateSoL

public void updateSoL()
Calculates the current SoL membership of the colony based on the liberty value and colonists.


calculateMembership

public int calculateMembership(int units)
Returns the SoL membership of the colony based on the liberty value and the number of colonists given.

Parameters:
units - an int value
Returns:
an int value

getMembers

public int getMembers()
Return the number of sons of liberty


getTory

public int getTory()
Returns the Tory membership of the colony.

Returns:
The current Tory membership of the colony.

getProductionBonus

public int getProductionBonus()
Returns the production bonus, if any, of the colony.

Returns:
The current production bonus of the colony.

getProductionModifier

public Modifier getProductionModifier(GoodsType goodsType)

toString

public java.lang.String toString()
Gets a string representation of the Colony. Currently this method just returns the name of the Colony, but that may change later.

Overrides:
toString in class FreeColGameObject
Returns:
The name of the colony.
See Also:
Settlement.getName()

getFoodProduction

public int getFoodProduction()
Gets the combined production of all food types.

Returns:
an int value

getProductionOf

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

Specified by:
getProductionOf in class Settlement
Parameters:
goodsType - The type of goods to get the production for.
Returns:
The production of the given type of goods the current turn by all of the Colony's buildings and tiles.

getVacantWorkLocationFor

public WorkLocation getVacantWorkLocationFor(Unit unit)
Gets a vacant WorkLocation for the given Unit.

Parameters:
unit - The Unit
Returns:
A vacant WorkLocation for the given Unit or null if there is no such location.

getBuildingFor

public Building getBuildingFor(Unit unit)
Return the Building best suited for the given Unit.

Parameters:
unit - an Unit value
Returns:
a Building value

getVacantColonyTileFor

public ColonyTile getVacantColonyTileFor(Unit unit,
                                         boolean allowClaim,
                                         GoodsType... goodsTypes)
Returns a vacant ColonyTile where the given unit produces the maximum output of the given goodsType.

Parameters:
unit - The Unit to find a vacant ColonyTile for.
allowClaim - Allow claiming free tiles from other settlements.
goodsTypes - The types of goods that should be produced.
Returns:
The ColonyTile giving the highest production of the given goods for the given unit or null if there is no available ColonyTile for producing that goods.

getProductionNextTurn

public int getProductionNextTurn(GoodsType goodsType)
Returns how much of a Good will be produced by this colony this turn

Parameters:
goodsType - The goods' type.
Returns:
The amount of the given goods will be produced for next turn.

getProductionNetOf

public int getProductionNetOf(GoodsType goodsType)
Returns how much of a Good will be produced by this colony this turn, taking into account how much is consumed - by workers, horses, etc.

Parameters:
goodsType - The goods' type.
Returns:
The amount of the given goods currently unallocated for next turn.

canBreed

public boolean canBreed(GoodsType goodsType)
Returns true if this Colony can breed the given type of Goods. Only animals (such as horses) are expected to be breedable.

Parameters:
goodsType - a GoodsType value
Returns:
a boolean value

canBuild

public boolean canBuild()
Describe canBuild method here.

Returns:
a boolean value

canBuild

public boolean canBuild(BuildableType buildableType)
Returns true if this Colony can build the given BuildableType.

Parameters:
buildableType - a BuildableType value
Returns:
a boolean value

getNoBuildReason

public Colony.NoBuildReason getNoBuildReason(BuildableType buildableType)
Return the reason why the give BuildableType can not be built.

Parameters:
buildableType - a BuildableType value
Returns:
a NoBuildReason value

createBuilding

public Building createBuilding(BuildingType buildingType)
Ask the server to create a building for us.

Parameters:
buildingType - a BuildingType value
Returns:
a Building value

createFreeBuilding

public Building createFreeBuilding(BuildingType buildingType)
Ask the server to create a free building for us.

Parameters:
buildingType - a BuildingType value
Returns:
a Building value

getPriceForBuilding

public int getPriceForBuilding()
Returns the price for the remaining hammers and tools for the Building that is currently being built.

Returns:
The price.
See Also:
payForBuilding()

getPriceForBuilding

public int getPriceForBuilding(BuildableType buildableType)
Returns the price for the remaining hammers and tools for the Building given.

Parameters:
buildableType - a BuildableType value
Returns:
The price.
See Also:
payForBuilding()

payForBuilding

public void payForBuilding()
Buys the remaining hammers and tools for the Building that is currently being built.

Throws:
java.lang.IllegalStateException - If the owner of this Colony has an insufficient amount of gold.
See Also:
getPriceForBuilding()

canPayToFinishBuilding

public boolean canPayToFinishBuilding()
Check if the owner can buy the remaining hammers and tools for the Building that is currently being built.

Throws:
java.lang.IllegalStateException - If the owner of this Colony has an insufficient amount of gold.
See Also:
getPriceForBuilding()

canPayToFinishBuilding

public boolean canPayToFinishBuilding(BuildableType buildableType)
Check if the owner can buy the remaining hammers and tools for the Building given.

Parameters:
buildableType - a BuildableType value
Returns:
a boolean value
Throws:
java.lang.IllegalStateException - If the owner of this Colony has an insufficient amount of gold.
See Also:
getPriceForBuilding()

getWarnings

public java.util.Collection<java.lang.String> getWarnings(GoodsType goodsType,
                                                          int amount,
                                                          int production)
determine if there is a problem with the production of the specified good

Parameters:
goodsType - for this good
amount - warehouse amount
production - production per turn
Returns:
all warnings

getRandomUnit

public Unit getRandomUnit()
Returns a random unit from this colony. At this moment, this method always returns the first unit in the colony.

Returns:
A random unit from this Colony. This Unit will either be working in a Building or a ColonyTile.

findTeacher

public Unit findTeacher(Unit unit)

governmentChange

public int governmentChange(int units)
Returns 1, 0, or -1 to indicate that government would improve, remain the same, or deteriorate if the colony had the given population.

Parameters:
units - an int value
Returns:
an int value

checkForGovMgtChangeMessage

public ModelMessage checkForGovMgtChangeMessage()

newTurn

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

Specified by:
newTurn in class Settlement

getWarehouseCapacity

public int getWarehouseCapacity()
Returns the capacity of this colony's warehouse. All goods above this limit, except Goods.FOOD, will be removed when calling newTurn().

Returns:
The capacity of this Colony's warehouse.

getWarehouse

public Building getWarehouse()

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent event)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

dispose

public void dispose()
Disposes this Colony. All WorkLocations owned by this Colony will also be destroyed.

Overrides:
dispose in class Settlement

getXMLElementTagName

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

Returns:
"colony".

getColony

public Colony getColony()
Returns just this Colony itself.

Specified by:
getColony in interface Location
Returns:
this colony.

hasStockade

public boolean hasStockade()
Returns true when colony has a stockade

Returns:
whether the colony has a stockade

getStockade

public Building getStockade()
Returns the stockade building

Returns:
a Building

getModifierSet

public final java.util.Set<Modifier> getModifierSet(java.lang.String id)
Get the Modifier value.

Parameters:
id - a String value
Returns:
a Modifier value

hasAbility

public boolean hasAbility(java.lang.String id)
Returns true if the Colony, or its owner has the ability identified by id.

Overrides:
hasAbility in class FreeColObject
Parameters:
id - a String value
Returns:
a boolean value

hasAbility

public boolean hasAbility(java.lang.String id,
                          FreeColGameObjectType type)
Returns true if the Colony, or its owner has the ability identified by id.

Parameters:
id - a String value
type - a FreeColGameObjectType value
Returns:
a boolean value

getFeatureContainer

public FeatureContainer getFeatureContainer()
Description copied from class: Settlement
Describe getFeatureContainer method here.

Overrides:
getFeatureContainer in class Settlement
Returns:
a FeatureContainer value

canBombardEnemyShip

public boolean canBombardEnemyShip()
Verify if colony has the conditions to bombard an enemy ship adjacent to it

Returns:
true if it can, false otherwise