Class TerrainGenerator


  • public class TerrainGenerator
    extends java.lang.Object
    Class for making a Map based upon a land map. FIXME: dynamic lakes, mountains and hills
    • Field Detail

      • logger

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

        public static final int LAND_REGIONS_SCORE_VALUE
        See Also:
        Constant Field Values
      • random

        private final java.util.Random random
        The pseudo random number generator.
      • landTileTypes

        private java.util.List<TileType> landTileTypes
        The cached land and ocean tile types.
      • oceanTileTypes

        private java.util.List<TileType> oceanTileTypes
    • Method Detail

      • limitToRange

        private int limitToRange​(int value,
                                 int lower,
                                 int upper)
      • getApproximateLandCount

        private int getApproximateLandCount​(Game game)
        Gets the approximate number of land tiles.
        Parameters:
        game - The Game to generate for.
        Returns:
        The approximate number of land tiles
      • getRandomLandTileType

        private TileType getRandomLandTileType​(Game game,
                                               int latitude)
        Gets a random land tile type based on the latitude.
        Parameters:
        game - The Game to generate for.
        latitude - The location of the tile relative to the north/south poles and equator: 0 is the mid-section of the map (equator) +/-90 is on the bottom/top of the map (poles).
        Returns:
        A suitable random land tile type.
      • getRandomOceanTileType

        private TileType getRandomOceanTileType​(Game game,
                                                int latitude)
        Gets a random ocean tile type.
        Parameters:
        game - The Game to generate for.
        latitude - The latitude of the proposed tile.
        Returns:
        A suitable random ocean tile type.
      • getRandomTileType

        private TileType getRandomTileType​(Game game,
                                           java.util.List<TileType> candidates,
                                           int latitude)
        Gets a tile type fitted to the regional requirements. FIXME: Can be used for mountains and rivers too.
        Parameters:
        game - The Game to generate for.
        candidates - A list of TileTypes to use for calculations.
        latitude - The tile latitude.
        Returns:
        A suitable TileType.
      • createLandRegions

        private java.util.List<ServerRegion> createLandRegions​(Map map,
                                                               LogBuilder lb)
        Creates land map regions in the given Map. First, the arctic/antarctic regions are defined, based on Map.POLAR_HEIGHT. For the remaining land tiles, one region per contiguous landmass is created.
        Parameters:
        map - The Map to work on.
        lb - A LogBuilder to log to.
        Returns:
        A list of created ServerRegions.
      • createMountains

        private java.util.List<ServerRegion> createMountains​(Map map,
                                                             LogBuilder lb)
        Creates mountain ranges on the given map. The number and size of mountain ranges depends on the map size.
        Parameters:
        map - The map to use.
        lb - A LogBuilder to log to.
        Returns:
        A list of created ServerRegions.
      • createRivers

        private java.util.List<ServerRegion> createRivers​(Map map,
                                                          LogBuilder lb)
        Creates rivers on the given map. The number of rivers depends on the map size.
        Parameters:
        map - The Map to create rivers on.
        lb - A LogBuilder to log to.
        Returns:
        A list of created ServerRegions.
      • createLakeRegions

        private java.util.List<ServerRegion> createLakeRegions​(Map map,
                                                               LogBuilder lb)
        Finds all the lake regions.
        Parameters:
        map - The Map to work on.
        lb - A LogBuilder to log to.
        Returns:
        A list of created ServerRegions.
      • makeLakes

        private java.util.List<ServerRegion> makeLakes​(Map map,
                                                       java.util.List<Tile> lakes)
        Make lake regions from unassigned lake tiles.
        Parameters:
        map - The Map to add to.
        lakes - A list of lake Tiles.
        Returns:
        A list of new ServerRegions.
      • perhapsAddBonus

        private void perhapsAddBonus​(Tile t,
                                     boolean generateBonus)
        Adds a terrain bonus with a probability determined by the MapGeneratorOptions.
        Parameters:
        t - The Tile to add bonuses to.
        generateBonus - Generate the bonus or not.
      • createResource

        private Resource createResource​(Tile tile)
        Create a random resource on a tile.
        Parameters:
        tile - The Tile to create the resource on.
        Returns:
        The created resource, or null if it is not possible.
      • encodeStyle

        public static void encodeStyle​(Tile tile)
        Sets the style of the tiles. Only relevant to water tiles for now. Public because it is used in the river generator.
        Parameters:
        tile - The Tile to set the style of.
      • generateMap

        public Map generateMap​(Game game,
                               Map importMap,
                               LandMap landMap,
                               LogBuilder lb)
        Make a Map.
        Parameters:
        game - The Game to generate a map for.
        importMap - An optional Map to import.
        landMap - The LandMap to use as a template.
        lb - A LogBuilder to log to.
        Returns:
        The new Map.