net.sf.freecol.server.generator
Class MapGenerator

java.lang.Object
  extended by net.sf.freecol.server.generator.MapGenerator
All Implemented Interfaces:
IMapGenerator

public class MapGenerator
extends java.lang.Object
implements IMapGenerator

Creates random maps and sets the starting locations for the players.


Nested Class Summary
private  class MapGenerator.Territory
           
 
Field Summary
private  LandGenerator landGenerator
           
private static java.util.logging.Logger logger
           
private  MapGeneratorOptions mapGeneratorOptions
           
private static float MIN_DISTANCE_FROM_POLE
           
private  java.util.Random random
           
private  TerrainGenerator terrainGenerator
           
 
Constructor Summary
MapGenerator(java.util.Random random)
          Creates a MapGenerator
 
Method Summary
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 the map with the current set options
private  UnitType generateSkillForLocation(Map map, Tile tile, NationType nationType)
          Generates a skill that could be taught from a settlement on the given Tile.
private  MapGenerator.Territory getClosestTerritory(Map map, Tile tile, java.util.List<MapGenerator.Territory> territories)
           
private  Tile getClosestTile(Map map, Map.Position center, java.util.List<Tile> tiles)
           
 LandGenerator getLandGenerator()
           
 MapGeneratorOptions getMapGeneratorOptions()
          Gets the options used when generating the map.
 TerrainGenerator getTerrainGenerator()
           
private  boolean isStartingPositionTooClose(Map map, int proposedY, int startingPositions, java.util.List<java.lang.Integer> usedYPositions)
          Determine whether a proposed ship starting Y position is "too close" to those already used.
private  Game loadSaveGame(java.io.File importFile)
          Loads a Game from the given File.
private  IndianSettlement placeIndianSettlement(Player player, boolean capital, Map.Position position, Map map)
          Builds a IndianSettlement at the given position.
 
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 MapGeneratorOptions 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

MapGenerator

public MapGenerator(java.util.Random random)
Creates a MapGenerator

See Also:
createMap(net.sf.freecol.common.model.Game)
Method Detail

createMap

public void createMap(Game game)
               throws FreeColException
Description copied from interface: IMapGenerator
Creates the map with the current set options

Specified by:
createMap in interface IMapGenerator
Throws:
FreeColException

loadSaveGame

private Game loadSaveGame(java.io.File importFile)
                   throws FreeColException
Loads a Game from the given File.

Parameters:
importFile - The File to be loading the Game from.
Returns:
The Game.
Throws:
FreeColException

getLandGenerator

public LandGenerator getLandGenerator()

getTerrainGenerator

public TerrainGenerator getTerrainGenerator()

getMapGeneratorOptions

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

Specified by:
getMapGeneratorOptions in interface IMapGenerator
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.

getClosestTile

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

getClosestTerritory

private MapGenerator.Territory getClosestTerritory(Map map,
                                                   Tile tile,
                                                   java.util.List<MapGenerator.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.

isStartingPositionTooClose

private boolean isStartingPositionTooClose(Map map,
                                           int proposedY,
                                           int startingPositions,
                                           java.util.List<java.lang.Integer> usedYPositions)
Determine whether a proposed ship starting Y position is "too close" to those already used.

Parameters:
map - a Map value
proposedY - Proposed ship starting Y position
startingPositions - The number of starting positions
Returns:
True if the proposed position is too close