Class ConnectingMapGenerator

java.lang.Object
com.github.yellowstonegames.place.ConnectingMapGenerator
All Implemented Interfaces:
PlaceGenerator

public class ConnectingMapGenerator extends Object implements PlaceGenerator
A room placing algorithm developed by Rayvolution for his game Fail To Hero, this was simple to implement but delivers complex connectivity. It is meant to ensure all rooms are connected, but usually not directly, and many routes need to wind throughout the map to get to a goal.
With roomWidth and roomHeight set to 3, and wallThickness set to 2:
┌────────────────────────────┐┌────────┐┌────────┐┌────────┐
│............................││........││........││........│
│............................││........││........││........│
│............................││........││........││........│
│...┌──────────┐...┌─────┐...││...┌┐...│└────┐...││...┌────┘
│...│┌───┐┌────┘...│┌────┘...└┘...││...└────┐│...││...└────┐
│...││...││........││.............││........││...││........│
│...││...││........││.............││........││...││........│
│...││...││........││.......<.....││........││...││........│
└───┘│...││...┌────┘│...┌─────────┘└────────┘│...│└────┐...│
┌────┘...││...└────┐│...│┌───────────────────┘...└─────┘...│
│........││........││...││.................................│
│.......>││........││...││.................................│
│........││........││...││.................................│
│...┌────┘└────┐...│└───┘│...┌─────────────────────────────┘
│...│┌────────┐│...└─────┘...└────┐┌───┐┌────────┐┌────────┐
│...││........││..................││...││........││........│
│...││........││..................││...││........││........│
│...││........││..................││...││........││........│
│...││...┌┐...│└────┐...┌─────────┘│...│└────┐...│└────┐...│
│...││...││...└─────┘...│┌────────┐│...└────┐│...└─────┘...│
│...││...││.............││........││........││.............│
│...││...││.............││........││........││.............│
│...││...││.............││........││........││.............│
│...││...││...┌─────────┘│...┌┐...││...┌────┘│...┌─────┐...│
│...└┘...││...└──────────┘...││...└┘...└─────┘...│┌────┘...│
│........││..................││..................││........│
│........││..................││..................││........│
│........││..................││..................││........│
└────────┘└──────────────────┘└──────────────────┘└────────┘

With roomWidth, roomHeight, and wallThickness all set to 1:
┌───────────────┬─┬───────────┬─────┬───┬─────────┬─┬───┬─┐
│...............│.│...........│.....│...│.........│.│...│.│
│.┌──────────.┌─┘.│.┌──.────┬─┤.┌───┤.│.│.──┐.──┐.│.│.│.│.│
│.│...........│.....│.......│.│.│...│.│.....│...│.│...│...│
├─┘.┌────.┌─┐.└─────┘.┌──.│.│.│.│.┌─┘.│.│.──┼───┤.└─┬─┘.│.│
│...│.....│.│.........│...│.│...│.│...│.│...│...│...│...│.│
│.┌─┴───┬─┘.│.┌──.┌───┤.──┤.│.┌─┤.│.┌─┴─┼─┐.│.│.└───┤.│.└─┤
│.│.....│...│.│...│...│...│.│.│.│...│...│.│...│.....│.│...│
├─┤.│.│.│.──┘.│.│.└─┐.├───┤.│.│.│.──┤.│.│.│.──┤.│.│.│.└─┐.│
│.│.│.│.......│.│...│.│...│.│.......│.│...│...│.│.│.│...│.│
│.│.└─┼────.┌─┘.└───┘.│.│.└─┴─┬─┬──.├─┤.──┴───┼─┤.├─┴─┐.└─┤
│.│...│>....│.........│.│.....│.│...│.│.......│.│.│...│...│
│.└─┐.│.┌───┴────.│.│.│.└─┬───┘.│.┌─┘.├───┐.┌─┘.├─┘.│.│.│<│
│...│.│.│.........│.│.....│.......│...│...│.│...│...│...│.│
├──.├─┼─┴──.│.│.┌─┘.├───┐.└──.──┬─┘.┌─┘.│.│.│.┌─┘.──┴───┤.│
│...│.│.....│.│.│...│...│.......│...│...│...│.│.........│.│
├─┐.│.│.──┬─┘.├─┘.┌─┤.──┼───┐.│.│.│.└──.└───┤.│.│.┌─┐.│.│.│
│.│...│...│...│...│.│...│...│.│.│.│.........│.│.│.│.│.│.│.│
│.│.│.└─┬─┴─┬─┴─┬─┤.├──.│.──┘.│.│.├──────.│.│.└─┤.│.│.└─┤.│
│...│...│...│...│.│.│.........│...│.......│.....│.│.│...│.│
│.┌─┤.│.│.│.│.│.│.│.│.──┐.──┐.├──.└───────┴─────┘.│.├──.├─┤
│.│.│.│.│.│.│.│...│.│...│...│.│...................│.│...│.│
│.│.├─┘.│.│.│.├──.│.└───┴─┐.│.└───────┐.──┐.──┬─┐.│.│.──┘.│
│.│.│.....│.│.│...│.......│.│.........│...│...│.│...│.....│
├─┘.│.┌──.│.└─┘.┌─┴────.│.│.├───────┐.└─┐.├──.│.└─┬─┘.┌──.│
│.....│...│.....│.......│...│.......│...│.│.......│...│...│
│.────┴─┐.├────.│.│.────┤.──┘.┌────.├───┘.│.┌────.├──.│.──┤
│.......│.│.......│.....│.....│.....│.....│.│.....│...│...│
└───────┴─┴───────┴─────┴─────┴─────┴─────┴─┴─────┴───┴───┘

With divideRooms set to 0.65:
┌─────┬───────────┬───────────┬─────┬─────┬─────┬─────┬─────┐
│.....+...........│...........│.....│.....│.....│.....+.....│
│.....│...........│...........│.....+.....│.....│.....│.....│
│.....│...........│...........+.....│.....│.....│.....│.....│
│.....│...........│...........│.....│.....│.....│.....│.....│
│.....│.......................│.....│.....│.....│.....│.....│
│.....│.....┌─────┬───+─┬─────┼─────┼─────┼──+──┼────+┼──+──┤
│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│
│.....│.....│.....│.....│.....│.....│.....│.....│.....│.....│
│.....│.....│.....│.....│.....│.....+.....│.....│.....│.....│
│.....│.....│.....│.....│.....+.....│.....│.....│.....│.....│
│.....│.....│.....│.....+.....│.....│.....+.....│.....│.....│
├────+┼───+─┼────+┼─────┴─────┴─────┘.....├─────┼─────┤.....│
│.....│.....│.....│.......................│.....│....>│.....│
│.....│.....│.....│.....│.................│.....│.....│.....│
│.....│.....│..<..│.....│.................│.....│.....│.....│
│.....│.....│.....+.....│.................│.....│.....+.....│
│.....│.....│.....│.....│.................│.....│.....│.....│
│.────┼────.├─────┼─────┴───────────┬────.├────.├──+──┼──+──┤
│.....│.....│.....│.................│.....│.....│.....│.....│
│.....│.....│.....│.................│.....│.....│.....│.....│
│.....│.....│.....│.................│.....│.....│.....│.....│
│.....│.....│.....│.................│.....│.....+.....│.....│
│.....│.....+.....│.................│.....│.....│.....│.....│
├───+─┼─────┼───+─┼────+──────┐.....└+────┼─────┼─────┼─.───┤
│.....│.....│.....│...........│...........│.....│.....+.....│
│.....│.....│.....│...........│...........│...........│.....│
│.....│.....│.....│...........│...........+.....│.....│.....│
│.....│.....│.....│...........│...........│.....│.....│.....│
│.....+.....│.....│...........│...........│.....│.....│.....│
└─────┴─────┴─────┴───────────┴───────────┴─────┴─────┴─────┘
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    This was set to 5 in the earliest version of the code, but it seems to be fine set to as low as 1.
    double
    If greater than 0, this is the chance that two connected rooms should only have a 1-cell-wide connection (which can be made into a door using DungeonProcessor).
    char[][]
    The place grid as a 2D char array.
    int[][]
    The environment as a 2D int array, with each int a constant in DungeonTools.
    int
    The height of the place grid to generate.
    int
    This was set to 15 in the earliest version of the code, but it seems to be fine set to as low as 1.
    com.github.yellowstonegames.grid.Region
    Reset on every call to generate().
    com.github.tommyettinger.random.EnhancedRandom
    Can be swapped out for another EnhancedRandom implementation, but must not be null.
    int
    The height of each room in cells; 1 is the minimum.
    int
    The width of each room in cells; 1 is the minimum.
    int
    How thick a wall between two rooms should be, in cells; 1 is the minimum, and this usually shouldn't be much more than roomWidth or roomHeight.
    int
    The width of the place grid to generate.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Calls ConnectingMapGenerator(int, int, int, int, EnhancedRandom, int) with width 80, height 80, roomWidth 8, roomHeight 8, a new WhiskerRandom for random, and wallThickness 2.
    ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random)
    ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random, int wallThickness)
     
    ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random, int wallThickness, double divideRooms)
     
    ConnectingMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random)
    Determines room width and room height by dividing width or height by 10; wallThickness is 2.
  • Method Summary

    Modifier and Type
    Method
    Description
    char[][]
    Generates a dungeon or other map as a 2D char array.
    int[][]
    Gets a 2D array of int constants, each representing a type of environment corresponding to a static field of DungeonTools.
    char[][]
    Gets the most recently-produced dungeon as a 2D char array, usually produced by calling generate() or some similar method present in a specific implementation.
     

    Methods inherited from class Object

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

    • width

      public int width
      The width of the place grid to generate.
    • height

      public int height
      The height of the place grid to generate.
    • roomWidth

      public int roomWidth
      The width of each room in cells; 1 is the minimum.
    • roomHeight

      public int roomHeight
      The height of each room in cells; 1 is the minimum.
    • wallThickness

      public int wallThickness
      How thick a wall between two rooms should be, in cells; 1 is the minimum, and this usually shouldn't be much more than roomWidth or roomHeight.
    • dungeon

      public char[][] dungeon
      The place grid as a 2D char array. Returned by getPlaceGrid().
    • environment

      public int[][] environment
      The environment as a 2D int array, with each int a constant in DungeonTools. Returned by getEnvironment().
    • region

      public com.github.yellowstonegames.grid.Region region
      Reset on every call to generate(). This can be reassigned, but it must not be null.
    • divideRooms

      public double divideRooms
      If greater than 0, this is the chance that two connected rooms should only have a 1-cell-wide connection (which can be made into a door using DungeonProcessor).
    • rng

      public com.github.tommyettinger.random.EnhancedRandom rng
      Can be swapped out for another EnhancedRandom implementation, but must not be null.
    • initialAttempts

      public int initialAttempts
      This was set to 15 in the earliest version of the code, but it seems to be fine set to as low as 1. The default value is now 1.
    • attempts

      public int attempts
      This was set to 5 in the earliest version of the code, but it seems to be fine set to as low as 1. The default value is now 1.
  • Constructor Details

    • ConnectingMapGenerator

      public ConnectingMapGenerator()
      Calls ConnectingMapGenerator(int, int, int, int, EnhancedRandom, int) with width 80, height 80, roomWidth 8, roomHeight 8, a new WhiskerRandom for random, and wallThickness 2.
    • ConnectingMapGenerator

      public ConnectingMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random)
      Determines room width and room height by dividing width or height by 10; wallThickness is 2.
      Parameters:
      width - total width of the map, in cells
      height - total height of the map, in cells
      random - an IRNG to make random choices for connecting rooms
    • ConnectingMapGenerator

      public ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random)
      Parameters:
      width - total width of the map, in cells
      height - total height of the map, in cells
      roomWidth - target width of each room, in cells; only counts the center floor area of a room
      roomHeight - target height of each room, in cells; only counts the center floor area of a room
      random - an IRNG to make random choices for connecting rooms
    • ConnectingMapGenerator

      public ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random, int wallThickness)
      Parameters:
      width - total width of the map, in cells
      height - total height of the map, in cells
      roomWidth - target width of each room, in cells; only counts the center floor area of a room
      roomHeight - target height of each room, in cells; only counts the center floor area of a room
      random - an EnhancedRandom to make random choices for connecting rooms
      wallThickness - how thick a wall between two rooms should be, in cells; 1 is minimum, and this usually shouldn't be much more than roomWidth or roomHeight
    • ConnectingMapGenerator

      public ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random, int wallThickness, double divideRooms)
      Parameters:
      width - total width of the map, in cells
      height - total height of the map, in cells
      roomWidth - target width of each room, in cells; only counts the center floor area of a room
      roomHeight - target height of each room, in cells; only counts the center floor area of a room
      random - an EnhancedRandom to make random choices for connecting rooms
      wallThickness - how thick a wall between two rooms should be, in cells; 1 is minimum, and this usually shouldn't be much more than roomWidth or roomHeight
      divideRooms - if greater than 0, this is the chance that two connected rooms should only have a 1-cell-wide connection (which can be made into a door using DungeonProcessor)
  • Method Details

    • generate

      public char[][] generate()
      Generates a dungeon or other map as a 2D char array. Uses the convention of '#' representing a wall and '.' representing a bare floor, and also fills environment with appropriate constants from DungeonTools, like DungeonTools.ROOM_FLOOR and DungeonTools.ROOM_WALL.
      Specified by:
      generate in interface PlaceGenerator
      Returns:
      a 2D char array representing a room-based map, using standard conventions for walls/floors
    • getPlaceGrid

      public char[][] getPlaceGrid()
      Gets the most recently-produced dungeon as a 2D char array, usually produced by calling 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:
      getPlaceGrid in interface PlaceGenerator
      Returns:
      the most recently-produced dungeon/map as a 2D char array
    • getEnvironment

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

      public String toString()
      Overrides:
      toString in class Object