aystar.h
author hackykid
Mon, 04 Jul 2005 14:58:55 +0000
changeset 2008 c9d6585c96c8
parent 1977 4392ae3d8e31
child 2186 461a2aff3486
permissions -rw-r--r--
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
- Feature: [pbs] Implement autoplacement of pbs blocks, when a block has an entry and an exit pbs signal, covert the entire block to pbs. Can be turned off in the patch settings.
- Feature: [pbs] Allow showing of reserved status by making the tracks darker, when the pbs debug level is at least 1.
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     1
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     2
 * This file has the header for AyStar
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     3
 *  AyStar is a fast pathfinding routine and is used for things like
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     4
 *  AI_pathfinding and Train_pathfinding.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     5
 *  For more information about AyStar (A* Algorithm), you can look at
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     6
 *	  http://en.wikipedia.org/wiki/A-star_search_algorithm
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     7
 */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     8
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
     9
#ifndef AYSTAR_H
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    10
#define AYSTAR_H
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    11
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    12
#include "queue.h"
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    13
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    14
//#define AYSTAR_DEBUG
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    15
enum {
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    16
	AYSTAR_FOUND_END_NODE,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    17
	AYSTAR_EMPTY_OPENLIST,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    18
	AYSTAR_STILL_BUSY,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    19
	AYSTAR_NO_PATH,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    20
	AYSTAR_LIMIT_REACHED,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    21
	AYSTAR_DONE
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    22
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    23
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    24
enum{
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    25
	AYSTAR_INVALID_NODE = -1,
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    26
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    27
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    28
typedef struct AyStarNode AyStarNode;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    29
struct AyStarNode {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1777
diff changeset
    30
	TileIndex tile;
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    31
	uint direction;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    32
	uint user_data[2];
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    33
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    34
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    35
// The resulting path has nodes looking like this.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    36
typedef struct PathNode PathNode;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    37
struct PathNode {
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    38
	AyStarNode node;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    39
	// The parent of this item
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    40
	PathNode *parent;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    41
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    42
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    43
// For internal use only
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    44
// We do not save the h-value, because it is only needed to calculate the f-value.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    45
//  h-value should _always_ be the distance left to the end-tile.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    46
typedef struct OpenListNode OpenListNode;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    47
struct OpenListNode {
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    48
	int g;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    49
	PathNode path;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    50
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    51
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    52
typedef struct AyStar AyStar;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    53
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    54
 * This function is called to check if the end-tile is found
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    55
 *  return values can be:
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    56
 *	AYSTAR_FOUND_END_NODE : indicates this is the end tile
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    57
 *	AYSTAR_DONE : indicates this is not the end tile (or direction was wrong)
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    58
 */
1617
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    59
/*
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    60
 * The 2nd parameter should be OpenListNode, and NOT AyStarNode. AyStarNode is
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    61
 * part of OpenListNode and so it could be accessed without any problems.
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    62
 * The good part about OpenListNode is, and how AIs use it, that you can
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    63
 * access the parent of the current node, and so check if you, for example
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    64
 * don't try to enter the file tile with a 90-degree curve. So please, leave
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    65
 * this an OpenListNode, it works just fine -- TrueLight
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    66
 */
55878ca5ada9 (svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
truelight
parents: 1459
diff changeset
    67
typedef int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current);
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    68
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    69
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    70
 * This function is called to calculate the G-value for AyStar Algorithm.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    71
 *  return values can be:
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    72
 *	AYSTAR_INVALID_NODE : indicates an item is not valid (e.g.: unwalkable)
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    73
 *	Any value >= 0 : the g-value for this tile
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    74
 */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    75
typedef int32 AyStar_CalculateG(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    76
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    77
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    78
 * This function is called to calculate the H-value for AyStar Algorithm.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    79
 *  Mostly, this must result the distance (Manhattan way) between the
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    80
 *   current point and the end point
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    81
 *  return values can be:
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    82
 *	Any value >= 0 : the h-value for this tile
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    83
 */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    84
typedef int32 AyStar_CalculateH(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    85
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    86
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    87
 * This function request the tiles around the current tile and put them in tiles_around
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    88
 *  tiles_around is never resetted, so if you are not using directions, just leave it alone.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    89
 * Warning: never add more tiles_around than memory allocated for it.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    90
 */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    91
typedef void AyStar_GetNeighbours(AyStar *aystar, OpenListNode *current);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    92
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    93
/*
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    94
 * If the End Node is found, this function is called.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    95
 *  It can do, for example, calculate the route and put that in an array
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    96
 */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    97
typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
    98
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
    99
/*
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
   100
 * Is called when aystar ends it pathfinding, but before cleanup.
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
   101
 */
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
   102
typedef void AyStar_BeforeExit(AyStar *aystar);
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
   103
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   104
// For internal use, see aystar.c
1777
d328484bd6f2 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1617
diff changeset
   105
typedef void AyStar_AddStartNode(AyStar *aystar, AyStarNode* start_node, uint g);
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   106
typedef int AyStar_Main(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   107
typedef int AyStar_Loop(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   108
typedef int AyStar_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   109
typedef void AyStar_Free(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   110
typedef void AyStar_Clear(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   111
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   112
struct AyStar {
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   113
/* These fields should be filled before initting the AyStar, but not changed
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   114
 * afterwards (except for user_data and user_path)! (free and init again to change them) */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   115
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   116
	/* These should point to the application specific routines that do the
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   117
	 * actual work */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   118
	AyStar_CalculateG* CalculateG;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   119
	AyStar_CalculateH* CalculateH;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   120
	AyStar_GetNeighbours* GetNeighbours;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   121
	AyStar_EndNodeCheck* EndNodeCheck;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   122
	AyStar_FoundEndNode* FoundEndNode;
2008
c9d6585c96c8 (svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents: 1977
diff changeset
   123
	AyStar_BeforeExit* BeforeExit;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   124
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   125
	/* These are completely untouched by AyStar, they can be accesed by
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   126
	 * the application specific routines to input and output data.
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   127
	 * user_path should typically contain data about the resulting path
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   128
	 * afterwards, user_target should typically contain information about
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   129
	 * what where looking for, and user_data can contain just about
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   130
	 * everything */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   131
	void *user_path;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   132
	void *user_target;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   133
	uint user_data[10];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   134
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   135
	/* How many loops are there called before AyStarMain_Main gives
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   136
	 * control back to the caller. 0 = until done */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   137
	byte loops_per_tick;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   138
	/* If the g-value goes over this number, it stops searching
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   139
	 *  0 = infinite */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   140
	uint max_path_cost;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   141
	/* The maximum amount of nodes that will be expanded, 0 = infinite */
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   142
	uint max_search_nodes;
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   143
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   144
	/* These should be filled with the neighbours of a tile by
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   145
	 * GetNeighbours */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   146
	AyStarNode neighbours[12];
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   147
	byte num_neighbours;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   148
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   149
	/* These will contain the methods for manipulating the AyStar. Only
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   150
	 * main() should be called externally */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   151
	AyStar_AddStartNode* addstart;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   152
	AyStar_Main* main;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   153
	AyStar_Loop* loop;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   154
	AyStar_Free* free;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   155
	AyStar_Clear* clear;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   156
	AyStar_CheckTile* checktile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   157
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   158
	/* These will contain the open and closed lists */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   159
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   160
	/* The actual closed list */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   161
	Hash ClosedListHash;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   162
	/* The open queue */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   163
	Queue OpenListQueue;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   164
	/* An extra hash to speed up the process of looking up an element in
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   165
	 * the open list */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   166
	Hash OpenListHash;
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   167
};
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   168
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   169
1777
d328484bd6f2 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1617
diff changeset
   170
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node, uint g);
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   171
int AyStarMain_Main(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   172
int AyStarMain_Loop(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   173
int AyStarMain_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   174
void AyStarMain_Free(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   175
void AyStarMain_Clear(AyStar *aystar);
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   176
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   177
/* Initialize an AyStar. You should fill all appropriate fields before
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   178
 * callling init_AyStar (see the declaration of AyStar for which fields are
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   179
 * internal */
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   180
void init_AyStar(AyStar* aystar, Hash_HashProc hash, uint num_buckets);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 84
diff changeset
   181
84
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   182
1e0721c29bad (svn r85) -Add: initial commit of new AI (enable in Patch menu)
truelight
parents:
diff changeset
   183
#endif