net.sf.freecol.server.generator
Class TerrainGenerator

java.lang.Object
  extended by net.sf.freecol.server.generator.TerrainGenerator

public class TerrainGenerator
extends java.lang.Object

Class for making a Map based upon a land map.


Field Summary
private  TileImprovementType fishBonusLandType
           
private  TileImprovementType fishBonusRiverType
           
private  TileType lake
           
static int LAND_REGION_MAX_SIZE
           
static int LAND_REGION_MIN_SCORE
           
static int LAND_REGIONS_SCORE_VALUE
           
private static java.util.logging.Logger logger
           
private  OptionGroup mapGeneratorOptions
           
private  java.util.ArrayList<TileType> oceanTileTypes
           
static int PACIFIC_SCORE_VALUE
           
private  java.util.Random random
           
private  TileImprovementType riverType
           
private  java.util.ArrayList<TileType> terrainTileTypes
           
 
Constructor Summary
TerrainGenerator(OptionGroup mapGeneratorOptions, java.util.Random random)
          Creates a new TerrainGenerator.
 
Method Summary
private  void createHighSeas(Map map)
          Places "high seas"-tiles on the border of the given map.
private static void createHighSeas(Map map, int distToLandFromHighSeas, int maxDistanceToEdge)
          Places "high seas"-tiles on the border of the given map.
(package private)  void createLandRegions(Map map)
          Creates land map regions in the given Map.
 void createMap(Game game, boolean[][] landMap)
          Creates a Map for the given Game.
 void createMap(Game game, Game importGame, boolean[][] landMap)
          Creates a Map for the given Game.
private  void createMountains(Map map)
          Creates mountain ranges on the given map.
(package private)  void createOceanRegions(Map map)
          Creates ocean map regions in the given Map.
 Resource createResource(Tile tile)
           
private  void createRivers(Map map)
          Creates rivers on the given map.
private  Tile createTile(Game game, int x, int y, boolean[][] landMap, int latitude)
           
static void determineHighSeas(Map map, int distToLandFromHighSeas, int maxDistanceToEdge)
          Places "high seas"-tiles on the border of the given map.
static void encodeStyle(Tile ocean)
           
private  void fillOcean(Map map, Map.Position p, Region region, java.awt.Rectangle bounds)
          Flood fill ocean regions.
private  void findLakes(Map map)
           
private  boolean[][] floodFill(boolean[][] boolmap, Map.Position p)
           
private  boolean[][] floodFill(boolean[][] boolmap, Map.Position p, int limit)
          Floodfills from a given Position p, based on connectivity information encoded in boolmap
private  int getLand()
          Returns the approximate number of land tiles.
private  OptionGroup getMapGeneratorOptions()
          Gets the MapGeneratorOptions.
 Map.Position getRandomLandPosition(Map map, java.util.Random random)
          Select a random land position on the map.
private  TileType getRandomLandTileType(Game game, int latitude)
          Gets a random land tile type based on the given percentage.
private  TileType getRandomOceanTileType(Game game, int latitude)
           
private  TileType getRandomTileType(Game game, java.util.List<TileType> candidates, int latitude)
          Returns a TileType, that fits to the regional requirements.
private  int limitToRange(int value, int lower, int upper)
           
private  void perhapsAddBonus(Tile t, boolean generateBonus)
          Adds a terrain bonus with a probability determined by the MapGeneratorOptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

PACIFIC_SCORE_VALUE

public static final int PACIFIC_SCORE_VALUE
See Also:
Constant Field Values

LAND_REGION_MAX_SIZE

public static final int LAND_REGION_MAX_SIZE
See Also:
Constant Field Values

mapGeneratorOptions

private final OptionGroup mapGeneratorOptions

random

private final java.util.Random random

lake

private TileType lake

riverType

private TileImprovementType riverType

fishBonusLandType

private TileImprovementType fishBonusLandType

fishBonusRiverType

private TileImprovementType fishBonusRiverType

terrainTileTypes

private java.util.ArrayList<TileType> terrainTileTypes

oceanTileTypes

private java.util.ArrayList<TileType> oceanTileTypes
Constructor Detail

TerrainGenerator

public TerrainGenerator(OptionGroup mapGeneratorOptions,
                        java.util.Random random)
Creates a new TerrainGenerator.

Parameters:
mapGeneratorOptions - The options.
random - A Random number source.
See Also:
createMap(net.sf.freecol.common.model.Game, boolean[][])
Method Detail

limitToRange

private int limitToRange(int value,
                         int lower,
                         int upper)

getRandomLandPosition

public Map.Position getRandomLandPosition(Map map,
                                          java.util.Random random)
Select a random land position on the map. Warning: This method should not be used by any model object unless we have completed restructuring the model (making all model changes at the server). The reason is the use of random numbers in this method.

Parameters:
map - The Map to search in.
random - A Random number source.
Returns:
Position selected

createMap

public void createMap(Game game,
                      boolean[][] landMap)
Creates a Map for the given Game. The Map is added to the Game after it is created.

Parameters:
game - The game.
landMap - Determines whether there should be land or ocean on a given tile. This array also specifies the size of the map that is going to be created.
See Also:
Map

createMap

public void createMap(Game game,
                      Game importGame,
                      boolean[][] landMap)
Creates a Map for the given Game. The Map is added to the Game after it is created.

Parameters:
game - The game.
importGame - The game to import information form.
landMap - Determines whether there should be land or ocean on a given tile. This array also specifies the size of the map that is going to be created.
See Also:
Map

encodeStyle

public static void encodeStyle(Tile ocean)

createTile

private Tile createTile(Game game,
                        int x,
                        int y,
                        boolean[][] landMap,
                        int latitude)

perhapsAddBonus

private void perhapsAddBonus(Tile t,
                             boolean generateBonus)
Adds a terrain bonus with a probability determined by the MapGeneratorOptions.

Parameters:
t - a Tile value
generateBonus - a boolean value

createResource

public Resource createResource(Tile tile)

getMapGeneratorOptions

private OptionGroup getMapGeneratorOptions()
Gets the MapGeneratorOptions.

Returns:
The MapGeneratorOptions being used when creating terrain.

getRandomOceanTileType

private TileType getRandomOceanTileType(Game game,
                                        int latitude)
Parameters:
game -
latitude -
Returns:

getRandomLandTileType

private TileType getRandomLandTileType(Game game,
                                       int latitude)
Gets a random land tile type based on the given percentage.

Parameters:
game - the Game
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).

getRandomTileType

private TileType getRandomTileType(Game game,
                                   java.util.List<TileType> candidates,
                                   int latitude)
Returns a TileType, that fits to the regional requirements.

TODO: Can be used for mountains and rivers too.

Parameters:
game - The game.
candidates - A list of TileTypes to use for calculations.
latitude - The latitude.
Returns:
A TileType that fits to the regional requirements.

createOceanRegions

void createOceanRegions(Map map)
Creates ocean map regions in the given Map. At the moment, the ocean is divided into two by two regions.

Parameters:
map - a Map value

fillOcean

private void fillOcean(Map map,
                       Map.Position p,
                       Region region,
                       java.awt.Rectangle bounds)
Flood fill ocean regions.

Parameters:
map - The Map to fill in.
p - A valid starting Position.
region - A Region to fill with.
bounds - A Rectangle that bounds the filling.

createLandRegions

void createLandRegions(Map map)
Creates land map regions in the given Map. First, the arctic/antarctic regions are defined, based on LandGenerator.POLAR_HEIGHT For the remaining land tiles, one region per contiguous landmass is created.

Parameters:
map - a Map value

createHighSeas

private void createHighSeas(Map map)
Places "high seas"-tiles on the border of the given map.

Parameters:
map - The Map to create high seas on.

determineHighSeas

public static void determineHighSeas(Map map,
                                     int distToLandFromHighSeas,
                                     int maxDistanceToEdge)
Places "high seas"-tiles on the border of the given map. All other tiles previously of type High Seas will be set to Ocean.

Parameters:
map - The Map to create high seas on.
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.

createHighSeas

private static void createHighSeas(Map map,
                                   int distToLandFromHighSeas,
                                   int maxDistanceToEdge)
Places "high seas"-tiles on the border of the given map.

Parameters:
map - The Map to create high seas on.
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.

getLand

private int getLand()
Returns the approximate number of land tiles.

Returns:
the approximate number of land tiles

createMountains

private void createMountains(Map map)
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.

createRivers

private void createRivers(Map map)
Creates rivers on the given map. The number of rivers depends on the map size.

Parameters:
map - The map to create rivers on.

findLakes

private void findLakes(Map map)

floodFill

private boolean[][] floodFill(boolean[][] boolmap,
                              Map.Position p,
                              int limit)
Floodfills from a given Position p, based on connectivity information encoded in boolmap

Parameters:
boolmap - The connectivity information for this floodfill
p - The starting position
limit - Limit to stop floodfill at
Returns:
A boolean[][] of the same size as boolmap, where "true" means was floodfilled

floodFill

private boolean[][] floodFill(boolean[][] boolmap,
                              Map.Position p)