OpenTTD
Data Structures | Typedefs | Enumerations | Variables
aystar.h File Reference

This file has the header for AyStar. More...

#include "queue.h"
#include "../../tile_type.h"
#include "../../track_type.h"

Go to the source code of this file.

Data Structures

struct  AyStarNode
 Node in the search. More...
struct  PathNode
 A path of nodes. More...
struct  OpenListNode
 Internal node. More...
struct  AyStar
 AyStar search algorithm struct. More...

Typedefs

typedef int32 AyStar_EndNodeCheck (AyStar *aystar, OpenListNode *current)
 Check whether the end-tile is found.
typedef int32 AyStar_CalculateG (AyStar *aystar, AyStarNode *current, OpenListNode *parent)
 Calculate the G-value for the AyStar algorithm.
typedef int32 AyStar_CalculateH (AyStar *aystar, AyStarNode *current, OpenListNode *parent)
 Calculate the H-value for the AyStar algorithm.
typedef void AyStar_GetNeighbours (AyStar *aystar, OpenListNode *current)
 This function requests the tiles around the current tile and put them in #tiles_around.
typedef void AyStar_FoundEndNode (AyStar *aystar, OpenListNode *current)
 If the End Node is found, this function is called.

Enumerations

enum  AystarStatus {
  AYSTAR_FOUND_END_NODE, AYSTAR_EMPTY_OPENLIST, AYSTAR_STILL_BUSY, AYSTAR_NO_PATH,
  AYSTAR_LIMIT_REACHED, AYSTAR_DONE
}
 Return status of AyStar methods. More...

Variables

static const int AYSTAR_INVALID_NODE = -1
 Item is not valid (for example, not walkable).

Detailed Description

This file has the header for AyStar.

AyStar is a fast path finding routine and is used for things like AI path finding and Train path finding. For more information about AyStar (A* Algorithm), you can look at http://en.wikipedia.org/wiki/A-star_search_algorithm.

Definition in file aystar.h.

Typedef Documentation

typedef int32 AyStar_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent)

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

Definition at line 86 of file aystar.h.

typedef int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent)

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)

Definition at line 93 of file aystar.h.

typedef int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current)

Check whether the end-tile is found.

Parameters
aystarAyStar search algorithm data.
currentNode to exam one.
Note
The 2nd parameter should be OpenListNode, and not AyStarNode. AyStarNode is part of OpenListNode and so it could be accessed without any problems. The good part about OpenListNode is, and how AIs use it, that you can access the parent of the current node, and so check if you, for example don't try to enter the file tile with a 90-degree curve. So please, leave this an OpenListNode, it works just fine.
Returns
Status of the node:

Definition at line 78 of file aystar.h.

typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current)

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

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

Definition at line 106 of file aystar.h.

typedef void AyStar_GetNeighbours(AyStar *aystar, OpenListNode *current)

This function requests the tiles around the current tile and put them in #tiles_around.

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

Warning
Never add more tiles_around than memory allocated for it.

Definition at line 100 of file aystar.h.

Enumeration Type Documentation

Return status of AyStar methods.

Enumerator:
AYSTAR_FOUND_END_NODE 

An end node was found.

AYSTAR_EMPTY_OPENLIST 

All items are tested, and no path has been found.

AYSTAR_STILL_BUSY 

Some checking was done, but no path found yet, and there are still items left to try.

AYSTAR_NO_PATH 

No path to the goal was found.

AYSTAR_LIMIT_REACHED 

The #max_nodes limit has been reached, aborting search.

AYSTAR_DONE 

Not an end-tile, or wrong direction.

Definition at line 28 of file aystar.h.