Package net.sf.freecol.common.model
Class Colony
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,Nameable
,Ownable
,TradeLocation
,ObjectWithId
- Direct Known Subclasses:
ServerColony
public class Colony extends Settlement implements TradeLocation
Represents a colony. A colony containsBuilding
s andColonyTile
s. The latter represents the tiles around theColony
where working is possible.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Colony.ColonyChangeEvent
static class
Colony.NoBuildReason
Reasons for not building a buildable.static class
Colony.TileImprovementSuggestion
Container class for tile exploration or improvement suggestions.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
BUILD_QUEUE_TAG
protected java.util.Map<java.lang.String,Building>
buildingMap
A map of Buildings, indexed by the id of their basic type.protected BuildQueue<BuildableType>
buildQueue
A list of items to be built.static int
CHANGE_UPPER_BOUND
private static int
COLONY_CLASS_INDEX
Class index for colonies.protected java.util.List<ColonyTile>
colonyTiles
A list of the ColonyTiles.protected int
displayUnitCount
protected Turn
established
The turn in which this colony was established.private static java.lang.String
ESTABLISHED_TAG
protected java.util.Map<java.lang.String,ExportData>
exportData
A map of ExportData, indexed by the ids of GoodsTypes.static int
FAMINE_TURNS
The number of turns of advanced warning of starvation.protected int
immigration
The number of immigration points.private static java.lang.String
IMMIGRATION_TAG
protected int
liberty
The number of liberty points.static int
LIBERTY_PER_REBEL
private static java.lang.String
LIBERTY_TAG
private static java.util.logging.Logger
logger
private static java.lang.String
NAME_TAG
private static java.lang.String
OLD_SONS_OF_LIBERTY_TAG
private static java.lang.String
OLD_TORIES_TAG
protected int
oldSonsOfLiberty
The SoL membership last turn.protected int
oldTories
The number of tories last turn.private static java.lang.String
POPULATION_QUEUE_TAG
protected BuildQueue<UnitType>
populationQueue
The colonists that may be born.private static java.lang.String
PRODUCTION_BONUS_TAG
protected int
productionBonus
The current production bonus.private ProductionCache
productionCache
Contains information about production and consumption.static java.lang.String
REARRANGE_COLONY
private static java.lang.String
SONS_OF_LIBERTY_TAG
protected int
sonsOfLiberty
The SoL membership this turn.static java.lang.String
TAG
protected int
tories
The number of tories this turn.private static java.lang.String
TORIES_TAG
private boolean
traceOccupation
The occupation tracing status.static int
TRADE_MARGIN
Number of colonies that a player will trade down to.private static java.lang.String
UNIT_COUNT_TAG
-
Fields inherited from class net.sf.freecol.common.model.Settlement
FOOD_PER_COLONIST, owner, tile
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
Fields inherited from interface net.sf.freecol.common.model.Location
LOCATION_RANK_EUROPE, LOCATION_RANK_HIGHSEAS, LOCATION_RANK_NOWHERE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
accumulateChoice(GoodsType workType, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)
private void
accumulateChoices(java.util.Collection<GoodsType> workTypes, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)
boolean
add(Locatable locatable)
Adds aLocatable
to this Location.boolean
addBuilding(Building building)
Add a Building to this Colony.private void
addColonyTile(ColonyTile ct)
Add a colony tile.boolean
addGoods(GoodsType type, int amount)
Adds a specified amount of a type of goods to this location.void
addLiberty(int amount)
Adds to the liberty points by increasing the liberty goods present.protected void
addPortAbility()
Add port ability to non-landlocked colonies.static int
calculateRebels(int uc, int solPercent)
Calculate the number of rebels given a SoL percentage and unit count.int
calculateSettlementValue(int value, Unit unit)
Determines the value of a potential attack on aColony
private int
calculateSoLPercentage(int uc, int liberty)
Calculate the SoL membership percentage of the colony based on the number of colonists and liberty.boolean
canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanelboolean
canBePillaged(Unit attacker)
Determines whether this colony is sufficiently unprotected and contains something worth pillaging.boolean
canBePlundered()
Checks if this colony can be plundered.boolean
canBreed(GoodsType goodsType)
Returnstrue
if this Colony can breed the given type of Goods.boolean
canBuild()
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 theBuilding
that is currently being built.boolean
canPayToFinishBuilding(BuildableType buildableType)
Check if the owner can buy the remaining hammers and tools for theBuilding
given.boolean
canProduce(GoodsType goodsType)
Can this colony produce certain goods?boolean
canProvideGoods(java.util.List<AbstractGoods> requiredGoods)
Determines if this settlement can build the given type of equipment.boolean
canReducePopulation()
Can this colony reduce its population voluntarily? This is generally the case, but can be prevented by buildings such as the stockade in classic mode.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.Constants.IntegrityType
checkBuildQueueIntegrity(boolean fix, LogBuilder lb)
Check the integrity of the build queues.ModelMessage
checkForGovMgtChangeMessage()
Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.protected void
clearBuildingMap()
Clear the building map.private void
clearColonyTiles()
Clear the colony tiles.boolean
contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.Colony
copyColony()
Creates a temporary copy of this colony for planning purposes.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
evaluateFor(Player player)
Evaluate this colony for a given player.Unit
findStudent(Unit teacher)
Find a student for the specified teacher.Unit
findTeacher(Unit student)
Find a teacher for the specified student.java.util.stream.Stream<Ability>
getAbilities(java.lang.String id, FreeColSpecObjectType type, Turn turn)
Gets the set of abilities with the given identifier from this object.int
getAdjustedNetProductionOf(GoodsType goodsType)
Returns the net production of the given GoodsType adjusted by the possible consumption of BuildQueues.StringTemplate
getAlarmLevelLabel(Player player)
Gets a label indicating the alarm level at this settlement with respect to another player.java.util.stream.Stream<WorkLocation>
getAllWorkLocations()
Gets a stream of every work location in this colony.java.util.List<WorkLocation>
getAllWorkLocationsList()
Gets a list of every work location in this colony.int
getApparentUnitCount()
Gets the apparent number of units at this colony.int
getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.java.util.stream.Stream<WorkLocation>
getAvailableWorkLocations()
Get a stream of all freely available work locations in this colony.java.util.List<WorkLocation>
getAvailableWorkLocationsList()
Gets a list of all freely available work locations in this colony.UnitType
getBestDefenderType()
Gets the best defender type available to this colony.Unit
getBetterExpert(Unit expert)
Finds another unit in this colony that would be better at doing the job of the specified unit.java.util.List<UnitType>
getBuildableUnits()
Gets a list of every unit type this colony may build.Building
getBuilding(BuildingType type)
Get building of the specified general type (note: *not* necessarily the exact building type supplied, but the building present in the colony that is a descendant of the ultimate ancestor of the specified type).java.util.List<Building>
getBuildings()
Get a list of everyBuilding
in thisColony
.java.util.List<BuildableType>
getBuildQueue()
Get the build queue contents.java.util.List<Building>
getBurnableBuildings()
Gets the buildings in this colony that could be burned by a raid.int
getClassIndex()
Accessor for the class index.Colony
getColony()
Get the colony at this location.ColonyTile
getColonyTile(Tile tile)
Get theColonyTile
matching the givenTile
.java.util.List<ColonyTile>
getColonyTiles()
java.util.List<Consumer>
getConsumers()
Get a list of allConsumer
s in the colony sorted by priority.int
getConsumptionOf(GoodsType goodsType)
Returns the number of goods of a given type used by the settlement each turn.<T extends FreeColObject>
TgetCorresponding(T fco)
Finds the corresponding FreeColObject from another copy of this colony.BuildableType
getCurrentlyBuilding()
Gets the type of building currently being built.java.util.stream.Stream<WorkLocation>
getCurrentWorkLocations()
Get a stream of all current work locations in this colony.java.util.List<WorkLocation>
getCurrentWorkLocationsList()
Gets a list of all current work locations in this colony.double
getDefenceRatio()
Get the ratio between defence at this settlement, and the general settlement size.Unit
getDefendingUnit(Unit attacker)
Gets theUnit
that is currently defending thisSettlement
.java.util.stream.Stream<RandomChoice<Disaster>>
getDisasterChoices()
Get a weighted list of natural disasters than can strike this colony.int
getDisplayUnitCount()
Get the display unit count.java.util.stream.Stream<FreeColGameObject>
getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away.Turn
getEstablished()
Get the turn this colony was established.int
getExportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be exported from this trade location after a given number of turns.protected java.util.Collection<ExportData>
getExportData()
Get the export data.ExportData
getExportData(GoodsType goodsType)
Get the export date for a goods type.int
getFoodProduction()
Gets the combined production of all food types.java.util.List<AbstractGoods>
getFullRequiredGoods(BuildableType buildable)
Gets all the goods required to complete a build.int
getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.int
getImmigration()
Gets the immigration points.int
getImportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be imported to this trade location after a given number of turns.private StringTemplate
getInsufficientProductionMessage(ProductionInfo info, AbstractGoods deficit)
Get a message about insufficient production for a buildingint
getLiberty()
Gets the liberty points.StringTemplate
getLocationLabelFor(Player player)
Get a label for this location for a particular player.java.lang.String
getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocationjava.util.List<Goods>
getLootableGoodsList()
Gets a list of all stored goods in this colony, suitable for being looted.int
getNetProductionOf(GoodsType goodsType)
Get the net production of the given goods type.int
getNewColonistTurns()
Get the number of turns before a new colonist will be born in this colony with current production levels.Colony.NoBuildReason
getNoBuildReason(BuildableType buildableType, java.util.List<BuildableType> assumeBuilt)
Return the reason why the giveBuildableType
can not be built.private Occupation
getOccupationFor(Unit unit, boolean userMode)
Gets the best occupation for a given unit.private Occupation
getOccupationFor(Unit unit, boolean userMode, LogBuilder lb)
Gets the best occupation for a given unit.private Occupation
getOccupationFor(Unit unit, java.util.Collection<GoodsType> workTypes)
Gets the best occupation for a given unit to produce one of a given set of goods types.private Occupation
getOccupationFor(Unit unit, java.util.Collection<GoodsType> workTypes, LogBuilder lb)
Gets the best occupation for a given unit to produce one of a given set of goods types.boolean
getOccupationTrace()
Gets the occupation tracing status.protected int
getOldSonsOfLiberty()
protected int
getOldTories()
RandomRange
getPlunderRange(Unit attacker)
Gets the range of gold plunderable when this settlement is captured.java.util.List<UnitType>
getPopulationQueue()
Get the population queue contents.int
getPreferredSizeChange()
Gets the number of units that would be good to add/remove from this colony.int
getPriceForBuilding()
Returns the price for the remaining hammers and tools for theBuilding
that is currently being built.int
getPriceForBuilding(BuildableType type)
Gets the price for the remaining resources to build a given buildable.int
getProductionBonus()
Gets the production bonus of the colony.ProductionInfo
getProductionInfo(java.lang.Object object)
Returns the ProductionInfo for the given Object.protected TypeCountMap<GoodsType>
getProductionMap()
Gets a copy of the current production map.java.util.stream.Stream<Modifier>
getProductionModifiers(GoodsType goodsType, UnitType unitType, WorkLocation wl)
Get the current productionModifier
, which is generated from the current production bonus.java.util.Collection<StringTemplate>
getProductionWarnings(GoodsType goodsType)
Determine if there is a problem with the production of a given goods type.StringTemplate
getReducePopulationMessage()
Gets the message to display if the colony can not reduce its population.java.util.List<AbstractGoods>
getRequiredGoods(BuildableType type)
Gets a map of the types of goods and amount thereof required to finish a buildable in this colony.int
getSoL()
Gets the current Sons of Liberty in this settlement.int
getSoLPercentage()
Calculate the SoL membership percentage of a colony.protected int
getSonsOfLiberty()
int
getStarvationTurns()
Get the number of turns before starvation occurs at this colony with current production levels.Building
getStockade()
Gets the stockade building in this colony.java.lang.String
getStockadeKey()
Gets the stockade key, as should be visible to the owner or a player that can see this colony.java.util.stream.Stream<Unit>
getTeachers()
Gets a list of all teachers currently present in the school building.java.util.List<Colony.TileImprovementSuggestion>
getTileImprovementSuggestions()
Collect suggestions for tiles that need exploration or improvement (which may depend on current use within the colony).protected int
getTories()
int
getTory()
Gets the Tory membership percentage of the colony.double
getTotalDefencePower()
Gets the total defence power.int
getTotalProductionOf(GoodsType goodsType)
Gets the total production of the given type of goods in this settlement.int
getTurnsToComplete(BuildableType buildable)
Returns how many turns it would take to build the givenBuildableType
.int
getTurnsToComplete(BuildableType buildable, AbstractGoods needed)
Returns how many turns it would take to build the givenBuildableType
.ModelMessage
getUnbuildableMessage(BuildableType buildable)
Gets the message to display if a colony can not build something.int
getUnitCount()
Gets the number of units at this Location.java.util.List<Unit>
getUnitList()
Gets a list of all the units present at this location.java.util.stream.Stream<Unit>
getUnits()
Gets a stream of all the units present at this location.int
getUnitsToAdd()
int
getUnitsToRemove()
int
getUpkeep()
Get the amount of gold necessary to maintain all of the settlement's buildings.Building
getWarehouse()
Get the warehouse-type building in this colony.WorkLocation
getWorkLocationFor(Unit unit)
Gets the work location best suited for the given unit.WorkLocation
getWorkLocationFor(Unit unit, GoodsType goodsType)
Gets the work location best suited for the given unit to produce a type of goods.WorkLocation
getWorkLocationForProducing(GoodsType goodsType)
Find a work location for producing a given type of goods.java.util.List<WorkLocation>
getWorkLocationsForConsuming(GoodsType goodsType)
Collect the work locations for consuming a given type of goods.java.util.List<WorkLocation>
getWorkLocationsForProducing(GoodsType goodsType)
Collect the work locations for producing a given type of goods.WorkLocation
getWorkLocationWithAbility(java.lang.String ability)
Gets a work location with a given ability.<T extends WorkLocation>
TgetWorkLocationWithAbility(java.lang.String ability, java.lang.Class<T> returnClass)
Gets a work location of a specific class with a given ability.WorkLocation
getWorkLocationWithModifier(java.lang.String modifier)
Gets a work location with a given modifier.<T extends WorkLocation>
TgetWorkLocationWithModifier(java.lang.String modifier, java.lang.Class<T> returnClass)
Gets a work location of a specific class with a given modifier.java.util.List<java.util.Collection<GoodsType>>
getWorkTypeChoices(Unit unit, boolean userMode)
Get a list of collections of goods types, in order of priority to try to produce in this colony by a given unit.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
goodsUseful(GoodsType goodsType)
Check if a goods type is still useful to this colony.int
governmentChange(int unitCount)
Returns 1, 0, or -1 to indicate that government would improve, remain the same, or deteriorate if the colony had the given population.boolean
hasContacted(Player player)
Has this settlement contacted a given player? Allow player == null as this is true in the map editor where the user player is moot.boolean
hasStockade()
Does this colony have a stockade?void
invalidateCache()
Invalidate any cache dependent on the goods levels.boolean
isAutomaticBuild(BuildingType buildingType)
Is a building type able to be automatically built at no cost.boolean
isBadlyDefended()
Is this settlement insufficiently defended?boolean
isConsuming(GoodsType goodsType)
Does this colony consume a goods type? This is more reliable than checking net or total consumption, either of which might be cancelling to zero.boolean
isProducing(GoodsType goodsType)
Does this colony produce a goods type? This is more reliable than checking net or total production, either of which might be cancelling to zero.boolean
isProductive(WorkLocation workLocation)
Is a work location productive?boolean
isTileInUse(Tile tile)
Is a tile actually in use by this colony?boolean
isUndead()
Does this colony have undead units?boolean
isUnderSiege()
Decide if the number of enemy combat units on all tiles that belong to the colony exceeds the number of friendly combat units.boolean
joinColony(Unit unit)
Special routine to handle non-specific add of unit to colony.void
modifyImmigration(int amount)
Modify the immigration points by amount given.void
modifyLiberty(int amount)
Modify the liberty points by amount given.private void
modifySpecialGoods(GoodsType goodsType, int amount)
Special goods need modifiers applied when changed, and immigration accumulates to the owner.int
priceGoodsForBuilding(java.util.List<AbstractGoods> required)
Gets a price for a map of resources to build a given buildable.void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
readChild(FreeColXMLReader xr)
Reads a single child object.void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.boolean
remove(Locatable locatable)
Removes aLocatable
from this Location.protected boolean
removeBuilding(Building building)
Remove a building from this Colony.Goods
removeGoods(GoodsType type, int amount)
Removes a specified amount of a type of Goods from this location.private int
returnPresent(GoodsType goodsType, int turns)
Calculate the present field.protected void
setBuildingMap(java.util.List<Building> buildings)
Reset the building map.void
setBuildQueue(java.util.List<BuildableType> buildQueue)
Set the build queue.protected void
setColonyTiles(java.util.List<ColonyTile> colonyTiles)
Set the colony tile list.void
setCurrentlyBuilding(BuildableType buildable)
Sets the current type of buildable to be built and if it is a building insist that there is only one in the queue.void
setDisplayUnitCount(int count)
Sets the apparent number of units at this colony.void
setEstablished(Turn newEstablished)
Set the turn of establishment.protected void
setExportData(java.util.Collection<ExportData> exportData)
Set the export data.void
setExportData(ExportData newExportData)
Set some export data.boolean
setOccupationTrace(boolean trace)
Sets the occupation tracing status.void
setPopulationQueue(java.util.List<UnitType> populationQueue)
Set the population queue.void
setProductionBonus(int productionBonus)
Sets the production bonus of the colony.java.lang.String
toShortString()
Get a short description of this location.java.lang.String
toString()
Location
up()
Promote this location to a more meaningful one if possible.void
updateEducation(Unit unit, boolean enable)
Signal to the colony that a unit is moving in or out or changing its internal work location to one with a different teaching ability.void
updatePopulation()
Signal to the colony that its population is changing.protected boolean
updateProductionBonus()
Update the colony's production bonus.void
updateProductionTypes()
Update all the production types.void
updateSoL()
Calculates the current SoL membership of the colony based on the liberty value and colonists.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.Settlement
addTile, canBombardEnemyShip, canImproveUnitMilitaryRole, changeOwner, disposeResources, equipForRole, exciseSettlement, getAllUnitsList, getConsumptionOf, getFeatureContainer, getFoodConsumption, getHighSeasCount, getLineOfSight, getLinkTarget, getLocationImageKey, getLocationLabel, getName, getNoAddReason, getOwnedTiles, getOwner, getPlunder, getRadius, getRank, getSettlement, getTile, getType, getVisibleTileSet, getWarehouseCapacity, isCapital, isConnectedPort, isLandLocked, placeSettlement, priceGoods, removeTile, setCapital, setName, setOwnedTiles, setOwner, setType
-
Methods inherited from class net.sf.freecol.common.model.GoodsLocation
addGoods, addGoods, containsGoods, getCompactGoodsList, getGoodsContainer, getGoodsCount, getGoodsList, moveGoods, removeAll, removeGoods, removeGoods, setGoodsContainer
-
Methods inherited from class net.sf.freecol.common.model.UnitLocation
canAdd, clearUnitList, getCarrierForUnit, getFirstUnit, getIndianSettlement, getLastUnit, getNavalUnits, getSpaceTaken, getTotalUnitCount, getUnitCapacity, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, equals, fundamentalDispose, getGame, getSpecification, hashCode, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.model.TradeLocation
getNameAsJlabel
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
COLONY_CLASS_INDEX
private static final int COLONY_CLASS_INDEX
Class index for colonies.- See Also:
- Constant Field Values
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
REARRANGE_COLONY
public static final java.lang.String REARRANGE_COLONY
- See Also:
- Constant Field Values
-
LIBERTY_PER_REBEL
public static final int LIBERTY_PER_REBEL
- See Also:
- Constant Field Values
-
CHANGE_UPPER_BOUND
public static final int CHANGE_UPPER_BOUND
- See Also:
- Constant Field Values
-
FAMINE_TURNS
public static final int FAMINE_TURNS
The number of turns of advanced warning of starvation.- See Also:
- Constant Field Values
-
TRADE_MARGIN
public static final int TRADE_MARGIN
Number of colonies that a player will trade down to.- See Also:
- Constant Field Values
-
buildingMap
protected final java.util.Map<java.lang.String,Building> buildingMap
A map of Buildings, indexed by the id of their basic type.
-
colonyTiles
protected final java.util.List<ColonyTile> colonyTiles
A list of the ColonyTiles.
-
exportData
protected final java.util.Map<java.lang.String,ExportData> exportData
A map of ExportData, indexed by the ids of GoodsTypes.
-
liberty
protected int liberty
The number of liberty points. Liberty points are an abstract game concept. They are generated by but are not identical to bells, and subject to further modification.
-
sonsOfLiberty
protected int sonsOfLiberty
The SoL membership this turn.
-
oldSonsOfLiberty
protected int oldSonsOfLiberty
The SoL membership last turn.
-
tories
protected int tories
The number of tories this turn.
-
oldTories
protected int oldTories
The number of tories last turn.
-
productionBonus
protected int productionBonus
The current production bonus.
-
immigration
protected int immigration
The number of immigration points. Immigration points are an abstract game concept. They are generated by but are not identical to crosses.
-
established
protected Turn established
The turn in which this colony was established.
-
buildQueue
protected final BuildQueue<BuildableType> buildQueue
A list of items to be built.
-
populationQueue
protected final BuildQueue<UnitType> populationQueue
The colonists that may be born.
-
displayUnitCount
protected int displayUnitCount
-
productionCache
private final ProductionCache productionCache
Contains information about production and consumption.
-
traceOccupation
private boolean traceOccupation
The occupation tracing status. Do not serialize.
-
BUILD_QUEUE_TAG
private static final java.lang.String BUILD_QUEUE_TAG
- See Also:
- Constant Field Values
-
ESTABLISHED_TAG
private static final java.lang.String ESTABLISHED_TAG
- See Also:
- Constant Field Values
-
IMMIGRATION_TAG
private static final java.lang.String IMMIGRATION_TAG
- See Also:
- Constant Field Values
-
LIBERTY_TAG
private static final java.lang.String LIBERTY_TAG
- See Also:
- Constant Field Values
-
PRODUCTION_BONUS_TAG
private static final java.lang.String PRODUCTION_BONUS_TAG
- See Also:
- Constant Field Values
-
NAME_TAG
private static final java.lang.String NAME_TAG
- See Also:
- Constant Field Values
-
OLD_SONS_OF_LIBERTY_TAG
private static final java.lang.String OLD_SONS_OF_LIBERTY_TAG
- See Also:
- Constant Field Values
-
OLD_TORIES_TAG
private static final java.lang.String OLD_TORIES_TAG
- See Also:
- Constant Field Values
-
POPULATION_QUEUE_TAG
private static final java.lang.String POPULATION_QUEUE_TAG
- See Also:
- Constant Field Values
-
SONS_OF_LIBERTY_TAG
private static final java.lang.String SONS_OF_LIBERTY_TAG
- See Also:
- Constant Field Values
-
TORIES_TAG
private static final java.lang.String TORIES_TAG
- See Also:
- Constant Field Values
-
UNIT_COUNT_TAG
private static final java.lang.String UNIT_COUNT_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Colony
protected Colony(Game game, Player owner, java.lang.String name, Tile tile)
Constructor for ServerColony.- Parameters:
game
- The enclosingGame
.owner
- ThePlayer
owning thisColony
.name
- The name of the newColony
.tile
- The containingTile
.
-
Colony
public Colony(Game game, java.lang.String id)
Create a newColony
with the given identifier. The object should later be initialized by calling eitherFreeColGameObject.readFromXML(FreeColXMLReader)
.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getBuildings
public java.util.List<Building> getBuildings()
Get a list of everyBuilding
in thisColony
.- Returns:
- A list of
Building
s.
-
getBuilding
public Building getBuilding(BuildingType type)
Get building of the specified general type (note: *not* necessarily the exact building type supplied, but the building present in the colony that is a descendant of the ultimate ancestor of the specified type).- Parameters:
type
- The type of the building to get.- Returns:
- The
Building
found.
-
setBuildingMap
protected void setBuildingMap(java.util.List<Building> buildings)
Reset the building map.- Parameters:
buildings
- The list of buildings to use.
-
clearBuildingMap
protected void clearBuildingMap()
Clear the building map.
-
getColonyTiles
public java.util.List<ColonyTile> getColonyTiles()
- Returns:
- A list of
ColonyTile
s. - See Also:
ColonyTile
-
setColonyTiles
protected void setColonyTiles(java.util.List<ColonyTile> colonyTiles)
Set the colony tile list.- Parameters:
colonyTiles
- The new list ofColonyTile
s.
-
clearColonyTiles
private void clearColonyTiles()
Clear the colony tiles.
-
getColonyTile
public ColonyTile getColonyTile(Tile tile)
Get theColonyTile
matching the givenTile
.- Parameters:
tile
- TheTile
to check.- Returns:
- The corresponding
ColonyTile
, or null if not found.
-
getExportData
protected java.util.Collection<ExportData> getExportData()
Get the export data.- Returns:
- The list of
ExportData
.
-
setExportData
protected void setExportData(java.util.Collection<ExportData> exportData)
Set the export data.- Parameters:
exportData
- The new list ofExportData
.
-
getExportData
public ExportData getExportData(GoodsType goodsType)
Get the export date for a goods type.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The required
ExportData
.
-
setExportData
public final void setExportData(ExportData newExportData)
Set some export data.- Parameters:
newExportData
- A newExportData
value.
-
getSonsOfLiberty
protected int getSonsOfLiberty()
-
getOldSonsOfLiberty
protected int getOldSonsOfLiberty()
-
getTories
protected int getTories()
-
getOldTories
protected int getOldTories()
-
getProductionBonus
public int getProductionBonus()
Gets the production bonus of the colony.- Returns:
- The current production bonus of the colony.
-
setProductionBonus
public void setProductionBonus(int productionBonus)
Sets the production bonus of the colony. Only public for the convenience of the test suite.- Parameters:
productionBonus
- The new production bonus of the colony.
-
modifyImmigration
public void modifyImmigration(int amount)
Modify the immigration points by amount given.- Parameters:
amount
- An amount of immigration.
-
getEstablished
public Turn getEstablished()
Get the turn this colony was established.- Returns:
- The establishment
Turn
.
-
setEstablished
public void setEstablished(Turn newEstablished)
Set the turn of establishment.- Parameters:
newEstablished
- The newTurn
of establishment.
-
getBuildQueue
public java.util.List<BuildableType> getBuildQueue()
Get the build queue contents.- Returns:
- A list of
Buildable
s.
-
setBuildQueue
public void setBuildQueue(java.util.List<BuildableType> buildQueue)
Set the build queue.- Parameters:
buildQueue
- A list of new values for the build queue.
-
getPopulationQueue
public java.util.List<UnitType> getPopulationQueue()
Get the population queue contents.- Returns:
- A list of
Buildable
s.
-
setPopulationQueue
public void setPopulationQueue(java.util.List<UnitType> populationQueue)
Set the population queue.- Parameters:
populationQueue
- A list of new values for the population queue.
-
getDisplayUnitCount
public int getDisplayUnitCount()
Get the display unit count.- Returns:
- The explicit unit count for display purposes.
-
setDisplayUnitCount
public void setDisplayUnitCount(int count)
Sets the apparent number of units at this colony. Used in client enemy colonies- Parameters:
count
- The new apparent number ofUnit
s at this colony.
-
getOccupationTrace
public boolean getOccupationTrace()
Gets the occupation tracing status.- Returns:
- The occupation tracing status.
-
setOccupationTrace
public boolean setOccupationTrace(boolean trace)
Sets the occupation tracing status.- Parameters:
trace
- The new occupation tracing status.- Returns:
- The original occupation tracing status.
-
accumulateChoices
private void accumulateChoices(java.util.Collection<GoodsType> workTypes, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)
-
accumulateChoice
private void accumulateChoice(GoodsType workType, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)
-
getWorkTypeChoices
public java.util.List<java.util.Collection<GoodsType>> getWorkTypeChoices(Unit unit, boolean userMode)
Get a list of collections of goods types, in order of priority to try to produce in this colony by a given unit.- Parameters:
unit
- TheUnit
to check.userMode
- If a user requested this, favour the current work type, if not favour goods that the unit requires.- Returns:
- The list of collections of
GoodsType
s.
-
getOccupationFor
private Occupation getOccupationFor(Unit unit, java.util.Collection<GoodsType> workTypes, LogBuilder lb)
Gets the best occupation for a given unit to produce one of a given set of goods types.- Parameters:
unit
- TheUnit
to find anOccupation
for.workTypes
- A collection ofGoodsType
to consider producing.lb
- ALogBuilder
to log to.- Returns:
- An
Occupation
for the given unit, or null if none found.
-
getOccupationFor
private Occupation getOccupationFor(Unit unit, boolean userMode, LogBuilder lb)
Gets the best occupation for a given unit.- Parameters:
unit
- TheUnit
to find anOccupation
for.userMode
- If a user requested this, favour the current work type, if not favour goods that the unit requires.lb
- ALogBuilder
to log to.- Returns:
- An
Occupation
for the given unit, or null if none found.
-
getOccupationFor
private Occupation getOccupationFor(Unit unit, java.util.Collection<GoodsType> workTypes)
Gets the best occupation for a given unit to produce one of a given set of goods types.- Parameters:
unit
- TheUnit
to find anOccupation
for.workTypes
- A collection ofGoodsType
to consider producing.- Returns:
- An
Occupation
for the given unit, or null if none found.
-
getOccupationFor
private Occupation getOccupationFor(Unit unit, boolean userMode)
Gets the best occupation for a given unit.- Parameters:
unit
- TheUnit
to find anOccupation
for.userMode
- If a user requested this, favour the current work type, if not favour goods that the unit requires.- Returns:
- An
Occupation
for the given unit, or null if none found.
-
getAllWorkLocationsList
public java.util.List<WorkLocation> getAllWorkLocationsList()
Gets a list of every work location in this colony.- Returns:
- The list of work locations.
-
getAllWorkLocations
public java.util.stream.Stream<WorkLocation> getAllWorkLocations()
Gets a stream of every work location in this colony.- Returns:
- The stream of work locations.
-
getAvailableWorkLocationsList
public java.util.List<WorkLocation> getAvailableWorkLocationsList()
Gets a list of all freely available work locations in this colony.- Returns:
- The list of available
WorkLocation
s.
-
getAvailableWorkLocations
public java.util.stream.Stream<WorkLocation> getAvailableWorkLocations()
Get a stream of all freely available work locations in this colony.- Returns:
- The stream of available
WorkLocation
s.
-
getCurrentWorkLocationsList
public java.util.List<WorkLocation> getCurrentWorkLocationsList()
Gets a list of all current work locations in this colony.- Returns:
- The list of current
WorkLocation
s.
-
getCurrentWorkLocations
public java.util.stream.Stream<WorkLocation> getCurrentWorkLocations()
Get a stream of all current work locations in this colony.- Returns:
- The stream of current
WorkLocation
s.
-
addBuilding
public boolean addBuilding(Building building)
Add a Building to this Colony. Lower level routine, do not use directly in-game (use buildBuilding). Used for serialization and public for the test suite. -til: Could change the tile appearance if the building is stockade-type- Parameters:
building
- TheBuilding
to build.- Returns:
- True if the building was added.
-
removeBuilding
protected boolean removeBuilding(Building building)
Remove a building from this Colony. -til: Could change the tile appearance if the building is stockade-type- Parameters:
building
- TheBuilding
to remove.- Returns:
- True if the building was removed.
-
addColonyTile
private void addColonyTile(ColonyTile ct)
Add a colony tile.- Parameters:
ct
- TheColonyTile
to add.
-
getWorkLocationWithAbility
public WorkLocation getWorkLocationWithAbility(java.lang.String ability)
Gets a work location with a given ability.- Parameters:
ability
- An ability key.- Returns:
- A
WorkLocation
with the requiredAbility
, or null if not found.
-
getWorkLocationWithAbility
public <T extends WorkLocation> T getWorkLocationWithAbility(java.lang.String ability, java.lang.Class<T> returnClass)
Gets a work location of a specific class with a given ability.- Type Parameters:
T
- The actual return type.- Parameters:
ability
- An ability key.returnClass
- The expected subclass.- Returns:
- A
WorkLocation
with the requiredAbility
, or null if not found.
-
getWorkLocationWithModifier
public WorkLocation getWorkLocationWithModifier(java.lang.String modifier)
Gets a work location with a given modifier.- Parameters:
modifier
- A modifier key.- Returns:
- A
WorkLocation
with the requiredModifier
, or null if not found.
-
getWorkLocationWithModifier
public <T extends WorkLocation> T getWorkLocationWithModifier(java.lang.String modifier, java.lang.Class<T> returnClass)
Gets a work location of a specific class with a given modifier.- Type Parameters:
T
- The actual return type.- Parameters:
modifier
- A modifier key.returnClass
- The expected subclass.- Returns:
- A
WorkLocation
with the requiredModifier
, or null if not found.
-
getWorkLocationsForConsuming
public java.util.List<WorkLocation> getWorkLocationsForConsuming(GoodsType goodsType)
Collect the work locations for consuming a given type of goods.- Parameters:
goodsType
- TheGoodsType
to consume.- Returns:
- A list of
WorkLocation
s which consume the given type of goods.
-
getWorkLocationsForProducing
public java.util.List<WorkLocation> getWorkLocationsForProducing(GoodsType goodsType)
Collect the work locations for producing a given type of goods.- Parameters:
goodsType
- TheGoodsType
to produce.- Returns:
- A list of
WorkLocation
s which produce the given type of goods.
-
getWorkLocationForProducing
public WorkLocation getWorkLocationForProducing(GoodsType goodsType)
Find a work location for producing a given type of goods. Beware that this may not be the optimal location for the production, for whichgetWorkLocationFor(net.sf.freecol.common.model.Unit, net.sf.freecol.common.model.GoodsType)
is better.- Parameters:
goodsType
- TheGoodsType
to produce.- Returns:
- A
WorkLocation
s which produces the given type of goods, or null if not found.
-
getWorkLocationFor
public WorkLocation getWorkLocationFor(Unit unit, GoodsType goodsType)
Gets the work location best suited for the given unit to produce a type of goods.- Parameters:
unit
- TheUnit
to get the building for.goodsType
- TheGoodsType
to produce.- Returns:
- The best
WorkLocation
found.
-
getWorkLocationFor
public WorkLocation getWorkLocationFor(Unit unit)
Gets the work location best suited for the given unit.- Parameters:
unit
- TheUnit
to check for.- Returns:
- The best
WorkLocation
found.
-
isTileInUse
public boolean isTileInUse(Tile tile)
Is a tile actually in use by this colony?- Parameters:
tile
- TheTile
to test.- Returns:
- True if this tile is actively in use by this colony.
-
getWarehouse
public Building getWarehouse()
Get the warehouse-type building in this colony.- Returns:
- The warehouse
Building
.
-
hasStockade
public boolean hasStockade()
Does this colony have a stockade?- Returns:
- True if the colony has a stockade.
-
getStockade
public Building getStockade()
Gets the stockade building in this colony.- Returns:
- The stockade
Building
.
-
getStockadeKey
public java.lang.String getStockadeKey()
Gets the stockade key, as should be visible to the owner or a player that can see this colony.- Returns:
- The stockade key, or null if no stockade-building is present.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Get a weighted list of natural disasters than can strike this colony. This list comprises all natural disasters that can strike the colony's tiles.- Returns:
- A stream of
Disaster
s.
-
isAutomaticBuild
public boolean isAutomaticBuild(BuildingType buildingType)
Is a building type able to be automatically built at no cost. True when the player has a modifier that collapses the cost to zero.- Parameters:
buildingType
- aBuildingType
value- Returns:
- True if the building is available at zero cost.
-
getBuildableUnits
public java.util.List<UnitType> getBuildableUnits()
Gets a list of every unit type this colony may build.- Returns:
- A list of buildable
UnitType
s.
-
getTurnsToComplete
public int getTurnsToComplete(BuildableType buildable)
Returns how many turns it would take to build the givenBuildableType
.- Parameters:
buildable
- TheBuildableType
to build.- Returns:
- The number of turns to build the buildable, negative if some goods are not being built, UNDEFINED if none is.
-
getTurnsToComplete
public int getTurnsToComplete(BuildableType buildable, AbstractGoods needed)
Returns how many turns it would take to build the givenBuildableType
.- Parameters:
buildable
- TheBuildableType
to build.needed
- TheAbstractGoods
needed to continue the build.- Returns:
- The number of turns to build the buildable (which may be zero, UNDEFINED if no useful work is being done, negative if some requirement is or will block completion (value is the negation of (turns-to-blockage + 1), and if the needed argument is supplied it is set to the goods deficit).
-
canBreed
public boolean canBreed(GoodsType goodsType)
Returnstrue
if this Colony can breed the given type of Goods. Only animals (such as horses) are expected to be breedable.- Parameters:
goodsType
- aGoodsType
value- Returns:
- a
boolean
value
-
getCurrentlyBuilding
public BuildableType getCurrentlyBuilding()
Gets the type of building currently being built.- Returns:
- The type of building currently being built.
-
setCurrentlyBuilding
public void setCurrentlyBuilding(BuildableType buildable)
Sets the current type of buildable to be built and if it is a building insist that there is only one in the queue.- Parameters:
buildable
- TheBuildableType
to build.
-
canBuild
public boolean canBuild()
-
canBuild
public boolean canBuild(BuildableType buildableType)
Returns true if this Colony can build the given BuildableType.- Parameters:
buildableType
- aBuildableType
value- Returns:
- a
boolean
value
-
getNoBuildReason
public Colony.NoBuildReason getNoBuildReason(BuildableType buildableType, java.util.List<BuildableType> assumeBuilt)
Return the reason why the giveBuildableType
can not be built.- Parameters:
buildableType
- ABuildableType
to build.assumeBuilt
- An optional list of other buildable types which can be assumed to be built, for the benefit of build queue checks.- Returns:
- A
NoBuildReason
value decribing the failure, includingNoBuildReason.NONE
on success.
-
getPriceForBuilding
public int getPriceForBuilding()
Returns the price for the remaining hammers and tools for theBuilding
that is currently being built.- Returns:
- The price.
- See Also:
InGameController.payForBuilding(net.sf.freecol.common.model.Colony)
-
getPriceForBuilding
public int getPriceForBuilding(BuildableType type)
Gets the price for the remaining resources to build a given buildable.- Parameters:
type
- TheBuildableType
to build.- Returns:
- The price.
- See Also:
InGameController.payForBuilding(net.sf.freecol.common.model.Colony)
-
priceGoodsForBuilding
public int priceGoodsForBuilding(java.util.List<AbstractGoods> required)
Gets a price for a map of resources to build a given buildable.- Parameters:
required
- A list of requiredAbstractGoods
.- Returns:
- The price.
- See Also:
InGameController.payForBuilding(net.sf.freecol.common.model.Colony)
-
getRequiredGoods
public java.util.List<AbstractGoods> getRequiredGoods(BuildableType type)
Gets a map of the types of goods and amount thereof required to finish a buildable in this colony.- Parameters:
type
- TheBuildableType
to build.- Returns:
- The map to completion.
-
getFullRequiredGoods
public java.util.List<AbstractGoods> getFullRequiredGoods(BuildableType buildable)
Gets all the goods required to complete a build. The list includes the prerequisite raw materials as well as the direct requirements (i.e. hammers, tools). If enough of a required goods is present in the colony, then that type is not returned. Take care to order types with raw materials first so that we can prioritize gathering what is required before manufacturing. Public for the benefit of AI planning and the test suite.- Parameters:
buildable
- TheBuildableType
to consider.- Returns:
- A list of required abstract goods.
-
canPayToFinishBuilding
public boolean canPayToFinishBuilding()
Check if the owner can buy the remaining hammers and tools for theBuilding
that is currently being built.- Returns:
- True if the user can afford to pay.
- Throws:
java.lang.IllegalStateException
- If the owner of thisColony
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 theBuilding
given.- Parameters:
buildableType
- aBuildableType
value- Returns:
- True if the user can afford to pay.
- Throws:
java.lang.IllegalStateException
- If the owner of thisColony
has an insufficient amount of gold.- See Also:
getPriceForBuilding()
-
addLiberty
public void addLiberty(int amount)
Adds to the liberty points by increasing the liberty goods present. Used only by DebugMenu.- Parameters:
amount
- The number of liberty to add.
-
modifyLiberty
public void modifyLiberty(int amount)
Modify the liberty points by amount given.- Parameters:
amount
- An amount of liberty.
-
updateSoL
public void updateSoL()
Calculates the current SoL membership of the colony based on the liberty value and colonists.
-
calculateSoLPercentage
private int calculateSoLPercentage(int uc, int liberty)
Calculate the SoL membership percentage of the colony based on the number of colonists and liberty.- Parameters:
uc
- The proposed number of units in the colony.liberty
- The amount of liberty.- Returns:
- The percentage of SoLs, negative if not calculable.
-
getSoLPercentage
public int getSoLPercentage()
Calculate the SoL membership percentage of a colony.- Returns:
- The percentage of SoLs, negative if not calculable.
-
calculateRebels
public static int calculateRebels(int uc, int solPercent)
Calculate the number of rebels given a SoL percentage and unit count.- Parameters:
uc
- The number of units in the colony.solPercent
- The percentage of SoLs.- Returns:
- The number of rebels.
-
getTory
public int getTory()
Gets the Tory membership percentage of the colony.- Returns:
- The current Tory membership of the colony.
-
updateProductionBonus
protected boolean updateProductionBonus()
Update the colony's production bonus.- Returns:
- True if the bonus changed.
-
getPreferredSizeChange
public int getPreferredSizeChange()
Gets the number of units that would be good to add/remove from this colony. That is the number of extra units that can be added without damaging the production bonus, or the number of units to remove to improve it.- Returns:
- The number of units to add to the colony, or if negative the negation of the number of units to remove.
-
getUnitsToAdd
public int getUnitsToAdd()
-
getUnitsToRemove
public int getUnitsToRemove()
-
joinColony
public boolean joinColony(Unit unit)
Special routine to handle non-specific add of unit to colony.- Parameters:
unit
- TheUnit
to add.- Returns:
- True if the add succeeds.
-
canReducePopulation
public boolean canReducePopulation()
Can this colony reduce its population voluntarily? This is generally the case, but can be prevented by buildings such as the stockade in classic mode.- Returns:
- True if the population can be reduced.
-
getReducePopulationMessage
public StringTemplate getReducePopulationMessage()
Gets the message to display if the colony can not reduce its population.- Returns:
- A
StringTemplate
describing why a colony can not reduce its population, or null if it can.
-
getUnbuildableMessage
public ModelMessage getUnbuildableMessage(BuildableType buildable)
Gets the message to display if a colony can not build something.- Parameters:
buildable
- TheBuildableType
that can not be built.- Returns:
- A
ModelMessage
describing the build failure.
-
governmentChange
public int governmentChange(int unitCount)
Returns 1, 0, or -1 to indicate that government would improve, remain the same, or deteriorate if the colony had the given population.- Parameters:
unitCount
- The proposed population for the colony.- Returns:
- 1, 0 or -1.
-
checkForGovMgtChangeMessage
public ModelMessage checkForGovMgtChangeMessage()
-
updatePopulation
public void updatePopulation()
Signal to the colony that its population is changing. Called from Unit.setLocation when a unit moves into or out of this colony, but *not* if it is moving within the colony.
-
updateEducation
public void updateEducation(Unit unit, boolean enable)
Signal to the colony that a unit is moving in or out or changing its internal work location to one with a different teaching ability. This requires either checking for a new teacher or student, or clearing any existing education relationships.- Parameters:
unit
- TheUnit
that is changing its education state.enable
- If true, check for new education opportunities, otherwise clear existing ones.
-
isUndead
public boolean isUndead()
Does this colony have undead units?- Returns:
- True if this colony has undead units.
-
getApparentUnitCount
public int getApparentUnitCount()
Gets the apparent number of units at this colony. Used in client enemy colonies- Returns:
- The apparent number of
Unit
s at this colony.
-
getBestDefenderType
public UnitType getBestDefenderType()
Gets the best defender type available to this colony.- Returns:
- The best available defender type.
-
getTotalDefencePower
public double getTotalDefencePower()
Gets the total defence power.- Returns:
- The total defence power.
-
canBePillaged
public boolean canBePillaged(Unit attacker)
Determines whether this colony is sufficiently unprotected and contains something worth pillaging. To be called by CombatModels when the attacker has defeated an unarmed colony defender.- Parameters:
attacker
- TheUnit
that has defeated the defender.- Returns:
- True if the attacker can pillage this colony.
-
canBePlundered
public boolean canBePlundered()
Checks if this colony can be plundered. That is, can it yield non-zero gold.- Returns:
- True if at least one piece of gold can be plundered from this colony.
-
getBurnableBuildings
public java.util.List<Building> getBurnableBuildings()
Gets the buildings in this colony that could be burned by a raid.- Returns:
- A list of burnable buildings.
-
getLootableGoodsList
public java.util.List<Goods> getLootableGoodsList()
Gets a list of all stored goods in this colony, suitable for being looted.- Returns:
- A list of lootable goods in this colony.
-
isUnderSiege
public boolean isUnderSiege()
Decide if the number of enemy combat units on all tiles that belong to the colony exceeds the number of friendly combat units. At the moment, only the colony owner's own units are considered friendly, but that could be extended to include the units of allied players. FIXME: if a colony is under siege, it should not be possible to put units outside the colony, unless those units are armed.- Returns:
- Whether the colony is under siege.
-
evaluateFor
public int evaluateFor(Player player)
Evaluate this colony for a given player.- Parameters:
player
- ThePlayer
to evaluate for.- Returns:
- A value for the player.
-
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.stream.Stream<Unit> getTeachers()
Gets a list of all teachers currently present in the school building.- Returns:
- A stream of teacher
Unit
s.
-
findTeacher
public Unit findTeacher(Unit student)
Find a teacher for the specified student. Do not search if ALLOW_STUDENT_SELECTION is true--- it is the player's job then.- Parameters:
student
- The studentUnit
that needs a teacher.- Returns:
- A potential teacher, or null of none found.
-
findStudent
public Unit findStudent(Unit teacher)
Find a student for the specified teacher. Do not search if ALLOW_STUDENT_SELECTION is true--- its the player's job then.- Parameters:
teacher
- The teacherUnit
that needs a student.- Returns:
- A potential student, or null of none found.
-
isProducing
public boolean isProducing(GoodsType goodsType)
Does this colony produce a goods type? This is more reliable than checking net or total production, either of which might be cancelling to zero.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- True if goods type is produced.
-
isConsuming
public boolean isConsuming(GoodsType goodsType)
Does this colony consume a goods type? This is more reliable than checking net or total consumption, either of which might be cancelling to zero.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- True if goods type is consumed.
-
getConsumers
public java.util.List<Consumer> getConsumers()
Get a list of allConsumer
s in the colony sorted by priority. Consumers include all object that consume goods, e.g. Units, Buildings and BuildQueues.- Returns:
- a list of consumers
-
getConsumptionOf
public int getConsumptionOf(GoodsType goodsType)
Returns the number of goods of a given type used by the settlement each turn.- Overrides:
getConsumptionOf
in classSettlement
- Parameters:
goodsType
-GoodsType
values- Returns:
- an
int
value
-
getFoodProduction
public int getFoodProduction()
Gets the combined production of all food types.- Returns:
- an
int
value
-
getStarvationTurns
public int getStarvationTurns()
Get the number of turns before starvation occurs at this colony with current production levels.- Returns:
- The number of turns before starvation occurs, or negative if it will not.
-
getNewColonistTurns
public int getNewColonistTurns()
Get the number of turns before a new colonist will be born in this colony with current production levels.- Returns:
- A number of turns, or negative if no colonist will be born.
-
getProductionModifiers
public java.util.stream.Stream<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType, WorkLocation wl)
Get the current productionModifier
, which is generated from the current production bonus.- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
to do the work.wl
- TheWorkLocation
- Returns:
- A stream of suitable
Modifier
s.
-
getNetProductionOf
public int getNetProductionOf(GoodsType goodsType)
Get the net production of the given goods type. (Also part of interface TradeLocation)- Parameters:
goodsType
- aGoodsType
value- Returns:
- an
int
value
-
isProductive
public boolean isProductive(WorkLocation workLocation)
Is a work location productive?- Parameters:
workLocation
- TheWorkLocation
to check.- Returns:
- True if something is being produced at the
WorkLocation
.
-
getAdjustedNetProductionOf
public int getAdjustedNetProductionOf(GoodsType goodsType)
Returns the net production of the given GoodsType adjusted by the possible consumption of BuildQueues.- Parameters:
goodsType
- aGoodsType
value- Returns:
- an
int
value
-
getProductionMap
protected TypeCountMap<GoodsType> getProductionMap()
Gets a copy of the current production map. Useful in the server at the point net production is applied to a colony.- Returns:
- A copy of the current production map.
-
getProductionInfo
public ProductionInfo getProductionInfo(java.lang.Object object)
Returns the ProductionInfo for the given Object.- Parameters:
object
- anObject
value- Returns:
- a
ProductionInfo
value
-
updateProductionTypes
public void updateProductionTypes()
Update all the production types. Called at initialization, to default to something rational when nothing was specified. This can not be done until all the tiles are present.
-
canProduce
public boolean canProduce(GoodsType goodsType)
Can this colony produce certain goods?- Parameters:
goodsType
- TheGoodsType
to check production of.- Returns:
- True if the goods can be produced.
-
getTileImprovementSuggestions
public java.util.List<Colony.TileImprovementSuggestion> getTileImprovementSuggestions()
Collect suggestions for tiles that need exploration or improvement (which may depend on current use within the colony).- Returns:
- A list of
TileImprovementSuggestion
s.
-
getBetterExpert
public Unit getBetterExpert(Unit expert)
Finds another unit in this colony that would be better at doing the job of the specified unit.- Parameters:
expert
- TheUnit
to consider.- Returns:
- A better expert, or null if none available.
-
getProductionWarnings
public java.util.Collection<StringTemplate> getProductionWarnings(GoodsType goodsType)
Determine if there is a problem with the production of a given goods type.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- A collection of warning messages.
-
getInsufficientProductionMessage
private StringTemplate getInsufficientProductionMessage(ProductionInfo info, AbstractGoods deficit)
Get a message about insufficient production for a building- Parameters:
info
- TheProductionInfo
for the work location.deficit
- TheAbstractGoods
in deficit.- Returns:
- A suitable
StringTemplate
or null if none required.
-
goodsUseful
public boolean goodsUseful(GoodsType goodsType)
Check if a goods type is still useful to this colony. In general, all goods are useful. However post-independence there is no need for more liberty once Sol% reaches 100, nor immigration. Note the latter may change when we implement sailing to other European ports.- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- True if these goods are still useful here.
-
modifySpecialGoods
private void modifySpecialGoods(GoodsType goodsType, int amount)
Special goods need modifiers applied when changed, and immigration accumulates to the owner.- Parameters:
goodsType
- TheGoodsType
to modify.amount
- The amount of modification.
-
copyColony
public Colony copyColony()
Creates a temporary copy of this colony for planning purposes. A simple colony.copy() can not work because all the colony tiles will be left referring to uncopied work tiles which the colony-copy does not own, which prevents them being used as valid work locations. We have to copy the colony tile (which includes the colony), and fix up all the colony tile work tiles to point to copies of the original tile, and fix the ownership of those tiles.- Returns:
- A scratch version of this colony.
-
getCorresponding
public <T extends FreeColObject> T getCorresponding(T fco)
Finds the corresponding FreeColObject from another copy of this colony.- Type Parameters:
T
- The actual return type.- Parameters:
fco
- TheFreeColObject
in the other colony.- Returns:
- The corresponding
FreeColObject
in this colony, or null if not found.
-
getAbilities
public java.util.stream.Stream<Ability> getAbilities(java.lang.String id, FreeColSpecObjectType type, Turn turn)
Gets the set of abilities with the given identifier from this object. Subclasses with complex ability handling should override this as all prior routines are derived from it.- Overrides:
getAbilities
in classFreeColObject
- Parameters:
id
- The object identifier.type
- An optionalFreeColSpecObjectType
the ability applies to.turn
- An optional applicableTurn
.- Returns:
- A set of abilities.
-
getDisposables
public java.util.stream.Stream<FreeColGameObject> getDisposables()
Collect this object and all its subparts that should be disposed of when this object goes away. Overriding routines should call upwards towards this routine, arranging that the object itself is last.- Overrides:
getDisposables
in classGoodsLocation
- Returns:
- A stream of
FreeColGameObject
s to dispose of.
-
getLocationLabelFor
public StringTemplate getLocationLabelFor(Player player)
Get a label for this location for a particular player.- Specified by:
getLocationLabelFor
in interfaceLocation
- Overrides:
getLocationLabelFor
in classUnitLocation
- Parameters:
player
- ThePlayer
to return the name for.- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatable
to this Location.- Specified by:
add
in interfaceLocation
- Overrides:
add
in classGoodsLocation
- Parameters:
locatable
- TheLocatable
to add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatable
from this Location.- Specified by:
remove
in interfaceLocation
- Overrides:
remove
in classGoodsLocation
- Parameters:
locatable
- TheLocatable
to remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.- Specified by:
contains
in interfaceLocation
- Overrides:
contains
in classGoodsLocation
- Parameters:
locatable
- TheLocatable
to test the presence of.- Returns:
- True if the locatable is present at this location.
-
getUnitCount
public int getUnitCount()
Gets the number of units at this Location.- Specified by:
getUnitCount
in interfaceLocation
- Overrides:
getUnitCount
in classUnitLocation
- Returns:
- The number of units at this Location.
-
getUnits
public java.util.stream.Stream<Unit> getUnits()
Gets a stream of all the units present at this location.- Specified by:
getUnits
in interfaceLocation
- Overrides:
getUnits
in classUnitLocation
- Returns:
- A stream of all the units at this location.
-
getUnitList
public java.util.List<Unit> getUnitList()
Gets a list of all the units present at this location.- Specified by:
getUnitList
in interfaceLocation
- Overrides:
getUnitList
in classUnitLocation
- Returns:
- A list of all the units at this location.
-
getColony
public final Colony getColony()
Get the colony at this location.- Specified by:
getColony
in interfaceLocation
- Overrides:
getColony
in classUnitLocation
- Returns:
- A
Colony
at this location if any, or null if none found.
-
up
public Location up()
Promote this location to a more meaningful one if possible. For example: a settlement is more meaningful than the tile it occupies.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Specified by:
toShortString
in interfaceLocation
- Returns:
- A short description.
-
invalidateCache
public void invalidateCache()
Invalidate any cache dependent on the goods levels.- Specified by:
invalidateCache
in classGoodsLocation
-
getGoodsCapacity
public int getGoodsCapacity()
Gets the maximum number ofGoods
this Location can hold.- Specified by:
getGoodsCapacity
in classGoodsLocation
- Returns:
- The capacity for goods
-
addGoods
public boolean addGoods(GoodsType type, int amount)
Adds a specified amount of a type of goods to this location.- Overrides:
addGoods
in classGoodsLocation
- Parameters:
type
- TheGoodsType
to add.amount
- The amount of goods to add.- Returns:
- True if the goods were added.
-
removeGoods
public Goods removeGoods(GoodsType type, int amount)
Removes a specified amount of a type of Goods from this location.- Overrides:
removeGoods
in classGoodsLocation
- Parameters:
type
- The type of goods to remove.amount
- The amount of goods to remove.- Returns:
- The goods that was removed, which may be less than that requested, or null if none.
-
getImmigration
public int getImmigration()
Gets the immigration points.- Overrides:
getImmigration
in classSettlement
- Returns:
- The current immigration.
-
getLiberty
public int getLiberty()
Gets the liberty points.- Overrides:
getLiberty
in classSettlement
- Returns:
- The current liberty.
-
getDefendingUnit
public Unit getDefendingUnit(Unit attacker)
Gets theUnit
that is currently defending thisSettlement
.- Specified by:
getDefendingUnit
in classSettlement
- Parameters:
attacker
- TheUnit
that is attacking thisSettlement
.- Returns:
- The
Unit
that has been chosen to defend thisSettlement
.
-
getDefenceRatio
public double getDefenceRatio()
Get the ratio between defence at this settlement, and the general settlement size.- Specified by:
getDefenceRatio
in classSettlement
- Returns:
- A ratio of defence power to settlement size.
-
isBadlyDefended
public boolean isBadlyDefended()
Is this settlement insufficiently defended?- Specified by:
isBadlyDefended
in classSettlement
- Returns:
- True if this settlement needs more defence.
-
getPlunderRange
public RandomRange getPlunderRange(Unit attacker)
Gets the range of gold plunderable when this settlement is captured.- Specified by:
getPlunderRange
in classSettlement
- Parameters:
attacker
- TheUnit
that takes the settlement.- Returns:
- A
RandomRange
encapsulating the range of plunder available.
-
getSoL
public int getSoL()
Gets the current Sons of Liberty in this settlement.- Specified by:
getSoL
in classSettlement
- Returns:
- The current SoL.
-
getUpkeep
public int getUpkeep()
Get the amount of gold necessary to maintain all of the settlement's buildings.- Specified by:
getUpkeep
in classSettlement
- Returns:
- The gold required for upkeep.
-
getTotalProductionOf
public int getTotalProductionOf(GoodsType goodsType)
Gets the total production of the given type of goods in this settlement.- Specified by:
getTotalProductionOf
in classSettlement
- Parameters:
goodsType
- The type of goods to get the production for.- Returns:
- The total production of the given type of goods.
-
canProvideGoods
public boolean canProvideGoods(java.util.List<AbstractGoods> requiredGoods)
Determines if this settlement can build the given type of equipment. Unlike priceGoods, this takes goods "reserved" for other purposes into account (e.g. breeding).- Overrides:
canProvideGoods
in classSettlement
- Parameters:
requiredGoods
- A list ofAbstractGoods
- Returns:
- True if the settlement can provide the equipment.
-
hasContacted
public boolean hasContacted(Player player)
Has this settlement contacted a given player? Allow player == null as this is true in the map editor where the user player is moot.- Specified by:
hasContacted
in classSettlement
- Parameters:
player
- The otherPlayer
to check.- Returns:
- True if the settlement has contacted the player.
-
getAlarmLevelLabel
public StringTemplate getAlarmLevelLabel(Player player)
Gets a label indicating the alarm level at this settlement with respect to another player.- Specified by:
getAlarmLevelLabel
in classSettlement
- Parameters:
player
- The otherPlayer
.- Returns:
- A
StringTemplate
describing the alarm.
-
calculateSettlementValue
public int calculateSettlementValue(int value, Unit unit)
Determines the value of a potential attack on aColony
- Specified by:
calculateSettlementValue
in classSettlement
- Parameters:
value
- The previously calculated input value from#scoreSettlementPath(AIUnit, PathNode, Settlement)
unit
- The Unit doing the attacking.- Returns:
- The newly calculated value.
-
returnPresent
private int returnPresent(GoodsType goodsType, int turns)
Calculate the present field.- Parameters:
goodsType
- TheGoodsType
to check for got import/export.turns
- The number of turns before the goods is required.- Returns:
- The amount of goods to export.
-
getAvailableGoodsCount
public int getAvailableGoodsCount(GoodsType goodsType)
Get the amount of a given goods type at this trade location.- Specified by:
getAvailableGoodsCount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.- Returns:
- The amount of goods present.
-
getExportAmount
public int getExportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be exported from this trade location after a given number of turns.- Specified by:
getExportAmount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.turns
- The number of turns before the goods is required.- Returns:
- The amount of goods to export.
-
getImportAmount
public int getImportAmount(GoodsType goodsType, int turns)
Gets the amount of a given goods type that can be imported to this trade location after a given number of turns.- Specified by:
getImportAmount
in interfaceTradeLocation
- Parameters:
goodsType
- TheGoodsType
to check.turns
- The number of turns before the goods will arrive.- Returns:
- The amount of goods to import.
-
getLocationName
public java.lang.String getLocationName(TradeLocation tradeLocation)
Function for returning the name of a TradeLocation- Specified by:
getLocationName
in interfaceTradeLocation
- Parameters:
tradeLocation
- TheTradeLocation
to return the name.- Returns:
- The name.
-
canBeInput
public boolean canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanel- Specified by:
canBeInput
in interfaceTradeLocation
- Returns:
- True if possible, false by default.
-
addPortAbility
protected void addPortAbility()
Add port ability to non-landlocked colonies.
-
checkBuildQueueIntegrity
public Constants.IntegrityType checkBuildQueueIntegrity(boolean fix, LogBuilder lb)
Check the integrity of the build queues. Catches build fails due to broken requirements.- Parameters:
fix
- Fix problems if possible.lb
- An optionalLogBuilder
to log to.- Returns:
- The integrity found.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrity
in classSettlement
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndex
in classFreeColGameObject
- Returns:
- The class index used by
ClientOptions
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classSettlement
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classSettlement
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classSettlement
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
public void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
public void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classSettlement
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-