aystar.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00018 #ifndef AYSTAR_H
00019 #define AYSTAR_H
00020
00021 #include "queue.h"
00022 #include "../../tile_type.h"
00023 #include "../../track_type.h"
00024
00025
00026
00028 enum AystarStatus {
00029 AYSTAR_FOUND_END_NODE,
00030 AYSTAR_EMPTY_OPENLIST,
00031 AYSTAR_STILL_BUSY,
00032 AYSTAR_NO_PATH,
00033 AYSTAR_LIMIT_REACHED,
00034 AYSTAR_DONE,
00035 };
00036
00037 static const int AYSTAR_INVALID_NODE = -1;
00038
00040 struct AyStarNode {
00041 TileIndex tile;
00042 Trackdir direction;
00043 uint user_data[2];
00044 };
00045
00047 struct PathNode {
00048 AyStarNode node;
00049 PathNode *parent;
00050 };
00051
00057 struct OpenListNode {
00058 int g;
00059 PathNode path;
00060 };
00061
00062 struct AyStar;
00063
00078 typedef int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current);
00079
00086 typedef int32 AyStar_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
00087
00093 typedef int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
00094
00100 typedef void AyStar_GetNeighbours(AyStar *aystar, OpenListNode *current);
00101
00106 typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current);
00107
00116 struct AyStar {
00117
00118
00119
00120
00121
00122 AyStar_CalculateG *CalculateG;
00123 AyStar_CalculateH *CalculateH;
00124 AyStar_GetNeighbours *GetNeighbours;
00125 AyStar_EndNodeCheck *EndNodeCheck;
00126 AyStar_FoundEndNode *FoundEndNode;
00127
00128
00129
00130
00131
00132
00133
00134 void *user_path;
00135 void *user_target;
00136 uint user_data[10];
00137
00138 byte loops_per_tick;
00139 uint max_path_cost;
00140 uint max_search_nodes;
00141
00142
00143
00144 AyStarNode neighbours[12];
00145 byte num_neighbours;
00146
00147 void Init(Hash_HashProc hash, uint num_buckets);
00148
00149
00150
00151 void AddStartNode(AyStarNode *start_node, uint g);
00152 int Main();
00153 int Loop();
00154 void Free();
00155 void Clear();
00156 void CheckTile(AyStarNode *current, OpenListNode *parent);
00157
00158 protected:
00159 Hash closedlist_hash;
00160 BinaryHeap openlist_queue;
00161 Hash openlist_hash;
00162
00163 void OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g);
00164 OpenListNode *OpenListIsInList(const AyStarNode *node);
00165 OpenListNode *OpenListPop();
00166
00167 void ClosedListAdd(const PathNode *node);
00168 PathNode *ClosedListIsInList(const AyStarNode *node);
00169 };
00170
00171 #endif