Class Colony

    • 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
      • REARRANGE_COLONY

        public static final java.lang.String REARRANGE_COLONY
        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.
      • 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.
      • PRODUCTION_BONUS_TAG

        private static final java.lang.String PRODUCTION_BONUS_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
      • 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
    • Constructor Detail

      • Colony

        protected Colony​(Game game,
                         Player owner,
                         java.lang.String name,
                         Tile tile)
        Constructor for ServerColony.
        Parameters:
        game - The enclosing Game.
        owner - The Player owning this Colony.
        name - The name of the new Colony.
        tile - The containing Tile.
      • Colony

        public Colony​(Game game,
                      java.lang.String id)
        Create a new Colony with the given identifier. The object should later be initialized by calling either FreeColGameObject.readFromXML(FreeColXMLReader).
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getBuildings

        public java.util.List<Building> getBuildings()
        Get a list of every Building in this Colony.
        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 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()
        Gets a List of every ColonyTile in this Colony.
        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 of ColonyTiles.
      • clearColonyTiles

        private void clearColonyTiles()
        Clear the colony tiles.
      • getColonyTile

        public ColonyTile getColonyTile​(Tile tile)
        Get the ColonyTile matching the given Tile.
        Parameters:
        tile - The Tile 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 of ExportData.
      • getExportData

        public ExportData getExportData​(GoodsType goodsType)
        Get the export date for a goods type.
        Parameters:
        goodsType - The GoodsType to check.
        Returns:
        The required ExportData.
      • setExportData

        public final void setExportData​(ExportData newExportData)
        Set some export data.
        Parameters:
        newExportData - A new ExportData 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 new Turn of 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 of Units 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 - The Unit 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 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 - The Unit to find an Occupation for.
        workTypes - A collection of GoodsType to consider producing.
        lb - A LogBuilder 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 - The Unit to find an Occupation for.
        userMode - If a user requested this, favour the current work type, if not favour goods that the unit requires.
        lb - A LogBuilder 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 - The Unit to find an Occupation for.
        workTypes - A collection of GoodsType 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 - The Unit to find an Occupation 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 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 - The Building 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 - The Building to remove.
        Returns:
        True if the building was removed.
      • addColonyTile

        private void addColonyTile​(ColonyTile ct)
        Add a colony tile.
        Parameters:
        ct - The ColonyTile 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 required Ability, 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 required Ability, 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 required Modifier, 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 required Modifier, 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 - The GoodsType to 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 - The GoodsType to produce.
        Returns:
        A list of WorkLocations which produce the given type of goods.
      • 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 - The Unit to get the building for.
        goodsType - The GoodsType 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 - The Unit 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 - The Tile 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 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 - a BuildingType 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 UnitTypes.
      • getTurnsToComplete

        public int getTurnsToComplete​(BuildableType buildable)
        Returns how many turns it would take to build the given BuildableType.
        Parameters:
        buildable - The BuildableType 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 given BuildableType.
        Parameters:
        buildable - The BuildableType to build.
        needed - The AbstractGoods 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)
        Returns true if this Colony can breed the given type of Goods. Only animals (such as horses) are expected to be breedable.
        Parameters:
        goodsType - a GoodsType value
        Returns:
        a boolean value
      • 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 - The BuildableType to build.
      • canBuild

        public boolean canBuild()
      • canBuild

        public boolean canBuild​(BuildableType buildableType)
        Returns true if this Colony can build the given BuildableType.
        Parameters:
        buildableType - a BuildableType value
        Returns:
        a boolean value
      • getNoBuildReason

        public Colony.NoBuildReason getNoBuildReason​(BuildableType buildableType,
                                                     java.util.List<BuildableType> assumeBuilt)
        Return the reason why the give BuildableType can not be built.
        Parameters:
        buildableType - A BuildableType 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, including NoBuildReason.NONE on success.
      • 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 - The BuildableType 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 - The BuildableType 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 the Building that is currently being built.
        Returns:
        True if the user can afford to pay.
        Throws:
        java.lang.IllegalStateException - If the owner of this Colony has an insufficient amount of gold.
        See Also:
        getPriceForBuilding()
      • canPayToFinishBuilding

        public boolean canPayToFinishBuilding​(BuildableType buildableType)
        Check if the owner can buy the remaining hammers and tools for the Building given.
        Parameters:
        buildableType - a BuildableType value
        Returns:
        True if the user can afford to pay.
        Throws:
        java.lang.IllegalStateException - If the owner of this Colony 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 - The Unit 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 - The BuildableType 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 - The Unit 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 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 - The Unit 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 - The Player 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 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 student Unit 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 teacher Unit 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 - The GoodsType 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 - The GoodsType to check.
        Returns:
        True if goods type is consumed.
      • getConsumers

        public java.util.List<Consumer> getConsumers()
        Get a list of all Consumers 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 class Settlement
        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 production Modifier, which is generated from the current production bonus.
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType to do the work.
        wl - The WorkLocation
        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 - a GoodsType value
        Returns:
        an int value
      • isProductive

        public boolean isProductive​(WorkLocation workLocation)
        Is a work location productive?
        Parameters:
        workLocation - The WorkLocation 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 - a GoodsType 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 - an Object 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 - The GoodsType 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 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 - The Unit 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 - The GoodsType 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 - The ProductionInfo for the work location.
        deficit - The AbstractGoods 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 - The GoodsType 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 - The GoodsType 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 - The FreeColObject 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 class FreeColObject
        Parameters:
        id - The object identifier.
        type - An optional FreeColSpecObjectType the ability applies to.
        turn - An optional applicable Turn.
        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 class GoodsLocation
        Returns:
        A stream of FreeColGameObjects to dispose of.
      • add

        public boolean add​(Locatable locatable)
        Adds a Locatable to this Location.
        Specified by:
        add in interface Location
        Overrides:
        add in class GoodsLocation
        Parameters:
        locatable - The Locatable to add to this Location.
        Returns:
        True if the locatable was added.
      • remove

        public boolean remove​(Locatable locatable)
        Removes a Locatable from this Location.
        Specified by:
        remove in interface Location
        Overrides:
        remove in class GoodsLocation
        Parameters:
        locatable - The Locatable to remove from this Location.
        Returns:
        True if the locatable was removed.
      • contains

        public boolean contains​(Locatable locatable)
        Checks if this Location contains the specified Locatable.
        Specified by:
        contains in interface Location
        Overrides:
        contains in class GoodsLocation
        Parameters:
        locatable - The Locatable 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 interface Location
        Overrides:
        getUnitCount in class UnitLocation
        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 interface Location
        Overrides:
        getUnits in class UnitLocation
        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 interface Location
        Overrides:
        getUnitList in class UnitLocation
        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 interface Location
        Overrides:
        getColony in class UnitLocation
        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.
        Specified by:
        up in interface Location
        Returns:
        A more meaningful Location, or this one.
      • toShortString

        public java.lang.String toShortString()
        Get a short description of this location.
        Specified by:
        toShortString in interface Location
        Returns:
        A short description.
      • invalidateCache

        public void invalidateCache()
        Invalidate any cache dependent on the goods levels.
        Specified by:
        invalidateCache in class GoodsLocation
      • getGoodsCapacity

        public int getGoodsCapacity()
        Gets the maximum number of Goods this Location can hold.
        Specified by:
        getGoodsCapacity in class GoodsLocation
        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 class GoodsLocation
        Parameters:
        type - The GoodsType 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 class GoodsLocation
        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 class Settlement
        Returns:
        The current immigration.
      • getLiberty

        public int getLiberty()
        Gets the liberty points.
        Overrides:
        getLiberty in class Settlement
        Returns:
        The current liberty.
      • getDefendingUnit

        public Unit getDefendingUnit​(Unit attacker)
        Gets the Unit that is currently defending this Settlement.
        Specified by:
        getDefendingUnit in class Settlement
        Parameters:
        attacker - The Unit that is attacking this Settlement.
        Returns:
        The Unit that has been chosen to defend this Settlement.
      • getDefenceRatio

        public double getDefenceRatio()
        Get the ratio between defence at this settlement, and the general settlement size.
        Specified by:
        getDefenceRatio in class Settlement
        Returns:
        A ratio of defence power to settlement size.
      • isBadlyDefended

        public boolean isBadlyDefended()
        Is this settlement insufficiently defended?
        Specified by:
        isBadlyDefended in class Settlement
        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 class Settlement
        Parameters:
        attacker - The Unit 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 class Settlement
        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 class Settlement
        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 class Settlement
        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 class Settlement
        Parameters:
        requiredGoods - A list of AbstractGoods
        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 class Settlement
        Parameters:
        player - The other Player 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 class Settlement
        Parameters:
        player - The other Player.
        Returns:
        A StringTemplate describing the alarm.
      • returnPresent

        private int returnPresent​(GoodsType goodsType,
                                  int turns)
        Calculate the present field.
        Parameters:
        goodsType - The GoodsType 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 interface TradeLocation
        Parameters:
        goodsType - The GoodsType 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 interface TradeLocation
        Parameters:
        goodsType - The GoodsType 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 interface TradeLocation
        Parameters:
        goodsType - The GoodsType 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 interface TradeLocation
        Parameters:
        tradeLocation - The TradeLocation 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 interface TradeLocation
        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 optional LogBuilder 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 class Settlement
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder to log to.
        Returns:
        A suitable IntegrityType.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class Settlement
        Type Parameters:
        T - The FreeColObject 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 class Settlement
        Parameters:
        xw - The FreeColXMLWriter 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 class Settlement
        Parameters:
        xw - The FreeColXMLWriter 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 class Settlement
        Parameters:
        xr - The FreeColXMLReader 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 class Settlement
        Parameters:
        xr - The FreeColXMLReader 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 class Settlement
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.