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 classSimpleMapGenerator.Territory
-
Field Summary
Fields Modifier and Type Field Description private RandomUtils.RandomIntCachecacheA cached random integer source.private static java.util.logging.Loggerloggerprivate static floatMIN_DISTANCE_FROM_POLETo 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.RandomrandomThe 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 voidcreateEuropeanUnits(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 TilefindFreeNeighbouringTile(IndianSettlement is, java.util.List<Tile> tiles)Find a free neighbouring tile to a settlement from a list of choices.private TilefindHistoricalStartingPosition(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 TilefindTileFor(Map map, int row, int start, boolean startAtSea, LogBuilder lb)MapgenerateEmptyMap(Game game, int width, int height, LogBuilder lb)Create an empty map.MapgenerateMap(Game game, Map importMap, boolean generateEuropeanPlayerUnits, LogBuilder lb)Creates the map with the current set optionsprivate UnitTypegenerateSkillForLocation(Map map, Tile tile, NationType nationType)Generates a skill that could be taught from a settlement on the given tile.private intgetApproximateLandCount(Game game)Gets the approximate number of land tiles.private SimpleMapGenerator.TerritorygetClosestTerritory(Tile tile, java.util.List<SimpleMapGenerator.Territory> territories)Find the closest territory to a given tile from a list of choices.private booleanimportIndianSettlements(Map map, Map importMap, LogBuilder lb)Import the native settlements from a game.private voidmakeLostCityRumours(Map map, Map importMap, LogBuilder lb)Make lost city rumours on the given map.private voidmakeNativeSettlements(Map map, Map importMap, LogBuilder lb)Make the native settlements, at least a capital for every nation and random numbers of other settlements.private IndianSettlementplaceCapital(Map map, SimpleMapGenerator.Territory territory, int radius, java.util.List<Tile> tiles, LogBuilder lb)Place a native capital in a territory.private IndianSettlementplaceIndianSettlement(Player player, boolean capital, Tile tile, Map map, LogBuilder lb)Builds aIndianSettlementat the given position.private booleansampleTiles(java.util.List<Tile> tiles, int number)Sample a list of tiles to pick spread out starting positions.private booleansuitableForNativeSettlement(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- TheRandomnumber 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- TheGameto 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- TheMapto use.importMap- An optionalMapto import from.lb- ALogBuilderto log to.
-
importIndianSettlements
private boolean importIndianSettlements(Map map, Map importMap, LogBuilder lb)
Import the native settlements from a game.- Parameters:
map- TheMapto import settlements to.importMap- TheMapto import from.lb- TheLogBuilderto 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- TheMapto place the indian settlements on.importMap- An optionalMapto import from.lb- ALogBuilderto 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- TheTileto 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- TheIndianSettlementthat might claim the tile.tiles- A list ofTiles 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- TheTileto search from.territories- The list ofTerritorys to choose from.- Returns:
- The closest
Territoryfound, 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- TheMapto place the settlement in.territory- TheTerritorywithin the map.radius- The settlement radius.tiles- A list ofTiles to select from.lb- ALogBuilderto log to.- Returns:
- The
IndianSettlementplaced, or null if none placed.
-
placeIndianSettlement
private IndianSettlement placeIndianSettlement(Player player, boolean capital, Tile tile, Map map, LogBuilder lb)
Builds aIndianSettlementat the given position.- Parameters:
player- The player owning the new settlement.capital-trueif the settlement should be acapital.tile- TheTileto place the settlement.map- The map that should get a new settlement.lb- ALogBuilderto log to.- Returns:
- The
IndianSettlementjust 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- TheTilewhere the settlement will be located.nationType- TheNationTypeto 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 ofTiles 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- ThePlayerto find a tile for.map- TheMapto search.east- A list of startingTiles on the east of the map.west- A list of startingTiles on the west of the map.- Returns:
- The best
Tilefound, 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- TheMapto place the european units on.players- The players to createSettlements and starting locations for. That is; both indian and european players.lb- ALogBuilderto 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:
generateEmptyMapin interfaceMapGenerator- Parameters:
game- TheGameto generate for.width- The map width.height- The map height.lb- ALogBuilderto 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:
generateMapin interfaceMapGenerator- Parameters:
game- TheGameto generate for.importMap- An optionalMapto import.generateEuropeanPlayerUnits- Iftrue, then the european player units are generated.lb- ALogBuilderto log to.- Returns:
- The new
Map.
-
-