Class SerpentMapGenerator
java.lang.Object
com.github.yellowstonegames.place.SerpentMapGenerator
- All Implemented Interfaces:
PlaceGenerator
Generate dungeons based on a random, winding, looping path through 2D space. Uses techniques from MixedGenerator.
Uses a Moore Curve, which is related to Hilbert Curves but loops back to its starting point, and stretches and
distorts the grid to make sure a visual correlation isn't obvious. 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.
To get a sense of what kinds of map this generates, you can look at a sample map on this Gist, which also includes a snippet of Java code that can generate that map.
The name comes from a vivid dream I had about gigantic, multi-colored snakes that completely occupied a roguelike dungeon. Shortly after, I made the connection to the Australian mythology I'd heard about the Rainbow Serpent, which in some stories dug water-holes and was similarly gigantic.
To get a sense of what kinds of map this generates, you can look at a sample map on this Gist, which also includes a snippet of Java code that can generate that map.
The name comes from a vivid dream I had about gigantic, multi-colored snakes that completely occupied a roguelike dungeon. Shortly after, I made the connection to the Australian mythology I'd heard about the Rainbow Serpent, which in some stories dug water-holes and was similarly gigantic.
-
Constructor Summary
ConstructorsConstructorDescriptionThis prepares a map generator that will generate a map with width 80 and height 80, using a random seed.SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom.SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random, boolean symmetrical) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom.SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, double branchingChance) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom.SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random, double branchingChance, boolean symmetrical) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom. -
Method Summary
Modifier and TypeMethodDescriptionchar[][]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.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 place as a 2D char array, usually produced by callingPlaceGenerator.generate()or some similar method present in a specific implementation.voidputBoxRoomCarvers(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.voidputCaveCarvers(int count) Changes the number of "carvers" that will create caves from one room to the next.voidputRoundRoomCarvers(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.voidputWalledBoxRoomCarvers(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.voidputWalledRoundRoomCarvers(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.toString()
-
Constructor Details
-
SerpentMapGenerator
public SerpentMapGenerator()This prepares a map generator that will generate a map with width 80 and height 80, using a random seed. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what 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.- See Also:
-
SerpentMapGenerator
public SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what 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 cellsheight- the height of the final map in cellsrng- an EnhancedRandom object to use for random choices; this makes a lot of random choices.- See Also:
-
SerpentMapGenerator
public SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random, boolean symmetrical) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what 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 cellsheight- the height of the final map in cellsrandom- an EnhancedRandom object to use for random choices; this makes a lot of random choices.symmetrical- true if this should generate a bi-radially symmetric map, false for a typical map- See Also:
-
SerpentMapGenerator
public SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng, double branchingChance) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what 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 cellsheight- the height of the final map in cellsrng- an EnhancedRandom object to use for random choices; this makes a lot of random choices.branchingChance- the chance from 0.0 to 1.0 that each room will branch at least once- See Also:
-
SerpentMapGenerator
public SerpentMapGenerator(int width, int height, com.github.tommyettinger.random.EnhancedRandom random, double branchingChance, boolean symmetrical) This prepares a map generator that will generate a map with the given width and height, using the given EnhancedRandom. The intended purpose is to carve a long path that loops through the whole dungeon, while hopefully maximizing the amount of rooms the player encounters. You call the different carver-adding methods to affect what 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 cellsheight- the height of the final map in cellsrandom- an EnhancedRandom object to use for random choices; this makes a lot of random choices.branchingChance- the chance from 0.0 to 1.0 that each room will branch at least oncesymmetrical- true if this should generate a bi-radially symmetric map, false for a typical map- See Also:
-
-
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 nextInt the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.- Parameters:
count- the number of carvers making caves nextInt rooms; only matters in relation to other carvers- See Also:
-
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 nextInt the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.- Parameters:
count- the number of carvers making box-shaped rooms and corridors nextInt them; only matters in relation to other carvers- See Also:
-
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 nextInt the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.- Parameters:
count- the number of carvers making box-shaped rooms and corridors nextInt them; only matters in relation to other carvers- See Also:
-
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 nextInt the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.- Parameters:
count- the number of carvers making circular rooms and corridors nextInt them; only matters in relation to other carvers- See Also:
-
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 nextInt the count of putCaveCarvers(), putBoxRoomCarvers(), and putRoundRoomCarvers() is reasonable.- Parameters:
count- the number of carvers making circular rooms and corridors nextInt them; only matters in relation to other carvers- See Also:
-
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:
generatein interfacePlaceGenerator- Returns:
- a char[][] where '#' is a wall and '.' is a floor or corridor; x first y second
- See Also:
-
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
-
getPlaceGrid
public char[][] getPlaceGrid()Description copied from interface:PlaceGeneratorGets the most recently-produced place as a 2D char array, usually produced by callingPlaceGenerator.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 IPlaceGenerator.- Specified by:
getPlaceGridin interfacePlaceGenerator- Returns:
- the most recently-produced dungeon/place as a 2D char array
-
toString
-