Class Map

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, Location, ObjectWithId

    public class Map
    extends FreeColGameObject
    implements Location
    A rectangular isometric map. The map is represented as a two-dimensional array of tiles. Off-map destinations, such as Europe, can be reached via the HighSeas. In theory, a Game might contain several Map instances connected by the HighSeas.
    • Field Detail

      • logger

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

        public static final int POLAR_HEIGHT
        The number of tiles from the upper edge that are considered polar by default.
        See Also:
        Constant Field Values
      • width

        private int width
        The width and height of the map.
      • height

        private int height
        The width and height of the map.
      • tileArray

        private Tile[][] tileArray
        The tiles that this map contains, as a 2D array. This starts out unassigned, but is initialized in setTiles(). Then the individual tiles are filled in with setTile(), however once a Tile is present further calls to setTile will copyIn to it.
      • tileList

        private java.util.List<Tile> tileList
        The tiles that this map contains, as a list. This is populated in setTile().
      • layer

        private Map.Layer layer
        The highest map layer included.
      • minimumLatitude

        private int minimumLatitude
        The latitude of the northern edge of the map. A negative value indicates northern latitude, a positive value southern latitude. Thus, -30 equals 30 degrees N, and 40 equals 40 degrees S.
      • maximumLatitude

        private int maximumLatitude
        The latitude of the southern edge of the map. A negative value indicates northern latitude, a positive value southern latitude. Thus, -30 equals 30 degrees N, and 40 equals 40 degrees S.
      • latitudePerRow

        private float latitudePerRow
        Variable used to convert rows to latitude.
      • regions

        private final java.util.List<Region> regions
        The regions on the map.
      • traceSearch

        private boolean traceSearch
        The search tracing status.
      • trivialSearchHeuristic

        private Map.SearchHeuristic trivialSearchHeuristic
        A trivial search heuristic that always returns zero.
      • MAXIMUM_LATITUDE_TAG

        private static final java.lang.String MAXIMUM_LATITUDE_TAG
        See Also:
        Constant Field Values
      • MINIMUM_LATITUDE_TAG

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

      • Map

        public Map​(Game game,
                   int width,
                   int height)
        Create a new Map from a collection of tiles.
        Parameters:
        game - The enclosing Game.
        width - The map width.
        height - The map height.
      • Map

        public Map​(Game game,
                   FreeColXMLReader xr)
            throws javax.xml.stream.XMLStreamException
        Create a new Map from an input stream.
        Parameters:
        game - The enclosing Game.
        xr - The input stream containing the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
      • Map

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

      • initializeTraceSearch

        private void initializeTraceSearch()
        Enable full path logging by default if in PATHS debug mode.
      • getWidth

        public int getWidth()
        Gets the width of this map.
        Returns:
        The width of this map.
      • getHeight

        public int getHeight()
        Gets the height of this map.
        Returns:
        The height of this map.
      • inBox

        public static boolean inBox​(int x,
                                    int y,
                                    int width,
                                    int height)
        Checks if an (x,y) coordinate tuple is within a map of specified width and height.
        Parameters:
        x - The x-coordinate of the position.
        y - The y-coordinate of the position.
        width - The width of the map.
        height - The height of the map.
        Returns:
        True if the given position is within the bounds of the map.
      • isValid

        public boolean isValid​(int x,
                               int y)
        Checks whether a position is valid (within the map limits).
        Parameters:
        x - The X coordinate to check.
        y - The Y coordinate to check.
        Returns:
        True if the coordinates are valid.
      • isValid

        public boolean isValid​(Map.Position position)
        Checks whether a position is valid (within the map limits).
        Parameters:
        position - The Position to check.
        Returns:
        True if the position is valid.
      • setTiles

        private java.lang.String setTiles​(int width,
                                          int height)
        Initialize the tile shape. This must be called *once* per map.
        Parameters:
        width - The new map width.
        height - The new map height.
        Returns:
        An error message if setting the tile array was invalid, null if valid.
      • updateTiles

        private java.lang.String updateTiles​(int width,
                                             int height)
        Update the tile shape, however it is an error to change the map size after the initial setting.
        Parameters:
        width - The new map width.
        height - The new map height.
        Returns:
        An error message if setting the tile array was invalid, null if valid.
      • getTile

        public Tile getTile​(int x,
                            int y)
        Gets the Tile at position (x, y). 'x' specifies a column and 'y' specifies a row. (0, 0) is the Tile at the top-left corner of the Map.
        Parameters:
        x - The x-coordinate of the Tile.
        y - The y-coordinate of the Tile.
        Returns:
        The Tile at (x, y), or null if the position is invalid.
      • getTile

        public Tile getTile​(Map.Position p)
        Gets the Tile at a requested position.
        Parameters:
        p - The Position to query.
        Returns:
        The Tile at the given position.
      • setTile

        private boolean setTile​(Tile tile,
                                int x,
                                int y)
        Set the tile at the given coordinates. This can be done *once* per tile. Currently that is enforced by calling setTile() only from populateTiles() where the map is being built or indirectly through updateTile() where the absence of the tile is checked.
        Parameters:
        x - The x-coordinate of the Tile.
        y - The y-coordinate of the Tile.
        tile - The Tile to set.
        Returns:
        True if the Tile was updated.
      • updateTile

        private boolean updateTile​(Tile tile)
        Update a tile in this map from the given tile.
        Parameters:
        tile - The Tile to update from.
        Returns:
        True if the tile was updated.
      • getLayer

        public final Map.Layer getLayer()
        Get the layer.
        Returns:
        The maximum implemented layer on this map.
      • setLayer

        public final void setLayer​(Map.Layer newLayer)
        Set the layer.
        Parameters:
        newLayer - The new maximum implemented layer for this map.
      • getMinimumLatitude

        public final int getMinimumLatitude()
        Get the minimum latitude.
        Returns:
        The minimum latitude of this map.
      • setMinimumLatitude

        public final void setMinimumLatitude​(int newMinimumLatitude)
        Set the minimum latitude.
        Parameters:
        newMinimumLatitude - The new minimum latitude for this map.
      • getMaximumLatitude

        public final int getMaximumLatitude()
        Get the maximum latitude.
        Returns:
        The maximum latitude of this map.
      • setMaximumLatitude

        public final void setMaximumLatitude​(int newMaximumLatitude)
        Set the maxmimum latitude.
        Parameters:
        newMaximumLatitude - The new maximum latitude for this map.
      • getLatitudePerRow

        public final float getLatitudePerRow()
        Get the latitude/row.
        Returns:
        The latitude change between rows.
      • calculateLatitudePerRow

        private final void calculateLatitudePerRow()
        Recalculate the latitude/row from the current maximum and minimum.
      • getLatitude

        public int getLatitude​(int row)
        Gets the latitude of the given map row.
        Parameters:
        row - The row to check.
        Returns:
        The row latitude.
      • getRow

        public int getRow​(int latitude)
        Gets the map row with the given latitude.
        Parameters:
        latitude - The latitude to find.
        Returns:
        The row closest to the supplied latitude.
      • getRegions

        public java.util.Collection<Region> getRegions()
        Gets the regions in this map.
        Returns:
        All the regions in this map.
      • addRegion

        public void addRegion​(Region region)
        Adds a region to this map.
        Parameters:
        region - The Region to add.
      • clearRegions

        public void clearRegions()
        Clear the regions list.
      • getFixedRegions

        public java.util.Map<java.lang.String,​Region> getFixedRegions()
        Get the fixed regions indexed by key.
        Returns:
        A map of the fixed regions.
      • getRegionByKey

        public Region getRegionByKey​(java.lang.String key)
        Gets a Region by name key.
        Parameters:
        key - The name key to lookup the region with.
        Returns:
        The Region with the given name key, or null if none found.
      • getRegionByName

        public Region getRegionByName​(java.lang.String name)
        Gets a Region by name.
        Parameters:
        name - The region name.
        Returns:
        The Region with the given name, or null if not found.
      • isSameLocation

        public static final boolean isSameLocation​(Location l1,
                                                   Location l2)
        Are two locations non-null and either the same or at the same tile. This routine is here because Location is an interface.
        Parameters:
        l1 - The first Location.
        l2 - The second Location.
        Returns:
        True if the locations are the same or at the same tile.
      • isSameContiguity

        public static final boolean isSameContiguity​(Location l1,
                                                     Location l2)
        Are two locations at least in the same contiguous land/sea-mass? This routine is here because Location is an interface.
        Parameters:
        l1 - The first Location.
        l2 - The second Location.
        Returns:
        True if the locations are the same or in the same land/sea-mass.
      • isPolar

        public boolean isPolar​(Tile tile)
        Is a tile in the map in a polar region?
        Parameters:
        tile - The Tile to examine.
        Returns:
        True if the tile is in a polar region.
      • getDirection

        public Direction getDirection​(Tile t1,
                                      Tile t2)
        Gets the direction a unit needs to move in order to get from t1 to t2
        Parameters:
        t1 - The tile to move from.
        t2 - The target tile if moving from t1 in the direction returned by this method.
        Returns:
        The direction you need to move from t1 in order to reach t2, or null if the two specified tiles are not neighbours.
      • getRoughDirection

        public static Direction getRoughDirection​(Tile src,
                                                  Tile dst)
        Get the approximate direction from one tile to another.
        Parameters:
        src - The source Tile.
        dst - The destination Tile.
        Returns:
        The approximate direction from source to direction, or null if source and destination are the same.
      • getAdjacentTile

        public Tile getAdjacentTile​(int x,
                                    int y,
                                    Direction direction)
        Gets the adjacent tile in a given direction from the given coordinates.
        Parameters:
        x - The x coordinate to work from.
        y - The y coordinate to work from.
        direction - The Direction to check.
        Returns:
        The adjacent Tile in the specified direction, or null if invalid.
      • getAdjacentTile

        public Tile getAdjacentTile​(Tile tile,
                                    Direction direction)
        Gets the adjacent tile in a given direction from a given tile.
        Parameters:
        tile - The starting Tile.
        direction - The Direction to check.
        Returns:
        The adjacent Tile in the specified direction, or null if invalid.
      • getDistance

        public int getDistance​(Tile t1,
                               Tile t2)
        Gets the distance between two tiles.
        Parameters:
        t1 - The first Tile.
        t2 - The second Tile.
        Returns:
        The distance between the tiles.
      • getClosestTile

        public Tile getClosestTile​(Tile tile,
                                   java.util.Collection<Tile> tiles)
        Get the closest tile to a given one from a list of other tiles.
        Parameters:
        tile - The Tile to start from.
        tiles - The list of Tiles to check.
        Returns:
        The closest tile found (may be null if the list is empty).
      • getRandomLandTile

        public Tile getRandomLandTile​(java.util.Random random)
        Select a random land tile on the map.
        Parameters:
        random - A Random number source.
        Returns:
        A random land tile, or null if none found.
      • getTileSet

        public java.util.Set<Tile> getTileSet​(java.util.function.Predicate<Tile> predicate)
        Get a list of all the tiles that match a predicate.
        Parameters:
        predicate - The Predicate to check.
        Returns:
        A List of all matching Tiles.
      • getTileList

        public java.util.List<Tile> getTileList​(java.util.function.Predicate<Tile> predicate)
        Get a list of all the tiles that match a predicate.
        Parameters:
        predicate - The Predicate to check.
        Returns:
        A List of all matching Tiles.
      • forEachTile

        public void forEachTile​(java.util.function.Consumer<Tile> consumer)
        Perform an action on each tile.
        Parameters:
        consumer - The Consumer action to perform.
      • forEachTile

        public void forEachTile​(java.util.function.Predicate<Tile> predicate,
                                java.util.function.Consumer<Tile> consumer)
        Perform an action on each tile that matches a predicate.
        Parameters:
        predicate - The Predicate to match.
        consumer - The Consumer action to perform.
      • populateTiles

        public boolean populateTiles​(java.util.function.BiFunction<java.lang.Integer,​java.lang.Integer,​Tile> func)
        Populate the map. To be called to build a new map.
        Parameters:
        func - A Function that makes a new Tile for the supplied x,y coordinates.
        Returns:
        True if the map was populated.
      • forSubMap

        public void forSubMap​(int x,
                              int y,
                              int w,
                              int h,
                              java.util.function.Consumer<Tile> consumer)
        Iterates through a rectangular subpart of the Map. Intentionally avoids calling methods doing redundant checks, which would slow down map display.
        Parameters:
        x - X-component of the position of first tile.
        y - Y-component of the position of first tile.
        w - Width of the rectangle.
        h - Height of the rectangle.
        consumer - Provides a function to call for each tile.
      • subMap

        public java.util.List<Tile> subMap​(int x,
                                           int y,
                                           int w,
                                           int h)
        Collect the tiles in a rectangular portion of the map.
        Parameters:
        x - X-component of the position of first tile.
        y - Y-component of the position of first tile.
        w - Width of the rectangle.
        h - Height of the rectangle.
        Returns:
        A list of Tiles found (empty on error).
      • getShuffledTiles

        public java.util.List<Tile> getShuffledTiles​(java.util.Random random)
        Get a shuffled list of all the tiles.
        Parameters:
        random - A pseudo-random number source.
        Returns:
        A shuffled list of all the Tiles in this map.
      • getCircleIterator

        public java.util.Iterator<Tile> getCircleIterator​(Tile center,
                                                          boolean isFilled,
                                                          int radius)
        Gets a circle iterator.
        Parameters:
        center - The center Tile to iterate around.
        isFilled - True to get all of the positions in the circle.
        radius - The radius of circle.
        Returns:
        The circle iterator.
      • getCircleTiles

        public java.lang.Iterable<Tile> getCircleTiles​(Tile center,
                                                       boolean isFilled,
                                                       int radius)
        Gets an iterable for all the tiles in a circle using an underlying CircleIterator.
        Parameters:
        center - The center Tile to iterate around.
        isFilled - True to get all of the positions in the circle.
        radius - The radius of circle.
        Returns:
        An Iterable for a circle of tiles.
      • getManhattenHeuristic

        private Map.SearchHeuristic getManhattenHeuristic​(Tile endTile)
        Gets a search heuristic using the Manhatten distance to an end tile.
        Parameters:
        endTile - The Tile to aim for.
        Returns:
        A new SearchHeuristic aiming for the end tile.
      • findRealEnd

        private Location findRealEnd​(Unit unit,
                                     Location end)
        Destination argument test for path searches. Find the actual destination of a path.
        Parameters:
        unit - An optional Unit to search for.
        end - The candidate end Location.
        Returns:
        The actual end location.
      • getBestEntryPath

        private PathNode getBestEntryPath​(Unit unit,
                                          Tile tile,
                                          Unit carrier,
                                          CostDecider costDecider)
        Gets the best (closest) path location for this unit to reach a given tile from off the map.
        Parameters:
        unit - The Unit to check.
        tile - The target Tile.
        carrier - An optional carrier Unitto use.
        costDecider - An optional CostDecider to use.
        Returns:
        A path to the best entry location tile to arrive on the map at, or null if none found.
      • getBestEntryTile

        public Tile getBestEntryTile​(Unit unit,
                                     Tile tile,
                                     Unit carrier,
                                     CostDecider costDecider)
        Gets the best (closest) entry location for this unit to reach a given tile from off the map.
        Parameters:
        unit - The Unit to check.
        tile - The target Tile.
        carrier - An optional carrier Unitto use.
        costDecider - An optional CostDecider to use.
        Returns:
        The best entry location tile to arrive on the map at, or null if none found.
      • findMapPath

        private PathNode findMapPath​(Unit unit,
                                     Tile start,
                                     Tile end,
                                     Unit carrier,
                                     CostDecider costDecider,
                                     LogBuilder lb)
        Find the quickest path for a unit (with optional carrier) from a start tile to an end tile.
        Parameters:
        unit - The Unit to find the path for.
        start - The Tile in which the path starts from.
        end - The Tile at the end of the path.
        carrier - An optional naval carrier Unit to use.
        costDecider - An optional CostDecider for determining the movement costs (uses default cost deciders for the unit/s if not provided).
        lb - An optional LogBuilder to log to.
        Returns:
        A path starting at the start tile and ending at the end tile, or null if none found.
      • finishPath

        private void finishPath​(PathNode path,
                                Unit unit,
                                LogBuilder lb)
        Finish processing a path.
        Parameters:
        path - The PathNode to finish.
        unit - The Unit that is travelling along the path.
        lb - An optional LogBuilder to log to.
      • findPath

        public PathNode findPath​(Unit unit,
                                 Location start,
                                 Location end,
                                 Unit carrier,
                                 CostDecider costDecider,
                                 LogBuilder lb)
        Find the quickest path for a unit (with optional carrier) from a start location to an end location.
        Parameters:
        unit - The Unit to find the path for.
        start - The Location in which the path starts from.
        end - The Location at the end of the path.
        carrier - An optional naval carrier Unit to use.
        costDecider - An optional CostDecider for determining the movement costs (uses default cost deciders for the unit/s if not provided).
        lb - An optional LogBuilder to log to.
        Returns:
        A path starting at the start location and ending at the end location, or null if none found.
      • search

        public PathNode search​(Unit unit,
                               Location start,
                               GoalDecider goalDecider,
                               CostDecider costDecider,
                               int maxTurns,
                               Unit carrier,
                               LogBuilder lb)
        Searches for a goal. Assumes units in Europe return to their current entry location, which is not optimal most of the time. Returns the full path including the start and end locations.
        Parameters:
        unit - The Unit to find a path for.
        start - The Location to start the search from.
        goalDecider - The object responsible for determining whether a given PathNode is a goal or not.
        costDecider - An optional CostDecider responsible for determining the path cost.
        maxTurns - The maximum number of turns the given Unit is allowed to move. This is the maximum search range for a goal.
        carrier - An optional naval carrier Unit to use.
        lb - An optional LogBuilder to log to.
        Returns:
        The path to a goal, or null if none can be found.
        Throws:
        java.lang.IllegalArgumentException - If the unit is null, or the start location does not make sense, or the carrier/unit combination is bogus.
      • getSearchTrace

        public boolean getSearchTrace()
        Gets the search tracing status.
        Returns:
        The search tracing status.
      • setSearchTrace

        public boolean setSearchTrace​(boolean trace)
        Sets the search tracing status.
        Parameters:
        trace - The new search tracing status.
        Returns:
        The original search tracing status.
      • usedCarrier

        private boolean usedCarrier​(PathNode path)
        Was a carrier used previously on a path? Beware! This is special case code for partially constructed paths that do not yet have valid .next links, so we can not use the generic PathNode routines.
        Parameters:
        path - The path the search.
        Returns:
        True if the path includes a previous on-carrier node.
      • searchMap

        private PathNode searchMap​(Unit unit,
                                   Tile start,
                                   GoalDecider goalDecider,
                                   CostDecider costDecider,
                                   int maxTurns,
                                   Unit carrier,
                                   Map.SearchHeuristic searchHeuristic,
                                   LogBuilder lb)
        Searches for a path to a goal determined by the given GoalDecider. Using A* with a List (closedMap) for marking the visited nodes and using a PriorityQueue (openMapQueue) for getting the next edge with the least cost. This implementation could be improved by having the visited attribute stored on each Tile in order to avoid both of the HashMaps currently being used to serve this purpose. If the SearchHeuristic is not supplied, then the algorithm degrades gracefully to Dijkstra's algorithm. The data structure for the open list is a combined structure: using a HashMap for membership tests and a PriorityQueue for getting the node with the minimal f (cost+heuristics). This gives O(1) on membership test and O(log N) for remove-best and insertions.
        Parameters:
        unit - The Unit to find a path for.
        start - The Tile to start the search from.
        goalDecider - The object responsible for determining whether a given PathNode is a goal or not.
        costDecider - An optional CostDecider responsible for determining the path cost.
        maxTurns - The maximum number of turns the given Unit is allowed to move. This is the maximum search range for a goal.
        carrier - An optional naval carrier Unit to use.
        searchHeuristic - An optional SearchHeuristic.
        lb - An optional LogBuilder to log to.
        Returns:
        A path to a goal determined by the given GoalDecider.
      • searchCircle

        public Tile searchCircle​(Tile start,
                                 GoalDecider goalDecider,
                                 int radius)
        Searches for a tile within a radius of a starting tile. Does not use a unit, and thus does not consider movement validity.
        Parameters:
        start - The starting Tile.
        goalDecider - A GoalDecider that chooses the goal, which must be capable of tolerating a null unit.
        radius - The maximum radius of tiles to search from the start.
        Returns:
        The goal tile as determined by the, or null if none found.
      • getLandWithinDistance

        public Tile getLandWithinDistance​(int x,
                                          int y,
                                          int distance)
        Searches for land within the given radius.
        Parameters:
        x - X-component of the position to search from.
        y - Y-component of the position to search from.
        distance - The radius in tiles that should be searched for land.
        Returns:
        The first land tile found within the radius, or null if none found.
      • floodFillBool

        public static boolean[][] floodFillBool​(boolean[][] boolmap,
                                                int x,
                                                int y)
        Flood fills from a given Position p, based on connectivity information encoded in boolmap
        Parameters:
        boolmap - The connectivity information for this floodfill.
        x - The starting x coordinate.
        y - The starting y coordinate.
        Returns:
        A boolean[][] of the same size as boolmap, where "true" means the fill succeeded at that location.
      • floodFillBool

        public static boolean[][] floodFillBool​(boolean[][] boolmap,
                                                int x,
                                                int y,
                                                int limit)
        Flood fills from a given Position p, based on connectivity information encoded in boolmap
        Parameters:
        boolmap - The connectivity information for this floodfill.
        x - The starting x coordinate.
        y - The starting y coordinate.
        limit - Limit to stop flood fill at.
        Returns:
        A boolean[][] of the same size as boolmap, where "true" means the fill succeeded at that location.
      • resetContiguity

        public void resetContiguity()
        Sets the contiguity identifier for all tiles.
      • floodFill

        private void floodFill​(int contig,
                               int ymax,
                               int xmax,
                               boolean[][] waterMap)
        Performs fill flood action and calculations
        Parameters:
        contig - The contiguity number.
        ymax - The Y-value
        xmax - The X-value
        waterMap - The boolean array containing the x and y coordinates
      • collectStartingTiles

        public void collectStartingTiles​(java.util.List<Tile> eastTiles,
                                         java.util.List<Tile> westTiles)
        Collect lists of valid starting tiles on this map. Called from the map generator to help choose starting tiles for European units.
        Parameters:
        eastTiles - A list of Tiles on the east of the map to fill in.
        westTiles - A list of Tiles on the west of the map to fill in.
      • resetHighSeas

        public void resetHighSeas​(int distToLandFromHighSeas,
                                  int maxDistanceToEdge)
        Places the "high seas"-tiles on the border of this map. All other tiles previously of type High Seas will be set to Ocean.
        Parameters:
        distToLandFromHighSeas - The distance between the land and the high seas (given in tiles).
        maxDistanceToEdge - The maximum distance a high sea tile can have from the edge of the map.
      • resetHighSeasCount

        public void resetHighSeasCount()
        Sets the high seas count for all tiles connected to the high seas. Any ocean tiles on the map vertical edges that do not have an explicit false moveToEurope attribute are given a true one. Set all high seas counts negative, then start with a count of zero for tiles with the moveToEurope attribute or of a type with that ability. Iterate outward by neighbouring tile, incrementing the count on each pass, stopping at land. Thus, only the coastal land tiles will have a non-negative high seas count. This significantly speeds up the colony site evaluator, as it does not have to try to find a path to Europe for each tile.
      • resetLayers

        public void resetLayers()
        Reset layer to reflect what is actually there.
      • fixupRegions

        public void fixupRegions()
        Fix the region parent/child relationships.
      • importTile

        public Tile importTile​(Tile other,
                               int x,
                               int y,
                               Map.Layer layer)
        Import a tile, possibly from another game.
        Parameters:
        other - The Tile to import.
        x - The x-coordinate of the new tile.
        y - The y-coordinate of the new tile.
        layer - The maximum layer to import.
        Returns:
        The new imported Tile.
      • scale

        public Map scale​(int width,
                         int height)
        Scale the map into the specified size. This implementation uses a simple linear scaling, and the isometric shape is not taken into account. FIXME: Find a better method for choosing a group of adjacent tiles. This group can then be merged into a common tile by using the average value (for example: are there a majority of ocean tiles?).
        Parameters:
        width - The width of the resulting map.
        height - The height of the resulting map.
        Returns:
        A scaled version of this map.
      • getTile

        public Tile getTile()
        Gets the location tile. Obviously not applicable to a Map.
        Specified by:
        getTile in interface Location
        Returns:
        Null.
      • getLocationLabelFor

        public StringTemplate getLocationLabelFor​(Player player)
        Get a label for this location for a particular player.
        Specified by:
        getLocationLabelFor in interface Location
        Parameters:
        player - The Player to return the name for.
        Returns:
        A label for this location.
      • add

        public boolean add​(Locatable locatable)
        Adds a Locatable to this Location.
        Specified by:
        add in interface Location
        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
        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
        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
        Parameters:
        locatable - The Locatable to add.
        Returns:
        True if the locatable can be added to this location.
      • getUnitCount

        public int getUnitCount()
        Gets the number of units at this Location.
        Specified by:
        getUnitCount in interface Location
        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
        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
        Returns:
        A list of all the units at this location.
      • getGoodsContainer

        public GoodsContainer getGoodsContainer()
        Gets the GoodsContainer this Location use for storing it's goods.
        Specified by:
        getGoodsContainer in interface Location
        Returns:
        The GoodsContainer or null if the Location cannot store any goods.
      • getSettlement

        public Settlement getSettlement()
        Gets the Settlement this Location is located in.
        Specified by:
        getSettlement in interface Location
        Returns:
        The associated Settlement, or null if none.
      • getColony

        public Colony getColony()
        Get the colony at this location.
        Specified by:
        getColony in interface Location
        Returns:
        A Colony at this location if any, or null if none found.
      • getIndianSettlement

        public IndianSettlement getIndianSettlement()
        Gets the native settlement at this location.
        Specified by:
        getIndianSettlement in interface Location
        Returns:
        The IndianSettlement 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.
      • 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.
      • 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.
      • copyIn

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