Class Tile

    • Field Detail

      • logger

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

        public static final java.util.Comparator<Tile> edgeDistanceComparator
        Comparator to sort tiles by increasing distance from the edge.
      • highSeasComparator

        public static final java.util.Comparator<Tile> highSeasComparator
        Comparator to find the smallest high seas count.
      • isSeaTile

        public static final java.util.function.Predicate<Tile> isSeaTile
        Predicate to identify ordinary sea tiles.
      • UNIT_CHANGE

        public static final java.lang.String UNIT_CHANGE
        This must be distinct from ColonyTile/Building.UNIT_CHANGE or the colony panel can get confused.
        See Also:
        Constant Field Values
      • FLAG_RECALCULATE

        public static final int FLAG_RECALCULATE
        Flag to assign to the high seas count to flag that the high seas connectivity needs recalculation after reading in the map.
        See Also:
        Constant Field Values
      • LOW_PRODUCTION_WARNING_VALUE

        private static final int LOW_PRODUCTION_WARNING_VALUE
        Warn about colonies that can not produce this amount of a building material.
        See Also:
        Constant Field Values
      • NEAR_RADIUS

        public static final int NEAR_RADIUS
        The maximum distance that will still be considered "near" when determining the location name.
        See Also:
        getLocationLabel(), Constant Field Values
      • type

        private TileType type
        The type of the tile. Beware: this may appear to be null in the client when the tile is unexplored.
      • x

        private int x
        The tile coordinates in the enclosing map.
      • y

        private int y
        The tile coordinates in the enclosing map.
      • owner

        private Player owner
        The player that consider this tile to be their land.
      • settlement

        private Settlement settlement
        The settlement located on this tile, if any.
      • owningSettlement

        private Settlement owningSettlement
        Indicates which settlement owns this tile (null indicates no owner). A colony owns the tile it is located on, and every tile it has claimed by successfully moving a worker on to it. Native settlements make more extensive and unpredictable claims. Note that while units and settlements are owned by a player, a tile is owned by a settlement.
      • tileItemContainer

        private TileItemContainer tileItemContainer
        Stores all Improvements and Resources (if any).
      • region

        private Region region
        The region this tile is in.
      • highSeasCount

        private int highSeasCount
        The number of tiles to traverse to get to the high seas.
      • moveToEurope

        private java.lang.Boolean moveToEurope
        Does this tile have an explicit moveToEurope state. If null, just use the defaults (usually not, unless water and on map edge), otherwise use the explicit value provided here.
      • style

        private int style
        The style of this Tile, as determined by adjacent tiles.
      • contiguity

        private int contiguity
        An artificial contiguous-region number to identify connected parts of the map. That is, all land tiles with the same contiguity number can be reached by a land unit on any of those tiles in the absence of extra-geographic blockages like settlements and other units. Similarly for water tiles/naval units. This is used to quickly scope out the sort of paths available to a unit attempting to reach some destination. It only needs serialization from server to client, as it is set by the TerrainGenerator on map import or creation.
      • cachedTiles

        private final java.util.Map<Player,​Tile> cachedTiles
        A map of cached tiles for each European player, null in clients.
      • playerIndianSettlements

        private final java.util.Map<Player,​Tile.IndianSettlementInternals> playerIndianSettlements
        A cache of native settlement internals for each European player, null in clients.
      • MOVE_TO_EUROPE_TAG

        private static final java.lang.String MOVE_TO_EUROPE_TAG
        See Also:
        Constant Field Values
      • OWNING_SETTLEMENT_TAG

        private static final java.lang.String OWNING_SETTLEMENT_TAG
        See Also:
        Constant Field Values
      • OLD_PLAYER_EXPLORED_TILE_TAG

        public static final java.lang.String OLD_PLAYER_EXPLORED_TILE_TAG
        See Also:
        Constant Field Values
      • OLD_TILE_ITEM_CONTAINER_TAG

        public static final java.lang.String OLD_TILE_ITEM_CONTAINER_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • Tile

        public Tile​(Game game,
                    TileType type,
                    int locX,
                    int locY)
        The main tile constructor.
        Parameters:
        game - The enclosing Game.
        type - The TileType.
        locX - The x-position of this tile on the map.
        locY - The y-position of this tile on the map.
      • Tile

        public Tile​(Game game,
                    java.lang.String id)
        Create a new Tile 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

      • getType

        public TileType getType()
        Gets the type of this Tile.
        Returns:
        The TileType.
      • setType

        public void setType​(TileType t)
        Sets the type for this Tile. -til: Changes appearance.
        Parameters:
        t - The new TileType for this Tile.
      • isExplored

        public boolean isExplored()
        Check if the tile has been explored.
        Returns:
        True if this is an explored Tile.
      • isLand

        public boolean isLand()
        Is this a land tile?
        Returns:
        True if this a land Tile.
      • isForested

        public boolean isForested()
        Is this a forested tile?
        Returns:
        True if this is a forested Tile.
      • getX

        public int getX()
        Gets the x-coordinate of this tile.
        Returns:
        The x-coordinate of this Tile.
      • getY

        public int getY()
        Gets the y-coordinate of this tile.
        Returns:
        The y-coordinate of this Tile.
      • getMap

        public Map getMap()
        Get the map in which this tile belongs.
        Returns:
        The enclosing Map.
      • setSettlement

        public void setSettlement​(Settlement settlement)
        Put a settlement onto this tile. A tile can only have one settlement located on it. The settlement will also become the owner of this tile. -til: Changes appearance.
        Parameters:
        settlement - A Settlement to put on this Tile.
        See Also:
        getSettlement()
      • hasSettlement

        public boolean hasSettlement()
        Does this tile have a settlement.
        Returns:
        True if there is a settlement present.
      • setOwningSettlement

        public void setOwningSettlement​(Settlement owner)
        Sets the settlement that owns this tile. -til: Changes appearance.
        Parameters:
        owner - The Settlement to own this Tile.
        See Also:
        getOwner()
      • getTileItemContainer

        public TileItemContainer getTileItemContainer()
        Gets this tiles TileItemContainer.
        Returns:
        The TileItemContainer.
      • setTileItemContainer

        public void setTileItemContainer​(TileItemContainer newTileItemContainer)
        Sets the TileItemContainer.
        Parameters:
        newTileItemContainer - The new TileItemContainer value.
      • getCompleteItems

        public java.util.List<TileItem> getCompleteItems()
        Get the completed tile items for this tile.
        Returns:
        A list of completed TileItems.
      • getRegion

        public Region getRegion()
        Get the tile region.
        Returns:
        The tile Region.
      • setRegion

        public void setRegion​(Region newRegion)
        Set the tile region. -til: Changes appearance.
        Parameters:
        newRegion - The new Region value.
      • getDiscoverableRegion

        public Region getDiscoverableRegion()
        Get the discoverable region of this tile.
        Returns:
        Any discoverable Region.
      • isHighSeasConnected

        public boolean isHighSeasConnected()
        Gets whether this tile is connected to the high seas.
        Returns:
        True if this Tile is connected to the high seas.
      • getHighSeasCount

        public int getHighSeasCount()
        Gets the high seas count.
        Returns:
        The high seas count value.
      • setHighSeasCount

        public void setHighSeasCount​(int count)
        Set the high seas count.
        Parameters:
        count - The new high seas count value.
      • isCoastland

        public boolean isCoastland()
        Is this a land tile on the sea coast (lakes do not count).
        Returns:
        True if this is a coastland tile.
      • getMoveToEurope

        public java.lang.Boolean getMoveToEurope()
        Get the move-to-Europe state of the tile.
        Returns:
        The move-to-Europe state of the Tile.
      • setMoveToEurope

        public void setMoveToEurope​(java.lang.Boolean moveToEurope)
        Set the move-to-Europe state of the tile.
        Parameters:
        moveToEurope - The new move-to-Europe state for the Tile.
      • isDirectlyHighSeasConnected

        public boolean isDirectlyHighSeasConnected()
        Can a unit move to the high seas from this tile?
        Returns:
        True if a unit can move to high seas from this tile.
      • isRiverCorner

        public boolean isRiverCorner()
        Is this tile on a river corner?
        Returns:
        True if this is a river corner.
      • getEdgeDistance

        private int getEdgeDistance()
        Get the minimum distance in tiles from this tile to the map edge.
        Returns:
        The distance to the edge.
      • getStyle

        public int getStyle()
        Get the style value.
        Returns:
        The Tile style.
      • setStyle

        public void setStyle​(int newStyle)
        Set the tile style. -til: Changes appearance.
        Parameters:
        newStyle - The new style value.
      • getContiguity

        public int getContiguity()
        Get the contiguity identifier for this tile.
        Returns:
        A contiguity number.
      • setContiguity

        public void setContiguity​(int contiguity)
        Sets the contiguity identifier for this tile.
        Parameters:
        contiguity - A contiguity number.
      • isConnectedTo

        public boolean isConnectedTo​(Tile other)
        Is this tile connected to another across the same contiguous piece of land or water?
        Parameters:
        other - The other Tile to check.
        Returns:
        True if the Tiles are connected.
      • getContiguityAdjacent

        public java.util.Set<Tile> getContiguityAdjacent​(int contiguity)
        Get the adjacent tiles that have a given contiguity.
        Parameters:
        contiguity - The contiguity to search for.
        Returns:
        A set of Tiles with the required contiguity.
      • isOnRiver

        public boolean isOnRiver()
        Is this tile on or adjacent to a navigable river but not the ocean.
        Returns:
        True if on a navigable river.
      • isBlocked

        public boolean isBlocked​(Unit unit)
        Quick test whether this tile is trivially blocked to moves from a unit. This is a simplification, use getMoveType().isProgress() for the full details.
        Parameters:
        unit - The Unit to test.
        Returns:
        True if the unit can not move to this tile.
      • getPlayerIndianSettlement

        private Tile.IndianSettlementInternals getPlayerIndianSettlement​(Player player)
        Gets the IndianSettlementInternals for the given player.
        Parameters:
        player - The Player to query.
        Returns:
        The IndianSettlementInternals for the given player, or null if none present.
      • getTileImprovements

        public java.util.List<TileImprovement> getTileImprovements()
        Gets a list of TileImprovements.
        Returns:
        A list of all the TileImprovements.
      • getCompleteTileImprovements

        public java.util.List<TileImprovement> getCompleteTileImprovements()
        Gets a list of completed TileImprovements.
        Returns:
        A list of all completed TileImprovements.
      • hasTileImprovement

        public boolean hasTileImprovement​(TileImprovementType type)
        Does this tile contain a completed improvement of the given type?
        Parameters:
        type - The TileImprovementType to look for.
        Returns:
        True if there is a completed improvement present.
      • getTileImprovement

        public TileImprovement getTileImprovement​(TileImprovementType type)
        Gets the TileImprovement of a given type, or null if there is no match.
        Parameters:
        type - The TileImprovementType to look for.
        Returns:
        The TileImprovement of the requested type found, or null if none.
      • hasLostCityRumour

        public boolean hasLostCityRumour()
        Does this tile have a LCR?
        Returns:
        True if this Tile has a LostCityRumour on it.
      • getLostCityRumour

        public LostCityRumour getLostCityRumour()
        Gets a lost city rumour on this tile.
        Returns:
        The LostCityRumour on this Tile, or null if none found.
      • hasResource

        public boolean hasResource()
        Does this tile have a resource?
        Returns:
        True if this is a resource Tile.
      • hasRiver

        public boolean hasRiver()
        Does this tile have a river?
        Returns:
        True if this is a river Tile.
      • getRiver

        public TileImprovement getRiver()
        Gets the river on this tile.
        Returns:
        A river TileImprovement, or null if none present.
      • getRiverStyle

        public TileImprovementStyle getRiverStyle()
        Gets the style of a river improvement on this tile.
        Returns:
        The river TileImprovementStyle.
      • hasRoad

        public boolean hasRoad()
        Does this tile have a road?
        Returns:
        True if this Tile has a road.
      • getRoad

        public TileImprovement getRoad()
        Gets the road on this tile.
        Returns:
        A road TileImprovement, or null if none present.
      • addTileItem

        private boolean addTileItem​(TileItem item)
        Adds a tile item to this tile. -til: Changes appearance.
        Parameters:
        item - The TileItem to add.
        Returns:
        True if the item was added.
      • removeTileItem

        private <T extends TileItem> T removeTileItem​(T item)
        Removes a tile item from this tile. -til: Changes appearance.
        Type Parameters:
        T - The actual TileItem type.
        Parameters:
        item - The TileItem to remove.
        Returns:
        The item removed, or null on failure.
      • addLostCityRumour

        public void addLostCityRumour​(LostCityRumour rumour)
        Adds a lost city rumour to this tile. -til: Changes appearance.
        Parameters:
        rumour - The LostCityRumour to add.
      • removeLostCityRumour

        public LostCityRumour removeLostCityRumour()
        Removes the lost city rumour from this Tile if there is one. -til: Changes appearance.
        Returns:
        The removed LostCityRumour.
      • addRiver

        public TileImprovement addRiver​(int magnitude,
                                        java.lang.String conns)
        Adds a new river to this tile. -til: Changes appearance.
        Parameters:
        magnitude - The magnitude of the river to be created
        conns - The encoded river size/connections.
        Returns:
        The new river added, or null on failure.
      • removeRiver

        public void removeRiver()
        Removes a river from this tile. -til: Changes appearance.
      • addRoad

        public TileImprovement addRoad()
        Adds a road to this tile. It is not complete. -til: Changes appearance.
        Returns:
        The new road added, or the existing one.
      • removeRoad

        public TileImprovement removeRoad()
        Removes a road from this tile. -til: Changes appearance.
        Returns:
        The removed road.
      • getResource

        public Resource getResource()
        Gets the resource on this tile.
        Returns:
        A Resource, or null if none present.
      • addResource

        public void addResource​(Resource resource)
        Adds a resource to this tile. -til: Changes appearance.
        Parameters:
        resource - The Resource to add.
      • removeResource

        public Resource removeResource()
        Removes a resource from this tile. -til: Changes appearance.
        Returns:
        The removed Resource.
      • getWorkAmount

        public int getWorkAmount​(TileImprovementType workType)
        Get the number of turns it takes for a non-expert pioneer to build the given TileImprovementType. It will check if it is valid for this TileType.
        Parameters:
        workType - The TileImprovementType to check.
        Returns:
        The number of turns it should take a non-expert pioneer to finish the work.
      • isImprovementTypeAllowed

        public boolean isImprovementTypeAllowed​(TileImprovementType type)
        Check if a given improvement type is valid for this tile.
        Parameters:
        type - The TileImprovementType to check.
        Returns:
        True if this tile can be improved with the improvement type.
      • isImprovementAllowed

        public boolean isImprovementAllowed​(TileImprovement tip)
        Check if a given improvement is valid for this tile.
        Parameters:
        tip - The TileImprovement to check.
        Returns:
        True if this tile can be improved with the improvement.
      • getDisasterChoices

        public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
        Gets a weighted list of natural disasters than can strike this tile. This list comprises all natural disasters that can strike a tile of this type or a completed tile improvement present.
        Returns:
        A stream of Disaster choices.
      • getLabel

        public StringTemplate getLabel()
        Gets a description of the Tile, with the name of the tile and any improvements on it (road/plow/etc) from TileItemContainer.
        Returns:
        The description label for this Tile.
      • getSimpleLabel

        public StringTemplate getSimpleLabel()
        Get a simple label for this tile, with just its coordinates.
        Returns:
        A simple StringTemplate label.
      • getNearLocationLabel

        private StringTemplate getNearLocationLabel​(Direction direction,
                                                    StringTemplate location)
        Get a label for a nearby location.
        Parameters:
        direction - The Direction from this tile to the nearby location.
        location - A StringTemplate describing the location.
        Returns:
        A StringTemplate stating that the location is nearby.
      • getDetailedLocationLabel

        private StringTemplate getDetailedLocationLabel()
        Get a detailed label for this tile.
        Returns:
        A suitable StringTemplate.
      • getDetailedLocationLabelFor

        private StringTemplate getDetailedLocationLabelFor​(Player player)
        Get a detailed label for this tile for a given player.
        Parameters:
        player - The Player to produce a label for.
        Returns:
        A suitable StringTemplate.
      • getColonyTileLocationLabel

        public StringTemplate getColonyTileLocationLabel​(Colony colony)
        Get a label for this tile assuming it is a colony tile of a given colony.
        Parameters:
        colony - The Colony assumed to own this tile.
        Returns:
        A suitable StringTemplate, or null if this tile is not close enough to the colony to be a colony tile.
      • getDistanceTo

        public int getDistanceTo​(Tile tile)
        Gets the distance in tiles between this tile and the specified one.
        Parameters:
        tile - The Tile to check the distance to.
        Returns:
        The distance.
      • getDirection

        public Direction getDirection​(Tile tile)
        Gets the direction to a neighbouring tile from this one.
        Parameters:
        tile - The other Tile.
        Returns:
        The direction to the other Tile, or null if the other tile is not a neighbour.
      • getNeighbourOrNull

        public Tile getNeighbourOrNull​(Direction direction)
        Get the neighbouring tile in the given direction.
        Parameters:
        direction - The Direction to check in.
        Returns:
        The neighbouring Tile in the given Direction, or null if none present.
      • isAdjacent

        public boolean isAdjacent​(Tile tile)
        Determines whether this tile is adjacent to the specified tile.
        Parameters:
        tile - A potentially adjacent Tile.
        Returns:
        True if the Tile is adjacent to this Tile.
      • isPolar

        public boolean isPolar()
        Is this tile in the polar regions?
        Returns:
        True if the Tile is polar.
      • isLandLocked

        public boolean isLandLocked()
        Is this tile land locked?
        Returns:
        True if land locked.
      • isShore

        public boolean isShore()
        Is this a shoreline tile? The tile can be water or land, and the water can be ocean, river or an inland lake. If this is true for a land tile with a colony, the colony can build docks.
        Returns:
        True if this Tile is on the shore.
      • isGoodHillTile

        public boolean isGoodHillTile()
        Is this a good tile to put hills on? Used by the terrain generator.
        Returns:
        True if this is a good potential hill tile.
      • isGoodMountainTile

        public boolean isGoodMountainTile​(TileType mountains)
        Is this a good tile to put mountains on? Used by the terrain generator.
        Parameters:
        mountains - The mountain tile type.
        Returns:
        True if this is a good potential elevated tile.
      • isGoodRiverTile

        public boolean isGoodRiverTile​(TileImprovementType riverType)
        Is this a good tile to start a river on? Used by the terrain generator.
        Parameters:
        riverType - The river TileImprovementType.
        Returns:
        True if this is a good place to start a river.
      • getSurroundingTiles

        public java.lang.Iterable<Tile> getSurroundingTiles​(int range)
        Gets all the tiles surrounding a tile within the given range. The center tile is not included.
        Parameters:
        range - How far away do we need to go starting from this.
        Returns:
        The tiles surrounding this Tile.
      • getSurroundingTiles

        public java.util.List<Tile> getSurroundingTiles​(int rangeMin,
                                                        int rangeMax)
        Gets all the tiles surrounding this tile within the given inclusive upper and lower bounds. getSurroundingTiles(r) is equivalent to getSurroundingTiles(1, r), thus this tile is included if rangeMin is zero.
        Parameters:
        rangeMin - The inclusive minimum distance from this Tile.
        rangeMax - The inclusive maximum distance from this Tile.
        Returns:
        A list of the tiles surrounding this Tile.
      • hasUnexploredAdjacent

        public boolean hasUnexploredAdjacent()
        Determine whether this tile has adjacent tiles that are unexplored.
        Returns:
        True if at least one neighbouring Tiles is unexplored.
      • getAvailableAdjacentCount

        public int getAvailableAdjacentCount()
        Get the number of tiles adjacent to this one that are of the same land/water type such as to be nominally accessible to a unit.
        Returns:
        The number of adjacent available tiles.
      • getAdjacentColonies

        public java.util.List<Colony> getAdjacentColonies()
        Get the adjacent colonies.
        Returns:
        A list of adjacent Colonys.
      • getNearestSettlement

        public Settlement getNearestSettlement​(Player owner,
                                               int radius,
                                               boolean same)
        Finds the nearest settlement to this tile.
        Parameters:
        owner - If non-null, the settlement should be owned by this player.
        radius - The maximum radius of the search.
        same - If true, require the settlement to be on the same land mass.
        Returns:
        The nearest settlement, or null if none.
      • getSafeTile

        public Tile getSafeTile​(Player player,
                                java.util.Random random)
        Finds a safe tile to put a unit on, near to this one. Useful on return from Europe.
        Parameters:
        player - The owner of the unit to place (may be null).
        random - An optional pseudo-random number source.
        Returns:
        A vacant Tile near this one.
      • getDefenceValue

        public double getDefenceValue()
        Get the defence value for this tile type.
        Returns:
        The defence value.
      • getDefenceBonusPercentage

        public int getDefenceBonusPercentage()
        Get the defence bonus as a percent.
        Returns:
        The percentage defence bonus.
      • getSafestSurroundingLandTiles

        public java.util.List<Tile> getSafestSurroundingLandTiles​(Player player)
        Get a list of surrounding land tiles, sorted with the most defensible first. Useful when planning an attack.
        Parameters:
        player - A Player to use to check for tile access.
        Returns:
        A list of land Tiles.
      • getBestDisembarkTile

        public Tile getBestDisembarkTile​(Player player)
        Get the adjacent land tile with the best defence bonus. Useful for incoming attackers as a disembark site.
        Parameters:
        player - A Player to use to check for tile access.
        Returns:
        The most defensible adjacent land Tile.
      • isDangerousToShip

        public boolean isDangerousToShip​(Unit ship)
        Is this tile dangerous for a naval unit to enter? That is, is there an adjacent settlement that is likely to bombard it.
        Parameters:
        ship - The naval Unit to check.
        Returns:
        True if moving the ship to this tile exposes it to attack.
      • getSafeAnchoringTiles

        public java.util.List<Tile> getSafeAnchoringTiles​(Unit unit)
        Get any safe sites for a naval transport unit to stop at to disembark a unit to this tile. To be safe, the tile must be adjacent to this one but not adjacent to a dangerous settlement.
        Parameters:
        unit - The transport Unit that needs a anchoring site.
        Returns:
        A list of suitable Tiles.
      • changeType

        public void changeType​(TileType type)
        Changes the type of this tile. The map generator et al should just use setType(), whereas this routine should be called for the special case of a change of an existing tile type (e.g. pioneer clearing forest). -til: Changes appearance.
        Parameters:
        type - The new TileType.
      • isInUse

        public boolean isInUse()
        Is this tile under active use?
        Returns:
        True if a Colony is using this Tile.
      • changeOwningSettlement

        public void changeOwningSettlement​(Settlement settlement)
        Changes the owning settlement for this tile. -til: Changes appearance.
        Parameters:
        settlement - The new owning Settlement for this Tile.
      • changeOwnership

        public void changeOwnership​(Player player,
                                    Settlement settlement)
        Change the tile ownership. Also change the owning settlement as the two are commonly related. -til: Changes appearance.
        Parameters:
        player - The Player to own the tile.
        settlement - The Settlement to own the Tile.
      • getBuildColonyWarnings

        public StringTemplate getBuildColonyWarnings​(Unit unit)
        A colony is proposed to be built on this tile. Collect warnings if this has disadvantages.
        Parameters:
        unit - The Unit which is to build the colony.
        Returns:
        A StringTemplate containing the warnings, or null if none.
      • canProduce

        public boolean canProduce​(GoodsType goodsType,
                                  UnitType unitType)
        Can this tile produce a given goods type? To produce goods either the tile type must have a suitable production type, or the tile item container contains suitable resource.
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType to use.
        Returns:
        True if the tile can produce the goods.
      • getBaseProduction

        public int getBaseProduction​(ProductionType productionType,
                                     GoodsType goodsType,
                                     UnitType unitType)
        Get the base production exclusive of any bonuses.
        Parameters:
        productionType - An optional ProductionType to use, if null the best available one is used.
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType to use.
        Returns:
        The base production due to tile type and resources.
      • getPotentialProduction

        public int getPotentialProduction​(GoodsType goodsType,
                                          UnitType unitType)
        Get the potential production of this tile for a given goods type and optional worker type.
        Parameters:
        goodsType - The GoodsType to check the potential for.
        unitType - An optional UnitType to do the work.
        Returns:
        The potential production of this Tile to produce the given GoodsType.
      • getProductionModifiers

        public java.util.stream.Stream<Modifier> getProductionModifiers​(GoodsType goodsType,
                                                                        UnitType unitType)
        Get the production modifiers for this tile.
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType to do the work.
        Returns:
        A stream of production Modifiers.
      • getMaximumPotential

        private int getMaximumPotential​(GoodsType goodsType,
                                        UnitType unitType,
                                        TileType tileType)
        Gets the maximum potential for producing the given type of goods with a given unit if this tile is (perhaps changed to) a given tile type.
        Parameters:
        goodsType - The GoodsType to check.
        unitType - A UnitType to do the work.
        tileType - A TileType to change to.
        Returns:
        The maximum potential.
      • getMaximumPotential

        public int getMaximumPotential​(GoodsType goodsType,
                                       UnitType unitType)
        Gets the maximum potential for producing the given type of goods. The maximum potential is the potential of a tile after the tile has been plowed/built road on.
        Parameters:
        goodsType - The GoodsType to check.
        unitType - A UnitType to do the work.
        Returns:
        The maximum potential.
      • getSortedPotential

        public java.util.List<AbstractGoods> getSortedPotential()
        Sort possible goods types according to potential.
        Returns:
        A list of goods, highest potential production first.
      • getSortedPotential

        public java.util.List<AbstractGoods> getSortedPotential​(Unit unit)
        Sort possible goods types according to potential.
        Parameters:
        unit - the Unit to work on this Tile
        Returns:
        A list of goods, highest potential production first.
      • getSortedPotential

        public java.util.List<AbstractGoods> getSortedPotential​(UnitType unitType,
                                                                Player owner)
        Sort possible goods types according to potential.
        Parameters:
        unitType - The UnitType to do the work.
        owner - the Player owning the unit.
        Returns:
        A list of goods, highest potential production first.
      • getBestFoodProduction

        public AbstractGoods getBestFoodProduction()
        Get the best food type to produce here.
        Returns:
        The AbstractGoods to produce.
      • updateColonyTiles

        private void updateColonyTiles()
        Update production after a change to this tile.
      • getCachedTiles

        private java.util.Map<Player,​Tile> getCachedTiles()
        Get the cached tile map.
        Returns:
        The map of cached tiles.
      • setCachedTiles

        private void setCachedTiles​(java.util.Map<Player,​Tile> cachedTiles)
        Get the cached tile map.
        Parameters:
        cachedTiles - The new map of cached Tiles.
      • getCachedTile

        private Tile getCachedTile​(Player player)
        Get a players view of this tile.
        Parameters:
        player - The Player who owns the view.
        Returns:
        The view of this Tile.
      • setCachedTile

        public void setCachedTile​(Player player,
                                  Tile tile)
        Set a players view of this tile.
        Parameters:
        player - The Player who owns the view.
        tile - The view of the Tile (either this tile, or an uninterned copy of it).
      • seeTile

        public void seeTile()
        Set the players view of this tile to the tile itself if the player can see it. Useful when the cache needs to be cleared forcibly such as when a native settlement is removed.
      • seeTile

        public void seeTile​(Player player)
        Set a players view of this tile to the tile itself.
        Parameters:
        player - The Player who owns the view.
      • getTileToCache

        public Tile getTileToCache()
        Get a copy of this tile suitable for caching (lacking units).
        Returns:
        An uninterned copy of this Tile.
      • cacheUnseen

        public void cacheUnseen()
        A change is about to occur on this tile. Cache it if unseen.
      • cacheUnseen

        public void cacheUnseen​(Player player)
        A change is about to occur on this tile. Cache it if unseen.
        Parameters:
        player - A Player that currently may not be able to see the tile, but will as a result of the change, and so should not cache it.
      • cacheUnseen

        public void cacheUnseen​(Tile copied)
        A change may have occured on this tile. Establish caches where needed. Use the copied tile if supplied (which should have been created previously with getTileToCache(),
        Parameters:
        copied - An optional Tile to cache.
      • cacheUnseen

        private void cacheUnseen​(Player player,
                                 Tile copied)
        A change may have occured on this tile. Establish caches where needed. Use the copied tile if supplied (which should have been created previously with getTileToCache().
        Parameters:
        player - A Player that currently may not be able to see the tile, but will as a result of the change, and so should not cache it.
        copied - An optional Tile to cache.
      • updateIndianSettlement

        public void updateIndianSettlement​(Player player)
        Updates the information about the native settlement on this Tile for the given Player.
        Parameters:
        player - The Player.
      • removeIndianSettlementInternals

        public void removeIndianSettlementInternals​(Player player)
      • getLearnableSkill

        public UnitType getLearnableSkill​(Player player)
      • getWantedGoods

        public java.util.List<GoodsType> getWantedGoods​(Player player)
      • setIndianSettlementInternals

        private void setIndianSettlementInternals​(Player player,
                                                  UnitType skill,
                                                  java.util.List<GoodsType> wanted)
        Set native settlement information. Do not check the current map state as we might leak destruction information.
        Parameters:
        player - The Player to pet belonged to.
        skill - The skill taught by the settlement.
        wanted - The goods wanted by the settlement.
      • isExploredBy

        public boolean isExploredBy​(Player player)
        Checks if this Tile has been explored by the given Player. If we are in the server, then the presence of a cached tile determines whether exploration has happened. In the client there are no cached tiles, but if the tile is explored the server will have updated the client with the tile type (checked by isExplored()).
        Parameters:
        player - The Player.
        Returns:
        True if this Tile has been explored by the given Player.
      • setExplored

        public void setExplored​(Player player,
                                boolean reveal)
        Explore/unexplore a tile for a player.
        Parameters:
        player - The Player that is exploring.
        reveal - The exploration state.
      • getDefendingUnit

        public Unit getDefendingUnit​(Unit attacker)
        Gets the unit that is currently defending this tile.

        If this tile has a settlement, the units inside the settlement are also considered as potential defenders.

        As this method is quite expensive, it should not be used to test for the presence of enemy units.

        Parameters:
        attacker - The Unit that would be attacking this Tile.
        Returns:
        The Unit that has been chosen to defend this Tile.
      • getOccupyingUnit

        public Unit getOccupyingUnit()
        Gets the unit that is occupying the tile.
        Returns:
        The Unit that is occupying this Tile.
        See Also:
        isOccupied()
      • isOccupied

        public boolean isOccupied()
        Checks whether there is an enemy unit occupying this tile. Units can not produce in occupied tiles.
        Returns:
        True if an enemy unit is occupying this Tile.
      • getTile

        public 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.
      • add

        public boolean add​(Locatable locatable)
        Adds a Locatable to this Location. -til: Changes appearance with TileItems.
        Specified by:
        add in interface Location
        Overrides:
        add in class UnitLocation
        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. -til: Changes appearance with TileItems.
        Specified by:
        remove in interface Location
        Overrides:
        remove in class UnitLocation
        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 UnitLocation
        Parameters:
        locatable - The Locatable to test the presence of.
        Returns:
        True if the locatable is present at this location.
      • canAdd

        public boolean canAdd​(Locatable locatable)
        Checks whether or not the specified locatable may be added to this Location.
        Specified by:
        canAdd in interface Location
        Overrides:
        canAdd in class UnitLocation
        Parameters:
        locatable - The Locatable to add.
        Returns:
        True if the locatable can be added to this location.
      • 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.
      • getRank

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

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

        public java.lang.String getNameKey()
        Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.
        Specified by:
        getNameKey in interface Named
        Returns:
        The name of the Named.
      • 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 owner)
        Sets the owner of this Ownable. -til: Changes appearance.
        Specified by:
        setOwner in interface Ownable
        Parameters:
        owner - The Player that should take ownership of this Ownable.
      • 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.
        Overrides:
        disposeResources in class UnitLocation
      • 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.
      • getAbilities

        public java.util.stream.Stream<Ability> getAbilities​(java.lang.String id,
                                                             FreeColSpecObjectType fcgot,
                                                             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.
        fcgot - An optional FreeColSpecObjectType the ability applies to.
        turn - An optional applicable Turn.
        Returns:
        A set of abilities.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class UnitLocation
        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.
      • getDisplayObject

        public FreeColObject getDisplayObject()
        Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.
        Overrides:
        getDisplayObject in class FreeColObject
        Returns:
        A suitable FreeColObject to display, defaults to this.
      • toXML

        public void toXML​(FreeColXMLWriter xw,
                          java.lang.String tag)
                   throws javax.xml.stream.XMLStreamException
        This method writes an XML-representation of this object with a specified tag to the given stream. Almost all FreeColObjects end up calling these, and implementing their own write{Attributes,Children} methods which begin by calling their superclass. This allows a clean nesting of the serialization routines throughout the class hierarchy. All attributes will be made visible.
        Overrides:
        toXML in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        tag - The tag to use.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • internalToXML

        private void internalToXML​(FreeColXMLWriter xw,
                                   java.lang.String tag)
                            throws javax.xml.stream.XMLStreamException
        Fundamental (post-cache) version of toXML.
        Parameters:
        xw - The FreeColXMLWriter to write to.
        tag - The tag to use.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • 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 UnitLocation
        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 UnitLocation
        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 UnitLocation
        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.