Package net.sf.freecol.server.generator
Class TerrainGenerator
- java.lang.Object
-
- net.sf.freecol.server.generator.TerrainGenerator
-
public class TerrainGenerator extends java.lang.Object
Class for making aMap
based upon a land map. FIXME: dynamic lakes, mountains and hills
-
-
Field Summary
Fields Modifier and Type Field Description private RandomUtils.RandomIntCache
cache
A cached random integer source.static int
LAND_REGION_MAX_SIZE
static int
LAND_REGION_MIN_SCORE
static int
LAND_REGIONS_SCORE_VALUE
private java.util.List<TileType>
landTileTypes
The cached land and ocean tile types.private static java.util.logging.Logger
logger
private java.util.List<TileType>
oceanTileTypes
private java.util.Random
random
The pseudo random number generator.
-
Constructor Summary
Constructors Constructor Description TerrainGenerator(java.util.Random random)
Creates a newTerrainGenerator
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<ServerRegion>
createLakeRegions(Map map, LogBuilder lb)
Finds all the lake regions.private java.util.List<ServerRegion>
createLandRegions(Map map, LogBuilder lb)
Creates land map regions in the given Map.private java.util.List<ServerRegion>
createMountains(Map map, LogBuilder lb)
Creates mountain ranges on the given map.private Resource
createResource(Tile tile)
Create a random resource on a tile.private java.util.List<ServerRegion>
createRivers(Map map, LogBuilder lb)
Creates rivers on the given map.static void
encodeStyle(Tile tile)
Sets the style of the tiles.Map
generateMap(Game game, Map importMap, LandMap landMap, LogBuilder lb)
Make aMap
.private int
getApproximateLandCount(Game game)
Gets the approximate number of land tiles.private TileType
getRandomLandTileType(Game game, int latitude)
Gets a random land tile type based on the latitude.private TileType
getRandomOceanTileType(Game game, int latitude)
Gets a random ocean tile type.private TileType
getRandomTileType(Game game, java.util.List<TileType> candidates, int latitude)
Gets a tile type fitted to the regional requirements.private int
limitToRange(int value, int lower, int upper)
private java.util.List<ServerRegion>
makeLakes(Map map, java.util.List<Tile> lakes)
Make lake regions from unassigned lake tiles.private void
perhapsAddBonus(Tile t, boolean generateBonus)
Adds a terrain bonus with a probability determined by theMapGeneratorOptions
.
-
-
-
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
-
LAND_REGION_MIN_SCORE
public static final int LAND_REGION_MIN_SCORE
- See Also:
- Constant Field Values
-
LAND_REGION_MAX_SIZE
public static final int LAND_REGION_MAX_SIZE
- See Also:
- Constant Field Values
-
random
private final java.util.Random random
The pseudo random number generator.
-
cache
private final RandomUtils.RandomIntCache cache
A cached random integer source.
-
landTileTypes
private java.util.List<TileType> landTileTypes
The cached land and ocean tile types.
-
oceanTileTypes
private java.util.List<TileType> oceanTileTypes
-
-
Constructor Detail
-
TerrainGenerator
public TerrainGenerator(java.util.Random random)
Creates a newTerrainGenerator
. FIXME: cache or randomizer???- Parameters:
random
- A pseudo-random number source.- See Also:
generateMap(net.sf.freecol.common.model.Game, net.sf.freecol.common.model.Map, net.sf.freecol.common.model.LandMap, net.sf.freecol.common.util.LogBuilder)
-
-
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
- TheGame
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
- TheGame
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
- TheGame
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
- TheGame
to generate for.candidates
- A list ofTileType
s 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 onMap.POLAR_HEIGHT
. For the remaining land tiles, one region per contiguous landmass is created.- Parameters:
map
- TheMap
to work on.lb
- ALogBuilder
to log to.- Returns:
- A list of created
ServerRegion
s.
-
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
- ALogBuilder
to log to.- Returns:
- A list of created
ServerRegion
s.
-
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
- TheMap
to create rivers on.lb
- ALogBuilder
to log to.- Returns:
- A list of created
ServerRegion
s.
-
createLakeRegions
private java.util.List<ServerRegion> createLakeRegions(Map map, LogBuilder lb)
Finds all the lake regions.- Parameters:
map
- TheMap
to work on.lb
- ALogBuilder
to log to.- Returns:
- A list of created
ServerRegion
s.
-
makeLakes
private java.util.List<ServerRegion> makeLakes(Map map, java.util.List<Tile> lakes)
Make lake regions from unassigned lake tiles.- Parameters:
map
- TheMap
to add to.lakes
- A list of lakeTile
s.- Returns:
- A list of new
ServerRegion
s.
-
perhapsAddBonus
private void perhapsAddBonus(Tile t, boolean generateBonus)
Adds a terrain bonus with a probability determined by theMapGeneratorOptions
.- Parameters:
t
- TheTile
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
- TheTile
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
- TheTile
to set the style of.
-
generateMap
public Map generateMap(Game game, Map importMap, LandMap landMap, LogBuilder lb)
Make aMap
.- Parameters:
game
- TheGame
to generate a map for.importMap
- An optionalMap
to import.landMap
- TheLandMap
to use as a template.lb
- ALogBuilder
to log to.- Returns:
- The new
Map
.
-
-