|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef NPF_H |
|
4 #define NPF_H |
|
5 |
|
6 #include "openttd.h" |
|
7 #include "aystar.h" |
|
8 #include "station.h" |
|
9 #include "vehicle.h" |
|
10 #include "tile.h" |
|
11 |
|
12 //mowing grass |
|
13 enum { |
|
14 NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */ |
|
15 /* Do no change below values */ |
|
16 NPF_HASH_SIZE = 1 << NPF_HASH_BITS, |
|
17 NPF_HASH_HALFBITS = NPF_HASH_BITS / 2, |
|
18 NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1 |
|
19 }; |
|
20 |
|
21 /* For new pathfinding. Define here so it is globally available without having |
|
22 * to include npf.h */ |
|
23 enum { |
|
24 NPF_TILE_LENGTH = 100 |
|
25 }; |
|
26 |
|
27 enum { |
|
28 /** This penalty is the equivalent of "inifite", which means that paths that |
|
29 * get this penalty will be chosen, but only if there is no other route |
|
30 * without it. Be careful with not applying this penalty to often, or the |
|
31 * total path cost might overflow.. |
|
32 * For now, this is just a Very Big Penalty, we might actually implement |
|
33 * this in a nicer way :-) |
|
34 */ |
|
35 NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH |
|
36 }; |
|
37 |
|
38 typedef struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */ |
|
39 TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */ |
|
40 StationID station_index; /* station index we're heading for, or INVALID_STATION when we're heading for a tile */ |
|
41 } NPFFindStationOrTileData; |
|
42 |
|
43 enum { /* Indices into AyStar.userdata[] */ |
|
44 NPF_TYPE = 0, /* Contains a TransportTypes value */ |
|
45 NPF_OWNER, /* Contains an Owner value */ |
|
46 NPF_RAILTYPES, /* Contains a bitmask the compatible RailTypes of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise. */ |
|
47 }; |
|
48 |
|
49 enum { /* Indices into AyStarNode.userdata[] */ |
|
50 NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */ |
|
51 NPF_NODE_FLAGS, |
|
52 }; |
|
53 |
|
54 typedef enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */ |
|
55 NPF_FLAG_SEEN_SIGNAL, /* Used to mark that a signal was seen on the way, for rail only */ |
|
56 NPF_FLAG_REVERSE, /* Used to mark that this node was reached from the second start node, if applicable */ |
|
57 NPF_FLAG_LAST_SIGNAL_RED, /* Used to mark that the last signal on this path was red */ |
|
58 } NPFNodeFlag; |
|
59 |
|
60 typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */ |
|
61 uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */ |
|
62 uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */ |
|
63 Trackdir best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ |
|
64 AyStarNode node; /* The node within the target the search led us to */ |
|
65 } NPFFoundTargetData; |
|
66 |
|
67 /* These functions below are _not_ re-entrant, in favor of speed! */ |
|
68 |
|
69 /* Will search from the given tile and direction, for a route to the given |
|
70 * station for the given transport type. See the declaration of |
|
71 * NPFFoundTargetData above for the meaning of the result. */ |
|
72 NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes); |
|
73 |
|
74 /* Will search as above, but with two start nodes, the second being the |
|
75 * reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which |
|
76 * direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */ |
|
77 NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, Trackdir trackdir1, TileIndex tile2, Trackdir trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner, RailTypeMask railtypes); |
|
78 |
|
79 /* Will search a route to the closest depot. */ |
|
80 |
|
81 /* Search using breadth first. Good for little track choice and inaccurate |
|
82 * heuristic, such as railway/road.*/ |
|
83 NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner, RailTypeMask railtypes); |
|
84 /* Same as above but with two start nodes, the second being the reverse. Call |
|
85 * NPFGetBit(result.node, NPF_FLAG_REVERSE) to see from which node the path |
|
86 * orginated. All pathfs from the second node will have the given |
|
87 * reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full |
|
88 * tile). |
|
89 */ |
|
90 NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, TileIndex tile2, Trackdir trackdir2, TransportType type, Owner owner, RailTypeMask railtypes, uint reverse_penalty); |
|
91 /* Search by trying each depot in order of Manhattan Distance. Good for lots |
|
92 * of choices and accurate heuristics, such as water. */ |
|
93 NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner, RailTypeMask railtypes); |
|
94 |
|
95 void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v); |
|
96 |
|
97 |
|
98 /* |
|
99 * Functions to manipulate the various NPF related flags on an AyStarNode. |
|
100 */ |
|
101 |
|
102 /** |
|
103 * Returns the current value of the given flag on the given AyStarNode. |
|
104 */ |
|
105 static inline bool NPFGetFlag(const AyStarNode* node, NPFNodeFlag flag) |
|
106 { |
|
107 return HASBIT(node->user_data[NPF_NODE_FLAGS], flag); |
|
108 } |
|
109 |
|
110 /** |
|
111 * Sets the given flag on the given AyStarNode to the given value. |
|
112 */ |
|
113 static inline void NPFSetFlag(AyStarNode* node, NPFNodeFlag flag, bool value) |
|
114 { |
|
115 if (value) |
|
116 SETBIT(node->user_data[NPF_NODE_FLAGS], flag); |
|
117 else |
|
118 CLRBIT(node->user_data[NPF_NODE_FLAGS], flag); |
|
119 } |
|
120 |
|
121 #endif /* NPF_H */ |