libtcod
Loading...
Searching...
No Matches
TCODDijkstra Class Reference

Public Member Functions

 TCODDijkstra (TCODMap *map, float diagonalCost=1.41f)
 TCODDijkstra (int width, int height, const ITCODPathCallback *listener, void *userData, float diagonalCost=1.41f)
 TCODDijkstra (const TCODDijkstra &)=delete
TCODDijkstraoperator= (const TCODDijkstra &)=delete
 TCODDijkstra (TCODDijkstra &&rhs) noexcept
TCODDijkstraoperator= (TCODDijkstra &&rhs) noexcept
void compute (int rootX, int rootY)
 In case of Dijkstra, this works in a slightly different way. In order to be able to compute a path, Dijkstra must first analyze the distances from the selected root (origin) node to all other nodes:
bool setPath (int toX, int toY)
 After the map is analyzed and all the distances from the root node are known, an unlimited number of paths can be set, all originating at the root node, using: The path setting function will return true if there's a path from the root node to the destination node. Otherwise, it will return false.
float getDistance (int x, int y)
 You can get the distance of any set of coordinates from the root node: Note that if the coordinates x,y are outside of the map or are a non-walkable position, the function will return -1.0f. This functionality is only available for Dijkstra's algorithm.
bool walk (int *x, int *y)
bool isEmpty () const
void reverse ()
int size () const
void get (int index, int *x, int *y) const

Member Function Documentation

◆ compute()

void TCODDijkstra::compute ( int rootX,
int rootY )

In case of Dijkstra, this works in a slightly different way. In order to be able to compute a path, Dijkstra must first analyze the distances from the selected root (origin) node to all other nodes:

@noop path_compute
Parameters
dijkstraIn the C version, the path handler returned by a creation function.
root_x,root_yCoordinates of the root node (origin) of the path. The coordinates should be inside the map, at a walkable position. Otherwise, the function's behaviour will be undefined.

◆ getDistance()

float TCODDijkstra::getDistance ( int x,
int y )

You can get the distance of any set of coordinates from the root node: Note that if the coordinates x,y are outside of the map or are a non-walkable position, the function will return -1.0f. This functionality is only available for Dijkstra's algorithm.

@noop path_read
Parameters
dijkstraIn the C version, the path handler returned by a creation function.
x,yThe coordinates whose distance from the root node are to be checked

◆ setPath()

bool TCODDijkstra::setPath ( int toX,
int toY )

After the map is analyzed and all the distances from the root node are known, an unlimited number of paths can be set, all originating at the root node, using: The path setting function will return true if there's a path from the root node to the destination node. Otherwise, it will return false.

@noop path_compute
Parameters
dijkstraIn the C version, the path handler returned by a creation function.
to_x,to_yCoordinates of the destination node of the path.

TCODMap *myMap = new TCODMap(50,50); TCODDijkstra *dijkstra = new TCODDijkstra(myMap); // allocate the path dijkstra->compute(25,25); // calculate distance from 25,25 to all other nodes dijkstra->setPath(5,5); // calculate a path to node 5,5 dijkstra->setPath(45,45); //calculate another path from the same origin

TCOD_map_t my_map=TCOD_map_new(50,50); TCOD_dijkstra_t dijkstra = TCOD_dijkstra_new(my_map); TCOD_dijkstra_compute(dijkstra,25,25); TCOD_dijkstra_path_set(dijkstra,5,5); TCOD_dijkstra_path_set(dijkstra,45,45);

my_map=libtcod.map_new(50,50) dijkstra = libtcod.dijkstra_new(my_map) libtcod.dijkstra_compute(dijkstra,25,25) libtcod.dijkstra_path_set(dijkstra,5,5) libtcod.dijkstra_path_set(dijkstra,45,45)


The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/path.hpp