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  MapGeneratorOptions mapGeneratorOptions
           
private  TileType ocean
           
static int PACIFIC_SCORE_VALUE
           
private  java.util.Random random
           
private  TileImprovementType riverType
           
private  java.util.ArrayList<TileType> terrainTileTypes
           
 
Constructor Summary
TerrainGenerator(MapGeneratorOptions 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.
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 tile)
           
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  MapGeneratorOptions getMapGeneratorOptions()
          Gets the MapGeneratorOptions.
private  TileType getRandomLandTileType(int latitudePercent)
          Gets a random land tile type based on the given percentage.
private  void perhapsAddBonus(Game game, 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 MapGeneratorOptions mapGeneratorOptions

random

private java.util.Random random

ocean

private TileType ocean

lake

private TileType lake

riverType

private TileImprovementType riverType

fishBonusLandType

private TileImprovementType fishBonusLandType

fishBonusRiverType

private TileImprovementType fishBonusRiverType

terrainTileTypes

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

TerrainGenerator

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

See Also:
createMap(net.sf.freecol.common.model.Game, boolean[][])
Method Detail

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 tile)

createTile

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

perhapsAddBonus

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

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

getMapGeneratorOptions

private MapGeneratorOptions getMapGeneratorOptions()
Gets the MapGeneratorOptions.

Returns:
The MapGeneratorOptions being used when creating terrain.

getRandomLandTileType

private TileType getRandomLandTileType(int latitudePercent)
Gets a random land tile type based on the given percentage.

Parameters:
latitudePercent - The location of the tile relative to the north/south poles and equator, 100% is the mid-section of the map (equator) 0% is on the top/bottom of the map (poles).

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.

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)