Package net.sf.freecol.server.generator
Class TerrainGenerator
- java.lang.Object
-
- net.sf.freecol.server.generator.TerrainGenerator
-
public class TerrainGenerator extends java.lang.ObjectClass for making aMapbased upon a land map. FIXME: dynamic lakes, mountains and hills
-
-
Field Summary
Fields Modifier and Type Field Description private RandomUtils.RandomIntCachecacheA cached random integer source.static intLAND_REGION_MAX_SIZEstatic intLAND_REGION_MIN_SCOREstatic intLAND_REGIONS_SCORE_VALUEprivate java.util.List<TileType>landTileTypesThe cached land and ocean tile types.private static java.util.logging.Loggerloggerprivate java.util.List<TileType>oceanTileTypesprivate java.util.RandomrandomThe 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 ResourcecreateResource(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 voidencodeStyle(Tile tile)Sets the style of the tiles.MapgenerateMap(Game game, Map importMap, LandMap landMap, LogBuilder lb)Make aMap.private intgetApproximateLandCount(Game game)Gets the approximate number of land tiles.private TileTypegetRandomLandTileType(Game game, int latitude)Gets a random land tile type based on the latitude.private TileTypegetRandomOceanTileType(Game game, int latitude)Gets a random ocean tile type.private TileTypegetRandomTileType(Game game, java.util.List<TileType> candidates, int latitude)Gets a tile type fitted to the regional requirements.private intlimitToRange(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 voidperhapsAddBonus(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- TheGameto 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- TheGameto 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- TheGameto 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- TheGameto generate for.candidates- A list ofTileTypes 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- TheMapto work on.lb- ALogBuilderto 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- ALogBuilderto 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- TheMapto create rivers on.lb- ALogBuilderto 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- TheMapto work on.lb- ALogBuilderto 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- TheMapto add to.lakes- A list of lakeTiles.- Returns:
- A list of new
ServerRegions.
-
perhapsAddBonus
private void perhapsAddBonus(Tile t, boolean generateBonus)
Adds a terrain bonus with a probability determined by theMapGeneratorOptions.- Parameters:
t- TheTileto add bonuses to.generateBonus- Generate the bonus or not.
-
createResource
private Resource createResource(Tile tile)
Create a random resource on a tile.- Parameters:
tile- TheTileto 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- TheTileto set the style of.
-
generateMap
public Map generateMap(Game game, Map importMap, LandMap landMap, LogBuilder lb)
Make aMap.- Parameters:
game- TheGameto generate a map for.importMap- An optionalMapto import.landMap- TheLandMapto use as a template.lb- ALogBuilderto log to.- Returns:
- The new
Map.
-
-