|
CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
|
Finds paths through maps. More...
#include <th_pathfind.h>
Public Member Functions | |
| pathfinder () | |
| ~pathfinder () | |
| void | set_default_map (const level_map *pMap) |
| bool | find_path (const level_map *pMap, int iStartX, int iStartY, int iEndX, int iEndY) |
| bool | find_idle_tile (const level_map *pMap, int iStartX, int iStartY, int iN, int parcelId) |
| bool | find_path_to_hospital (const level_map *pMap, int iStartX, int iStartY) |
| bool | visit_objects (const level_map *pMap, int iStartX, int iStartY, object_type eTHOB, int iMaxDistance, lua_State *L, int iVisitFunction, bool anyObjectType) |
| int | get_path_length () const |
| bool | get_path_end (int *pX, int *pY) const |
| void | push_result (lua_State *L) const |
| void | persist (lua_persist_writer *pWriter) const |
| void | depersist (lua_persist_reader *pReader) |
| void | allocate_node_cache (int iWidth, int iHeight) |
| Allocate node cache for all tiles of the map. | |
| path_node * | pop_from_open_heap () |
| void | push_to_open_heap (path_node *pNode) |
| void | open_heap_promote (path_node *pNode) |
Public Attributes | |
| const level_map * | default_map |
| std::vector< path_node > | nodes |
| 2D array of nodes, one for each map cell | |
| path_node ** | dirty_node_list |
| Array of "dirty" nodes which need to be reset before the next path find. | |
| std::vector< path_node * > | open_heap |
| Heap of not yet evaluated nodes as a 0-based array. | |
| path_node * | destination |
| int | node_cache_width |
| int | node_cache_height |
| int | dirty_node_count |
Finds paths through maps.
A pathfinder is used for finding a path through a map. A single pathfinder instance is not reentrant, but separate instances are. Users of the class should call find_path() to test if there is a path between two points on a map, and then use get_path_length() and/or push_result() to get the actual path.
Internally, the A* search algorithm is used. The open set is implemented as a heap in open_heap, and there is no explicit closed set. For each cell of the map, a path_node structure is created (and cached between searches if the map size is constant), which holds information about said map cell in the current search. The algorithm is implemented in such a way that most path find operations do not need to allocate (or free) any memory.
| pathfinder::pathfinder | ( | ) |
| pathfinder::~pathfinder | ( | ) |
Allocate node cache for all tiles of the map.
| iWidth | Width of the map. |
| iHeight | Height of the map. |
| void pathfinder::depersist | ( | lua_persist_reader * | pReader | ) |
|
inline |
|
inline |
| int pathfinder::get_path_length | ( | ) | const |
| void pathfinder::persist | ( | lua_persist_writer * | pWriter | ) | const |
| path_node * pathfinder::pop_from_open_heap | ( | ) |
|
inline |
| path_node* pathfinder::destination |
| int pathfinder::dirty_node_count |
| path_node** pathfinder::dirty_node_list |
Array of "dirty" nodes which need to be reset before the next path find.
This array is always large enough to hold every single node, and dirty_node_count holds the number of items currently in the array.
| int pathfinder::node_cache_height |
| int pathfinder::node_cache_width |
| std::vector<path_node> pathfinder::nodes |
2D array of nodes, one for each map cell
| std::vector<path_node*> pathfinder::open_heap |
Heap of not yet evaluated nodes as a 0-based array.
This array conforms to the conditions: value(i) <= value(i * 2 + 1) value(i) <= value(i * 2 + 2) This causes the array to be a minimum binary heap.