Class RoomFinder
java.lang.Object
com.github.yellowstonegames.place.RoomFinder
A small class that can analyze a dungeon or other map and identify areas as being "room" or "corridor" based on how
thick the walkable areas are. Corridors are at most 2 cells wide at their widest, rooms are anything else. Most
methods of this class return 2D char arrays or Lists thereof, with the subset of the map that is in a specific region
kept the same, but everything else replaced with '#'.
-
Field Summary
FieldsModifier and TypeFieldDescriptioncom.github.yellowstonegames.grid.Regioncom.github.yellowstonegames.grid.Regioncom.github.yellowstonegames.grid.Regioncom.github.yellowstonegames.grid.Regionchar[][]A copy of the place map, however it was passed to the constructor.com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> Not likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API.com.github.yellowstonegames.grid.Coord[]When a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here.com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> Not likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API.com.github.yellowstonegames.grid.Coord[]When a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here.int[][]intchar[][]A copy of the place map, however it was passed to the constructor.com.github.yellowstonegames.grid.Coord[]When a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here.com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> Not likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API.int -
Constructor Summary
ConstructorsConstructorDescriptionRoomFinder(char[][] place) Constructs a RoomFinder given a place map, and finds rooms, corridors, and their connections on the map.RoomFinder(char[][] place, int environmentKind) Constructs a RoomFinder given a place map and a general kind of environment for the whole map, then finds rooms, corridors, and their connections on the map.RoomFinder(char[][] place, int[][] environment) Constructs a RoomFinder given a place map and an environment map (typically obtained withPlaceGenerator.getEnvironment()after generating a map withPlaceGenerator.getPlaceGrid()), and finds rooms, corridors, caves, and their connections on the map. -
Method Summary
Modifier and TypeMethodDescriptioncom.github.tommyettinger.ds.ObjectList<char[][]> Gets all the caves this found during construction, returning them as an ObjectList of 2D char arrays.com.github.tommyettinger.ds.ObjectList<char[][]> Gets all the corridors this found during construction, returning them as an ObjectList of 2D char arrays.com.github.tommyettinger.ds.ObjectList<char[][]> Gets all the rooms, corridors, and caves this found during construction, returning them as an ObjectList of 2D char arrays.com.github.tommyettinger.ds.ObjectList<char[][]> Gets all the rooms this found during construction, returning them as an ObjectList of 2D char arrays.static char[][]merge(com.github.tommyettinger.ds.ObjectList<char[][]> regions, int width, int height) Merges multiple 2D char arrays where the '#' character means "no value", and combines them so all cells with value are on one map, with '#' filling any other cells.char[][]regionAt(int x, int y) Takes an x, y position and finds the room, corridor, or cave at that position, if there is one, returning the same 2D char array format as the other methods.com.github.tommyettinger.ds.ObjectList<char[][]> regionsConnected(int x, int y) Takes an x, y position and finds the rooms or corridors that are directly connected to the room, corridor or cave at that position, and returns the group as an ObjectList of 2D char arrays, one per connecting region.char[][]regionsNear(int x, int y) Takes an x, y position and finds the room or corridor at that position and the rooms, corridors or caves that it directly connects to, and returns the group as one merged 2D char array.reset(char[][] place) Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances.reset(char[][] place, int environmentKind) Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances.reset(char[][] place, int[][] environment) Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances.toString()
-
Field Details
-
map
public char[][] mapA copy of the place map, however it was passed to the constructor. -
basic
public char[][] basicA copy of the place map, however it was passed to the constructor. -
environment
public int[][] environment -
rooms
public com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> roomsNot likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API. -
corridors
public com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> corridorsNot likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API. -
caves
public com.github.tommyettinger.ds.ObjectObjectOrderedMap<com.github.yellowstonegames.grid.Region, com.github.tommyettinger.ds.ObjectList<com.github.yellowstonegames.grid.Region>> cavesNot likely to be used directly, but there may be things you can do with these that are cumbersome using only RoomFinder's simpler API. -
allRooms
public com.github.yellowstonegames.grid.Region allRooms -
allCaves
public com.github.yellowstonegames.grid.Region allCaves -
allCorridors
public com.github.yellowstonegames.grid.Region allCorridors -
allFloors
public com.github.yellowstonegames.grid.Region allFloors -
connections
public com.github.yellowstonegames.grid.Coord[] connectionsWhen a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here. -
doorways
public com.github.yellowstonegames.grid.Coord[] doorwaysWhen a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here. -
mouths
public com.github.yellowstonegames.grid.Coord[] mouthsWhen a RoomFinder is constructed, it stores all points of rooms that are adjacent to another region here. -
width
public int width -
height
public int height
-
-
Constructor Details
-
RoomFinder
public RoomFinder(char[][] place) Constructs a RoomFinder given a place map, and finds rooms, corridors, and their connections on the map. Does not find caves; if a collection of caves is requested from this, it will be non-null but empty.- Parameters:
place- a 2D char array that uses '#', box drawing characters, or ' ' for walls.
-
RoomFinder
public RoomFinder(char[][] place, int environmentKind) Constructs a RoomFinder given a place map and a general kind of environment for the whole map, then finds rooms, corridors, and their connections on the map. Defaults to treating all areas as cave unlessenvironmentKindisDungeonTools.ROOM_FLOOR.- Parameters:
place- a 2D char array that uses '#', box drawing characters, or ' ' for walls.environmentKind- if (DungeonTools.ROOM_FLOOR), this will find rooms and corridors, else caves
-
RoomFinder
public RoomFinder(char[][] place, int[][] environment) Constructs a RoomFinder given a place map and an environment map (typically obtained withPlaceGenerator.getEnvironment()after generating a map withPlaceGenerator.getPlaceGrid()), and finds rooms, corridors, caves, and their connections on the map.- Parameters:
place- a 2D char array that uses '#' for walls.environment- a 2D int array using constants from DungeonTools; typically produced by a call to getEnvironment() in a PlaceGenerator after place generation.
-
-
Method Details
-
reset
Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances. This always treats the place as being made of rooms and corridors, with no natural (cave) areas. This works well ifplaceis the same size as the 2D char array used to construct this RoomFinder, and can avoid much allocation in that case.- Parameters:
place- a 2D char array typically produced by aPlaceGenerator- Returns:
- this, for chaining
-
reset
Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances. This works well ifplaceis the same size as the 2D char array used to construct this RoomFinder, and can avoid much allocation in that case.- Parameters:
place- a 2D char array typically produced by aPlaceGeneratorenvironmentKind- ifDungeonTools.ROOM_FLOOR, this treats the place as entirely rooms and corridors; otherwise, all caves- Returns:
- this, for chaining
-
reset
Recreates this RoomFinder while trying to reuse existing mutable objects, like Region instances. This works well ifplaceis the same size as the 2D char array used to construct this RoomFinder, and can avoid much allocation in that case. This overload allows every cell to be a different environment type. Theenvironmentof this RoomFinder will be a copy of theenvironmentparameter that will not contain any optional lock-and-key or level information that might be present in the parameter.- Parameters:
place- a 2D char array typically produced by aPlaceGeneratorenvironment- a 2D int array typically returned byPlaceGenerator.getEnvironment()- Returns:
- this, for chaining
-
findRooms
public com.github.tommyettinger.ds.ObjectList<char[][]> findRooms()Gets all the rooms this found during construction, returning them as an ObjectList of 2D char arrays. Every individual room is "masked" so only its contents have normal map chars and the rest have only '#'.- Returns:
- an ObjectList of 2D char arrays representing rooms.
-
findCorridors
public com.github.tommyettinger.ds.ObjectList<char[][]> findCorridors()Gets all the corridors this found during construction, returning them as an ObjectList of 2D char arrays. Every individual corridor is "masked" so only its contents have normal map chars and the rest have only '#'.- Returns:
- an ObjectList of 2D char arrays representing corridors.
-
findCaves
public com.github.tommyettinger.ds.ObjectList<char[][]> findCaves()Gets all the caves this found during construction, returning them as an ObjectList of 2D char arrays. Every individual room is "masked" so only its contents have normal map chars and the rest have only '#'. Will only return a non-empty collection if the environment contains caves.- Returns:
- an ObjectList of 2D char arrays representing caves.
-
findRegions
public com.github.tommyettinger.ds.ObjectList<char[][]> findRegions()Gets all the rooms, corridors, and caves this found during construction, returning them as an ObjectList of 2D char arrays. Every individual room or corridor is "masked" so only its contents have normal map chars and the rest have only '#'.- Returns:
- an ObjectList of 2D char arrays representing rooms, corridors, or caves.
-
merge
public static char[][] merge(com.github.tommyettinger.ds.ObjectList<char[][]> regions, int width, int height) Merges multiple 2D char arrays where the '#' character means "no value", and combines them so all cells with value are on one map, with '#' filling any other cells. If regions is empty, this uses width and height to construct a blank map, all '#'. It will also use width and height for the size of the returned 2D array.- Parameters:
regions- An ObjectList of 2D char array regions, where '#' is an empty value and all others will be mergedwidth- the width of any map this returnsheight- the height of any map this returns- Returns:
- a 2D char array that merges all non-'#' areas in regions, and fills the rest with '#'
-
regionAt
public char[][] regionAt(int x, int y) Takes an x, y position and finds the room, corridor, or cave at that position, if there is one, returning the same 2D char array format as the other methods.- Parameters:
x- the x coordinate of a position that should be in a room or corridory- the y coordinate of a position that should be in a room or corridor- Returns:
- a masked 2D char array where anything not in the current region is '#'
-
regionsNear
public char[][] regionsNear(int x, int y) Takes an x, y position and finds the room or corridor at that position and the rooms, corridors or caves that it directly connects to, and returns the group as one merged 2D char array.- Parameters:
x- the x coordinate of a position that should be in a room or corridory- the y coordinate of a position that should be in a room or corridor- Returns:
- a masked 2D char array where anything not in the current region or one nearby is '#'
-
regionsConnected
public com.github.tommyettinger.ds.ObjectList<char[][]> regionsConnected(int x, int y) Takes an x, y position and finds the rooms or corridors that are directly connected to the room, corridor or cave at that position, and returns the group as an ObjectList of 2D char arrays, one per connecting region.- Parameters:
x- the x coordinate of a position that should be in a room or corridory- the y coordinate of a position that should be in a room or corridor- Returns:
- an ObjectList of masked 2D char arrays where anything not in a connected region is '#'
-
toString
-