net.sf.freecol.server.generator
Class LandGenerator

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

public class LandGenerator
extends java.lang.Object

Class for creating a land map.

A land map is a two-dimensional array with the boolean values:


Field Summary
private  int genType
           
private  int height
           
private  int landMass
           
private  boolean[][] map
           
private  OptionGroup mapGeneratorOptions
           
private  int minimumNumberOfTiles
           
private  int numberOfLandTiles
           
private  int preferredDistanceToEdge
           
private  java.util.Random random
           
private  int width
           
 
Constructor Summary
LandGenerator(OptionGroup mapGeneratorOptions, java.util.Random random)
          Creates a new LandGenerator.
 
Method Summary
private  void addLandmass(int minsize, int maxsize)
           
private  void addLandmass(int minsize, int maxsize, int x, int y)
          Tries to create a new land mass (unconnected to existing land masses) of size=maxsize, and adds it to the current map if it is at least size=minsize.
private  void addPolarRegions()
          Adds land to the first two and last two rows.
private  void cleanMap()
          Removes any 1x1 islands on the map.
private  void createClassicLandMap()
           
 boolean[][] createLandMap()
          Creates a new land map.
private  void growLand(int i, int j)
          Determines, based on position, number of adjacent land tiles and some random factor, whether a given map position should be set to land.
static boolean[][] importLandMap(Game game)
          Imports the land map from the given Game.
private  boolean isSingleTile(int x, int y)
          Returns true if there are no adjacent land to the given coordinates.
private  void setLand(int x, int y)
          Sets a given map position to land.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapGeneratorOptions

private final OptionGroup mapGeneratorOptions

random

private final java.util.Random random

map

private boolean[][] map

width

private int width

height

private int height

landMass

private int landMass

preferredDistanceToEdge

private int preferredDistanceToEdge

numberOfLandTiles

private int numberOfLandTiles

minimumNumberOfTiles

private int minimumNumberOfTiles

genType

private int genType
Constructor Detail

LandGenerator

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

Parameters:
mapGeneratorOptions - The options to be used when creating a land map.
random - The Random number source to use.
See Also:
createLandMap()
Method Detail

importLandMap

public static boolean[][] importLandMap(Game game)
Imports the land map from the given Game.

Parameters:
game - The Game to get the land map from.
Returns:
An array where true means land and false means ocean.

createLandMap

public boolean[][] createLandMap()
Creates a new land map.

Returns:
An array where true means land and false means ocean.

createClassicLandMap

private void createClassicLandMap()

addLandmass

private void addLandmass(int minsize,
                         int maxsize,
                         int x,
                         int y)
Tries to create a new land mass (unconnected to existing land masses) of size=maxsize, and adds it to the current map if it is at least size=minsize.


addLandmass

private void addLandmass(int minsize,
                         int maxsize)

addPolarRegions

private void addPolarRegions()
Adds land to the first two and last two rows.


cleanMap

private void cleanMap()
Removes any 1x1 islands on the map.


isSingleTile

private boolean isSingleTile(int x,
                             int y)
Returns true if there are no adjacent land to the given coordinates.


setLand

private void setLand(int x,
                     int y)
Sets a given map position to land. Calls #gl(int,int) for all valid adjacent map positions, which may recursively call setLand for these.


growLand

private void growLand(int i,
                      int j)
Determines, based on position, number of adjacent land tiles and some random factor, whether a given map position should be set to land. This is called for all valid map positions adjacent to a position that has been set to land by #setLand(int,int), and may recursively call setLand for the current position.