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 containsBuildings andColonyTiles. The latter represents the tiles around theColonywhere working is possible.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classColony.ColonyChangeEventstatic classColony.NoBuildReasonReasons for not building a buildable.static classColony.TileImprovementSuggestionContainer 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.StringBUILD_QUEUE_TAGprotected java.util.Map<java.lang.String,Building>buildingMapA map of Buildings, indexed by the id of their basic type.protected BuildQueue<BuildableType>buildQueueA list of items to be built.static intCHANGE_UPPER_BOUNDprivate static intCOLONY_CLASS_INDEXClass index for colonies.protected java.util.List<ColonyTile>colonyTilesA list of the ColonyTiles.protected intdisplayUnitCountprotected TurnestablishedThe turn in which this colony was established.private static java.lang.StringESTABLISHED_TAGprotected java.util.Map<java.lang.String,ExportData>exportDataA map of ExportData, indexed by the ids of GoodsTypes.static intFAMINE_TURNSThe number of turns of advanced warning of starvation.protected intimmigrationThe number of immigration points.private static java.lang.StringIMMIGRATION_TAGprotected intlibertyThe number of liberty points.static intLIBERTY_PER_REBELprivate static java.lang.StringLIBERTY_TAGprivate static java.util.logging.Loggerloggerprivate static java.lang.StringNAME_TAGprivate static java.lang.StringOLD_SONS_OF_LIBERTY_TAGprivate static java.lang.StringOLD_TORIES_TAGprotected intoldSonsOfLibertyThe SoL membership last turn.protected intoldToriesThe number of tories last turn.private static java.lang.StringPOPULATION_QUEUE_TAGprotected BuildQueue<UnitType>populationQueueThe colonists that may be born.private static java.lang.StringPRODUCTION_BONUS_TAGprotected intproductionBonusThe current production bonus.private ProductionCacheproductionCacheContains information about production and consumption.static java.lang.StringREARRANGE_COLONYprivate static java.lang.StringSONS_OF_LIBERTY_TAGprotected intsonsOfLibertyThe SoL membership this turn.static java.lang.StringTAGprotected inttoriesThe number of tories this turn.private static java.lang.StringTORIES_TAGprivate booleantraceOccupationThe occupation tracing status.static intTRADE_MARGINNumber of colonies that a player will trade down to.private static java.lang.StringUNIT_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 voidaccumulateChoice(GoodsType workType, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)private voidaccumulateChoices(java.util.Collection<GoodsType> workTypes, java.util.Collection<GoodsType> tried, java.util.List<java.util.Collection<GoodsType>> result)booleanadd(Locatable locatable)Adds aLocatableto this Location.booleanaddBuilding(Building building)Add a Building to this Colony.private voidaddColonyTile(ColonyTile ct)Add a colony tile.booleanaddGoods(GoodsType type, int amount)Adds a specified amount of a type of goods to this location.voidaddLiberty(int amount)Adds to the liberty points by increasing the liberty goods present.protected voidaddPortAbility()Add port ability to non-landlocked colonies.static intcalculateRebels(int uc, int solPercent)Calculate the number of rebels given a SoL percentage and unit count.intcalculateSettlementValue(int value, Unit unit)Determines the value of a potential attack on aColonyprivate intcalculateSoLPercentage(int uc, int liberty)Calculate the SoL membership percentage of the colony based on the number of colonists and liberty.booleancanBeInput()Can a TradeLocation be set as the input location on a TradeRouteInputPanelbooleancanBePillaged(Unit attacker)Determines whether this colony is sufficiently unprotected and contains something worth pillaging.booleancanBePlundered()Checks if this colony can be plundered.booleancanBreed(GoodsType goodsType)Returnstrueif this Colony can breed the given type of Goods.booleancanBuild()booleancanBuild(BuildableType buildableType)Returns true if this Colony can build the given BuildableType.booleancanPayToFinishBuilding()Check if the owner can buy the remaining hammers and tools for theBuildingthat is currently being built.booleancanPayToFinishBuilding(BuildableType buildableType)Check if the owner can buy the remaining hammers and tools for theBuildinggiven.booleancanProduce(GoodsType goodsType)Can this colony produce certain goods?booleancanProvideGoods(java.util.List<AbstractGoods> requiredGoods)Determines if this settlement can build the given type of equipment.booleancanReducePopulation()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.booleancanTrain(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.booleancanTrain(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.IntegrityTypecheckBuildQueueIntegrity(boolean fix, LogBuilder lb)Check the integrity of the build queues.ModelMessagecheckForGovMgtChangeMessage()Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.protected voidclearBuildingMap()Clear the building map.private voidclearColonyTiles()Clear the colony tiles.booleancontains(Locatable locatable)Checks if thisLocationcontains the specifiedLocatable.ColonycopyColony()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.intevaluateFor(Player player)Evaluate this colony for a given player.UnitfindStudent(Unit teacher)Find a student for the specified teacher.UnitfindTeacher(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.intgetAdjustedNetProductionOf(GoodsType goodsType)Returns the net production of the given GoodsType adjusted by the possible consumption of BuildQueues.StringTemplategetAlarmLevelLabel(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.intgetApparentUnitCount()Gets the apparent number of units at this colony.intgetAvailableGoodsCount(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.UnitTypegetBestDefenderType()Gets the best defender type available to this colony.UnitgetBetterExpert(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.BuildinggetBuilding(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 everyBuildingin 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.intgetClassIndex()Accessor for the class index.ColonygetColony()Get the colony at this location.ColonyTilegetColonyTile(Tile tile)Get theColonyTilematching the givenTile.java.util.List<ColonyTile>getColonyTiles()java.util.List<Consumer>getConsumers()Get a list of allConsumers in the colony sorted by priority.intgetConsumptionOf(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.BuildableTypegetCurrentlyBuilding()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.doublegetDefenceRatio()Get the ratio between defence at this settlement, and the general settlement size.UnitgetDefendingUnit(Unit attacker)Gets theUnitthat is currently defending thisSettlement.java.util.stream.Stream<RandomChoice<Disaster>>getDisasterChoices()Get a weighted list of natural disasters than can strike this colony.intgetDisplayUnitCount()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.TurngetEstablished()Get the turn this colony was established.intgetExportAmount(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.ExportDatagetExportData(GoodsType goodsType)Get the export date for a goods type.intgetFoodProduction()Gets the combined production of all food types.java.util.List<AbstractGoods>getFullRequiredGoods(BuildableType buildable)Gets all the goods required to complete a build.intgetGoodsCapacity()Gets the maximum number ofGoodsthis Location can hold.intgetImmigration()Gets the immigration points.intgetImportAmount(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 StringTemplategetInsufficientProductionMessage(ProductionInfo info, AbstractGoods deficit)Get a message about insufficient production for a buildingintgetLiberty()Gets the liberty points.StringTemplategetLocationLabelFor(Player player)Get a label for this location for a particular player.java.lang.StringgetLocationName(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.intgetNetProductionOf(GoodsType goodsType)Get the net production of the given goods type.intgetNewColonistTurns()Get the number of turns before a new colonist will be born in this colony with current production levels.Colony.NoBuildReasongetNoBuildReason(BuildableType buildableType, java.util.List<BuildableType> assumeBuilt)Return the reason why the giveBuildableTypecan not be built.private OccupationgetOccupationFor(Unit unit, boolean userMode)Gets the best occupation for a given unit.private OccupationgetOccupationFor(Unit unit, boolean userMode, LogBuilder lb)Gets the best occupation for a given unit.private OccupationgetOccupationFor(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 OccupationgetOccupationFor(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.booleangetOccupationTrace()Gets the occupation tracing status.protected intgetOldSonsOfLiberty()protected intgetOldTories()RandomRangegetPlunderRange(Unit attacker)Gets the range of gold plunderable when this settlement is captured.java.util.List<UnitType>getPopulationQueue()Get the population queue contents.intgetPreferredSizeChange()Gets the number of units that would be good to add/remove from this colony.intgetPriceForBuilding()Returns the price for the remaining hammers and tools for theBuildingthat is currently being built.intgetPriceForBuilding(BuildableType type)Gets the price for the remaining resources to build a given buildable.intgetProductionBonus()Gets the production bonus of the colony.ProductionInfogetProductionInfo(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.StringTemplategetReducePopulationMessage()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.intgetSoL()Gets the current Sons of Liberty in this settlement.intgetSoLPercentage()Calculate the SoL membership percentage of a colony.protected intgetSonsOfLiberty()intgetStarvationTurns()Get the number of turns before starvation occurs at this colony with current production levels.BuildinggetStockade()Gets the stockade building in this colony.java.lang.StringgetStockadeKey()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 intgetTories()intgetTory()Gets the Tory membership percentage of the colony.doublegetTotalDefencePower()Gets the total defence power.intgetTotalProductionOf(GoodsType goodsType)Gets the total production of the given type of goods in this settlement.intgetTurnsToComplete(BuildableType buildable)Returns how many turns it would take to build the givenBuildableType.intgetTurnsToComplete(BuildableType buildable, AbstractGoods needed)Returns how many turns it would take to build the givenBuildableType.ModelMessagegetUnbuildableMessage(BuildableType buildable)Gets the message to display if a colony can not build something.intgetUnitCount()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.intgetUnitsToAdd()intgetUnitsToRemove()intgetUpkeep()Get the amount of gold necessary to maintain all of the settlement's buildings.BuildinggetWarehouse()Get the warehouse-type building in this colony.WorkLocationgetWorkLocationFor(Unit unit)Gets the work location best suited for the given unit.WorkLocationgetWorkLocationFor(Unit unit, GoodsType goodsType)Gets the work location best suited for the given unit to produce a type of goods.WorkLocationgetWorkLocationForProducing(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.WorkLocationgetWorkLocationWithAbility(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.WorkLocationgetWorkLocationWithModifier(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.StringgetXMLTagName()Get the serialization tag for this object.booleangoodsUseful(GoodsType goodsType)Check if a goods type is still useful to this colony.intgovernmentChange(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.booleanhasContacted(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.booleanhasStockade()Does this colony have a stockade?voidinvalidateCache()Invalidate any cache dependent on the goods levels.booleanisAutomaticBuild(BuildingType buildingType)Is a building type able to be automatically built at no cost.booleanisBadlyDefended()Is this settlement insufficiently defended?booleanisConsuming(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.booleanisProducing(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.booleanisProductive(WorkLocation workLocation)Is a work location productive?booleanisTileInUse(Tile tile)Is a tile actually in use by this colony?booleanisUndead()Does this colony have undead units?booleanisUnderSiege()Decide if the number of enemy combat units on all tiles that belong to the colony exceeds the number of friendly combat units.booleanjoinColony(Unit unit)Special routine to handle non-specific add of unit to colony.voidmodifyImmigration(int amount)Modify the immigration points by amount given.voidmodifyLiberty(int amount)Modify the liberty points by amount given.private voidmodifySpecialGoods(GoodsType goodsType, int amount)Special goods need modifiers applied when changed, and immigration accumulates to the owner.intpriceGoodsForBuilding(java.util.List<AbstractGoods> required)Gets a price for a map of resources to build a given buildable.voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidreadChild(FreeColXMLReader xr)Reads a single child object.voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.booleanremove(Locatable locatable)Removes aLocatablefrom this Location.protected booleanremoveBuilding(Building building)Remove a building from this Colony.GoodsremoveGoods(GoodsType type, int amount)Removes a specified amount of a type of Goods from this location.private intreturnPresent(GoodsType goodsType, int turns)Calculate the present field.protected voidsetBuildingMap(java.util.List<Building> buildings)Reset the building map.voidsetBuildQueue(java.util.List<BuildableType> buildQueue)Set the build queue.protected voidsetColonyTiles(java.util.List<ColonyTile> colonyTiles)Set the colony tile list.voidsetCurrentlyBuilding(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.voidsetDisplayUnitCount(int count)Sets the apparent number of units at this colony.voidsetEstablished(Turn newEstablished)Set the turn of establishment.protected voidsetExportData(java.util.Collection<ExportData> exportData)Set the export data.voidsetExportData(ExportData newExportData)Set some export data.booleansetOccupationTrace(boolean trace)Sets the occupation tracing status.voidsetPopulationQueue(java.util.List<UnitType> populationQueue)Set the population queue.voidsetProductionBonus(int productionBonus)Sets the production bonus of the colony.java.lang.StringtoShortString()Get a short description of this location.java.lang.StringtoString()Locationup()Promote this location to a more meaningful one if possible.voidupdateEducation(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.voidupdatePopulation()Signal to the colony that its population is changing.protected booleanupdateProductionBonus()Update the colony's production bonus.voidupdateProductionTypes()Update all the production types.voidupdateSoL()Calculates the current SoL membership of the colony based on the liberty value and colonists.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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- ThePlayerowning thisColony.name- The name of the newColony.tile- The containingTile.
-
Colony
public Colony(Game game, java.lang.String id)
Create a newColonywith 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 everyBuildingin thisColony.- Returns:
- A list of
Buildings.
-
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
Buildingfound.
-
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
ColonyTiles. - See Also:
ColonyTile
-
setColonyTiles
protected void setColonyTiles(java.util.List<ColonyTile> colonyTiles)
Set the colony tile list.- Parameters:
colonyTiles- The new list ofColonyTiles.
-
clearColonyTiles
private void clearColonyTiles()
Clear the colony tiles.
-
getColonyTile
public ColonyTile getColonyTile(Tile tile)
Get theColonyTilematching the givenTile.- Parameters:
tile- TheTileto 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- TheGoodsTypeto check.- Returns:
- The required
ExportData.
-
setExportData
public final void setExportData(ExportData newExportData)
Set some export data.- Parameters:
newExportData- A newExportDatavalue.
-
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 newTurnof establishment.
-
getBuildQueue
public java.util.List<BuildableType> getBuildQueue()
Get the build queue contents.- Returns:
- A list of
Buildables.
-
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
Buildables.
-
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 ofUnits 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- TheUnitto 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
GoodsTypes.
-
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- TheUnitto find anOccupationfor.workTypes- A collection ofGoodsTypeto consider producing.lb- ALogBuilderto log to.- Returns:
- An
Occupationfor 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- TheUnitto find anOccupationfor.userMode- If a user requested this, favour the current work type, if not favour goods that the unit requires.lb- ALogBuilderto log to.- Returns:
- An
Occupationfor 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- TheUnitto find anOccupationfor.workTypes- A collection ofGoodsTypeto consider producing.- Returns:
- An
Occupationfor 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- TheUnitto find anOccupationfor.userMode- If a user requested this, favour the current work type, if not favour goods that the unit requires.- Returns:
- An
Occupationfor 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
WorkLocations.
-
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
WorkLocations.
-
getCurrentWorkLocationsList
public java.util.List<WorkLocation> getCurrentWorkLocationsList()
Gets a list of all current work locations in this colony.- Returns:
- The list of current
WorkLocations.
-
getCurrentWorkLocations
public java.util.stream.Stream<WorkLocation> getCurrentWorkLocations()
Get a stream of all current work locations in this colony.- Returns:
- The stream of current
WorkLocations.
-
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- TheBuildingto 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- TheBuildingto remove.- Returns:
- True if the building was removed.
-
addColonyTile
private void addColonyTile(ColonyTile ct)
Add a colony tile.- Parameters:
ct- TheColonyTileto add.
-
getWorkLocationWithAbility
public WorkLocation getWorkLocationWithAbility(java.lang.String ability)
Gets a work location with a given ability.- Parameters:
ability- An ability key.- Returns:
- A
WorkLocationwith 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
WorkLocationwith 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
WorkLocationwith 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
WorkLocationwith 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- TheGoodsTypeto consume.- Returns:
- A list of
WorkLocations 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- TheGoodsTypeto produce.- Returns:
- A list of
WorkLocations 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- TheGoodsTypeto produce.- Returns:
- A
WorkLocations 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- TheUnitto get the building for.goodsType- TheGoodsTypeto produce.- Returns:
- The best
WorkLocationfound.
-
getWorkLocationFor
public WorkLocation getWorkLocationFor(Unit unit)
Gets the work location best suited for the given unit.- Parameters:
unit- TheUnitto check for.- Returns:
- The best
WorkLocationfound.
-
isTileInUse
public boolean isTileInUse(Tile tile)
Is a tile actually in use by this colony?- Parameters:
tile- TheTileto 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
Disasters.
-
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- aBuildingTypevalue- 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
UnitTypes.
-
getTurnsToComplete
public int getTurnsToComplete(BuildableType buildable)
Returns how many turns it would take to build the givenBuildableType.- Parameters:
buildable- TheBuildableTypeto 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- TheBuildableTypeto build.needed- TheAbstractGoodsneeded 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)
Returnstrueif this Colony can breed the given type of Goods. Only animals (such as horses) are expected to be breedable.- Parameters:
goodsType- aGoodsTypevalue- Returns:
- a
booleanvalue
-
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- TheBuildableTypeto build.
-
canBuild
public boolean canBuild()
-
canBuild
public boolean canBuild(BuildableType buildableType)
Returns true if this Colony can build the given BuildableType.- Parameters:
buildableType- aBuildableTypevalue- Returns:
- a
booleanvalue
-
getNoBuildReason
public Colony.NoBuildReason getNoBuildReason(BuildableType buildableType, java.util.List<BuildableType> assumeBuilt)
Return the reason why the giveBuildableTypecan not be built.- Parameters:
buildableType- ABuildableTypeto 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
NoBuildReasonvalue decribing the failure, includingNoBuildReason.NONEon success.
-
getPriceForBuilding
public int getPriceForBuilding()
Returns the price for the remaining hammers and tools for theBuildingthat 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- TheBuildableTypeto 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- TheBuildableTypeto 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- TheBuildableTypeto consider.- Returns:
- A list of required abstract goods.
-
canPayToFinishBuilding
public boolean canPayToFinishBuilding()
Check if the owner can buy the remaining hammers and tools for theBuildingthat is currently being built.- Returns:
- True if the user can afford to pay.
- Throws:
java.lang.IllegalStateException- If the owner of thisColonyhas 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 theBuildinggiven.- Parameters:
buildableType- aBuildableTypevalue- Returns:
- True if the user can afford to pay.
- Throws:
java.lang.IllegalStateException- If the owner of thisColonyhas 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- TheUnitto 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
StringTemplatedescribing 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- TheBuildableTypethat can not be built.- Returns:
- A
ModelMessagedescribing 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- TheUnitthat 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
Units 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- TheUnitthat 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- ThePlayerto 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:
trueif 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:
trueif 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
Units.
-
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 studentUnitthat 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 teacherUnitthat 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- TheGoodsTypeto 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- TheGoodsTypeto check.- Returns:
- True if goods type is consumed.
-
getConsumers
public java.util.List<Consumer> getConsumers()
Get a list of allConsumers 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:
getConsumptionOfin classSettlement- Parameters:
goodsType-GoodsTypevalues- Returns:
- an
intvalue
-
getFoodProduction
public int getFoodProduction()
Gets the combined production of all food types.- Returns:
- an
intvalue
-
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- TheGoodsTypeto produce.unitType- An optionalUnitTypeto do the work.wl- TheWorkLocation- Returns:
- A stream of suitable
Modifiers.
-
getNetProductionOf
public int getNetProductionOf(GoodsType goodsType)
Get the net production of the given goods type. (Also part of interface TradeLocation)- Parameters:
goodsType- aGoodsTypevalue- Returns:
- an
intvalue
-
isProductive
public boolean isProductive(WorkLocation workLocation)
Is a work location productive?- Parameters:
workLocation- TheWorkLocationto 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- aGoodsTypevalue- Returns:
- an
intvalue
-
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- anObjectvalue- Returns:
- a
ProductionInfovalue
-
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- TheGoodsTypeto 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
TileImprovementSuggestions.
-
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- TheUnitto 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- TheGoodsTypeto 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- TheProductionInfofor the work location.deficit- TheAbstractGoodsin deficit.- Returns:
- A suitable
StringTemplateor 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- TheGoodsTypeto 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- TheGoodsTypeto 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- TheFreeColObjectin the other colony.- Returns:
- The corresponding
FreeColObjectin 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:
getAbilitiesin classFreeColObject- Parameters:
id- The object identifier.type- An optionalFreeColSpecObjectTypethe 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:
getDisposablesin classGoodsLocation- Returns:
- A stream of
FreeColGameObjects to dispose of.
-
getLocationLabelFor
public StringTemplate getLocationLabelFor(Player player)
Get a label for this location for a particular player.- Specified by:
getLocationLabelForin interfaceLocation- Overrides:
getLocationLabelForin classUnitLocation- Parameters:
player- ThePlayerto return the name for.- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatableto this Location.- Specified by:
addin interfaceLocation- Overrides:
addin classGoodsLocation- Parameters:
locatable- TheLocatableto add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatablefrom this Location.- Specified by:
removein interfaceLocation- Overrides:
removein classGoodsLocation- Parameters:
locatable- TheLocatableto remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocationcontains the specifiedLocatable.- Specified by:
containsin interfaceLocation- Overrides:
containsin classGoodsLocation- Parameters:
locatable- TheLocatableto 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:
getUnitCountin interfaceLocation- Overrides:
getUnitCountin 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:
getUnitsin interfaceLocation- Overrides:
getUnitsin 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:
getUnitListin interfaceLocation- Overrides:
getUnitListin classUnitLocation- Returns:
- A list of all the units at this location.
-
getColony
public final Colony getColony()
Get the colony at this location.- Specified by:
getColonyin interfaceLocation- Overrides:
getColonyin classUnitLocation- Returns:
- A
Colonyat 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:
toShortStringin interfaceLocation- Returns:
- A short description.
-
invalidateCache
public void invalidateCache()
Invalidate any cache dependent on the goods levels.- Specified by:
invalidateCachein classGoodsLocation
-
getGoodsCapacity
public int getGoodsCapacity()
Gets the maximum number ofGoodsthis Location can hold.- Specified by:
getGoodsCapacityin 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:
addGoodsin classGoodsLocation- Parameters:
type- TheGoodsTypeto 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:
removeGoodsin 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:
getImmigrationin classSettlement- Returns:
- The current immigration.
-
getLiberty
public int getLiberty()
Gets the liberty points.- Overrides:
getLibertyin classSettlement- Returns:
- The current liberty.
-
getDefendingUnit
public Unit getDefendingUnit(Unit attacker)
Gets theUnitthat is currently defending thisSettlement.- Specified by:
getDefendingUnitin classSettlement- Parameters:
attacker- TheUnitthat is attacking thisSettlement.- Returns:
- The
Unitthat 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:
getDefenceRatioin classSettlement- Returns:
- A ratio of defence power to settlement size.
-
isBadlyDefended
public boolean isBadlyDefended()
Is this settlement insufficiently defended?- Specified by:
isBadlyDefendedin 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:
getPlunderRangein classSettlement- Parameters:
attacker- TheUnitthat takes the settlement.- Returns:
- A
RandomRangeencapsulating the range of plunder available.
-
getSoL
public int getSoL()
Gets the current Sons of Liberty in this settlement.- Specified by:
getSoLin 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:
getUpkeepin 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:
getTotalProductionOfin 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:
canProvideGoodsin 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:
hasContactedin classSettlement- Parameters:
player- The otherPlayerto 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:
getAlarmLevelLabelin classSettlement- Parameters:
player- The otherPlayer.- Returns:
- A
StringTemplatedescribing the alarm.
-
calculateSettlementValue
public int calculateSettlementValue(int value, Unit unit)Determines the value of a potential attack on aColony- Specified by:
calculateSettlementValuein 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- TheGoodsTypeto 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:
getAvailableGoodsCountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getExportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getImportAmountin interfaceTradeLocation- Parameters:
goodsType- TheGoodsTypeto 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:
getLocationNamein interfaceTradeLocation- Parameters:
tradeLocation- TheTradeLocationto return the name.- Returns:
- The name.
-
canBeInput
public boolean canBeInput()
Can a TradeLocation be set as the input location on a TradeRouteInputPanel- Specified by:
canBeInputin 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 optionalLogBuilderto log to.- Returns:
- The integrity found.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrityin classSettlement- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto log to.- Returns:
- A suitable
IntegrityType.
-
getClassIndex
public int getClassIndex()
Accessor for the class index.- Overrides:
getClassIndexin 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:
copyInin classSettlement- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classSettlement- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classSettlement- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classSettlement- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classSettlement- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classSettlement- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-