|
@@ -190,7 +190,7 @@ static void heap_push_node(struct node_heap *heap, struct path_node *node)
|
|
{
|
|
{
|
|
#ifndef __clang_analyzer__ // TODO: Figure out why clang's static analyzer doesn't like this
|
|
#ifndef __clang_analyzer__ // TODO: Figure out why clang's static analyzer doesn't like this
|
|
BHEAP_ENSURE(*heap, 1, 256);
|
|
BHEAP_ENSURE(*heap, 1, 256);
|
|
- BHEAP_PUSH(*heap, node, NODE_MINTOPCMP, swap_ptr);
|
|
|
|
|
|
+ BHEAP_PUSH2(*heap, node, NODE_MINTOPCMP, swap_ptr);
|
|
#endif // __clang_analyzer__
|
|
#endif // __clang_analyzer__
|
|
}
|
|
}
|
|
|
|
|
|
@@ -203,8 +203,7 @@ static int heap_update_node(struct node_heap *heap, struct path_node *node)
|
|
ShowError("heap_update_node: node not found\n");
|
|
ShowError("heap_update_node: node not found\n");
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
- BHEAP_POPINDEX(*heap, i, NODE_MINTOPCMP, swap_ptr);
|
|
|
|
- BHEAP_PUSH(*heap, node, NODE_MINTOPCMP, swap_ptr);
|
|
|
|
|
|
+ BHEAP_UPDATE(*heap, i, NODE_MINTOPCMP, swap_ptr);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -361,7 +360,7 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x
|
|
}
|
|
}
|
|
|
|
|
|
current = BHEAP_PEEK(open_set); // Look for the lowest f_cost node in the 'open' set
|
|
current = BHEAP_PEEK(open_set); // Look for the lowest f_cost node in the 'open' set
|
|
- BHEAP_POP(open_set, NODE_MINTOPCMP, swap_ptr); // Remove it from 'open' set
|
|
|
|
|
|
+ BHEAP_POP2(open_set, NODE_MINTOPCMP, swap_ptr); // Remove it from 'open' set
|
|
|
|
|
|
x = current->x;
|
|
x = current->x;
|
|
y = current->y;
|
|
y = current->y;
|
|
@@ -381,24 +380,22 @@ bool path_search(struct walkpath_data *wpd, int16 m, int16 x0, int16 y0, int16 x
|
|
|
|
|
|
#define chk_dir(d) ((allowed_dirs & (d)) == (d))
|
|
#define chk_dir(d) ((allowed_dirs & (d)) == (d))
|
|
// Process neighbors of current node
|
|
// Process neighbors of current node
|
|
- // TODO: Processing order affects chosen path if there is more than one path with same cost.
|
|
|
|
- // In few cases path found by server will be different than path found by game client.
|
|
|
|
- if (chk_dir(DIR_SOUTH))
|
|
|
|
- e += add_path(&open_set, tp, x, y-1, g_cost + MOVE_COST, current, heuristic(x, y-1, x1, y1)); // (x, y-1) 4
|
|
|
|
- if (chk_dir(DIR_SOUTH|DIR_WEST) && !map_getcellp(md, x-1, y-1, cell))
|
|
|
|
- e += add_path(&open_set, tp, x-1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y-1, x1, y1)); // (x-1, y-1) 3
|
|
|
|
- if (chk_dir(DIR_WEST))
|
|
|
|
- e += add_path(&open_set, tp, x-1, y, g_cost + MOVE_COST, current, heuristic(x-1, y, x1, y1)); // (x-1, y) 2
|
|
|
|
- if (chk_dir(DIR_NORTH|DIR_WEST) && !map_getcellp(md, x-1, y+1, cell))
|
|
|
|
- e += add_path(&open_set, tp, x-1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y+1, x1, y1)); // (x-1, y+1) 1
|
|
|
|
- if (chk_dir(DIR_NORTH))
|
|
|
|
- e += add_path(&open_set, tp, x, y+1, g_cost + MOVE_COST, current, heuristic(x, y+1, x1, y1)); // (x, y+1) 0
|
|
|
|
- if (chk_dir(DIR_NORTH|DIR_EAST) && !map_getcellp(md, x+1, y+1, cell))
|
|
|
|
- e += add_path(&open_set, tp, x+1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y+1, x1, y1)); // (x+1, y+1) 7
|
|
|
|
- if (chk_dir(DIR_EAST))
|
|
|
|
- e += add_path(&open_set, tp, x+1, y, g_cost + MOVE_COST, current, heuristic(x+1, y, x1, y1)); // (x+1, y) 6
|
|
|
|
if (chk_dir(DIR_SOUTH|DIR_EAST) && !map_getcellp(md, x+1, y-1, cell))
|
|
if (chk_dir(DIR_SOUTH|DIR_EAST) && !map_getcellp(md, x+1, y-1, cell))
|
|
e += add_path(&open_set, tp, x+1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y-1, x1, y1)); // (x+1, y-1) 5
|
|
e += add_path(&open_set, tp, x+1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y-1, x1, y1)); // (x+1, y-1) 5
|
|
|
|
+ if (chk_dir(DIR_EAST))
|
|
|
|
+ e += add_path(&open_set, tp, x+1, y, g_cost + MOVE_COST, current, heuristic(x+1, y, x1, y1)); // (x+1, y) 6
|
|
|
|
+ if (chk_dir(DIR_NORTH|DIR_EAST) && !map_getcellp(md, x+1, y+1, cell))
|
|
|
|
+ e += add_path(&open_set, tp, x+1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x+1, y+1, x1, y1)); // (x+1, y+1) 7
|
|
|
|
+ if (chk_dir(DIR_NORTH))
|
|
|
|
+ e += add_path(&open_set, tp, x, y+1, g_cost + MOVE_COST, current, heuristic(x, y+1, x1, y1)); // (x, y+1) 0
|
|
|
|
+ if (chk_dir(DIR_NORTH|DIR_WEST) && !map_getcellp(md, x-1, y+1, cell))
|
|
|
|
+ e += add_path(&open_set, tp, x-1, y+1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y+1, x1, y1)); // (x-1, y+1) 1
|
|
|
|
+ if (chk_dir(DIR_WEST))
|
|
|
|
+ e += add_path(&open_set, tp, x-1, y, g_cost + MOVE_COST, current, heuristic(x-1, y, x1, y1)); // (x-1, y) 2
|
|
|
|
+ if (chk_dir(DIR_SOUTH|DIR_WEST) && !map_getcellp(md, x-1, y-1, cell))
|
|
|
|
+ e += add_path(&open_set, tp, x-1, y-1, g_cost + MOVE_DIAGONAL_COST, current, heuristic(x-1, y-1, x1, y1)); // (x-1, y-1) 3
|
|
|
|
+ if (chk_dir(DIR_SOUTH))
|
|
|
|
+ e += add_path(&open_set, tp, x, y-1, g_cost + MOVE_COST, current, heuristic(x, y-1, x1, y1)); // (x, y-1) 4
|
|
#undef chk_dir
|
|
#undef chk_dir
|
|
if (e) {
|
|
if (e) {
|
|
BHEAP_CLEAR(open_set);
|
|
BHEAP_CLEAR(open_set);
|