public class SectionMap
extends java.lang.Object
implements java.io.Serializable
Coord
s to find the associated name and/or number, or or looking up
a subdivision with a name or number to get a GreasedRegion
back. This also stores connections between
sections, which can be useful as part of a graph-like algorithm. It is fed the information it needs by a
RoomFinder
instance passed to the constructor or to reinitialize(RoomFinder)
. A RoomFinder is ready
for usage after generating any dungeon with SectionDungeonGenerator
or one of its subclasses; the field
SectionDungeonGenerator.finder
should usually be all that needs to be given to this class. If you don't use
SectionDungeonGenerator, there's no reason you can't construct a RoomFinder independently and pass that (they can
take a little time to construct on large or very complex maps, but shouldn't be heavy after construction).
Zone
interface, then the GreasedRegion
objects this
can return do implement Zone, MutableZone
, and Iterable
of Coord.
GreasedRegion is significantly faster than the alternatives (CoordPacker
and manual
Lists of Coord) for the spatial manipulations that RoomFinder needs to do to find room-like shapes, and this just
gets its GreasedRegion values from RoomFinder directly.
RegionMap
, which has different functionality and a different
pupose; RegionMap simply is a slight extension on OrderedMap to conveniently handle regions as short arrays produced
by CoordPacker
, while this class offers additional features for labeling and looking up
sections of a map that were found by a RoomFinder
.
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<IntVLA> |
connections |
protected int[][] |
map |
protected Arrangement<java.lang.String> |
names |
protected java.util.ArrayList<GreasedRegion> |
regions |
Constructor and Description |
---|
SectionMap()
This shouldn't usually be used unless you for some reason need to construct a SectionMap before you have access
to a dungeon for it to map.
|
SectionMap(RoomFinder rf)
The preferred constructor; takes a RoomFinder (often one already created in dungeon generation and available via
SectionDungeonGenerator.finder ) and uses it to give unique String names and identifying numbers to each
room, corridor, and cave area that had been identified by that RoomFinder. |
SectionMap(SectionMap other)
Copy constructor; takes an already-initialized SectionMap and deep-copies each element into this one.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(Coord position)
Checks if this contains the given position (that is, it is within map bounds).
|
boolean |
contains(int number)
Checks if this contains the given identifying number.
|
boolean |
contains(int x,
int y)
Checks if this contains the given position (that is, x and y are within map bounds).
|
boolean |
contains(java.lang.String name)
Checks if this contains the given name.
|
IntVLA |
nameToConnections(java.lang.String name)
Gets the list of connected sections (by their identifying numbers) given a name of a section.
|
int |
nameToNumber(java.lang.String name)
Gets the identifying number corresponding to the given name.
|
GreasedRegion |
nameToRegion(java.lang.String name)
Gets the GreasedRegion that has the given name.
|
IntVLA |
numberToConnections(int number)
Gets the list of connected sections (by their identifying numbers) given an identifying number of a section.
|
java.lang.String |
numberToName(int number)
Gets the name that corresponds to the given identifying number.
|
GreasedRegion |
numberToRegion(int number)
Gets the GreasedRegion that has the given identifying number.
|
IntVLA |
positionToConnections(Coord position)
Gets the list of connected sections (by their identifying numbers) given a position inside that section.
|
IntVLA |
positionToConnections(int x,
int y)
Gets the list of connected sections (by their identifying numbers) given a position inside that section.
|
GreasedRegion |
positionToContaining(Coord position)
Gets the GreasedRegion (a group of points as made by the constructor) that contains the given x, y point.
|
GreasedRegion |
positionToContaining(int x,
int y)
Gets the GreasedRegion (a group of points as made by the constructor) that contains the given x, y point.
|
java.lang.String |
positionToName(Coord position)
Gets the name of the area that contains the given position.
|
java.lang.String |
positionToName(int x,
int y)
Gets the name of the area that contains the given x, y position.
|
int |
positionToNumber(Coord position)
Gets the identifying number of the area that contains the given position.
|
int |
positionToNumber(int x,
int y)
Gets the identifying number of the area that contains the given x, y position.
|
SectionMap |
reinitialize(RoomFinder rf)
If this SectionMap hasn't been initialized or the map has completely changed (such as if the player went to a
different floor of a dungeon), then you can call this method to avoid discarding some of the state from an
earlier SectionMap.
|
int |
size()
The number of regions this knows about; includes an entry for "unused cells" so this may be one larger than the
amount of GreasedRegions present in a RoomFinder used to construct this.
|
protected int[][] map
protected Arrangement<java.lang.String> names
protected java.util.ArrayList<GreasedRegion> regions
protected java.util.ArrayList<IntVLA> connections
public SectionMap()
reinitialize(RoomFinder)
to get any
use out of this object.public SectionMap(RoomFinder rf)
SectionDungeonGenerator.finder
) and uses it to give unique String names and identifying numbers to each
room, corridor, and cave area that had been identified by that RoomFinder. In the rare but possible chance that
a room, corridor, or cave overlaps with another such area, the one given the highest identifying number takes
precedence, but this should probably only happen if RoomFinder was subclassed or its internal state was modified.
Any cells that aren't a room, corridor, or cave (usually this contains all walls) are given identifying number 0,
with the corresponding name "unused0." All other cells will then have positive, non-zero identifying numbers.
Rooms are named next, starting at "room1" and going up to "room2" and so on until all rooms are named; the 1 in
the name corresponds to the identifying number. After the last room has been found, e.g. "room5", then corridors
are named, starting after the last room's number, so in the example that would be "corridor6", followed by
"corridor7". The numbers in the names still correspond to identifying numbers. After corridors, caves follow the
same pattern; in this example "cave8" would be followed by "cave9".rf
- a RoomFinder object; usually obtained via SectionDungeonGenerator.finder
public SectionMap(SectionMap other)
other
, which will make an empty SectionMap. This shouldn't be needed very often because SectionMap
values are immutable, though their contents can in some cases be mutated independently, and this would allow one
SectionMap to be copied and then have its items changed without changing the original.other
- a SectionMap to deep-copy into this onepublic SectionMap reinitialize(RoomFinder rf)
SectionMap(RoomFinder)
does, so refer to that
constructor's documentation for the names and numbers this assigns.rf
- a RoomFinder object; usually obtained via SectionDungeonGenerator.finder
public int positionToNumber(int x, int y)
x
- the x-coordinate to find the identifying number for; should be within bounds of the mapy
- the y-coordinate to find the identifying number for; should be within bounds of the mappublic int positionToNumber(Coord position)
position
- the Coord to find the identifying number for; should be within bounds of the map and non-nullpublic java.lang.String positionToName(int x, int y)
x
- the x-coordinate to find the name for; should be within bounds of the mapy
- the y-coordinate to find the name for; should be within bounds of the mappublic java.lang.String positionToName(Coord position)
position
- a Coord that should be within bounds of the map and non-nullpublic int nameToNumber(java.lang.String name)
name
- the name to look up, like "room1"public java.lang.String numberToName(int number)
number
- the number to look up, like 1public GreasedRegion numberToRegion(int number)
number
- the number to look up, like 1public GreasedRegion nameToRegion(java.lang.String name)
name
- the name to look up, like "room1"public GreasedRegion positionToContaining(int x, int y)
x
- the x-coordinate to find the containing region for; should be within bounds of the mapy
- the y-coordinate to find the containing region for; should be within bounds of the mappublic GreasedRegion positionToContaining(Coord position)
position
- the Coord to find the containing region for; should be within bounds of the map and non-nullpublic IntVLA numberToConnections(int number)
number
- an identifying number; should be non-negative and less than size()
public IntVLA nameToConnections(java.lang.String name)
name
- a String name; should be present in this SectionMap or this will return nullpublic IntVLA positionToConnections(int x, int y)
x
- the x-coordinate of the position to look up; should be within boundsy
- the y-coordinate of the position to look up; should be within boundspublic IntVLA positionToConnections(Coord position)
position
- the Coord position to look up; should be within bounds and non-nullpublic int size()
public boolean contains(java.lang.String name)
name
- the name to checkpublic boolean contains(int number)
number
- the number to checkpublic boolean contains(int x, int y)
x
- the x-coordinate of the position to checky
- the y-coordinate of the position to checkpublic boolean contains(Coord position)
position
- the position to checkCopyright © Eben Howard 2012–2022. All rights reserved.