Package net.sf.freecol.common.model
Class LandMap
- java.lang.Object
-
- net.sf.freecol.common.model.LandMap
-
public class LandMap extends java.lang.Object
A class to encapsulate a binary land map.
-
-
Field Summary
Fields Modifier and Type Field Description private RandomUtils.RandomIntCache
cache
A cached random integer source.private int
height
The map height.private static java.util.logging.Logger
logger
private boolean[][]
map
The land map.private int
numberOfLandTiles
Number of land tiles on the map.private int
width
The map width.
-
Constructor Summary
Constructors Constructor Description LandMap(int width, int height, RandomUtils.RandomIntCache cache)
Create a new land map with specified dimensions.LandMap(Map map, RandomUtils.RandomIntCache cache)
Create a land map by importing it from a given map.LandMap(OptionGroup mgo, RandomUtils.RandomIntCache cache)
Create a new land map using parameters from a supplied map generator options option group.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
addLandMass(int minSize, int maxSize, int x, int y, int distanceToEdge)
Create a new land mass (unconnected to existing land masses) of size up to maxSize, and adds it to the current map if it is at least minSize.private void
addPolarRegions()
Add land to the polar map rows at the top and bottom of the map, with height determined by Map.POLAR_HEIGHT.private void
cleanMap()
Remove any 1x1 islands on the map.private void
createClassicLandMap(int distanceToEdge, int minNumberOfTiles)
Create the standard FreeCol land map.private void
generate(int type, int distanceToEdge, int minNumberOfTiles)
Generate the land map using the given generator type.int
getHeight()
Get the height of the land map.int
getWidth()
Get the width of the land map.private void
growLand(int x, int y, int distanceToEdge)
Determines, based on position, number of adjacent land tiles and some random factor, whether a given map position should be set to land.private boolean
hasAdjacentLand(int x, int y)
Do the given coordinates correspond to a location in the land map with adjacent land? Note: does not check the tile at the coordinates itself.boolean
hasLand()
Is there any land in this land map?boolean
isLand(int x, int y)
Is there land on this map at a given xy coordinate?boolean
isValid(int x, int y)
Is an xy coordinate valid on this map?private java.util.List<Map.Position>
newPositions(Map.Position position, int distanceToEdge)
Get the positions surrounding a central position that are potential valid land positions.private boolean
setLand(int x, int y)
Set a map position to land, and increase the land tile count.private void
setLand(int x, int y, int distanceToEdge)
Sets a given map position to land and grow outward.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
width
private final int width
The map width.
-
height
private final int height
The map height.
-
cache
private final RandomUtils.RandomIntCache cache
A cached random integer source.
-
map
private boolean[][] map
The land map. True means land.
-
numberOfLandTiles
private int numberOfLandTiles
Number of land tiles on the map.
-
-
Constructor Detail
-
LandMap
public LandMap(int width, int height, RandomUtils.RandomIntCache cache)
Create a new land map with specified dimensions.- Parameters:
width
- The map width.height
- The map height.cache
- A pseudo random number source.
-
LandMap
public LandMap(Map map, RandomUtils.RandomIntCache cache)
Create a land map by importing it from a given map.- Parameters:
map
- TheMap
to get the land map from.cache
- A pseudo random number source.
-
LandMap
public LandMap(OptionGroup mgo, RandomUtils.RandomIntCache cache)
Create a new land map using parameters from a supplied map generator options option group.- Parameters:
mgo
- The map generatorOptionGroup
to use.cache
- A pseudo random number source.
-
-
Method Detail
-
getWidth
public final int getWidth()
Get the width of the land map.- Returns:
- The map width.
-
getHeight
public final int getHeight()
Get the height of the land map.- Returns:
- The map height.
-
isValid
public boolean isValid(int x, int y)
Is an xy coordinate valid on this map?- Parameters:
x
- The x coordinate.y
- The y coordinate.- Returns:
- True if there coordinate is valid.
-
isLand
public boolean isLand(int x, int y)
Is there land on this map at a given xy coordinate?- Parameters:
x
- The x coordinate.y
- The y coordinate.- Returns:
- True if there is land present.
-
hasLand
public boolean hasLand()
Is there any land in this land map?- Returns:
- True if any land is present.
-
setLand
private boolean setLand(int x, int y)
Set a map position to land, and increase the land tile count.- Parameters:
x
- The x coordinate of the new land.y
- The y coordinate of the new land.- Returns:
- True if the land tile was set.
-
setLand
private void setLand(int x, int y, int distanceToEdge)
Sets a given map position to land and grow outward. Calls #growLand(int,int) for all valid adjacent map positions, which may recursively call setLand for these.- Parameters:
x
- The x coordinate of the new land.y
- The y coordinate of the new land.distanceToEdge
- The preferred distance to the map edge.
-
generate
private final void generate(int type, int distanceToEdge, int minNumberOfTiles)
Generate the land map using the given generator type.- Parameters:
type
- The generator type.minNumberOfTiles
- The minimum land tiles to generate.distanceToEdge
- The preferred distance to the map edge.
-
createClassicLandMap
private void createClassicLandMap(int distanceToEdge, int minNumberOfTiles)
Create the standard FreeCol land map.- Parameters:
distanceToEdge
- The nominal edge clearance.minNumberOfTiles
- Lower bound for the tiles to create.
-
addPolarRegions
private void addPolarRegions()
Add land to the polar map rows at the top and bottom of the map, with height determined by Map.POLAR_HEIGHT. FIXME: Make POLAR_HEIGHT an option.
-
cleanMap
private void cleanMap()
Remove any 1x1 islands on the map.
-
hasAdjacentLand
private boolean hasAdjacentLand(int x, int y)
Do the given coordinates correspond to a location in the land map with adjacent land? Note: does not check the tile at the coordinates itself.- Parameters:
x
- The x coordinate to check.y
- The y coordinate to check.- Returns:
- True if this tile has adjacent land.
-
newPositions
private java.util.List<Map.Position> newPositions(Map.Position position, int distanceToEdge)
Get the positions surrounding a central position that are potential valid land positions.- Parameters:
position
- The centralPosition
to work from.distanceToEdge
- The preferred distance to the map edge.- Returns:
- A list of suitable
Position
s.
-
growLand
private void growLand(int x, int y, int distanceToEdge)
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.- Parameters:
x
- The x coordinate to grow land at.y
- The y coordinate to grow land at.distanceToEdge
- The preferred distance to the map edge.
-
addLandMass
private int addLandMass(int minSize, int maxSize, int x, int y, int distanceToEdge)
Create a new land mass (unconnected to existing land masses) of size up to maxSize, and adds it to the current map if it is at least minSize.- Parameters:
minSize
- Minimum number of tiles in the land mass.maxSize
- Maximum number of tiles in the land mass.x
- Optional starting x coordinate (chosen randomly if negative).y
- Optional starting y coordinate (chosen randomly if negative).distanceToEdge
- The preferred distance to the map edge.- Returns:
- The number of tiles added.
-
-