Class Settlement

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • owner

        protected Player owner
        The Player owning this Settlement.
      • name

        private java.lang.String name
        The name of the Settlement.
      • tile

        protected Tile tile
        The Tile where this Settlement is located.
      • ownedTiles

        private final java.util.Set<Tile> ownedTiles
        The tiles this settlement owns.
      • featureContainer

        private final FeatureContainer featureContainer
        Contains the abilities and modifiers of this Settlement.
      • SETTLEMENT_TYPE_TAG

        private static final java.lang.String SETTLEMENT_TYPE_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • Settlement

        protected Settlement​(Game game,
                             Player owner,
                             java.lang.String name,
                             Tile tile)
        Create a new Settlement.
        Parameters:
        game - The enclosing Game.
        owner - The owning Player.
        name - The settlement name.
        tile - The containing Tile.
      • Settlement

        public Settlement​(Game game,
                          java.lang.String id)
        Initiates a new Settlement with the given identifier. The object should be initialized later.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getType

        public final SettlementType getType()
        Get the type of this settlement.
        Returns:
        The settlement type.
      • setType

        public void setType​(SettlementType newType)
        Set the settlement type.
        Parameters:
        newType - The new SettlementType.
      • getImmigration

        public int getImmigration()
        Gets the immigration points.
        Returns:
        The current immigration.
      • getLiberty

        public int getLiberty()
        Gets the liberty points.
        Returns:
        The current liberty.
      • isLandLocked

        public boolean isLandLocked()
        Is this settlement landlocked?
        Returns:
        True if no adjacent tiles are water.
      • changeType

        private final void changeType​(SettlementType newType)
        Change the settlement type, setting the consequent features.
        Parameters:
        newType - The new SettlementType.
      • isCapital

        public boolean isCapital()
        Is this a national capital?
        Returns:
        True if this is a national capital.
      • setCapital

        public void setCapital​(boolean capital)
      • getOwnedTiles

        public java.util.Set<Tile> getOwnedTiles()
        Get the tiles this settlement owns.
        Returns:
        A set of tiles.
      • setOwnedTiles

        protected void setOwnedTiles​(java.util.Collection<Tile> ownedTiles)
        Set the owned tiles set.
        Parameters:
        ownedTiles - The new set of owned Tiles.
      • addTile

        public void addTile​(Tile tile)
        Adds a tile to this settlement. We can not clear the settlement owned tiles container when the settlement is read because this is called when the Tile is read, and tiles can appear before and after the settlement in the map definition. So we just accumulate and defend against duplicates.
        Parameters:
        tile - The Tile to add.
      • removeTile

        public void removeTile​(Tile tile)
        Removes a tile from this settlement.
        Parameters:
        tile - The Tile to remove.
      • getRadius

        public int getRadius()
        Gets the radius of what the Settlement considers as it's own land.
        Returns:
        Settlement radius
      • getLineOfSight

        public int getLineOfSight()
        Gets this settlement's line of sight value.
        Returns:
        The line of sight value.
      • getPlunder

        public int getPlunder​(Unit attacker,
                              java.util.Random random)
        Gets an amount of plunder when this settlement is taken.
        Parameters:
        attacker - The Unit that takes the settlement.
        random - A pseudo-random number source.
        Returns:
        An amount of gold plundered.
      • getVisibleTileSet

        public java.util.Set<Tile> getVisibleTileSet()
        Get the tiles visible from this settlement.
        Returns:
        A set of visible tiles.
      • placeSettlement

        public void placeSettlement​(boolean maximal)
        Put a prepared settlement onto the map. -vis: Several visibility issues accumulated here. -til: Several tile appearance issues accumulated here.
        Parameters:
        maximal - If true, also claim all the tiles possible.
      • exciseSettlement

        public void exciseSettlement()
        Remove a settlement from the map. -vis: Visibility reduced when settlement goes away. -til: Several tile appearance issues accumulated here. Several visibility issues accumulated here.
      • changeOwner

        public void changeOwner​(Player newOwner)
        Change the owner of this Settlement. Does not fix up the units! That is handled in the server. -vis: Changes visibility. -til: Changes tile appearance.
        Parameters:
        newOwner - The Player that shall own this Settlement.
        See Also:
        getOwner()
      • isConnectedPort

        public boolean isConnectedPort()
        Gets whether this settlement is connected to the high seas. This is more than merely non-landlocked, because the settlement could be on an inland lake.
        Returns:
        True if the settlement is connected to the high seas.
      • getHighSeasCount

        public int getHighSeasCount()
        Gets the minimum high seas count of the adjacent high-seas-connected tiles. This is a measure of how close this settlement is to Europe.
        Returns:
        A high seas count, INFINITY if not connected.
      • getConsumptionOf

        protected int getConsumptionOf​(GoodsType goodsType)
        Returns the number of goods of a given type used by the settlement each turn.
        Parameters:
        goodsType - a GoodsType value
        Returns:
        an int value
      • getConsumptionOf

        protected int getConsumptionOf​(java.util.List<GoodsType> goodsTypes)
        Returns the number of goods of all given types used by the settlement each turn.
        Parameters:
        goodsTypes - GoodsType values
        Returns:
        an int value
      • getFoodConsumption

        public int getFoodConsumption()
        Gives the food needed to keep all units alive in this Settlement.
        Returns:
        The amount of food eaten in this colony each this turn.
      • canProvideGoods

        protected boolean canProvideGoods​(java.util.List<AbstractGoods> goods)
        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).
        Parameters:
        goods - A list of AbstractGoods
        Returns:
        True if the settlement can provide the equipment.
      • getWarehouseCapacity

        public int getWarehouseCapacity()
        Gets the storage capacity of this settlement.
        Returns:
        The storage capacity of this settlement.
        See Also:
        GoodsLocation.getGoodsCapacity()
      • canBombardEnemyShip

        public boolean canBombardEnemyShip()
        Check if colony has the ability to bombard an enemy ship adjacent to it. Only sea-side colonies can bombard. Does it have the buildings that give such abilities?
        Returns:
        True if bombarding is allowed.
      • canImproveUnitMilitaryRole

        public Role canImproveUnitMilitaryRole​(Unit unit)
        Can this settlement provide the goods to improve a given unit's role?
        Parameters:
        unit - The Unit to check.
        Returns:
        The Role that this settlement could provide.
      • getAllUnitsList

        public java.util.List<Unit> getAllUnitsList()
        Get all the units present here. That is, not just the units in the settlement but also the units on the tile.
        Returns:
        A list of Units.
      • getLinkTarget

        public FreeColGameObject getLinkTarget​(Player player)
        Get a suitable game object to use as a clickable link in messages to a player. Objects do not have links by default, hence the null return here. However, for example, a player's colony should return itself as a link target.
        Overrides:
        getLinkTarget in class FreeColGameObject
        Parameters:
        player - The Player to make a link for.
        Returns:
        A suitable link target if available, although usually null.
      • disposeResources

        public void disposeResources()
        Dispose of the resources of this object, and finally remove it from the game. To be extended by subclasses, but they must tail call up towards this. -vis: Visibility changes when the settlement is removed.
        Overrides:
        disposeResources in class UnitLocation
      • getName

        public java.lang.String getName()
        Get the name of this Settlement.
        Specified by:
        getName in interface Nameable
        Returns:
        The settlement name.
      • setName

        public void setName​(java.lang.String newName)
        Sets the name of this Settlement. -til: Changes the tile appearance.
        Specified by:
        setName in interface Nameable
        Parameters:
        newName - The new name.
      • getOwner

        public Player getOwner()
        Gets the owner of this Ownable.
        Specified by:
        getOwner in interface Ownable
        Returns:
        The Player controlling this Ownable.
      • setOwner

        public void setOwner​(Player player)
        Sets the owner of this Ownable. -vis: Changes visibility. -til: Changes tile appearance.
        Specified by:
        setOwner in interface Ownable
        Parameters:
        player - The Player that should take ownership of this Ownable.
      • getTile

        public final Tile getTile()
        Gets the Tile associated with this Location.
        Specified by:
        getTile in interface Location
        Overrides:
        getTile in class UnitLocation
        Returns:
        The Tile associated with this Location, or null if none found.
      • getRank

        public final int getRank()
        Get a integer for this location, for the benefit of location comparators.
        Specified by:
        getRank in interface Location
        Returns:
        A suitable integer.
      • getLocationImageKey

        public java.lang.String getLocationImageKey()
        Get an image key for this location.
        Specified by:
        getLocationImageKey in interface Location
        Returns:
        A key for image lookup, null by default.
      • getNoAddReason

        public UnitLocation.NoAddReason getNoAddReason​(Locatable locatable)
        Gets the reason why a given Locatable can not be added to this Location. Be careful to test for unit presence last before success (NoAddReason.NONE) except perhaps for the capacity test, so that we can treat ALREADY_PRESENT as success in some cases (e.g. if the unit changes type --- does it still have a required skill?) FIXME: consider moving this up to Location?
        Overrides:
        getNoAddReason in class GoodsLocation
        Parameters:
        locatable - The Locatable to test.
        Returns:
        The reason why adding would fail.
      • priceGoods

        public int priceGoods​(java.util.List<AbstractGoods> goods)
                       throws FreeColException
        What would the price be for a collection of goods at this location?
        Overrides:
        priceGoods in class UnitLocation
        Parameters:
        goods - The list of AbstractGoods to check for.
        Returns:
        The net cost of acquiring the goods at this location.
        Throws:
        FreeColException - if the goods are unavailable for any reason.
      • equipForRole

        public boolean equipForRole​(Unit unit,
                                    Role role,
                                    int roleCount)
        Equip a unit for a role using resources at this location.
        Overrides:
        equipForRole in class UnitLocation
        Parameters:
        unit - The Unit to equip.
        role - The Role to build for.
        roleCount - The role count.
        Returns:
        True if the equipping succeeded.
      • getDefendingUnit

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

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

        public abstract boolean isBadlyDefended()
        Is this settlement insufficiently defended?
        Returns:
        True if this settlement needs more defence.
      • getPlunderRange

        public abstract RandomRange getPlunderRange​(Unit attacker)
        Gets the range of gold plunderable when this settlement is captured.
        Parameters:
        attacker - The Unit that takes the settlement.
        Returns:
        A RandomRange encapsulating the range of plunder available.
      • getSoL

        public abstract int getSoL()
        Gets the current Sons of Liberty in this settlement.
        Returns:
        The current SoL.
      • getUpkeep

        public abstract int getUpkeep()
        Get the amount of gold necessary to maintain all of the settlement's buildings.
        Returns:
        The gold required for upkeep.
      • getTotalProductionOf

        public abstract int getTotalProductionOf​(GoodsType goodsType)
        Gets the total production of the given type of goods in this settlement.
        Parameters:
        goodsType - The type of goods to get the production for.
        Returns:
        The total production of the given type of goods.
      • hasContacted

        public abstract 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.
        Parameters:
        player - The other Player to check.
        Returns:
        True if the settlement has contacted the player.
      • getAlarmLevelLabel

        public abstract StringTemplate getAlarmLevelLabel​(Player player)
        Gets a label indicating the alarm level at this settlement with respect to another player.
        Parameters:
        player - The other Player.
        Returns:
        A StringTemplate describing the alarm.
      • calculateSettlementValue

        public abstract int calculateSettlementValue​(int value,
                                                     Unit unit)
        Get the value of attacking a Settlement
        Parameters:
        value - The previously calculated input value from #scoreSettlementPath(AIUnit, PathNode, Settlement)
        unit - The Unit doing the attacking.
        Returns:
        The calculated value
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class GoodsLocation
        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 FreeColObject
        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 GoodsLocation
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class FreeColGameObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChildren

        protected void readChildren​(FreeColXMLReader xr)
                             throws javax.xml.stream.XMLStreamException
        Reads the children of this object from an XML stream.
        Overrides:
        readChildren in class GoodsLocation
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChild

        protected 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 GoodsLocation
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.