net.sf.freecol.server.generator
Class SimpleMapGenerator

java.lang.Object
  extended by 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.


Nested Class Summary
private  class SimpleMapGenerator.Territory
           
 
Field Summary
private  LandGenerator landGenerator
           
private static java.util.logging.Logger logger
           
private  OptionGroup mapGeneratorOptions
           
private static float MIN_DISTANCE_FROM_POLE
           
private  java.util.Random random
           
private  TerrainGenerator terrainGenerator
           
 
Constructor Summary
SimpleMapGenerator(java.util.Random random, Specification specification)
          Creates a MapGenerator
 
Method Summary
private  void createDebugUnits(Map map, Player player, Tile startTile)
           
 void createEmptyMap(Game game, boolean[][] landMap)
          Creates a Map for the given Game.
private  void createEuropeanUnits(Map map, java.util.List<Player> players)
          Create two ships, one with a colonist, for each player, and select suitable starting positions.
private  void createIndianSettlements(Map map, java.util.List<Player> players)
          Create the Indian settlements, at least a capital for every nation and random numbers of other settlements.
private  void createLostCityRumours(Map map, Game importGame)
          Creates lost city rumours on the given map.
 void createMap(Game game)
          Creates a map given for a game.
private  Tile findFreeNeighbouringTile(IndianSettlement is, java.util.List<Tile> tiles, java.util.Random random)
           
private  Tile findTileFor(Map map, int row, int start, boolean startAtSea)
           
private  UnitType generateSkillForLocation(Map map, Tile tile, NationType nationType)
          Generates a skill that could be taught from a settlement on the given Tile.
private  java.util.List<Map.Position> generateStartingPositions(Map map, java.util.List<Player> players)
           
private  SimpleMapGenerator.Territory getClosestTerritory(Tile tile, java.util.List<SimpleMapGenerator.Territory> territories)
           
private  Tile getClosestTile(Map.Position center, java.util.List<Tile> tiles)
           
private  int getLand()
          Returns the approximate number of land tiles.
 LandGenerator getLandGenerator()
           
 OptionGroup getMapGeneratorOptions()
          Gets the options used when generating the map.
 TerrainGenerator getTerrainGenerator()
           
private  IndianSettlement placeIndianSettlement(Player player, boolean capital, Map.Position position, Map map)
          Builds a IndianSettlement at the given position.
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.
 
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

random

private final java.util.Random random

mapGeneratorOptions

private final OptionGroup mapGeneratorOptions

landGenerator

private final LandGenerator landGenerator

terrainGenerator

private final TerrainGenerator terrainGenerator

MIN_DISTANCE_FROM_POLE

private static final float MIN_DISTANCE_FROM_POLE
See Also:
Constant Field Values
Constructor Detail

SimpleMapGenerator

public SimpleMapGenerator(java.util.Random random,
                          Specification specification)
Creates a MapGenerator

Parameters:
random - The Random number source to use.
specification - a Specification value
See Also:
createMap(net.sf.freecol.common.model.Game)
Method Detail

getLand

private int getLand()
Returns the approximate number of land tiles.

Returns:
the approximate number of land tiles

createMap

public void createMap(Game game)
               throws FreeColException
Creates a map given for a game.

Specified by:
createMap in interface MapGenerator
Parameters:
game - The Game to use.
Throws:
FreeColException
See Also:
net.sf.freecol.server.generator.IMapGenerator#createMap(net.sf.freecol.common.model.Game), net.sf.freecol.server.generator.IMapGenerator#createMap(net.sf.freecol.common.model.Game)

createEmptyMap

public void createEmptyMap(Game game,
                           boolean[][] landMap)
Creates a Map for the given Game. The Map is added to the Game after it is created.

Specified by:
createEmptyMap in interface MapGenerator
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, TerrainGenerator.createMap(net.sf.freecol.common.model.Game, boolean[][])

getLandGenerator

public LandGenerator getLandGenerator()

getTerrainGenerator

public TerrainGenerator getTerrainGenerator()

getMapGeneratorOptions

public OptionGroup getMapGeneratorOptions()
Description copied from interface: MapGenerator
Gets the options used when generating the map.

Specified by:
getMapGeneratorOptions in interface MapGenerator
Returns:
The MapGeneratorOptions.

createLostCityRumours

private void createLostCityRumours(Map map,
                                   Game importGame)
Creates lost city rumours on the given map. The number of rumours depends on the map size.

Parameters:
map - The map to use.
importGame - The game to lost city rumours from.

createIndianSettlements

private void createIndianSettlements(Map map,
                                     java.util.List<Player> players)
Create the Indian settlements, at least a capital for every nation and random numbers of other settlements.

Parameters:
map - The Map to place the indian settlements on.
players - The players to create Settlements and starting locations for. That is; both indian and european players. If players does not contain any indian players, no settlements are added.

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. TODO: degrade the second test to usability, but fix this when the natives-use-water situation is sorted.

Parameters:
tile - The Tile to examine.
Returns:
True if this tile is suitable.

findFreeNeighbouringTile

private Tile findFreeNeighbouringTile(IndianSettlement is,
                                      java.util.List<Tile> tiles,
                                      java.util.Random random)

getClosestTile

private Tile getClosestTile(Map.Position center,
                            java.util.List<Tile> tiles)

getClosestTerritory

private SimpleMapGenerator.Territory getClosestTerritory(Tile tile,
                                                         java.util.List<SimpleMapGenerator.Territory> territories)

placeIndianSettlement

private IndianSettlement placeIndianSettlement(Player player,
                                               boolean capital,
                                               Map.Position position,
                                               Map map)
Builds a IndianSettlement at the given position.

Parameters:
player - The player owning the new settlement.
capital - true if the settlement should be a capital.
position - The position to place the settlement.
map - The map that should get a new settlement.
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 - The Map.
tile - The tile where the settlement will be located.
Returns:
A skill that can be taught to Europeans.

createEuropeanUnits

private void createEuropeanUnits(Map map,
                                 java.util.List<Player> players)
Create two ships, one with a colonist, for each player, and select suitable starting positions.

Parameters:
map - The Map to place the european units on.
players - The players to create Settlements and starting locations for. That is; both indian and european players.

createDebugUnits

private void createDebugUnits(Map map,
                              Player player,
                              Tile startTile)

generateStartingPositions

private java.util.List<Map.Position> generateStartingPositions(Map map,
                                                               java.util.List<Player> players)

findTileFor

private Tile findTileFor(Map map,
                         int row,
                         int start,
                         boolean startAtSea)