/usr/include/libtcod/path.hpp is in libtcod-dev 1.6.1+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | /*
* libtcod 1.6.0
* Copyright (c) 2008,2009,2010,2012,2013 Jice & Mingos
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The name of Jice or Mingos may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JICE AND MINGOS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JICE OR MINGOS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _TCOD_PATH_HPP
#define _TCOD_PATH_HPP
class TCODLIB_API ITCODPathCallback {
public :
virtual ~ITCODPathCallback() {}
virtual float getWalkCost( int xFrom, int yFrom, int xTo, int yTo, void *userData ) const = 0;
};
/**
@PageName path
@PageTitle Path finding
@PageCategory Roguelike toolkits
@PageDesc This toolkit allows one to easily calculate the optimal path between two points in your dungeon by using either the <a href="http://en.wikipedia.org/wiki/A*">A* algorithm</a> or <a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm">Dijkstra's algorithm</a>.
Please note that the paths generated with the two algorithms may differ slightly. Due to how they're implemented, A* will usually prefer diagonal moves over orthogonal, while Dijkstra will have the opposite preference. In other words, paths from point X to point Y will look like this:
<div class="code"><pre>
Dijkstra: A*:
.......... ..........
.X........ .X*.......
..*....... ...**.....
...*...... .....**...
....****Y. .......*Y.
.......... ..........
</pre></div>
*/
class TCODLIB_API TCODPath {
public :
/**
@PageName path_init
@PageFather path
@PageTitle Creating a path
@FuncTitle Allocating a pathfinder from a map
@FuncDesc First, you have to allocate a path using a map from <a href="fov.html">the Field of view module</a>.
@Cpp
TCODPath::TCODPath(const TCODMap *map, float diagonalCost=1.41f)
TCODDijkstra::TCODDijkstra(const TCODMap *map, float diagonalCost=1.41f)
@C
TCOD_path_t TCOD_path_new_using_map(TCOD_map_t map, float diagonalCost)
TCOD_dijkstra_t TCOD_dijkstra_new(TCOD_map_t map, float diagonalCost)
@Py
path_new_using_map(map, diagonalCost=1.41)
dijkstra_new(map, diagonalCost=1.41)
@C#
TCODPath(TCODMap map, float diagonalCost)
TCODPath(TCODMap map)
TCODDijkstra(TCODMap map, float diagonalCost)
TCODDijkstra(TCODMap map)
@Param map The map. The path finder will use the 'walkable' property of the cells to find a path.
@Param diagonalCost Cost of a diagonal movement compared to an horizontal or vertical movement. On a standard cartesian map, it should be sqrt(2) (1.41f).
It you want the same cost for all movements, use 1.0f.
If you don't want the path finder to use diagonal movements, use 0.0f.
@CppEx
// A* :
TCODMap *myMap = new TCODMap(50,50);
TCODPath *path = new TCODPath(myMap); // allocate the path
// Dijkstra:
TCODMap *myMap = new TCODMap(50,50);
TCODDijkstra *dijkstra = new TCODDijkstra(myMap); // allocate the path
@CEx
// A* :
TCOD_map_t my_map=TCOD_map_new(50,50,true);
TCOD_path_t path = TCOD_path_new_using_map(my_map,1.41f);
// Dijkstra :
TCOD_map_t my_map=TCOD_map_new(50,50,true);
TCOD_dijkstra_t dijk = TCOD_dijkstra_new(my_map,1.41f);
@PyEx
# A* :
my_map=libtcod.map_new(50,50,True)
path = libtcod.path_new_using_map(my_map)
# Dijkstra
my_map=libtcod.map_new(50,50,True)
dijk = libtcod.dijkstra_new(my_map)
*/
TCODPath(const TCODMap *map, float diagonalCost=1.41f);
/**
@PageName path_init
@FuncTitle Allocating a pathfinder using a callback
@FuncDesc Since the walkable status of a cell may depend on a lot of parameters (the creature type, the weather, the terrain type...), you can also create a path by providing a function rather than relying on a TCODMap.
@Cpp
// Callback :
class ITCODPathCallback {
public: virtual float getWalkCost( int xFrom, int yFrom, int xTo, int yTo, void *userData ) const = 0;
};
// A* constructor:
TCODPath::TCODPath(int width, int height, const ITCODPathCallback *callback, void *userData, float diagonalCost=1.41f)
// Dijkstra constructor
TCODDijkstra::TCODDijkstra(int width, int height, const ITCODPathCallback *callback, void *userData, float diagonalCost=1.41f)
@C
typedef float (*TCOD_path_func_t)( int xFrom, int yFrom, int xTo, int yTo, void *user_data )
TCOD_path_t TCOD_path_new_using_function(int width, int height, TCOD_path_func_t callback, void *user_data, float diagonalCost)
TCOD_dijkstra_t TCOD_dijkstra_new_using_function(int width, int height, TCOD_path_func_t callback, void *user_data, float diagonalCost)
@Py
def path_func(xFrom,yFrom,xTo,yTo,userData) : ...
path_new_using_function(width, height, path_func, user_data=0, diagonalCost=1.41)
dijkstra_new_using_function(width, height, path_func, user_data=0, diagonalCost=1.41)
@C#
TCODPath(int width, int height, ITCODPathCallback listener, float diagonalCost)
TCODPath(int width, int height, ITCODPathCallback listener)
TCODDijkstra(int width, int height, ITCODPathCallback listener, float diagonalCost)
TCODDijkstra(int width, int height, ITCODPathCallback listener)
@Param width,height The size of the map (in map cells).
@Param callback A custom function that must return the walk cost from coordinates xFrom,yFrom to coordinates xTo,yTo.
The cost must be > 0.0f if the cell xTo,yTo is walkable.
It must be equal to 0.0f if it's not.
You must not take additional cost due to diagonal movements into account as it's already done by the pathfinder.
@Param userData Custom data that will be passed to the function.
@Param diagonalCost Cost of a diagonal movement compared to an horizontal or vertical movement. On a standard cartesian map, it should be sqrt(2) (1.41f).
It you want the same cost for all movements, use 1.0f.
If you don't want the path finder to use diagonal movements, use 0.0f.
@CppEx
class MyCallback : public ITCODPathCallback {
public :
float getWalkCost(int xFrom, int yFrom, int xTo, int yTo, void *userData ) const { ... }
};
TCODPath *path = new TCODPath(50,50,new MyCallback(),NULL); // allocate the path
TCODDijkstra *dijkstra = new TCODDijkstra(50,50,new MyCallback(),NULL); // allocate Dijkstra
@CEx
float my_func(int xFrom, int yFrom, int xTo, int yTo, void *user_data) { ... }
TCOD_path_t path = TCOD_path_new_using_function(50,50,my_func,NULL,1.41f);
TCOD_dijkstra_t dijkstra = TCOD_dijkstra_new_using_function(50,50,my_func,NULL,1.41f);
@PyEx
def my_func(xFrom, yFrom, xTo, yTo, user_data) :
# return a float cost for this movement
return 1.0
path = libtcod.path_new_using_function(50,50,my_func)
dijkstra = libtcod.dijkstra_new_using_function(50,50,my_func)
*/
TCODPath(int width, int height, const ITCODPathCallback *listener, void *userData, float diagonalCost=1.41f);
/**
@PageName path_init
@FuncTitle Destroying a path
@FuncDesc To release the resources used by a path, destroy it with :
@Cpp
TCODPath::~TCODPath()
TCODDijkstra::~TCODDijkstra()
@C
void TCOD_path_delete(TCOD_path_t path)
void TCOD_dijkstra_delete(TCOD_dijkstra_t dijkstra)
@Py
path_delete(path)
dijkstra_delete(dijkstra)
@C#
void TCODPath::Dispose()
void TCODDijkstra::Dispose()
@Param path In the C version, the path handler returned by one of the TCOD_path_new_* function.
@Param dijkstra In the C version, the path handler returned by one of the TCOD_dijkstra_new* function.
@CppEx
TCODPath *path = new TCODPath(myMap); // allocate the path
// use the path...
delete path; // destroy the path
TCODDijkstra *dijkstra = new TCODDijkstra(myMap); // allocate the path
// use the path...
delete dijkstra; // destroy the path
@CEx
TCOD_path_t path = TCOD_path_new_using_map(my_map);
// use the path ...
TCOD_path_delete(path);
TCOD_dijkstra_t dijkstra = TCOD_dijkstra_new(my_map);
// use the path ...
TCOD_dijkstra_delete(dijkstra);
@PyEx
path = libtcod.path_new_using_map(my_map)
# use the path ...
libtcod.path_delete(path)
dijkstra = libtcod.dijkstra_new(my_map)
# use the path ...
libtcod.dijkstra_delete(dijkstra)
*/
virtual ~TCODPath();
/**
@PageName path_compute
@PageFather path
@PageTitle Computing the path
@FuncTitle Computing an A* path
@FuncDesc Once you created a TCODPath object, you can compute the path between two points:
@Cpp bool TCODPath::compute(int ox, int oy, int dx, int dy)
@C bool TCOD_path_compute(TCOD_path_t path, int ox,int oy, int dx, int dy)
@Py path_compute(path, ox, oy, dx, dy)
@C# void TCODPath::compute(int ox, int oy, int dx, int dy)
@Param path In the C version, the path handler returned by a creation function.
@Param ox,oy Coordinates of the origin of the path.
@Param dx,dy Coordinates of the destination of the path.
Both points should be inside the map, and at a walkable position. The function returns false if there is no possible path.
@CppEx
TCODMap *myMap = new TCODMap(50,50);
TCODPath *path = new TCODPath(myMap); // allocate the path
path->compute(5,5,25,25); // calculate path from 5,5 to 25,25
@CEx
TCOD_map_t my_map=TCOD_map_new(50,50);
TCOD_path_t path = TCOD_path_new_using_map(my_map);
TCOD_path_compute(path,5,5,25,25);
@PyEx
my_map=libtcod.map_new(50,50)
path = libtcod.path_new_using_map(my_map)
libtcod.path_compute(path,5,5,25,25)
*/
bool compute(int ox, int oy, int dx, int dy);
/**
@PageName path_compute
@FuncTitle Reversing a path
@FuncDesc Once you computed a path, you can exchange origin and destination :
@Cpp
void TCODPath::reverse()
void TCODDijkstra::reverse()
@C
void TCOD_path_reverse(TCOD_path_t path)
void TCOD_dijkstra_reverse(TCOD_dijkstra_t dijkstra)
@Py
path_reverse(path)
dijkstra_reverse(dijkstra)
@C#
void TCODPath::reverse()
void TCODDijkstra::reverse()
@Param path In the C version, the path handler returned by a creation function.
@CppEx
TCODMap *myMap = new TCODMap(50,50);
TCODPath *path = new TCODPath(myMap); // allocate the path
path->compute(5,5,25,25); // calculate path from 5,5 to 25,25
path->reverse(); // now the path goes from 25,25 to 5,5
@CEx
TCOD_map_t my_map=TCOD_map_new(50,50);
TCOD_path_t path = TCOD_path_new_using_map(my_map);
TCOD_path_compute(path,5,5,25,25); // calculate path from 5,5 to 25,25
TCOD_path_reverse(path); // now the path goes from 25,25 to 5,5
@PyEx
my_map=libtcod.map_new(50,50)
path = libtcod.path_new_using_map(my_map)
libtcod.path_compute(path,5,5,25,25) # calculate path from 5,5 to 25,25
libtcod.path_reverse(path) # now the path goes from 25,25 to 5,5
*/
void reverse();
/**
@PageName path_read
@PageTitle Reading path information
@PageFather path
@PageDescDesc Once the path has been computed, you can get information about it using of one those functions.
@FuncTitle Getting the path origin and destination
@FuncDesc
You can read the current origin and destination cells with getOrigin/getDestination.
Note that when you walk the path, the origin changes at each step.
@Cpp
void TCODPath::getOrigin(int *x,int *y) const
void TCODPath::getDestination(int *x,int *y) const
@C
void TCOD_path_get_origin(TCOD_path_t path, int *x, int *y)
void TCOD_path_get_destination(TCOD_path_t path, int *x, int *y)
@Py
path_get_origin(path) # returns x,y
path_get_destination(path) # returns x,y
@C#
void TCODPath::getOrigin(out int x, out int y)
void TCODPath::getDestination(out int x, out int y)
@Param path In the C version, the path handler returned by a creation function.
@Param x,y The function returns the cell coordinates in these variables
*/
void getOrigin(int *x,int *y) const;
void getDestination(int *x,int *y) const;
/**
@PageName path_read
@FuncTitle Getting the path length
@FuncDesc You can get the number of steps needed to reach destination :
@Cpp
int TCODPath::size() const
int TCODDijkstra::size() const
@C
int TCOD_path_size(TCOD_path_t path)
int TCOD_dijkstra_size(TCOD_dijkstra_t dijkstra)
@Py
path_size(path)
dijkstra_size(dijkstra)
@C#
int TCODPath::size()
int TCODDijkstra::size()
@Param path, dijkstra In the C version, the path handler returned by a creation function.
*/
int size() const;
/**
@PageName path_read
@FuncTitle Read the path cells' coordinates
@FuncDesc You can get the coordinates of each point along the path :
@Cpp
void TCODPath::get(int index, int *x, int *y) const
void TCODDijkstra::get(int index, int *x, int *y) const
@C
void TCOD_path_get(TCOD_path_t path, int index, int *x, int *y)
void TCOD_dijkstra_get(TCOD_dijkstra_t dijkstra, int index, int *x, int *y)
@Py
path_get(path, index) # returns x,y
dijkstra_get(dijkstra, index) # returns x,y
@C#
int TCODPath::size()
int TCODDijkstra::size()
@Param path, dijkstra In the C version, the path handler returned by a creation function.
@Param index Step number.
0 <= index < path size
@Param x,y Address of the variables receiving the coordinates of the point.
@CppEx
for (int i=0; i < path->size(); i++ ) {
int x,y;
path->get(i,&x,&y);
printf ("Astar coord : %d %d\n", x,y );
}
for (int i=0; i < dijkstra->size(); i++ ) {
int x,y;
dijkstra->get(i,&x,&y);
printf ("Dijkstra coord : %d %d\n", x,y );
}
@CEx
int i;
for (i=0; i < TCOD_path_size(path); i++ ) {
int x,y;
TCOD_path_get(path,i,&x,&y);
printf ("Astar coord : %d %d\n", x,y );
}
for (i=0; i < TCOD_dijkstra_size(dijkstra); i++ ) {
int x,y;
TCOD_dijkstra_get(dijkstra,i,&x,&y);
printf ("Dijsktra coord : %d %d\n", x,y );
}
@PyEx
for i in range (libtcod.path_size(path)) :
x,y=libtcod.path_get(path,i)
print 'Astar coord : ',x,y
for i in range (libtcod.dijkstra_size(dijkstra)) :
x,y=libtcod.dijkstra_get(dijkstra,i)
print 'Dijkstra coord : ',x,y
*/
void get(int index, int *x, int *y) const;
/**
@PageName path_read
@FuncTitle Checking if the path is empty
@FuncDesc If you want a creature to follow the path, a more convenient way is to walk the path :
You know when you reached destination when the path is empty :
@Cpp
bool TCODPath::isEmpty() const
bool TCODDijkstra::isEmpty() const
@C
bool TCOD_path_is_empty(TCOD_path_t path)
bool TCOD_dijkstra_is_empty(TCOD_dijkstra_t dijkstra)
@Py
path_is_empty(path)
dijkstra_is_empty(dijkstra)
@C#
bool TCODPath::isEmpty()
bool TCODDijkstra::isEmpty()
@Param path, dijkstra In the C version, the path handler returned by a creation function.
*/
bool isEmpty() const;
/**
@PageName path_read
@FuncTitle Walking the path
@FuncDesc You can walk the path and go to the next step with :
Note that walking the path consume one step (and decrease the path size by one). The function returns false if recalculateWhenNeeded is false and the next cell on the path is no longer walkable, or if recalculateWhenNeeded is true, the next cell on the path is no longer walkable and no other path has been found. Also note that recalculateWhenNeeded only applies to A*.
@Cpp
bool TCODPath::walk(int *x, int *y, bool recalculateWhenNeeded)
bool TCODDijkstra::walk(int *x, int *y)
@C
bool TCOD_path_walk(TCOD_path_t path, int *x, int *y, bool recalculate_when_needed)
bool TCOD_dijkstra_walk(TCOD_dijkstra_t dijkstra, int *x, int *y)
@Py
path_walk(TCOD_path_t path, recalculate_when_needed) # returns x,y or None,None if no path
dijkstra_walk(TCOD_dijkstra_t dijkstra)
@C#
bool TCODPath::walk(ref int x, ref int y, bool recalculateWhenNeeded)
bool TCODDijkstra::walk(ref int x, ref int y)
@Param path, dijkstra In the C version, the path handler returned by a creation function.
@Param x,y Address of the variables receiving the coordinates of the next point.
@Param recalculateWhenNeeded If the next point is no longer walkable (another creature may be in the way), recalculate a new path and walk it.
@CppEx
while (! path->isEmpty()) {
int x,y;
if (path->walk(&x,&y,true)) {
printf ("Astar coord: %d %d\n",x,y );
} else {
printf ("I'm stuck!\n" );
break;
}
}
while (! dijkstra->isEmpty()) {
int x,y;
if (dijkstra->walk(&x,&y)) {
printf ("Dijkstra coord: %d %d\n",x,y );
} else {
printf ("I'm stuck!\n" );
break;
}
}
@CEx
while (! TCOD_path_is_empty(path)) {
int x,y;
if (TCOD_path_walk(path,&x,&y,true)) {
printf ("Astar coord: %d %d\n",x,y );
} else {
printf ("I'm stuck!\n" );
break;
}
}
while (! TCOD_dijkstra_is_empty(dijkstra)) {
int x,y;
if (TCOD_dijkstra_walk(dijkstra,&x,&y)) {
printf ("Dijkstra coord: %d %d\n",x,y );
} else {
printf ("I'm stuck!\n" );
break;
}
}
@PyEx
while not libtcod.path_is_empty(path)) :
x,y=libtcod.path_walk(path,True)
if not x is None :
print 'Astar coord: ',x,y
else :
print "I'm stuck!"
break
while not libtcod.dijkstra_is_empty(dijkstra)) :
x,y=libtcod.dijkstra_walk(dijkstra,True)
if not x is None :
print 'Dijkstra coord: ',x,y
else :
print "I'm stuck!"
break
*/
bool walk(int *x, int *y, bool recalculateWhenNeeded);
protected :
friend float TCOD_path_func(int xFrom, int yFrom, int xTo,int yTo, void *data);
TCOD_path_t data;
struct WrapperData {
void *userData;
const ITCODPathCallback *listener;
} cppData;
};
//Dijkstra kit
class TCODLIB_API TCODDijkstra {
public:
TCODDijkstra (TCODMap *map, float diagonalCost=1.41f);
TCODDijkstra (int width, int height, const ITCODPathCallback *listener, void *userData, float diagonalCost=1.41f);
~TCODDijkstra (void);
/**
@PageName path_compute
@FuncTitle Computing a Dijkstra grid
@FuncDesc In case of Dijkstra, this works in a slightly different way. In order to be able to compute a path, Dijkstra must first analyse the distances from the selected root (origin) node to all other nodes:
@Cpp void TCODDijkstra::compute(int rootX, int rootY)
@C void TCOD_dijkstra_compute(TCOD_dijkstra_t dijkstra, int root_x, int root_y)
@Py dijkstra_compute(dijkstra, root_x, root_y)
@C# void TCODDijkstra::compute(int rootX, int rootY)
@Param dijkstra In the C version, the path handler returned by a creation function.
@Param root_x,root_y Coordinates 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.
*/
void compute (int rootX, int rootY);
/**
@PageName path_compute
@FuncTitle Computing a path from a Dijkstra grid
@FuncDesc After the map is analysed 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.
@Cpp bool TCODDijkstra::setPath(int toX, int toY)
@C bool TCOD_dijkstra_path_set(TCOD_dijkstra_t dijkstra, int to_x, int to_y)
@Py dijkstra_path_set(dijkstra, to_x, to_y)
@C# bool TCODDijkstra::setPath(int toX, int toY)
@Param dijkstra In the C version, the path handler returned by a creation function.
@Param to_x,to_y Coordinates of the destination node of the path.
@CppEx
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
@CEx
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);
@PyEx
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)
*/
bool setPath (int toX, int toY);
/**
@PageName path_read
@FuncTitle Getting the distance from a cell to the root node
@FuncDesc 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.
@Cpp float TCODDijkstra::getDistance(int x, int y)
@C float TCOD_dijkstra_get_distance(TCOD_dijkstra_t dijkstra, int x, int y)
@Py dijkstra_get_distance(dijkstra, x, y)
@C# float TCODDijkstra::getDistance(int x, int y)
@Param dijkstra In the C version, the path handler returned by a creation function.
@Param x,y The coordinates whose distance from the root node are to be checked
*/
float getDistance (int x, int y);
bool walk (int *x, int *y);
bool isEmpty() const;
void reverse();
int size() const;
void get(int index, int *x, int *y) const;
private:
TCOD_dijkstra_t data;
struct WrapperData {
void *userData;
const ITCODPathCallback *listener;
} cppData;
};
#endif
|