OpenTTD Source 20250611-master-gf8776b0a6f
aystar.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
16#ifndef AYSTAR_H
17#define AYSTAR_H
18
19#include "yapf/nodelist.hpp"
20#include "yapf/yapf_node.hpp"
21
22static const int AYSTAR_DEF_MAX_SEARCH_NODES = 10000;
23
25enum class AyStarStatus : uint8_t {
28 StillBusy,
29 NoPath,
31 Done,
32};
33
34static const int AYSTAR_INVALID_NODE = -1;
35
37
38struct PathNode : CYapfNodeT<AyStarNode, PathNode> {
39};
40
44class AyStar {
45protected:
52 virtual int32_t CalculateG(const AyStarNode &current, const PathNode &parent) const = 0;
53
59 virtual int32_t CalculateH(const AyStarNode &current, const PathNode &parent) const = 0;
60
65 virtual void GetNeighbours(const PathNode &current, std::vector<AyStarNode> &neighours) const = 0;
66
74 virtual AyStarStatus EndNodeCheck(const PathNode &current) const = 0;
75
80 virtual void FoundEndNode(const PathNode &current) = 0;
81
82 void AddStartNode(AyStarNode *start_node, int g);
83
85
86public:
87 virtual ~AyStar() = default;
88
89private:
91 mutable std::vector<AyStarNode> neighbours;
92
94 void OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g);
95 void CheckTile(AyStarNode *current, PathNode *parent);
96};
97
98#endif /* AYSTAR_H */
AyStarStatus
Return status of AyStar methods.
Definition aystar.h:25
@ 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.
@ Done
Not an end-tile, or wrong direction.
static const int AYSTAR_INVALID_NODE
Item is not valid (for example, not walkable).
Definition aystar.h:34
static const int AYSTAR_DEF_MAX_SEARCH_NODES
Reference limit for #AyStar::max_search_nodes.
Definition aystar.h:22
AyStar search algorithm struct.
Definition aystar.h:44
void OpenListAdd(PathNode *parent, const AyStarNode *node, int f, int g)
Adds a node to the open list.
Definition aystar.cpp:25
virtual AyStarStatus EndNodeCheck(const PathNode &current) const =0
Check whether the end-tile is found.
virtual void GetNeighbours(const PathNode &current, std::vector< AyStarNode > &neighours) const =0
This function requests the tiles around the current tile.
AyStarStatus Loop()
This function is the core of AyStar.
Definition aystar.cpp:91
virtual void FoundEndNode(const PathNode &current)=0
If the End Node is found, this function is called.
AyStarStatus Main()
This is the function you call to run AyStar.
Definition aystar.cpp:132
virtual int32_t CalculateH(const AyStarNode &current, 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.
Definition aystar.cpp:38
void AddStartNode(AyStarNode *start_node, int g)
Adds a node from where to start an algorithm.
Definition aystar.cpp:161
virtual int32_t CalculateG(const AyStarNode &current, const PathNode &parent) const =0
Calculate the G-value for the AyStar algorithm.
Hash table based node list multi-container class.
Definition nodelist.hpp:21
List of nodes used for the A-star pathfinder.
Yapf Node base.
Definition yapf_node.hpp:62
Node in the pathfinder's graph.