Class ConnectingMapGenerator

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

public class ConnectingMapGenerator
extends Object
implements IDungeonGenerator
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.

 ┌────────────────────────────┐┌────────┐┌────────┐┌────────┐
 │............................││........││........││........│
 │............................││........││........││........│
 │............................││........││........││........│
 │...┌──────────┐...┌─────┐...││...┌┐...│└────┐...││...┌────┘
 │...│┌───┐┌────┘...│┌────┘...└┘...││...└────┐│...││...└────┐
 │...││...││........││.............││........││...││........│
 │...││...││........││.............││........││...││........│
 │...││...││........││.......<.....││........││...││........│
 └───┘│...││...┌────┘│...┌─────────┘└────────┘│...│└────┐...│
 ┌────┘...││...└────┐│...│┌───────────────────┘...└─────┘...│
 │........││........││...││.................................│
 │.......>││........││...││.................................│
 │........││........││...││.................................│
 │...┌────┘└────┐...│└───┘│...┌─────────────────────────────┘
 │...│┌────────┐│...└─────┘...└────┐┌───┐┌────────┐┌────────┐
 │...││........││..................││...││........││........│
 │...││........││..................││...││........││........│
 │...││........││..................││...││........││........│
 │...││...┌┐...│└────┐...┌─────────┘│...│└────┐...│└────┐...│
 │...││...││...└─────┘...│┌────────┐│...└────┐│...└─────┘...│
 │...││...││.............││........││........││.............│
 │...││...││.............││........││........││.............│
 │...││...││.............││........││........││.............│
 │...││...││...┌─────────┘│...┌┐...││...┌────┘│...┌─────┐...│
 │...└┘...││...└──────────┘...││...└┘...└─────┘...│┌────┘...│
 │........││..................││..................││........│
 │........││..................││..................││........│
 │........││..................││..................││........│
 └────────┘└──────────────────┘└──────────────────┘└────────┘
 


 ┌───────────────┬─┬───────────┬─────┬───┬─────────┬─┬───┬─┐
 │...............│.│...........│.....│...│.........│.│...│.│
 │.┌──────────.┌─┘.│.┌──.────┬─┤.┌───┤.│.│.──┐.──┐.│.│.│.│.│
 │.│...........│.....│.......│.│.│...│.│.....│...│.│...│...│
 ├─┘.┌────.┌─┐.└─────┘.┌──.│.│.│.│.┌─┘.│.│.──┼───┤.└─┬─┘.│.│
 │...│.....│.│.........│...│.│...│.│...│.│...│...│...│...│.│
 │.┌─┴───┬─┘.│.┌──.┌───┤.──┤.│.┌─┤.│.┌─┴─┼─┐.│.│.└───┤.│.└─┤
 │.│.....│...│.│...│...│...│.│.│.│...│...│.│...│.....│.│...│
 ├─┤.│.│.│.──┘.│.│.└─┐.├───┤.│.│.│.──┤.│.│.│.──┤.│.│.│.└─┐.│
 │.│.│.│.......│.│...│.│...│.│.......│.│...│...│.│.│.│...│.│
 │.│.└─┼────.┌─┘.└───┘.│.│.└─┴─┬─┬──.├─┤.──┴───┼─┤.├─┴─┐.└─┤
 │.│...│>....│.........│.│.....│.│...│.│.......│.│.│...│...│
 │.└─┐.│.┌───┴────.│.│.│.└─┬───┘.│.┌─┘.├───┐.┌─┘.├─┘.│.│.│<│
 │...│.│.│.........│.│.....│.......│...│...│.│...│...│...│.│
 ├──.├─┼─┴──.│.│.┌─┘.├───┐.└──.──┬─┘.┌─┘.│.│.│.┌─┘.──┴───┤.│
 │...│.│.....│.│.│...│...│.......│...│...│...│.│.........│.│
 ├─┐.│.│.──┬─┘.├─┘.┌─┤.──┼───┐.│.│.│.└──.└───┤.│.│.┌─┐.│.│.│
 │.│...│...│...│...│.│...│...│.│.│.│.........│.│.│.│.│.│.│.│
 │.│.│.└─┬─┴─┬─┴─┬─┤.├──.│.──┘.│.│.├──────.│.│.└─┤.│.│.└─┤.│
 │...│...│...│...│.│.│.........│...│.......│.....│.│.│...│.│
 │.┌─┤.│.│.│.│.│.│.│.│.──┐.──┐.├──.└───────┴─────┘.│.├──.├─┤
 │.│.│.│.│.│.│.│...│.│...│...│.│...................│.│...│.│
 │.│.├─┘.│.│.│.├──.│.└───┴─┐.│.└───────┐.──┐.──┬─┐.│.│.──┘.│
 │.│.│.....│.│.│...│.......│.│.........│...│...│.│...│.....│
 ├─┘.│.┌──.│.└─┘.┌─┴────.│.│.├───────┐.└─┐.├──.│.└─┬─┘.┌──.│
 │.....│...│.....│.......│...│.......│...│.│.......│...│...│
 │.────┴─┐.├────.│.│.────┤.──┘.┌────.├───┘.│.┌────.├──.│.──┤
 │.......│.│.......│.....│.....│.....│.....│.│.....│...│...│
 └───────┴─┴───────┴─────┴─────┴─────┴─────┴─┴─────┴───┴───┘
 

Created by Tommy Ettinger on 5/7/2019.
  • Field Details

  • Constructor Details

    • ConnectingMapGenerator

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

      public ConnectingMapGenerator​(int width, int height, IRNG 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, IRNG 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, IRNG 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 IRNG 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
  • 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 DungeonUtility, like DungeonUtility.ROOM_FLOOR and DungeonUtility.ROOM_WALL.
      Specified by:
      generate in interface IDungeonGenerator
      Returns:
      a 2D char array representing a room-based map, using standard conventions for walls/floors
    • getDungeon

      public char[][] getDungeon()
      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:
      getDungeon in interface IDungeonGenerator
      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 DungeonUtility. 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).
      • DungeonUtility.UNTOUCHED, equal to 0, is used for any cells that aren't near a floor.
      • DungeonUtility.ROOM_FLOOR, equal to 1, is used for floor cells inside wide room areas.
      • DungeonUtility.ROOM_WALL, equal to 2, is used for wall cells around wide room areas.
      • DungeonUtility.CAVE_FLOOR, equal to 3, is used for floor cells inside rough cave areas.
      • DungeonUtility.CAVE_WALL, equal to 4, is used for wall cells around rough cave areas.
      • DungeonUtility.CORRIDOR_FLOOR, equal to 5, is used for floor cells inside narrow corridor areas.
      • DungeonUtility.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 DungeonUtility