Class Dungeon
Implements dungeon generation by room accretion method.
Usage:
Dungeon():buildDungeon(width, height)
Info:
- Copyright: Creative Commons Attribution 4.0 International License
- Author: LonelyOwl
Methods
-
dungeonClass:_addTile (x, y, tile)
-
Add a tile at location, removes any tileCache reference at index
Parameters:
-
dungeonClass:serializeChanges ()
-
Serialize the dungeonClass.changes table, and push changes.
All serialization is pushed on tile-by-tile basis.
-
dungeonClass:_resolveCornerDoors (tile)
-
Swaps floor tiles to wall tiles adjacent to corner doors.
Needed for circle & cellular automata rooms.
Parameters:
-
dungeonClass:_getAllTilesAsNodes ()
-
A function to return a list of tiles for Dijkstra mapping.
-
dungeonClass:_floodFillTile (start, list)
-
(Deprecated) basic flood fill algorithm. Not in use currently.
Parameters:
-
dungeonClass:analyzeMapConnectivity ()
-
Analyzes the map by visualizing a Dijkstra node map.
-
dungeonClass:getNumberOfRooms ()
-
Returns an int value of # of rooms.
Since rooms are indexed by ID, need to re-iterate every time.
-
dungeonClass:deleteRoom ()
-
Deletes a room by removing tiles individually.
Removes tile index from dungeonClass.tileCache
-
dungeonClass:removeBadHallways ()
-
Iterate over hallways, delete those without any children.
No children indicate the hallway is a deadend.
-
dungeonClass:_isValidChasmPlacement (room, x, y)
-
(DEPRECATED) Was needed before tileCache was expanded to contain multiple tiles.
function dungeonClass:cleanRoom(room)
for y = 1, #room.tiles do
for x = 1, #room.tiles[y] do
if room.tiles[y][x].type ~= 'empty' then
insert(self.changes, room.tiles[y][x])
end
end
end
end
Parameters:
-
dungeonClass:buildDungeon ()
-
Starts dungeon generation.
Usage:
Dungeon():buildDungeon()
-
dungeon.Class
-
List of data structures contained within.
Any array that serves the purpose of a cache is simply a
list of ids indexed by ids. So tileCache is simply an array
conntaining tile id's indexed by (x, y) position.
- width
(int) width of dungeon in tiles.
- height
(int) height of dungeon in tiles.
- id
(int) a unique identifier for rooms.
- roomCount
(int) a count of rooms generated successfully.
- tileCache
(table) 2D array of room id's indexed by x, and y values.
- sleep
(float) value for slowing down generation for visualization.
Methods
-
dungeon.printc (text)
-
Shortcut for printing to runtime console.
Parameters:
-
dungeon._createUUID ()
-
Generates a unique UUID for rooms.
-
dungeonClass:_createRoom ()
-
Read shape data from theme, and output room object.
-
dungeonClass:generateRoom ()
-
Generates a random pre-authored room.
-
dungeon.sortByConnections (a, b)
-
Sort room by (newest) room added.
Parameters:
-
dungeon.sortByConnectionsCenter (a, b)
-
Sort room by (oldest) room added.
Parameters:
-
dungeonClass:_getRandomRoom ()
-
Returns a random room Object from dungeonClass.listOfRooms.
-
dungeonClass:_getTileByRoomID ()
-
Retrieve a tile Object from a Room id.
-
dungeonClass:_throwRoomAtDungeon ()
-
"Throw" a generated room at the dungeon. If it is
a valid placement, place the room into the dungeon.
-
dungeonClass:_isValidRoomPlacement ()
-
Check if room placement at (x, y) is valid.
-
dungeonClass:_addRoom ()
-
Place room into dungeon at (x,y), assign the room a UUID.
-
dungeonClass:_getTileNeighbors ()
-
Return an array of tiles neighbors, unsorted.
-
dungeonClass:_getMapValue ()
-
Returns the cost to move to specified node
-
dungeonClass:_manhattanDistance ()
-
Uses the Manhattan Distance formula for returning cost.
Used in Dijkstra mapping.
-
dungeonClass:_dijkstra ()
-
Implements Dijkstra path algorithm.
-
dungeon._getTileFromStart ()
-
Returns a random floor tile from the "starting" room.