Class ConnectingMapGenerator
java.lang.Object
com.github.yellowstonegames.place.ConnectingMapGenerator
- All Implemented Interfaces:
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
With
With
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
FieldsModifier and TypeFieldDescriptionintThis was set to 5 in the earliest version of the code, but it seems to be fine set to as low as 1.doubleIf 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 usingDungeonProcessor).char[][]The place grid as a 2D char array.int[][]The environment as a 2D int array, with each int a constant inDungeonTools.intThe height of the place grid to generate.intThis 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.RegionReset on every call togenerate().com.github.tommyettinger.random.EnhancedRandomCan be swapped out for another EnhancedRandom implementation, but must not be null.intThe height of each room in cells; 1 is the minimum.intThe width of each room in cells; 1 is the minimum.intHow 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.intThe width of the place grid to generate. -
Constructor Summary
ConstructorsConstructorDescriptionCallsConnectingMapGenerator(int, int, int, int, EnhancedRandom, int)with width 80, height 80, roomWidth 8, roomHeight 8, a newWhiskerRandomfor random, and wallThickness 2.ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, com.github.tommyettinger.random.EnhancedRandom random) Exactly likeConnectingMapGenerator(int, int, int, int, EnhancedRandom, int)with wallThickness 2.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 TypeMethodDescriptionchar[][]generate()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 callinggenerate()or some similar method present in a specific implementation.toString()
-
Field Details
-
width
public int widthThe width of the place grid to generate. -
height
public int heightThe height of the place grid to generate. -
roomWidth
public int roomWidthThe width of each room in cells; 1 is the minimum. -
roomHeight
public int roomHeightThe height of each room in cells; 1 is the minimum. -
wallThickness
public int wallThicknessHow 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[][] dungeonThe place grid as a 2D char array. Returned bygetPlaceGrid(). -
environment
public int[][] environmentThe environment as a 2D int array, with each int a constant inDungeonTools. Returned bygetEnvironment(). -
region
public com.github.yellowstonegames.grid.Region regionReset on every call togenerate(). This can be reassigned, but it must not be null. -
divideRooms
public double divideRoomsIf 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 usingDungeonProcessor). -
rng
public com.github.tommyettinger.random.EnhancedRandom rngCan be swapped out for another EnhancedRandom implementation, but must not be null. -
initialAttempts
public int initialAttemptsThis 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 attemptsThis 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()CallsConnectingMapGenerator(int, int, int, int, EnhancedRandom, int)with width 80, height 80, roomWidth 8, roomHeight 8, a newWhiskerRandomfor 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 cellsheight- total height of the map, in cellsrandom- 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) Exactly likeConnectingMapGenerator(int, int, int, int, EnhancedRandom, int)with wallThickness 2.- Parameters:
width- total width of the map, in cellsheight- total height of the map, in cellsroomWidth- target width of each room, in cells; only counts the center floor area of a roomroomHeight- target height of each room, in cells; only counts the center floor area of a roomrandom- 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 cellsheight- total height of the map, in cellsroomWidth- target width of each room, in cells; only counts the center floor area of a roomroomHeight- target height of each room, in cells; only counts the center floor area of a roomrandom- an EnhancedRandom to make random choices for connecting roomswallThickness- 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 cellsheight- total height of the map, in cellsroomWidth- target width of each room, in cells; only counts the center floor area of a roomroomHeight- target height of each room, in cells; only counts the center floor area of a roomrandom- an EnhancedRandom to make random choices for connecting roomswallThickness- 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 roomHeightdivideRooms- 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 usingDungeonProcessor)
-
-
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 fillsenvironmentwith appropriate constants from DungeonTools, likeDungeonTools.ROOM_FLOORandDungeonTools.ROOM_WALL.- Specified by:
generatein interfacePlaceGenerator- 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 callinggenerate()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:
getPlaceGridin interfacePlaceGenerator- 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:
getEnvironmentin interfacePlaceGenerator- Returns:
- a 2D int array where each element is an environment type constant in DungeonTools
-
toString
-