Devilution
Diablo devolved - magic behind the 1996 computer game
|
Go to the documentation of this file.
30 const char pathxdir[8] = { -1, -1, 1, 1, -1, 0, 1, 0 };
31 const char pathydir[8] = { -1, 1, -1, 1, 0, -1, 0, 1 };
51 int FindPath(BOOL (*PosOk)(
int,
int,
int),
int PosOkArg,
int sx,
int sy,
int dx,
int dy,
char *path)
53 PATHNODE *path_start, *next_node, *current;
65 path_start->
f = path_start->
h + path_start->
g;
71 if (next_node->
x == dx && next_node->
y == dy) {
81 for (i = 0; i < path_length; i++)
100 int delta_x = abs(sx - dx);
101 int delta_y = abs(sy - dy);
103 int min = delta_x < delta_y ? delta_x : delta_y;
104 int max = delta_x > delta_y ? delta_x : delta_y;
107 return 2 * (min + max);
119 if (pPath->
x == dx || pPath->
y == dy)
133 if (result == NULL) {
184 for (i = 0; i < 8; i++) {
187 ok = PosOk(PosOkArg, dx, dy);
214 for (i = 0; i < 8; i++) {
215 if (pPath->
Child[i] == NULL)
218 pPath->
Child[i] = dxdy;
219 if (next_g < dxdy->g) {
224 dxdy->
f = next_g + dxdy->
h;
231 for (i = 0; i < 8; i++) {
232 if (pPath->
Child[i] == NULL)
235 pPath->
Child[i] = dxdy;
240 dxdy->
f = next_g + dxdy->
h;
252 dxdy->
f = next_g + dxdy->
h;
258 for (i = 0; i < 8; i++) {
259 if (pPath->
Child[i] == NULL)
262 pPath->
Child[i] = dxdy;
274 while (result != NULL && (result->
x != dx || result->
y != dy))
285 while (result != NULL && (result->
x != dx || result->
y != dy))
305 while (next && next->
f < f) {
326 for (i = 0; i < 8; i++) {
327 PathAct = PathOld->
Child[i];
333 PathAct->
Parent = PathOld;
335 PathAct->
f = PathAct->
g + PathAct->
h;
374 memset(new_node, 0,
sizeof(
PATHNODE));
void path_push_active_step(PATHNODE *pPath)
push pPath onto the pnode_tblptr stack
DEVILUTION_BEGIN_NAMESPACE PATHNODE path_nodes[MAXPATHNODES]
Notes visisted by the path finding algorithm.
struct PATHNODE * Child[8]
const char pathxdir[8]
For iterating over the 8 possible movement directions.
int gdwCurNodes
the number of in-use nodes in path_nodes
PATHNODE * path_pop_active_step()
pop and return a node from the pnode_tblptr stack
int path_get_h_cost(int sx, int sy, int dx, int dy)
heuristic, estimated cost from (sx,sy) to (dx,dy)
int dPiece[MAXDUNX][MAXDUNY]
BOOLEAN nSolidTable[2049]
List of path blocking dPieces.
char path_directions[9]
each step direction is assigned a number like this: dx -1 0 1 +--— -1|5 1 6 dy 0|2 0 3 1|8 4 7
BOOL path_parent_path(PATHNODE *pPath, int dx, int dy, int sx, int sy)
add a step from pPath to (dx,dy), return 1 if successful, and update the frontier/visited nodes accor...
#define DEVILUTION_END_NAMESPACE
BOOL path_get_path(BOOL(*PosOk)(int, int, int), int PosOkArg, PATHNODE *pPath, int x, int y)
perform a single step of A* bread-first search by trying to step in every possible direction from pPa...
struct PATHNODE * NextNode
PATHNODE * path_get_node1(int dx, int dy)
return a node for (dx,dy) on the frontier, or NULL if not found
BOOL path_solid_pieces(PATHNODE *pPath, int dx, int dy)
check if stepping from pPath to (dx,dy) cuts a corner.
int gdwCurPathStep
size of the pnode_tblptr stack
PATHNODE * path_get_node2(int dx, int dy)
return a node for (dx,dy) if it was visited, or NULL if not found
int FindPath(BOOL(*PosOk)(int, int, int), int PosOkArg, int sx, int sy, int dx, int dy, char *path)
find the shortest path from (sx,sy) to (dx,dy), using PosOk(PosOkArg,x,y) to check that each step is ...
int path_check_equal(PATHNODE *pPath, int dx, int dy)
return 2 if pPath is horizontally/vertically aligned with (dx,dy), else 3
PATHNODE * pnode_tblptr[MAXPATHNODES]
A stack for recursively searching nodes.
int pnode_vals[MAX_PATH_LENGTH]
for reconstructing the path after the A* search is done.
PATHNODE * path_new_step()
zero one of the preallocated nodes and return a pointer to it, or NULL if none are available
PATHNODE path_unusednodes[MAXPATHNODES]
void path_set_coords(PATHNODE *pPath)
update all path costs using depth-first search starting at pPath
PATHNODE * path_2_nodes
A linked list of the A* frontier, sorted by distance.
void path_next_node(PATHNODE *pPath)
insert pPath into the frontier (keeping the frontier sorted by total distance)
PATHNODE * pnode_ptr
A linked list of all visited nodes.
PATHNODE * GetNextPath()
get the next node on the A* frontier to explore (estimated to be closest to the goal),...