|
Atrinik Server 2.5
|
#include <global.h>Go to the source code of this file.
Pathfinding related code.
Good pathfinding resources:
Possible enhancements (profile and identify need before spending time on):
About monster-to-player paths:
Definition in file pathfinder.c.
| #define HEURISTIC_ERROR -666. |
Used to indicate an error in distance_heuristic().
Definition at line 45 of file pathfinder.c.
| #define PATHFINDER_NODEBUF 300 |
This is used as static memory for search tree nodes (avoids lots of mallocs).
Definition at line 68 of file pathfinder.c.
| #define PATHFINDER_QUEUE_SIZE 100 |
Size of the pathfinder queue.
Definition at line 52 of file pathfinder.c.
Compress a path by removing redundant segments.
Current implementation removes segments that can be traversed by walking in a single direction.
Something advanced could be to use a hughes transform / or something smart with cross products.
| path | Path node. |
Definition at line 463 of file pathfinder.c.
| static float distance_heuristic | ( | path_node * | start, |
| path_node * | current, | ||
| path_node * | goal | ||
| ) | [static] |
Heuristic used for A* search. Should return an estimate of the "cost" (number of moves) needed to get from current to goal.
If this function overestimates, we are not guaranteed an optimal path.
get_rangevector() can fail here if there is no maptile path between start and goal. If it does, we have to return an error value.
| start | The initial starting position. |
| current | Current position. |
| goal | Goal position. |
Definition at line 531 of file pathfinder.c.
Generate a string representation of a path.
Ideas on how to store paths:
| path | Path node. |
Definition at line 327 of file pathfinder.c.
| static int find_neighbours | ( | path_node * | node, |
| path_node ** | open_list, | ||
| path_node * | start, | ||
| path_node * | goal, | ||
| object * | op, | ||
| uint32 | id | ||
| ) | [static] |
Find untraversed neighbors of the node and add to the open_list.
| node | Node. |
| open_list | Open list. |
| start | Starting position. |
| goal | Goal position. |
| op | Object. |
| id | Traversal ID. |
Definition at line 585 of file pathfinder.c.
| path_node* find_path | ( | object * | op, |
| mapstruct * | map1, | ||
| int | x1, | ||
| int | y1, | ||
| mapstruct * | map2, | ||
| int | x2, | ||
| int | y2 | ||
| ) |
Find a path for op from location on map1 to location on map2.
| op | Object. |
| map1 | From map. |
| x1 | From X position. |
| y1 | From Y position. |
| map2 | To map. |
| x2 | To X position. |
| y2 | To Y position. |
Definition at line 667 of file pathfinder.c.
| object* get_next_requested_path | ( | ) |
Get the next (valid) waypoint for which a path is requested
Definition at line 146 of file pathfinder.c.
| int get_path_next | ( | shstr * | buf, |
| sint16 * | off, | ||
| shstr ** | mappath, | ||
| mapstruct ** | map, | ||
| int * | x, | ||
| int * | y | ||
| ) |
Get the next location from a textual path description (generated by encode_path()) starting from the character index indicated by off.
Example text path description:
| buf | Buffer. |
| off | Offset. |
| mappath | Map path. |
| map | Map. Should be initialized with whatever map the object we are working on currently lives on (to handle paths without map strings). |
| x | X position. |
| y | Y position. |
Definition at line 368 of file pathfinder.c.
Insert a node into a list.
| node | Node to insert. |
| list | List to insert into. |
Definition at line 238 of file pathfinder.c.
Insert a node in a sorted list (lowest heuristic first in list).
| node | Node to insert. |
| list | List to insert into. |
Definition at line 256 of file pathfinder.c.
| static path_node* make_node | ( | mapstruct * | map, |
| sint16 | x, | ||
| sint16 | y, | ||
| uint16 | cost, | ||
| path_node * | parent | ||
| ) | [static] |
Allocate and initialize a node.
| map | Map. |
| x | X position. |
| y | Y position. |
| cost | Cost. |
| parent | Parent node. |
Definition at line 184 of file pathfinder.c.
| static object* pathfinder_queue_dequeue | ( | int * | count | ) | [static] |
Get the first waypoint from the queue.
| [out] | count | Waypoint's ID if there is a valid waypoint. |
Definition at line 101 of file pathfinder.c.
| static int pathfinder_queue_enqueue | ( | object * | waypoint | ) | [static] |
Enqueue a waypoint for path computation.
| waypoint | Waypoint. |
Definition at line 78 of file pathfinder.c.
Remove a node from a list.
| node | Node to remove. |
| list | List to remove from. |
Definition at line 215 of file pathfinder.c.
| void request_new_path | ( | object * | waypoint | ) |
path_node pathfinder_nodebuf[PATHFINDER_NODEBUF] [static] |
The node buffers.
Definition at line 72 of file pathfinder.c.
int pathfinder_nodebuf_next = 0 [static] |
Next node buf.
Definition at line 70 of file pathfinder.c.
int pathfinder_queue_first = 0 [static] |
First in the queue.
Definition at line 54 of file pathfinder.c.
int pathfinder_queue_last = 0 [static] |
Last in the queue.
Definition at line 56 of file pathfinder.c.
Waypoint object.
Definition at line 61 of file pathfinder.c.
Waypoint's ID.
Definition at line 64 of file pathfinder.c.
1.7.4