Package net.sf.freecol.server.generator
Class SimpleMapGenerator
- java.lang.Object
-
- net.sf.freecol.server.generator.SimpleMapGenerator
-
- All Implemented Interfaces:
MapGenerator
public class SimpleMapGenerator extends java.lang.Object implements MapGenerator
Creates random maps and sets the starting locations for the players. No visibility implications here as this all happens pre-game, so no +/-vis annotations are needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SimpleMapGenerator.Territory
-
Field Summary
Fields Modifier and Type Field Description private RandomUtils.RandomIntCache
cache
A cached random integer source.private static java.util.logging.Logger
logger
private static float
MIN_DISTANCE_FROM_POLE
To avoid starting positions too close to the poles, this percentage indicating how much of the half map close to the pole cannot be spawned on.private java.util.Random
random
The random number source.
-
Constructor Summary
Constructors Constructor Description SimpleMapGenerator(java.util.Random random)
Creates aMapGenerator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<Unit>
createDebugUnits(Map map, Player player, Tile startTile, LogBuilder lb)
private void
createEuropeanUnits(Map map, java.util.List<Player> players, LogBuilder lb)
Create two ships, one with a colonist, for each player, and select suitable starting positions.private Tile
findFreeNeighbouringTile(IndianSettlement is, java.util.List<Tile> tiles)
Find a free neighbouring tile to a settlement from a list of choices.private Tile
findHistoricalStartingPosition(Player player, Map map, java.util.List<Tile> east, java.util.List<Tile> west)
Find the best historical starting position for a player from lists of tiles.private Tile
findTileFor(Map map, int row, int start, boolean startAtSea, LogBuilder lb)
Map
generateEmptyMap(Game game, int width, int height, LogBuilder lb)
Create an empty map.Map
generateMap(Game game, Map importMap, boolean generateEuropeanPlayerUnits, LogBuilder lb)
Creates the map with the current set optionsprivate UnitType
generateSkillForLocation(Map map, Tile tile, NationType nationType)
Generates a skill that could be taught from a settlement on the given tile.private int
getApproximateLandCount(Game game)
Gets the approximate number of land tiles.private SimpleMapGenerator.Territory
getClosestTerritory(Tile tile, java.util.List<SimpleMapGenerator.Territory> territories)
Find the closest territory to a given tile from a list of choices.private boolean
importIndianSettlements(Map map, Map importMap, LogBuilder lb)
Import the native settlements from a game.private void
makeLostCityRumours(Map map, Map importMap, LogBuilder lb)
Make lost city rumours on the given map.private void
makeNativeSettlements(Map map, Map importMap, LogBuilder lb)
Make the native settlements, at least a capital for every nation and random numbers of other settlements.private IndianSettlement
placeCapital(Map map, SimpleMapGenerator.Territory territory, int radius, java.util.List<Tile> tiles, LogBuilder lb)
Place a native capital in a territory.private IndianSettlement
placeIndianSettlement(Player player, boolean capital, Tile tile, Map map, LogBuilder lb)
Builds aIndianSettlement
at the given position.private boolean
sampleTiles(java.util.List<Tile> tiles, int number)
Sample a list of tiles to pick spread out starting positions.private boolean
suitableForNativeSettlement(Tile tile)
Is a tile suitable for a native settlement? Require the tile be settleable, and at least half its neighbours also be settleable.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
MIN_DISTANCE_FROM_POLE
private static final float MIN_DISTANCE_FROM_POLE
To avoid starting positions too close to the poles, this percentage indicating how much of the half map close to the pole cannot be spawned on.- See Also:
- Constant Field Values
-
random
private final java.util.Random random
The random number source.
-
cache
private final RandomUtils.RandomIntCache cache
A cached random integer source.
-
-
Constructor Detail
-
SimpleMapGenerator
public SimpleMapGenerator(java.util.Random random)
Creates aMapGenerator
- Parameters:
random
- TheRandom
number source to use.- See Also:
generateMap(net.sf.freecol.common.model.Game, net.sf.freecol.common.model.Map, boolean, net.sf.freecol.common.util.LogBuilder)
-
-
Method Detail
-
getApproximateLandCount
private int getApproximateLandCount(Game game)
Gets the approximate number of land tiles.- Parameters:
game
- TheGame
to look up options in.- Returns:
- The approximate number of land tiles
-
makeLostCityRumours
private void makeLostCityRumours(Map map, Map importMap, LogBuilder lb)
Make lost city rumours on the given map. The number of rumours depends on the map size.- Parameters:
map
- TheMap
to use.importMap
- An optionalMap
to import from.lb
- ALogBuilder
to log to.
-
importIndianSettlements
private boolean importIndianSettlements(Map map, Map importMap, LogBuilder lb)
Import the native settlements from a game.- Parameters:
map
- TheMap
to import settlements to.importMap
- TheMap
to import from.lb
- TheLogBuilder
to log to.- Returns:
- True if the settlements were imported.
-
makeNativeSettlements
private void makeNativeSettlements(Map map, Map importMap, LogBuilder lb)
Make the native settlements, at least a capital for every nation and random numbers of other settlements.- Parameters:
map
- TheMap
to place the indian settlements on.importMap
- An optionalMap
to import from.lb
- ALogBuilder
to log to.
-
suitableForNativeSettlement
private boolean suitableForNativeSettlement(Tile tile)
Is a tile suitable for a native settlement? Require the tile be settleable, and at least half its neighbours also be settleable. FIXME: degrade the second test to usability, but wait until the natives-use-water situation is sorted.- Parameters:
tile
- TheTile
to examine.- Returns:
- True if this tile is suitable.
-
findFreeNeighbouringTile
private Tile findFreeNeighbouringTile(IndianSettlement is, java.util.List<Tile> tiles)
Find a free neighbouring tile to a settlement from a list of choices.- Parameters:
is
- TheIndianSettlement
that might claim the tile.tiles
- A list ofTile
s to start searching from.- Returns:
- The first suitable tile found, or null if none present.
-
getClosestTerritory
private SimpleMapGenerator.Territory getClosestTerritory(Tile tile, java.util.List<SimpleMapGenerator.Territory> territories)
Find the closest territory to a given tile from a list of choices.- Parameters:
tile
- TheTile
to search from.territories
- The list ofTerritory
s to choose from.- Returns:
- The closest
Territory
found, or null if none.
-
placeCapital
private IndianSettlement placeCapital(Map map, SimpleMapGenerator.Territory territory, int radius, java.util.List<Tile> tiles, LogBuilder lb)
Place a native capital in a territory.- Parameters:
map
- TheMap
to place the settlement in.territory
- TheTerritory
within the map.radius
- The settlement radius.tiles
- A list ofTile
s to select from.lb
- ALogBuilder
to log to.- Returns:
- The
IndianSettlement
placed, or null if none placed.
-
placeIndianSettlement
private IndianSettlement placeIndianSettlement(Player player, boolean capital, Tile tile, Map map, LogBuilder lb)
Builds aIndianSettlement
at the given position.- Parameters:
player
- The player owning the new settlement.capital
-true
if the settlement should be acapital
.tile
- TheTile
to place the settlement.map
- The map that should get a new settlement.lb
- ALogBuilder
to log to.- Returns:
- The
IndianSettlement
just being placed on the map.
-
generateSkillForLocation
private UnitType generateSkillForLocation(Map map, Tile tile, NationType nationType)
Generates a skill that could be taught from a settlement on the given tile.- Parameters:
map
- TheMap
.tile
- TheTile
where the settlement will be located.nationType
- TheNationType
to generate a skill for.- Returns:
- A skill that can be taught to Europeans.
-
sampleTiles
private boolean sampleTiles(java.util.List<Tile> tiles, int number)
Sample a list of tiles to pick spread out starting positions. Shuffle the result or clear it if there were too few tiles.- Parameters:
tiles
- The list ofTile
s to sample.number
- The number of players, which determines the spacing.- Returns:
- True if there were enough tiles in the list.
-
findHistoricalStartingPosition
private Tile findHistoricalStartingPosition(Player player, Map map, java.util.List<Tile> east, java.util.List<Tile> west)
Find the best historical starting position for a player from lists of tiles.- Parameters:
player
- ThePlayer
to find a tile for.map
- TheMap
to search.east
- A list of startingTile
s on the east of the map.west
- A list of startingTile
s on the west of the map.- Returns:
- The best
Tile
found, or null if none suitable.
-
createEuropeanUnits
private void createEuropeanUnits(Map map, java.util.List<Player> players, LogBuilder lb)
Create two ships, one with a colonist, for each player, and select suitable starting positions.- Parameters:
map
- TheMap
to place the european units on.players
- The players to createSettlement
s and starting locations for. That is; both indian and european players.lb
- ALogBuilder
to log to.
-
findTileFor
private Tile findTileFor(Map map, int row, int start, boolean startAtSea, LogBuilder lb)
-
createDebugUnits
private java.util.List<Unit> createDebugUnits(Map map, Player player, Tile startTile, LogBuilder lb)
-
generateEmptyMap
public Map generateEmptyMap(Game game, int width, int height, LogBuilder lb)
Create an empty map.- Specified by:
generateEmptyMap
in interfaceMapGenerator
- Parameters:
game
- TheGame
to generate for.width
- The map width.height
- The map height.lb
- ALogBuilder
to log to.- Returns:
- A new empty
Map
.
-
generateMap
public Map generateMap(Game game, Map importMap, boolean generateEuropeanPlayerUnits, LogBuilder lb)
Creates the map with the current set options- Specified by:
generateMap
in interfaceMapGenerator
- Parameters:
game
- TheGame
to generate for.importMap
- An optionalMap
to import.generateEuropeanPlayerUnits
- Iftrue
, then the european player units are generated.lb
- ALogBuilder
to log to.- Returns:
- The new
Map
.
-
-