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(*current, *parent);
51 new_g += parent->cost;
54 int new_h = this->
CalculateH(*current, *parent);
59 int new_f = new_g + new_h;
66 if (check !=
nullptr) {
68 if (new_g > check->cost)
return;
71 check->estimate = new_f;
73 check->parent = closedlist_parent;
78 this->
OpenListAdd(closedlist_parent, current, new_f, new_g);
111 for (
auto &neighbour : this->neighbours) {
164 Debug(misc, 0,
"[AyStar] Starting A* Algorithm from node ({}, {}, {})\n",
165 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_DEF_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).
static const int AYSTAR_DEF_MAX_SEARCH_NODES
Reference limit for #AyStar::max_search_nodes.
void OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g)
Adds a node to the open list.
virtual AyStarStatus EndNodeCheck(const PathNode ¤t) const =0
Check whether the end-tile is found.
virtual void GetNeighbours(const PathNode ¤t, std::vector< AyStarNode > &neighours) const =0
This function requests the tiles around the current tile.
AyStarStatus Loop()
This function is the core of AyStar.
AyStarStatus Main()
This is the function you call to run AyStar.
virtual int32_t CalculateH(const AyStarNode ¤t, const PathNode &parent) const =0
Calculate the H-value for the AyStar algorithm.
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.
virtual int32_t CalculateG(const AyStarNode ¤t, const PathNode &parent) const =0
Calculate the G-value for the AyStar algorithm.
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,...)
Output 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.