16#include "../../stdafx.h"
19#include "../../safeguards.h"
29 new_node.Set(parent, node->tile, node->td,
true);
30 new_node.estimate = f;
44 int new_g = this->CalculateG(
this, current, parent);
51 new_g += parent->cost;
55 int new_h = this->CalculateH(
this, current, parent);
60 int new_f = new_g + new_h;
67 if (check !=
nullptr) {
69 if (new_g > check->cost)
return;
72 check->estimate = new_f;
74 check->parent = closedlist_parent;
79 this->
OpenListAdd(closedlist_parent, current, new_f, new_g);
101 if (this->FoundEndNode !=
nullptr) {
102 this->FoundEndNode(
this, current);
111 this->GetNeighbours(
this, current);
114 for (
auto &neighbour : this->neighbours) {
172 Debug(misc, 0,
"[AyStar] Starting A* Algorithm from node ({}, {}, {})\n",
173 TileX(start_node->tile),
TileY(start_node->tile), start_node->direction);
This file has the header for AyStar.
AyStarStatus
Return status of AyStar methods.
@ EmptyOpenList
All items are tested, and no path has been found.
@ StillBusy
Some checking was done, but no path found yet, and there are still items left to try.
@ LimitReached
The AyStar::max_search_nodes limit has been reached, aborting search.
@ NoPath
No path to the goal was found.
@ FoundEndNode
An end node was found.
static const int AYSTAR_INVALID_NODE
Item is not valid (for example, not walkable).
void InsertClosedNode(Titem &item)
close node
Titem * FindClosedNode(const Key &key)
return the closed node specified by a key or nullptr if not found
void InsertOpenNode(Titem &item)
insert given item as open node (into open_nodes and open_queue)
Titem * PopBestOpenNode()
remove and return the best open node
int ClosedCount()
return number of closed nodes
Titem & CreateNewNode()
allocate new data item from items
Titem & PopOpenNode(const Key &key)
remove and return the open node specified by a key
Titem * FindOpenNode(const Key &key)
return the open node specified by a key or nullptr if not found
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
int max_search_nodes
The maximum number of nodes that will be expanded, 0 = infinite.
void OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g)
Adds a node to the open list.
int max_path_cost
If the g-value goes over this number, it stops searching, 0 = infinite.
AyStarStatus Loop()
This function is the core of AyStar.
AyStarStatus Main()
This is the function you call to run AyStar.
void CheckTile(AyStarNode *current, PathNode *parent)
Checks one tile and calculate its f-value.
void AddStartNode(AyStarNode *start_node, int g)
Adds a node from where to start an algorithm.
uint8_t loops_per_tick
How many loops are there called before Main() gives control back to the caller. 0 = until done.