OpenTTD Source 20250426-master-gbb1d561369
AyStar Class Referenceabstract

AyStar search algorithm struct. More...

#include <aystar.h>

Inheritance diagram for AyStar:
RiverBuilder

Protected Member Functions

virtual int32_t CalculateG (const AyStarNode &current, const PathNode &parent) const =0
 Calculate the G-value for the AyStar algorithm.
 
virtual int32_t CalculateH (const AyStarNode &current, const PathNode &parent) const =0
 Calculate the H-value for the AyStar algorithm.
 
virtual void GetNeighbours (const PathNode &current, std::vector< AyStarNode > &neighours) const =0
 This function requests the tiles around the current tile.
 
virtual AyStarStatus EndNodeCheck (const PathNode &current) const =0
 Check whether the end-tile is found.
 
virtual void FoundEndNode (const PathNode &current)=0
 If the End Node is found, this function is called.
 
void AddStartNode (AyStarNode *start_node, int g)
 Adds a node from where to start an algorithm.
 
AyStarStatus Main ()
 This is the function you call to run AyStar.
 

Private Member Functions

AyStarStatus Loop ()
 This function is the core of AyStar.
 
void OpenListAdd (PathNode *parent, const AyStarNode *node, int f, int g)
 Adds a node to the open list.
 
void CheckTile (AyStarNode *current, PathNode *parent)
 Checks one tile and calculate its f-value.
 

Private Attributes

NodeList< PathNode, 8, 10 > nodes
 
std::vector< AyStarNodeneighbours
 

Detailed Description

AyStar search algorithm struct.

Definition at line 44 of file aystar.h.

Member Function Documentation

◆ AddStartNode()

void AyStar::AddStartNode ( AyStarNode start_node,
int  g 
)
protected

Adds a node from where to start an algorithm.

Multiple nodes can be added if wanted.

Parameters
start_nodeNode to start with.
gthe cost for starting with this node.

Definition at line 161 of file aystar.cpp.

References Debug, OpenListAdd(), TileX(), and TileY().

Referenced by RiverBuilder::Exec().

◆ CalculateG()

virtual int32_t AyStar::CalculateG ( const AyStarNode current,
const PathNode parent 
) const
protectedpure virtual

Calculate the G-value for the AyStar algorithm.

Returns
G value of the node:
  • AYSTAR_INVALID_NODE : indicates an item is not valid (e.g.: unwalkable)
  • Any value >= 0 : the g-value for this tile

Implemented in RiverBuilder.

Referenced by CheckTile().

◆ CalculateH()

virtual int32_t AyStar::CalculateH ( const AyStarNode current,
const PathNode parent 
) const
protectedpure virtual

Calculate the H-value for the AyStar algorithm.

Mostly, this must return the distance (Manhattan way) between the current point and the end point.

Returns
The h-value for this tile (any value >= 0)

Implemented in RiverBuilder.

Referenced by CheckTile().

◆ CheckTile()

◆ EndNodeCheck()

virtual AyStarStatus AyStar::EndNodeCheck ( const PathNode current) const
protectedpure virtual

Check whether the end-tile is found.

Parameters
currentNode to exam.
Returns
Status of the node:

Implemented in RiverBuilder.

Referenced by Loop().

◆ FoundEndNode()

virtual void AyStar::FoundEndNode ( const PathNode current)
protectedpure virtual

If the End Node is found, this function is called.

It can do, for example, calculate the route and put that in an array.

Implemented in RiverBuilder.

◆ GetNeighbours()

virtual void AyStar::GetNeighbours ( const PathNode current,
std::vector< AyStarNode > &  neighours 
) const
protectedpure virtual

This function requests the tiles around the current tile.

neighbours is never reset, so if you are not using directions, just leave it alone.

Implemented in RiverBuilder.

Referenced by Loop().

◆ Loop()

◆ Main()

AyStarStatus AyStar::Main ( )
protected

This is the function you call to run AyStar.

Returns
Possible values:

Definition at line 132 of file aystar.cpp.

References Debug, EmptyOpenList, FoundEndNode, LimitReached, Loop(), NoPath, and StillBusy.

Referenced by RiverBuilder::Exec().

◆ OpenListAdd()

void AyStar::OpenListAdd ( PathNode parent,
const AyStarNode node,
int  f,
int  g 
)
private

Adds a node to the open list.

It makes a copy of node, and puts the pointer of parent in the struct.

Definition at line 25 of file aystar.cpp.

References NodeList< Titem, Thash_bits_open, Thash_bits_closed >::CreateNewNode(), and NodeList< Titem, Thash_bits_open, Thash_bits_closed >::InsertOpenNode().

Referenced by AddStartNode(), and CheckTile().

Field Documentation

◆ neighbours

std::vector<AyStarNode> AyStar::neighbours
mutableprivate

Definition at line 91 of file aystar.h.

◆ nodes

NodeList<PathNode, 8, 10> AyStar::nodes
private

Definition at line 90 of file aystar.h.


The documentation for this class was generated from the following files: