author | matthijs |
Sun, 06 Feb 2005 22:36:08 +0000 | |
changeset 1330 | 8a67d04016ce |
parent 1247 | 01711347f9ac |
child 1459 | 6c1f01803928 |
permissions | -rw-r--r-- |
1247 | 1 |
#ifndef NPF_H |
2 |
#define NPF_H |
|
3 |
||
4 |
#include "ttd.h" |
|
5 |
#include "aystar.h" |
|
6 |
#include "vehicle.h" |
|
7 |
||
8 |
//#define NPF_DEBUG |
|
9 |
//#define NPF_MARKROUTE //Mark the routes considered by the pathfinder by |
|
10 |
//mowing grass |
|
11 |
||
12 |
typedef struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */ |
|
13 |
TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */ |
|
14 |
int station_index; /* station index we're heading for, or -1 when we're heading for a tile */ |
|
15 |
} NPFFindStationOrTileData; |
|
16 |
||
17 |
enum { /* Indices into AyStar.userdata[] */ |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
18 |
NPF_TYPE = 0, /* Contains a TransportTypes value */ |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
19 |
NPF_OWNER, /* Contains an Owner value */ |
1247 | 20 |
}; |
21 |
||
22 |
enum { /* Indices into AyStarNode.userdata[] */ |
|
23 |
NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */ |
|
24 |
NPF_NODE_FLAGS, |
|
25 |
}; |
|
26 |
enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]*/ |
|
27 |
NPF_FLAG_SEEN_SIGNAL = 1, /* Used to mark that a signal was seen on the way, for rail only */ |
|
28 |
NPF_FLAG_REVERSE = 2, /* Used to mark that this node was reached from the second start node, if applicable */ |
|
29 |
}; |
|
30 |
||
31 |
typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */ |
|
32 |
uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */ |
|
33 |
uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */ |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
34 |
byte best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ |
1247 | 35 |
AyStarNode node; /* The node within the target the search led us to */ |
36 |
} NPFFoundTargetData; |
|
37 |
||
38 |
/* These functions below are _not_ re-entrant, in favor of speed! */ |
|
39 |
||
40 |
/* Will search from the given tile and direction, for a route to the given |
|
41 |
* station for the given transport type. See the declaration of |
|
42 |
* NPFFoundTargetData above for the meaning of the result. */ |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
43 |
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner); |
1247 | 44 |
/* Will search as above, but with two start nodes, the second being the |
45 |
* reverse. Look at the NPF_NODE_REVERSE flag in the result node to see which |
|
46 |
* direction was taken */ |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
47 |
NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner); |
1247 | 48 |
|
49 |
/* Will search a route to the closest depot. */ |
|
50 |
||
51 |
/* Search using breadth first. Good for little track choice and inaccurate |
|
52 |
* heuristic, such as railway/road */ |
|
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
53 |
NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type, Owner owner); |
1247 | 54 |
/* Search by trying each depot in order of Manhattan Distance. Good for lots |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
55 |
* of choices and accurate heuristics, such as water. */ |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1247
diff
changeset
|
56 |
NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type, Owner owner); |
1247 | 57 |
|
58 |
void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v); |
|
59 |
||
60 |
/* |
|
61 |
* Some tables considering tracks, directions and signals. |
|
62 |
* XXX: Better place to but these? |
|
63 |
*/ |
|
64 |
||
65 |
/** |
|
66 |
* Maps a trackdir to the bit that stores its status in the map arrays, in the |
|
67 |
* direction along with the trackdir. |
|
68 |
*/ |
|
69 |
const byte _signal_along_trackdir[14]; |
|
70 |
||
71 |
/** |
|
72 |
* Maps a trackdir to the bit that stores its status in the map arrays, in the |
|
73 |
* direction against the trackdir. |
|
74 |
*/ |
|
75 |
const byte _signal_against_trackdir[14]; |
|
76 |
||
77 |
/** |
|
78 |
* Maps a trackdir to the trackdirs that can be reached from it (ie, when |
|
79 |
* entering the next tile. |
|
80 |
*/ |
|
81 |
const uint16 _trackdir_reaches_trackdirs[14]; |
|
82 |
||
83 |
/** |
|
84 |
* Maps a trackdir to all trackdirs that make 90 deg turns with it. |
|
85 |
*/ |
|
86 |
const uint16 _trackdir_crosses_trackdirs[14]; |
|
87 |
||
88 |
/** |
|
89 |
* Maps a track to all tracks that make 90 deg turns with it. |
|
90 |
*/ |
|
91 |
const byte _track_crosses_tracks[6]; |
|
92 |
||
93 |
/** |
|
94 |
* Maps a trackdir to the (4-way) direction the tile is exited when following |
|
95 |
* that trackdir. |
|
96 |
*/ |
|
97 |
const byte _trackdir_to_exitdir[14]; |
|
98 |
||
99 |
/** |
|
100 |
* Maps a track and an (4-way) dir to the trackdir that represents the track |
|
101 |
* with the exit in the given direction. |
|
102 |
*/ |
|
103 |
const byte _track_exitdir_to_trackdir[6][4]; |
|
104 |
||
105 |
/** |
|
106 |
* Maps a track and a full (8-way) direction to the trackdir that represents |
|
107 |
* the track running in the given direction. |
|
108 |
*/ |
|
109 |
const byte _track_direction_to_trackdir[6][8]; |
|
110 |
||
111 |
/** |
|
112 |
* Maps a (4-way) direction to the diagonal track that runs in that |
|
113 |
* direction. |
|
114 |
*/ |
|
115 |
const byte _dir_to_diag_trackdir[4]; |
|
116 |
||
117 |
/** |
|
118 |
* Maps a (4-way) direction to the reverse. |
|
119 |
*/ |
|
120 |
const byte _reverse_dir[4]; |
|
121 |
||
122 |
/** |
|
123 |
* Maps a trackdir to the reverse trackdir. |
|
124 |
*/ |
|
125 |
const byte _reverse_trackdir[14]; |
|
126 |
||
127 |
#define REVERSE_TRACKDIR(trackdir) (trackdir ^ 0x8) |
|
128 |
||
129 |
#endif // NPF_H |