Package squidpony.squidgrid.mapping
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.
┌────────────────────────────┐┌────────┐┌────────┐┌────────┐
│............................││........││........││........│
│............................││........││........││........│
│............................││........││........││........│
│...┌──────────┐...┌─────┐...││...┌┐...│└────┐...││...┌────┘
│...│┌───┐┌────┘...│┌────┘...└┘...││...└────┐│...││...└────┐
│...││...││........││.............││........││...││........│
│...││...││........││.............││........││...││........│
│...││...││........││.......<.....││........││...││........│
└───┘│...││...┌────┘│...┌─────────┘└────────┘│...│└────┐...│
┌────┘...││...└────┐│...│┌───────────────────┘...└─────┘...│
│........││........││...││.................................│
│.......>││........││...││.................................│
│........││........││...││.................................│
│...┌────┘└────┐...│└───┘│...┌─────────────────────────────┘
│...│┌────────┐│...└─────┘...└────┐┌───┐┌────────┐┌────────┐
│...││........││..................││...││........││........│
│...││........││..................││...││........││........│
│...││........││..................││...││........││........│
│...││...┌┐...│└────┐...┌─────────┘│...│└────┐...│└────┐...│
│...││...││...└─────┘...│┌────────┐│...└────┐│...└─────┘...│
│...││...││.............││........││........││.............│
│...││...││.............││........││........││.............│
│...││...││.............││........││........││.............│
│...││...││...┌─────────┘│...┌┐...││...┌────┘│...┌─────┐...│
│...└┘...││...└──────────┘...││...└┘...└─────┘...│┌────┘...│
│........││..................││..................││........│
│........││..................││..................││........│
│........││..................││..................││........│
└────────┘└──────────────────┘└──────────────────┘└────────┘
┌───────────────┬─┬───────────┬─────┬───┬─────────┬─┬───┬─┐
│...............│.│...........│.....│...│.........│.│...│.│
│.┌──────────.┌─┘.│.┌──.────┬─┤.┌───┤.│.│.──┐.──┐.│.│.│.│.│
│.│...........│.....│.......│.│.│...│.│.....│...│.│...│...│
├─┘.┌────.┌─┐.└─────┘.┌──.│.│.│.│.┌─┘.│.│.──┼───┤.└─┬─┘.│.│
│...│.....│.│.........│...│.│...│.│...│.│...│...│...│...│.│
│.┌─┴───┬─┘.│.┌──.┌───┤.──┤.│.┌─┤.│.┌─┴─┼─┐.│.│.└───┤.│.└─┤
│.│.....│...│.│...│...│...│.│.│.│...│...│.│...│.....│.│...│
├─┤.│.│.│.──┘.│.│.└─┐.├───┤.│.│.│.──┤.│.│.│.──┤.│.│.│.└─┐.│
│.│.│.│.......│.│...│.│...│.│.......│.│...│...│.│.│.│...│.│
│.│.└─┼────.┌─┘.└───┘.│.│.└─┴─┬─┬──.├─┤.──┴───┼─┤.├─┴─┐.└─┤
│.│...│>....│.........│.│.....│.│...│.│.......│.│.│...│...│
│.└─┐.│.┌───┴────.│.│.│.└─┬───┘.│.┌─┘.├───┐.┌─┘.├─┘.│.│.│<│
│...│.│.│.........│.│.....│.......│...│...│.│...│...│...│.│
├──.├─┼─┴──.│.│.┌─┘.├───┐.└──.──┬─┘.┌─┘.│.│.│.┌─┘.──┴───┤.│
│...│.│.....│.│.│...│...│.......│...│...│...│.│.........│.│
├─┐.│.│.──┬─┘.├─┘.┌─┤.──┼───┐.│.│.│.└──.└───┤.│.│.┌─┐.│.│.│
│.│...│...│...│...│.│...│...│.│.│.│.........│.│.│.│.│.│.│.│
│.│.│.└─┬─┴─┬─┴─┬─┤.├──.│.──┘.│.│.├──────.│.│.└─┤.│.│.└─┤.│
│...│...│...│...│.│.│.........│...│.......│.....│.│.│...│.│
│.┌─┤.│.│.│.│.│.│.│.│.──┐.──┐.├──.└───────┴─────┘.│.├──.├─┤
│.│.│.│.│.│.│.│...│.│...│...│.│...................│.│...│.│
│.│.├─┘.│.│.│.├──.│.└───┴─┐.│.└───────┐.──┐.──┬─┐.│.│.──┘.│
│.│.│.....│.│.│...│.......│.│.........│...│...│.│...│.....│
├─┘.│.┌──.│.└─┘.┌─┴────.│.│.├───────┐.└─┐.├──.│.└─┬─┘.┌──.│
│.....│...│.....│.......│...│.......│...│.│.......│...│...│
│.────┴─┐.├────.│.│.────┤.──┘.┌────.├───┘.│.┌────.├──.│.──┤
│.......│.│.......│.....│.....│.....│.....│.│.....│...│...│
└───────┴─┴───────┴─────┴─────┴─────┴─────┴─┴─────┴───┴───┘
Created by Tommy Ettinger on 5/7/2019.
-
Field Summary
Fields Modifier and Type Field Description char[][]
dungeon
int[][]
environment
int
height
GreasedRegion
region
IRNG
rng
int
roomHeight
int
roomWidth
int
wallThickness
int
width
-
Constructor Summary
Constructors Constructor Description ConnectingMapGenerator()
CallsConnectingMapGenerator(int, int, int, int, IRNG, int)
with width 80, height 80, roomWidth 8, roomHeight 8, a newGWTRNG
for random, and wallThickness 2.ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, IRNG random)
Exactly likeConnectingMapGenerator(int, int, int, int, IRNG, int)
with wallThickness 2.ConnectingMapGenerator(int width, int height, int roomWidth, int roomHeight, IRNG random, int wallThickness)
ConnectingMapGenerator(int width, int height, IRNG 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[][]
generate()
Generates a dungeon or other map as a 2D char array.char[][]
getDungeon()
Gets the most recently-produced dungeon as a 2D char array, usually produced by callinggenerate()
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 DungeonUtility.
-
Field Details
-
Constructor Details
-
ConnectingMapGenerator
public ConnectingMapGenerator()CallsConnectingMapGenerator(int, int, int, int, IRNG, int)
with width 80, height 80, roomWidth 8, roomHeight 8, a newGWTRNG
for random, and wallThickness 2. -
ConnectingMapGenerator
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
Exactly likeConnectingMapGenerator(int, int, int, int, IRNG, 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, IRNG 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 IRNG 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
-
-
Method Details
-
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 fillsenvironment
with appropriate constants from DungeonUtility, likeDungeonUtility.ROOM_FLOOR
andDungeonUtility.ROOM_WALL
.- Specified by:
generate
in interfaceIDungeonGenerator
- Returns:
- a 2D char array representing a room-based map, using standard conventions for walls/floors
-
getDungeon
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:
getDungeon
in interfaceIDungeonGenerator
- Returns:
- the most recently-produced dungeon/map as a 2D char array
-
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
-