Module ROT.DijkstraMap
DijkstraMap Pathfinding.
Based on the DijkstraMap Article on RogueBasin, http://roguebasin.roguelikedevelopment.org/index.php?title=The_Incredible_Power_of_Dijkstra_Maps
Functions
init (goalX, goalY, mapWidth, mapHeight, passableCallback) | Constructor. |
compute () | Establish values for all cells in map. |
addGoal (gx, gy) | Add new goal position. |
removeGoals ([gx=nil[, gy=nil]]) | Remove all goals. |
writeMapToConsole (returnString) | Output map values to console. |
getWidth () | Get Width of map. |
getHeight () | Get Height of map. |
getDimensions () | Get Dimensions as table. |
getMap () | Get the map table. |
getGoals () | Get the goal cell as a table. |
dirTowardsGoal (x, y) | Get the direction of the goal from a given position |
iterateThroughMap (callback) | Run a callback function on every cell in the map |
Functions
- init (goalX, goalY, mapWidth, mapHeight, passableCallback)
-
Constructor.
Parameters:
- goalX int x-position of cell that map will 'roll down' to
- goalY int y-position of cell that map will 'roll down' to
- mapWidth int width of the map
- mapHeight int height of the map
- passableCallback function a function with two parameters (x, y) that returns true if a map cell is passable
- compute ()
- Establish values for all cells in map. call after ROT.DijkstraMap:new(goalX, goalY, mapWidth, mapHeight, passableCallback)
- addGoal (gx, gy)
-
Add new goal position.
Inserts a new cell to be used as a goal.
Parameters:
- gx int the new x-value of the goal cell
- gy int the new y-value of the goal cell
- removeGoals ([gx=nil[, gy=nil]])
-
Remove all goals.
Will delete all goal cells. You must insert another goal before computing.
You can specify one goal to be inserted after the goal remove takes place.
The method only checks that the coordinates are provided before setting the new goal cell.
Parameters:
- gx int Will use this value as the x-coordinate of a new goal cell to be inserted (default nil)
- gy int Will use this value as the y-coordinate of a new goal cell to be inserted (default nil)
- writeMapToConsole (returnString)
-
Output map values to console.
For debugging, will send a comma separated output of cell values to the console.
Parameters:
- returnString boolean[opt=false] Will return the output in addition to sending it to console if true.
- getWidth ()
-
Get Width of map.
Returns:
-
int
w width of map
- getHeight ()
-
Get Height of map.
Returns:
-
int
h height of map
- getDimensions ()
-
Get Dimensions as table.
Returns:
- table dimensions A table of width and height values
- int dimensions.w width of map
- int dimensions.h height of map
- getMap ()
-
Get the map table.
Returns:
-
table
map A 2d array of map values, access like map[x][y]
- getGoals ()
-
Get the goal cell as a table.
Returns:
- table goal table containing goal position
- int goal.x x-value of goal cell
- dirTowardsGoal (x, y)
-
Get the direction of the goal from a given position
Parameters:
- x int x-value of current position
- y int y-value of current position
Returns:
- int xDir X-Direction towards goal. Either -1, 0, or 1
- int yDir Y-Direction towards goal. Either -1, 0, or 1
- iterateThroughMap (callback)
-
Run a callback function on every cell in the map
Parameters:
- callback function A function with x and y parameters that will be run on every cell in the map