Class LanesMapGenerator

java.lang.Object
squidpony.squidgrid.mapping.LanesMapGenerator
All Implemented Interfaces:
IDungeonGenerator

public class LanesMapGenerator
extends Object
implements IDungeonGenerator
Generate dungeons with between 1 and 3 primary "lanes" going from the upper left "base" to the bottom right "base" (and vice versa, since this is symmetrical). Also fills the area not covered by lanes with "jungle" (random, but symmetrical, room or cave connections). Dungeons are produced by MixedGenerator, like those SerpentMapGenerator makes, but include the wide lanes going from corner to corner. You can call different methods like putCaveCarvers(), putBoxRoomCarvers(), putWalledRoundRoomCarvers(), etc. to affect the "jungle", which defaults to caves unless one or more of the putXXXCarvers methods was called. The lanes are always 5 floor cells wide, measured 8-way. This supports the getEnvironment() method, which can be used in conjunction with RoomFinder to find where separate room, corridor, and cave areas have been placed.
A preview can be seen here https://gist.github.com/tommyettinger/4f57cff23eead11b17bf , with dungeons created with one, two, and three lanes, and only using box-shaped rooms for "jungle." Currently, the two-lane dungeon seems to be ideal for maps that aren't incredibly large; the samples are 80x80, but larger maps may have better jungle layout with three lanes than those three-lane maps can manage on smaller sizes. Another potential advantage of the two-lane approach is that it can be used to generate a "ring" of wide paths around a central "core" of jungle, which wasn't originally intended as a use of this generator but could be very useful for games that, for instance, want guards patrolling an obvious ring, while the player, monsters, and/or other prisoners start in the jungle. Created by Tommy Ettinger on 10/24/2015.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int[] columns  
    protected int lanes  
    protected SymmetryDungeonGenerator mix  
    protected IRNG random  
    protected int[] rows  
  • Constructor Summary

    Constructors 
    Constructor Description
    LanesMapGenerator​(int width, int height, IRNG rng, int lanes)
    This prepares a map generator that will generate a map with the given width and height, using the given RNG.
  • Method Summary

    Modifier and Type Method Description
    char[][] generate()
    This generates a new map by stretching a 16x16 grid of potential rooms to fit the width and height passed to the constructor, randomly expanding columns and rows before contracting the whole to fit perfectly.
    char[][] getDungeon()
    Gets the most recently-produced dungeon as a 2D char array, usually produced by calling IDungeonGenerator.generate() or some similar method present in a specific implementation.
    int[][] getEnvironment()
    Gets a 2D array of int constants, each representing a type of environment corresponding to a static field of MixedGenerator.
    void putBoxRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one.
    void putCaveCarvers​(int count)
    Changes the number of "carvers" that will create caves from one room to the next.
    void putRoundRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one.
    void putWalledBoxRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one.
    void putWalledRoundRoomCarvers​(int count)
    Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LanesMapGenerator

      public LanesMapGenerator​(int width, int height, IRNG rng, int lanes)
      This prepares a map generator that will generate a map with the given width and height, using the given RNG. The dungeon will have the specified number of wide lanes going from upper left to lower right, possibly taking a longer path to approach the other corners. You call the different carver-adding methods to affect what the non-lane portion of the dungeon will look like, putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers(), defaulting to only caves if none are called. You call generate() after adding carvers, which returns a char[][] for a map.
      Parameters:
      width - the width of the final map in cells
      height - the height of the final map in cells
      rng - an RNG object to use for random choices; this make a lot of random choices.
      lanes - between 1 and 3; the number of wide paths to generate going from upper left to lower right.
      See Also:
      MixedGenerator
  • Method Details

    • putCaveCarvers

      public void putCaveCarvers​(int count)
      Changes the number of "carvers" that will create caves from one room to the next. If count is 0 or less, no caves will be made. If count is at least 1, caves are possible, and higher numbers relative to the other carvers make caves more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making caves between rooms; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putBoxRoomCarvers

      public void putBoxRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one. If count is 0 or less, no box-shaped rooms will be made. If count is at least 1, box-shaped rooms are possible, and higher numbers relative to the other carvers make box-shaped rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making box-shaped rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putWalledBoxRoomCarvers

      public void putWalledBoxRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a box shape at the start and end, and a small room at the corner if there is one. This also ensures walls will be placed around the room, only allowing corridors and small cave openings to pass. If count is 0 or less, no box-shaped rooms will be made. If count is at least 1, box-shaped rooms are possible, and higher numbers relative to the other carvers make box-shaped rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making box-shaped rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putRoundRoomCarvers

      public void putRoundRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one. If count is 0 or less, no circular rooms will be made. If count is at least 1, circular rooms are possible, and higher numbers relative to the other carvers make circular rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making circular rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • putWalledRoundRoomCarvers

      public void putWalledRoundRoomCarvers​(int count)
      Changes the number of "carvers" that will create right-angle corridors from one room to the next, create rooms with a random size in a circle shape at the start and end, and a small circular room at the corner if there is one. This also ensures walls will be placed around the room, only allowing corridors and small cave openings to pass. If count is 0 or less, no circular rooms will be made. If count is at least 1, circular rooms are possible, and higher numbers relative to the other carvers make circular rooms more likely. Carvers are shuffled when used, then repeat if exhausted during generation. Since typically about 30-40 rooms are carved, large totals for carver count aren't really needed; aiming for a total of 10 between the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.
      Parameters:
      count - the number of carvers making circular rooms and corridors between them; only matters in relation to other carvers
      See Also:
      MixedGenerator
    • generate

      public char[][] generate()
      This generates a new map by stretching a 16x16 grid of potential rooms to fit the width and height passed to the constructor, randomly expanding columns and rows before contracting the whole to fit perfectly. This uses the Moore Curve, a space-filling curve that loops around on itself, to guarantee that the rooms will always have a long path through the dungeon that, if followed completely, will take you back to your starting room. Some small branches are possible, and large rooms may merge with other rooms nearby. This uses MixedGenerator.
      Specified by:
      generate in interface IDungeonGenerator
      Returns:
      a char[][] where '#' is a wall and '.' is a floor or corridor; x first y second
      See Also:
      MixedGenerator
    • getEnvironment

      public int[][] getEnvironment()
      Gets a 2D array of int constants, each representing a type of environment corresponding to a static field of MixedGenerator. This array will have the same size as the last char 2D array prduced by generate(), and the value of this method if called before generate() is undefined, but probably will be a 2D array of all 0 (UNTOUCHED).
      • MixedGenerator.UNTOUCHED, equal to 0, is used for any cells that aren't near a floor.
      • MixedGenerator.ROOM_FLOOR, equal to 1, is used for floor cells inside wide room areas.
      • MixedGenerator.ROOM_WALL, equal to 2, is used for wall cells around wide room areas.
      • MixedGenerator.CAVE_FLOOR, equal to 3, is used for floor cells inside rough cave areas.
      • MixedGenerator.CAVE_WALL, equal to 4, is used for wall cells around rough cave areas.
      • MixedGenerator.CORRIDOR_FLOOR, equal to 5, is used for floor cells inside narrow corridor areas.
      • MixedGenerator.CORRIDOR_WALL, equal to 6, is used for wall cells around narrow corridor areas.
      Returns:
      a 2D int array where each element is an environment type constant in MixedGenerator
    • getDungeon

      public char[][] getDungeon()
      Description copied from interface: IDungeonGenerator
      Gets the most recently-produced dungeon as a 2D char array, usually produced by calling IDungeonGenerator.generate() or some similar method present in a specific implementation. This normally passes a direct reference and not a copy, so you can normally modify the returned array to propagate changes back into this IDungeonGenerator.
      Specified by:
      getDungeon in interface IDungeonGenerator
      Returns:
      the most recently-produced dungeon/map as a 2D char array