|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Settlement
net.sf.freecol.common.model.Colony
public final class Colony
Represents a colony. A colony contains Building
s and
ColonyTile
s. 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 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 |
---|
public static final int LIBERTY_PER_REBEL
public static final int FOOD_PER_COLONIST
public static final Ability HAS_PORT
public static final FreeColGameObjectType SOL_MODIFIER_SOURCE
Constructor Detail |
---|
public Colony(Game game, Player owner, java.lang.String name, Tile tile)
Colony
.
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
.public Colony(Game game, javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException
Colony
from an XML representation.
game
- The Game
this object belongs to.in
- The input stream containing the XML.
javax.xml.stream.XMLStreamException
- if an error occurred during parsing.public Colony(Game game, org.w3c.dom.Element e)
Colony
from an XML representation.
game
- The Game
this object belongs to.e
- An XML-element that will be used to initialize this object.public Colony(Game game, java.lang.String id)
Colony
with the given ID. The object
should later be initialized by calling either
FreeColGameObject.readFromXML(XMLStreamReader)
or
FreeColObject.readFromXMLElement(Element)
.
game
- The Game
in which this object belong.id
- The unique identifier for this object.Method Detail |
---|
public void addBuilding(Building building)
building
- a Building
valuepublic boolean canReducePopulation()
boolean
valuepublic void updatePopulation(int difference)
difference
- an int
valuepublic ExportData getExportData(GoodsType goodsType)
getExportData
method here.
goodsType
- a GoodsType
value
ExportData
valuepublic final void setExportData(ExportData newExportData)
setExportData
method here.
newExportData
- an ExportData
valuepublic boolean isLandLocked()
true
if there are no adjacent tiles to this
Colony
's tile being water tiles.public boolean isConnected()
true
if this Colony
is connected
to Europe.public boolean isUndead()
public void setOwner(Player owner)
Colony
, including all units
within, and change main tile nation ownership.
setOwner
in interface Ownable
setOwner
in class Settlement
owner
- The Player
that shall own this
Settlement
.Settlement.getOwner()
public void setUnitCount(int unitCount)
unitCount
- The units inside the colonygetUnitCount()
public java.util.List<Building> getBuildingsForProducing(GoodsType goodsType)
goodsType
- The type of goods.
List
of Building
s which produce
the given type of goods.public java.util.List<Building> getBuildingsForConsuming(GoodsType goodsType)
goodsType
- The type of goods.
List
of Building
s which consume
the given type of goods.Goods
public Building getBuildingForProducing(GoodsType goodsType)
goodsType
- The type of goods.
Building
which produces the given type of goods,
or null
if such a building can not be found.public Building getBuildingForConsuming(GoodsType goodsType)
goodsType
- The type of goods.
Building
which consumes the given type of goods,
or null
if such a building can not be found.public java.util.List<WorkLocation> getWorkLocations()
List
of every WorkLocation
in this
Colony
.
List
.WorkLocation
public java.util.List<Building> getBuildings()
List
of every Building
in this
Colony
.
List
.Building
public java.util.List<ColonyTile> getColonyTiles()
List
of every ColonyTile
in this
Colony
.
List
.ColonyTile
public Building getBuilding(BuildingType type)
Building
of the specified type.
type
- The type of the building to get.
Building
.public Building getBuildingWithAbility(java.lang.String ability)
Building
with the given
Ability
, or null, if none exists.
ability
- a String
value
Building
valuepublic ColonyTile getColonyTile(int x, int y)
ColonyTile
.
x
- The x-coordinate of the Tile
.y
- The y-coordinate of the Tile
.
ColonyTile
for the Tile
returned by Settlement.getTile(int, int)
.public ColonyTile getColonyTile(Tile t)
ColonyTile
matching the given
Tile
.
t
- The Tile
to get the ColonyTile
for.
ColonyTile
public void incrementLiberty(int amount)
public void incrementImmigration(int amount)
public void add(Locatable locatable)
Locatable
to this Location.
add
in interface Location
add
in class Settlement
locatable
- The Locatable
to add to this Location.public void removeGoods(GoodsType type, int amount)
removeGoods
in class Settlement
type
- The type of Goods to remove from this settlement.amount
- The amount of Goods to remove from this settlement.public void removeGoods(AbstractGoods goods)
removeGoods
in class Settlement
goods
- a Goods
valuepublic void removeGoods(GoodsType type)
removeGoods
in class Settlement
type
- a GoodsType
valuepublic void addGoods(GoodsType type, int amount)
addGoods
method here.
addGoods
in class Settlement
type
- a GoodsType
valueamount
- an int
valuepublic void addGoods(AbstractGoods goods)
addGoods
in class Settlement
public void remove(Locatable locatable)
Locatable
from this Location.
remove
in interface Location
remove
in class Settlement
locatable
- The Locatable
to remove from this
Location.public int getUnitCount()
WorkLocation
in this Colony
.
getUnitCount
in interface Location
getUnitCount
in class Settlement
public java.util.List<Unit> getUnitList()
Location
getUnitList
in interface Location
public java.util.Iterator<Unit> getUnitIterator()
Location
Iterator
of every Unit
directly
located on this Location
.
getUnitIterator
in interface Location
Iterator
.public boolean contains(Locatable locatable)
Location
Location
contains the specified
Locatable
.
contains
in interface Location
contains
in class Settlement
locatable
- The Locatable
to test the presence of.
Locatable
is
on this Location
and
public boolean canAdd(Locatable locatable)
Location
Location
.
canAdd
in interface Location
canAdd
in class Settlement
locatable
- The Locatable
to add.
public boolean canTrain(Unit unit)
unit
- The unit to add as a teacher.
true
if this unit type could be added.public boolean canTrain(UnitType unitType)
unitType
- The unit type to add as a teacher.
true
if this unit type could be added.public java.util.List<Unit> getTeachers()
public Unit getDefendingUnit(Unit attacker)
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.
getDefendingUnit
in class Settlement
attacker
- The unit that would be attacking this colony.
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.
java.lang.IllegalStateException
- if there are units in the colonyTile.getDefendingUnit(Unit)
public java.util.List<UnitType> getBuildableUnits()
List
with every unit type this colony may
build.
List
with UnitType
public BuildableType getCurrentlyBuilding()
public void setCurrentlyBuilding(BuildableType buildable)
buildable
- The type of building to be built.public int getTurnsToComplete(BuildableType buildable)
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
buildable
- a BuildableType
value
int
valuepublic java.util.List<BuildableType> getBuildQueue()
BuildQueue
value.
List
valuepublic void setBuildQueue(java.util.List<BuildableType> newBuildQueue)
BuildQueue
value.
newBuildQueue
- The new BuildQueue value.public int getLiberty()
getLiberty
method here.
int
valuepublic void addLiberty(int amount)
amount
- The number of liberty to add.public int getImmigration()
getImmigration
method here.
int
valuepublic int getConsumption(GoodsType goodsType)
goodsType
- a GoodsType
value
int
valuepublic int getSoL()
public void updateSoL()
public int calculateMembership(int units)
units
- an int
value
int
valuepublic int getMembers()
public int getTory()
public int getProductionBonus()
public Modifier getProductionModifier(GoodsType goodsType)
public java.lang.String toString()
Colony
, but that may change
later.
toString
in class FreeColGameObject
Settlement.getName()
public int getFoodProduction()
int
valuepublic int getProductionOf(GoodsType goodsType)
getProductionOf
in class Settlement
goodsType
- The type of goods to get the production for.
Colony
's buildings
and
tiles
.public WorkLocation getVacantWorkLocationFor(Unit unit)
WorkLocation
for the given Unit
.
unit
- The Unit
WorkLocation
for the given
Unit
or null
if there is no such
location.public Building getBuildingFor(Unit unit)
unit
- an Unit
value
Building
valuepublic ColonyTile getVacantColonyTileFor(Unit unit, boolean allowClaim, GoodsType... goodsTypes)
ColonyTile
where the given
unit
produces the maximum output of the given
goodsType
.
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.
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.public int getProductionNextTurn(GoodsType goodsType)
goodsType
- The goods' type.
public int getProductionNetOf(GoodsType goodsType)
goodsType
- The goods' type.
public boolean canBreed(GoodsType goodsType)
true
if this Colony can breed the given
type of Goods. Only animals (such as horses) are expected to be
breedable.
goodsType
- a GoodsType
value
boolean
valuepublic boolean canBuild()
canBuild
method here.
boolean
valuepublic boolean canBuild(BuildableType buildableType)
buildableType
- a BuildableType
value
boolean
valuepublic Colony.NoBuildReason getNoBuildReason(BuildableType buildableType)
BuildableType
can
not be built.
buildableType
- a BuildableType
value
NoBuildReason
valuepublic Building createBuilding(BuildingType buildingType)
buildingType
- a BuildingType
value
Building
valuepublic Building createFreeBuilding(BuildingType buildingType)
buildingType
- a BuildingType
value
Building
valuepublic int getPriceForBuilding()
Building
that is currently being built.
payForBuilding()
public int getPriceForBuilding(BuildableType buildableType)
Building
given.
buildableType
- a BuildableType
value
payForBuilding()
public void payForBuilding()
Building
that is
currently being built.
java.lang.IllegalStateException
- If the owner of this Colony
has an insufficient amount of gold.getPriceForBuilding()
public boolean canPayToFinishBuilding()
Building
that is currently being built.
java.lang.IllegalStateException
- If the owner of this Colony
has an insufficient amount of gold.getPriceForBuilding()
public boolean canPayToFinishBuilding(BuildableType buildableType)
Building
given.
buildableType
- a BuildableType
value
boolean
value
java.lang.IllegalStateException
- If the owner of this Colony
has an insufficient amount of gold.getPriceForBuilding()
public java.util.Collection<java.lang.String> getWarnings(GoodsType goodsType, int amount, int production)
goodsType
- for this goodamount
- warehouse amountproduction
- production per turn
public Unit getRandomUnit()
Colony
. This
Unit
will either be working in a Building
or a ColonyTile
.public Unit findTeacher(Unit unit)
public int governmentChange(int units)
units
- an int
value
int
valuepublic ModelMessage checkForGovMgtChangeMessage()
public void newTurn()
Colony
for a new turn.
newTurn
in class Settlement
public int getWarehouseCapacity()
Goods.FOOD
, will be removed when calling
newTurn()
.
Colony
's warehouse.public Building getWarehouse()
public void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
public void dispose()
Colony
. All WorkLocation
s
owned by this Colony
will also be destroyed.
dispose
in class Settlement
public static java.lang.String getXMLElementTagName()
public Colony getColony()
getColony
in interface Location
public boolean hasStockade()
public Building getStockade()
Building
public final java.util.Set<Modifier> getModifierSet(java.lang.String id)
Modifier
value.
id
- a String
value
Modifier
valuepublic boolean hasAbility(java.lang.String id)
id
.
hasAbility
in class FreeColObject
id
- a String
value
boolean
valuepublic boolean hasAbility(java.lang.String id, FreeColGameObjectType type)
id
.
id
- a String
valuetype
- a FreeColGameObjectType
value
boolean
valuepublic FeatureContainer getFeatureContainer()
Settlement
getFeatureContainer
method here.
getFeatureContainer
in class Settlement
FeatureContainer
valuepublic boolean canBombardEnemyShip()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |