Hello!
Bird, the location of the next node in the path is placed in the following skill slots:
// my._PF_NEXT_NODE_X = x coordinate of the next node to follow
// my._PF_NEXT_NODE_Y = y coordinate of the next node to follow
// my._PF_NEXT_NODE_Z = z coordinate of the next node to follow
(these are defined as...)
DEFINE _PF_NEXT_NODE_X, skill91;
DEFINE _PF_NEXT_NODE_Y, skill92;
DEFINE _PF_NEXT_NODE_Z, skill93;
Also, I haven't tested out the speed of my algorithm, but it should be
fast.
Here's the C++ code that traverses the nodes. (This is my own code.)
Code:
// This function contains a recursive call, which makes it particulary
// difficult to document. However, the general idea is to visit each node,
// all the while keeping track of the distance travelled. If the destination
// node is found, then that distance is returned. Otherwise, max distance
// is returned.
// while the nodes are being traversed, their "visited" flag is set so that
// nodes are not traversed twice (which would result in an infinite recursion)
int pf_next_node_ex(pf_node *node, pf_node *end_node, int dist)
{
pf_node *neighbor;
int path_length;
int shortest_path_length = 1000;
int t;
if (node == end_node) { return(dist); }
if (node->visited_flag == 1) { return(1000); }
node->visited_flag = 1;
dist++;
// Foreach path available from this node, find the path's length. Store
// the shortest length.
for (t=0; t<4; t++)
{
neighbor = node->pfp_neighbors[t];
if (neighbor != NULL)
{
path_length = pf_next_node_ex(neighbor, end_node, dist);
// A path length of 0 indicates that there's no route to the
// destination.
if ((path_length > 0) && (path_length < shortest_path_length))
{
shortest_path_length = path_length;
}
}
}
node->visited_flag = 0;
return (shortest_path_length);
}
But in all honesty, it's not the pathfinding that's going to slow you down... it's the helper code that you write that's involved in walking the path. It can get pretty tricky. My code handles a lot of that irritating code, like choosing the proper "first node" to take, behind the scenes. Hopefully that extra code didn't slow things down too much!
- Bret