Class 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.
    • 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.
    • Method Detail

      • getApproximateLandCount

        private int getApproximateLandCount​(Game game)
        Gets the approximate number of land tiles.
        Parameters:
        game - The Game 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 - The Map to use.
        importMap - An optional Map to import from.
        lb - A LogBuilder to log to.
      • importIndianSettlements

        private boolean importIndianSettlements​(Map map,
                                                Map importMap,
                                                LogBuilder lb)
        Import the native settlements from a game.
        Parameters:
        map - The Map to import settlements to.
        importMap - The Map to import from.
        lb - The LogBuilder 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 - The Map to place the indian settlements on.
        importMap - An optional Map to import from.
        lb - A LogBuilder 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 - The Tile 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 - The IndianSettlement that might claim the tile.
        tiles - A list of Tiles 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 - The Tile to search from.
        territories - The list of Territorys 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 - The Map to place the settlement in.
        territory - The Territory within the map.
        radius - The settlement radius.
        tiles - A list of Tiles to select from.
        lb - A LogBuilder 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 a IndianSettlement at the given position.
        Parameters:
        player - The player owning the new settlement.
        capital - true if the settlement should be a capital.
        tile - The Tile to place the settlement.
        map - The map that should get a new settlement.
        lb - A LogBuilder 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 - The Map.
        tile - The Tile where the settlement will be located.
        nationType - The NationType 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 of Tiles 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 - The Player to find a tile for.
        map - The Map to search.
        east - A list of starting Tiles on the east of the map.
        west - A list of starting Tiles 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 - 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.
        lb - A LogBuilder to log to.
      • findTileFor

        private Tile findTileFor​(Map map,
                                 int row,
                                 int start,
                                 boolean startAtSea,
                                 LogBuilder lb)
      • generateEmptyMap

        public Map generateEmptyMap​(Game game,
                                    int width,
                                    int height,
                                    LogBuilder lb)
        Create an empty map.
        Specified by:
        generateEmptyMap in interface MapGenerator
        Parameters:
        game - The Game to generate for.
        width - The map width.
        height - The map height.
        lb - A LogBuilder 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 interface MapGenerator
        Parameters:
        game - The Game to generate for.
        importMap - An optional Map to import.
        generateEuropeanPlayerUnits - If true, then the european player units are generated.
        lb - A LogBuilder to log to.
        Returns:
        The new Map.