Class DungeonTools
java.lang.Object
com.github.yellowstonegames.place.DungeonTools
A static class that can be used to modify the char[][] dungeons that other generators produce.
Includes various utilities for random floor-finding, but also provides ways to take dungeons that use '#'
for walls and make a copy that uses unicode box drawing characters.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for environment tiles that are floors for a corridor.static final intConstant for environment tiles that are walls near a corridor.static final intConstant for environment tiles that are floors for a cave or other natural part of a map.static final intConstant for environment tiles that are walls near a cave or other natural part of a map.static final intConstant for environment tiles that are floors for a room.static final intConstant for environment tiles that are walls near a room.static final intConstant for environment tiles that are not near a cave, room, or corridor. -
Method Summary
Modifier and TypeMethodDescriptionstatic com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> allMatching(char[][] map, char... matching) static List<com.github.yellowstonegames.grid.Coord> Gets a List of Coord that are within radius distance of (x,y), and appends them to buf if it is non-null or makes a fresh List to append to otherwise.static char[][]closeDoors(char[][] map) When a map is generated by DungeonGenerator with addDoors enabled, different chars are used for vertical and horizontal doors ('+' for vertical and '/' for horizontal).static intcountCells(char[][] level, char match) Quickly counts the number of char elements in level that are equal to match.static voiddebugPrint(char[][] level) For when you want to print a 2D char array.static char[][]doubleWidth(char[][] map) Takes a dungeon map with either '#' as the only wall character or the unicode box drawing characters used by hashesToLines(), and returns a new char[][] dungeon map with two characters per cell, mostly filling the spaces next to non-walls with space characters, and only doing anything different if a box-drawing character would continue into an adjacent cell, or if a '#' wall needs another '#' wall next to it.static com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> ensurePath(char[][] map, com.github.tommyettinger.random.EnhancedRandom rng, char replacement, char... blocking) Ensures a path exists in a rough ring around the map by first creating the path (usingpointPath(int, int, EnhancedRandom)with the given EnhancedRandom), then finding chars in blocking that are on that path and replacing them with replacement.static booleaninLevel(char[][] level, int x, int y) static booleaninLevel(char[][] level, com.github.yellowstonegames.grid.Coord c) static booleaninLevel(float[][] level, int x, int y) static booleaninLevel(float[][] level, com.github.yellowstonegames.grid.Coord c) static <T> booleaninLevel(T[][] level, int x, int y) static <T> booleaninLevel(T[][] level, com.github.yellowstonegames.grid.Coord c) static char[][]openDoors(char[][] map) When a map is generated by DungeonGenerator with addDoors enabled, different chars are used for vertical and horizontal doors ('+' for vertical and '/' for horizontal).static com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> pointPath(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng) static char[][]simplifyDungeon(char[][] map) Takes a char[][] dungeon map and returns a copy with all box drawing chars, special placeholder chars, or '#' chars changed to '#' and everything else changed to '.' .static char[][]unDoubleWidth(char[][] map) Takes a dungeon map that uses two characters per cell, and condenses it to use only the left (lower index) character in each cell.static char[][]wallWrap(char[][] map) Changes the outer edge of a char[][] to the wall char, '#'.
-
Field Details
-
UNTOUCHED
public static final int UNTOUCHEDConstant for environment tiles that are not near a cave, room, or corridor. Value is 0. Used by several classes that distinguish types of dungeon environment.- See Also:
-
ROOM_FLOOR
public static final int ROOM_FLOORConstant for environment tiles that are floors for a room. Value is 1. Used by several classes that distinguish types of dungeon environment.- See Also:
-
ROOM_WALL
public static final int ROOM_WALLConstant for environment tiles that are walls near a room. Value is 2. Used by several classes that distinguish types of dungeon environment.- See Also:
-
NATURAL_FLOOR
public static final int NATURAL_FLOORConstant for environment tiles that are floors for a cave or other natural part of a map. Value is 3. Used by several classes that distinguish types of dungeon environment. Also used byWildernessGeneratorfor almost everything it generates.- See Also:
-
NATURAL_WALL
public static final int NATURAL_WALLConstant for environment tiles that are walls near a cave or other natural part of a map. Value is 4. Used by several classes that distinguish types of dungeon environment. May be used byWildernessGeneratorfor ledges and other natural obstacles.- See Also:
-
CORRIDOR_FLOOR
public static final int CORRIDOR_FLOORConstant for environment tiles that are floors for a corridor. Value is 5. Used by several classes that distinguish types of dungeon environment.- See Also:
-
CORRIDOR_WALL
public static final int CORRIDOR_WALLConstant for environment tiles that are walls near a corridor. Value is 6. Used by several classes that distinguish types of dungeon environment.- See Also:
-
-
Method Details
-
closeDoors
public static char[][] closeDoors(char[][] map) When a map is generated by DungeonGenerator with addDoors enabled, different chars are used for vertical and horizontal doors ('+' for vertical and '/' for horizontal). This makes all doors '+', which is useful if you want '/' to be used for a different purpose and/or to distinguish open and closed doors.- Parameters:
map- a char[][] that may have both '+' and '/' for doors- Returns:
- a char[][] that only uses '+' for all doors
-
openDoors
public static char[][] openDoors(char[][] map) When a map is generated by DungeonGenerator with addDoors enabled, different chars are used for vertical and horizontal doors ('+' for vertical and '/' for horizontal). This makes all doors '/', which is useful if you want '+' to be used for a different purpose and/or to distinguish open and closed doors.- Parameters:
map- a char[][] that may have both '+' and '/' for doors- Returns:
- a char[][] that only uses '/' for all doors
-
simplifyDungeon
public static char[][] simplifyDungeon(char[][] map) Takes a char[][] dungeon map and returns a copy with all box drawing chars, special placeholder chars, or '#' chars changed to '#' and everything else changed to '.' .- Parameters:
map- a char[][] with different characters that can be simplified to "wall" or "floor"- Returns:
- a copy of map with all box-drawing, placeholder, wall or space characters as '#' and everything else '.'
-
doubleWidth
public static char[][] doubleWidth(char[][] map) Takes a dungeon map with either '#' as the only wall character or the unicode box drawing characters used by hashesToLines(), and returns a new char[][] dungeon map with two characters per cell, mostly filling the spaces next to non-walls with space characters, and only doing anything different if a box-drawing character would continue into an adjacent cell, or if a '#' wall needs another '#' wall next to it. The recommended approach is to keep both the original non-double-width map and the newly-returned double-width map, since the single-width maps can be used more easily for pathfinding. If you need to undo this function, call unDoubleWidth().- Parameters:
map- a char[][] that uses either '#' or box-drawing characters for walls, but one per cell- Returns:
- a widened copy of map that uses two characters for every cell, connecting box-drawing chars correctly
-
unDoubleWidth
public static char[][] unDoubleWidth(char[][] map) Takes a dungeon map that uses two characters per cell, and condenses it to use only the left (lower index) character in each cell. This should (probably) only be called on the result of doubleWidth(), and will throw an exception if called on a map with an odd number of characters for width, such as "#...#" .- Parameters:
map- a char[][] that has been widened by doubleWidth()- Returns:
- a copy of map that uses only one char per cell
-
inLevel
public static boolean inLevel(char[][] level, com.github.yellowstonegames.grid.Coord c) - Parameters:
level- dungeon/map level as 2D char array. x,y indexedc- Coord to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
inLevel
public static boolean inLevel(char[][] level, int x, int y) - Parameters:
level- dungeon/map level as 2D char array. x,y indexedx- x coordinate to checky- y coordinate to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
inLevel
public static boolean inLevel(float[][] level, com.github.yellowstonegames.grid.Coord c) - Parameters:
level- dungeon/map level as 2D double array. x,y indexedc- Coord to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
inLevel
public static boolean inLevel(float[][] level, int x, int y) - Parameters:
level- dungeon/map level as 2D double array. x,y indexedx- x coordinate to checky- y coordinate to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
inLevel
public static <T> boolean inLevel(T[][] level, com.github.yellowstonegames.grid.Coord c) - Parameters:
level- a dungeon/map level as 2D array. x,y indexedc- Coord to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
inLevel
public static <T> boolean inLevel(T[][] level, int x, int y) - Parameters:
level- a dungeon/map level as 2D array. x,y indexedx- x coordinate to checky- y coordinate to check- Returns:
trueifcis valid inlevel,falseotherwise.
-
countCells
public static int countCells(char[][] level, char match) Quickly counts the number of char elements in level that are equal to match.- Parameters:
level- the 2D char array to count cells inmatch- the char to search for- Returns:
- the number of cells that matched
-
debugPrint
public static void debugPrint(char[][] level) For when you want to print a 2D char array. Prints on multiple lines, with a trailing newline. To match how libGDX displays on the screen, this prints with the y-axis pointing up, that is, row 0 is at the bottom and the highest y-value is at the top.- Parameters:
level- a 2D char array to print with a trailing newline
-
wallWrap
public static char[][] wallWrap(char[][] map) Changes the outer edge of a char[][] to the wall char, '#'.- Parameters:
map- A char[][] that stores map data; will be modified in place- Returns:
- the modified-in-place map with its edge replaced with '#'
-
pointPath
public static com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> pointPath(int width, int height, com.github.tommyettinger.random.EnhancedRandom rng) -
ensurePath
public static com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> ensurePath(char[][] map, com.github.tommyettinger.random.EnhancedRandom rng, char replacement, char... blocking) Ensures a path exists in a rough ring around the map by first creating the path (usingpointPath(int, int, EnhancedRandom)with the given EnhancedRandom), then finding chars in blocking that are on that path and replacing them with replacement. Modifies map in-place and returns an ObjectList of Coord points that will always be on the path.- Parameters:
map- a 2D char array, x then y, etc. that will be modified directly; this is the "returned map"rng- used for random factors in the path choicereplacement- the char that will fill be used where a path needs to be carved out; usually '.'blocking- an array or vararg of char that are considered blocking for the path and will be replaced if they are in the way- Returns:
- the ObjectList of Coord points that are on the carved path, including existing non-blocking cells; will be empty if any parameters are invalid
-
allMatching
public static com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Coord> allMatching(char[][] map, char... matching) -
circle
public static List<com.github.yellowstonegames.grid.Coord> circle(int x, int y, int radius, List<com.github.yellowstonegames.grid.Coord> buf) Gets a List of Coord that are within radius distance of (x,y), and appends them to buf if it is non-null or makes a fresh List to append to otherwise. Returns buf if non-null, else the fresh List of Coord. May produce Coord values that are not within the boundaries of a map, such as (-5,-4), if the center is too close to the edge or radius is too high. You can useRadius.inCircle(int, int, int, boolean, int, int, List)with surpassEdges as false if you want to limit Coords to within the map, or the more generalRadius.pointsInside(int, int, int, boolean, int, int, List)on a Radius.SQUARE or Radius.DIAMOND enum value if you want a square or diamond shape.- Parameters:
x- center x of the circley- center y of the circleradius- inclusive radius to extend from the center; radius 0 gives just the centerbuf- Where to add the coordinates, or null for this method to allocate a fresh list.- Returns:
- The coordinates of a circle centered
(x, y), whose diameter is(radius * 2) + 1. - See Also:
-