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

Functions

dungeonClass:_addTile (x, y, tile) Add a tile at location, removes any tileCache reference at index
dungeonClass:serializeChanges () Serialize the dungeonClass.changes table, and push changes.
dungeonClass:_resolveCornerDoors (tile) Swaps floor tiles to wall tiles adjacent to corner doors.
dungeonClass:_getAllTilesAsNodes () A function to return a list of tiles for Dijkstra mapping.
dungeonClass:_floodFillTile (start, list) (Deprecated) basic flood fill algorithm.
dungeonClass:analyzeMapConnectivity () Analyzes the map by visualizing a Dijkstra node map.
dungeonClass:getNumberOfRooms () Returns an int value of # of rooms.
dungeonClass:deleteRoom () Deletes a room by removing tiles individually.
dungeonClass:removeBadHallways () Iterate over hallways, delete those without any children.
dungeonClass:_isValidChasmPlacement (room, x, y) (DEPRECATED) Was needed before tileCache was expanded to contain multiple tiles.
dungeonClass:buildDungeon () Starts dungeon generation.

Fields

dungeon.Class List of data structures contained within.

Local Functions

dungeon.printc (text) Shortcut for printing to runtime console.
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.
dungeon.sortByConnectionsCenter (a, b) Sort room by (oldest) room added.
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.
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.
dungeonClass:_dijkstra () Implements Dijkstra path algorithm.
dungeon._getTileFromStart () Returns a random floor tile from the "starting" room.


Functions

Methods
dungeonClass:_addTile (x, y, tile)
Add a tile at location, removes any tileCache reference at index

Parameters:

  • x
  • y
  • tile
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:

  • tile
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:

  • start
  • list
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:

  • room
  • x
  • y
dungeonClass:buildDungeon ()
Starts dungeon generation.

Usage:

    Dungeon():buildDungeon()

Fields

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.

Local Functions

Methods
dungeon.printc (text)
Shortcut for printing to runtime console.

Parameters:

  • text
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:

  • a
  • b
dungeon.sortByConnectionsCenter (a, b)
Sort room by (oldest) room added.

Parameters:

  • a
  • b
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.
generated by LDoc 1.5.0 Last updated 2023-09-01 10:24:59