public class DungeonUtility extends Object
Created by Tommy Ettinger on 4/1/2015.
Modifier and Type | Field and Description |
---|---|
StatefulRNG |
rng
The random number generator that will be used for all methods in this class with a random component.
|
Constructor and Description |
---|
DungeonUtility() |
DungeonUtility(RNG rng) |
DungeonUtility(StatefulRNG rng) |
Modifier and Type | Method and Description |
---|---|
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 int |
countCells(char[][] level,
char match)
Quickly counts the number of char elements in level that are equal to match.
|
static void |
debugPrint(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 double[][] |
generateAStarCostMap(char[][] map,
Map<Character,Double> costs,
double defaultValue)
Given a char[][] for the map, a Map of Character keys to Double values that will be used to determine costs, and
a double value for unhandled characters, produces a double[][] that can be used as a map by AStarSearch.
|
static int[][] |
generateBGPaletteIndices(char[][] map)
Produces an int[][] that can be used with any palette of your choice for methods in SquidPanel or for your own
rendering method, but meant for the background palette.
|
static int[][] |
generateBGPaletteIndices(char[][] map,
char deepChar,
int deepIndex,
char shallowChar,
int shallowIndex)
Produces an int[][] that can be used with any palette of your choice for methods in SquidPanel or for your own
rendering method, but meant for the background palette.
|
static double[][] |
generateCostMap(char[][] map,
Map<Character,Double> costs,
double defaultValue)
Given a char[][] for the map, a Map of Character keys to Double values that will be used to determine costs, and
a double value for unhandled characters, produces a double[][] that can be used as a costMap by DijkstraMap.
|
static int[][] |
generateLightnessModifiers(char[][] map)
Produces an int[][] that can be used with SquidLayers to alter the background colors.
|
static int[][] |
generateLightnessModifiers(char[][] map,
double frame)
Produces an int[][] that can be used with SquidLayers to alter the background colors, accepting a parameter for
animation frame if rippling water and waving grass using Perlin Noise are desired.
|
static int[][] |
generateLightnessModifiers(char[][] map,
double frame,
char deepLiquid,
char shallowLiquid)
Produces an int[][] that can be used with SquidLayers to alter the background colors, accepting a parameter for
animation frame if rippling water and waving grass using Perlin Noise are desired.
|
static int[][] |
generatePaletteIndices(char[][] map)
Produces an int[][] that can be used with any palette of your choice for methods in SquidPanel or for your own
rendering method.
|
static int[][] |
generatePaletteIndices(char[][] map,
char deepChar,
int deepIndex,
char shallowChar,
int shallowIndex)
Produces an int[][] that can be used with any palette of your choice for methods in SquidPanel or for your own
rendering method.
|
static double[][] |
generateResistances(char[][] map)
Given a char[][] for the map, produces a double[][] that can be used with FOV.calculateFOV().
|
static Coord |
getRandomCell(RNG rng,
char[][] map,
Set<Character> acceptable,
int frustration) |
static char[][] |
hashesToLines(char[][] map)
Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box
drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were
filled with more walls before) with space characters, ' '.
|
static char[][] |
hashesToLines(char[][] map,
boolean keepSingleHashes)
Takes a char[][] dungeon map that uses '#' to represent walls, and returns a new char[][] that uses unicode box
drawing characters to draw straight, continuous lines for walls, filling regions between walls (that were
filled with more walls before) with space characters, ' '.
|
static boolean |
inLevel(char[][] level,
Coord c) |
static boolean |
inLevel(char[][] level,
int x,
int y) |
static <T> boolean |
inLevel(T[][] level,
Coord c) |
static <T> boolean |
inLevel(T[][] level,
int x,
int y) |
static char[][] |
linesToHashes(char[][] map)
Reverses most of the effects of hashesToLines().
|
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 short[] |
packedFloors(char[][] map)
A convenience wrapper for getting a packed-data representation of all floors ('.') in map, for randomCell().
|
Coord |
randomCell(short[] packed)
Finds a random Coord where the x and y match up to a [x][y] location that is encoded as "on" in packed.
|
Coord |
randomFloor(char[][] map)
Finds a random Coord where the x and y match up to a [x][y] location on map that has '.' as a value.
|
Coord |
randomFloorLarge(char[][] map,
int size)
Finds a random Coord where the x and y match up to a [x][y] location on map that has '.' as a value,
and a square of cells extending in the positive x and y directions with a side length of size must also have
'.' as their values.
|
Coord |
randomMatchingTile(char[][] map,
char tile)
Finds a random Coord where the x and y match up to a [x][y] location on map that has the same value as the
parameter tile.
|
Coord |
randomStep(char[][] map,
Coord start,
boolean eightWay)
Gets a random Coord that is adjacent to start, validating whether the position can exist on the given map.
|
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 double[][] |
translateAStarToDijkstra(double[][] astar) |
static double[][] |
translateDijkstraToAStar(double[][] dijkstra) |
static char[][] |
transposeLines(char[][] map)
If you call hashesToLines() on a map that uses [y][x] conventions instead of [x][y], it will have the lines not
connect as you expect.
|
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, '#'.
|
public StatefulRNG rng
public DungeonUtility()
public DungeonUtility(StatefulRNG rng)
public DungeonUtility(RNG rng)
public Coord randomFloor(char[][] map)
map
- a char[][] that should contain a '.' floor tilepublic Coord randomCell(short[] packed)
DungeonUtility.packedFloors(char[][] map)
to encode all floors in map,
or CoordPacker.pack(char[][] map, char... yes)
to encode all cells in a char[][] map that match a
particular type, like '.' for floors or '~' for deep water, and want to efficiently get one randomly-chosen tile
from it. Calling pack() is likely slightly less efficient than using randomFloor(), but it only needs to be done
once per map and cell type, and this method should be substantially more efficient when the type of cell is
uncommon on the map.
Uses this class' rng field for pseudo-random number generation.packed
- a packed array produced by CoordPacker encoding the cells to choose from as "on"public static short[] packedFloors(char[][] map)
CoordPacker.pack(map, '.')
.map
- a char[][] that uses '.' to represent floorspublic Coord randomMatchingTile(char[][] map, char tile)
map
- a char[][] that should contain the desired tiletile
- the char to search forpublic Coord randomStep(char[][] map, Coord start, boolean eightWay)
map
- a char[][] map that this will only use for its width and height; contents are ignoredstart
- the starting positioneightWay
- true to choose a random orthogonal or diagonal direction; false to only choose from orthogonalpublic Coord randomFloorLarge(char[][] map, int size)
map
- a char[][] that should contain at least one floor represented by '.'size
- the side length of a square that must be completely filled with floors for this to return itpublic static char[][] hashesToLines(char[][] map)
map
- a 2D char array indexed with x,y that uses '#' for wallspublic static char[][] hashesToLines(char[][] map, boolean keepSingleHashes)
map
- a 2D char array indexed with x,y that uses '#' for wallskeepSingleHashes
- true if walls that are not orthogonally adjacent to other walls should stay as '#'public static char[][] linesToHashes(char[][] map)
map
- a 2D char array indexed with x,y that uses box-drawing characters for wallspublic static char[][] transposeLines(char[][] map)
map
- a 2D char array indexed with y,x that uses box-drawing characters for wallspublic static char[][] closeDoors(char[][] map)
map
- a char[][] that may have both '+' and '/' for doorspublic static char[][] openDoors(char[][] map)
map
- a char[][] that may have both '+' and '/' for doorspublic static char[][] simplifyDungeon(char[][] map)
map
- a char[][] with different characters that can be simplified to "wall" or "floor"public static char[][] doubleWidth(char[][] map)
map
- a char[][] that uses either '#' or box-drawing characters for walls, but one per cellpublic static char[][] unDoubleWidth(char[][] map)
map
- a char[][] that has been widened by doubleWidth()public static int[][] generatePaletteIndices(char[][] map)
map
- a char[][] containing foreground characters that you want foreground palette indices forpublic static int[][] generatePaletteIndices(char[][] map, char deepChar, int deepIndex, char shallowChar, int shallowIndex)
map
- a char[][] containing foreground characters that you want foreground palette indices forpublic static int[][] generateBGPaletteIndices(char[][] map)
map
- a char[][] containing foreground characters that you want background palette indices forpublic static int[][] generateBGPaletteIndices(char[][] map, char deepChar, int deepIndex, char shallowChar, int shallowIndex)
map
- a char[][] containing foreground characters that you want background palette indices forpublic static int[][] generateLightnessModifiers(char[][] map)
map
- a char[][] that you want to be find background lightness modifiers forpublic static int[][] generateLightnessModifiers(char[][] map, double frame)
map
- a char[][] that you want to be find background lightness modifiers forframe
- a counter that typically should increase by between 10.0 and 20.0 each second; higher numbers make
water and grass move morepublic static int[][] generateLightnessModifiers(char[][] map, double frame, char deepLiquid, char shallowLiquid)
map
- a char[][] that you want to be find background lightness modifiers forframe
- a counter that typically should increase by between 10.0 and 20.0 each second; higher numbers make
water and grass move moredeepLiquid
- a char that will be treated like deep water when animating ripplesshallowLiquid
- a char that will be treated like shallow water when animating ripplespublic static double[][] generateResistances(char[][] map)
map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors()public static double[][] generateCostMap(char[][] map, Map<Character,Double> costs, double defaultValue)
map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors() .costs
- a Map of Character keys representing possible elements in map, and Double values for their cost.defaultValue
- a double that will be used as the cost for any characters that don't have a key in costs.public static double[][] generateAStarCostMap(char[][] map, Map<Character,Double> costs, double defaultValue)
map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors() .costs
- a Map of Character keys representing possible elements in map, and Double values for their cost.defaultValue
- a double that will be used as the cost for any characters that don't have a key in costs.public static double[][] translateAStarToDijkstra(double[][] astar)
public static double[][] translateDijkstraToAStar(double[][] dijkstra)
public static Coord getRandomCell(RNG rng, char[][] map, Set<Character> acceptable, int frustration)
rng
- map
- acceptable
- frustration
- The number of trials that this method can do. Usually 16 or
32.map
whose symbol is in
acceptable
. Or null
if not found.public static boolean inLevel(char[][] level, Coord c)
level
- dungeon/map level as 2D char array. x,y indexedc
- Coord to checktrue
if c
is valid in level
,
false
otherwise.public static boolean inLevel(char[][] level, int x, int y)
level
- dungeon/map level as 2D char array. x,y indexedx
- x coordinate to checky
- y coordinate to checktrue
if c
is valid in level
,
false
otherwise.public static <T> boolean inLevel(T[][] level, Coord c)
level
- a dungeon/map level as 2D array. x,y indexedc
- Coord to checktrue
if c
is valid in level
,
false
otherwise.public static <T> boolean inLevel(T[][] level, int x, int y)
level
- a dungeon/map level as 2D array. x,y indexedx
- x coordinate to checky
- y coordinate to checktrue
if c
is valid in level
,
false
otherwise.public static int countCells(char[][] level, char match)
level
- the 2D char array to count cells inmatch
- the char to search forpublic static void debugPrint(char[][] level)
level
- a 2D char array to print with a trailing newlinepublic static char[][] wallWrap(char[][] map)
map
- A char[][] that stores map data; will be modified in placeCopyright © 2012–2016. All rights reserved.