3 #ifndef YAPF_H |
3 #ifndef YAPF_H |
4 #define YAPF_H |
4 #define YAPF_H |
5 |
5 |
6 #include "../debug.h" |
6 #include "../debug.h" |
7 |
7 |
|
8 /** Finds the best path for given ship. |
|
9 @param v - the ship that needs to find a path |
|
10 @param tile - the tile to find the path from (should be next tile the ship is about to enter) |
|
11 @param enterdir - diagonal direction which the ship will enter this new tile from |
|
12 @param tracks - available tracks on the new tile (to choose from) |
|
13 @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found |
|
14 */ |
8 Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); |
15 Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); |
|
16 |
|
17 /** Finds the best path for given road vehicle. |
|
18 @param v - the RV that needs to find a path |
|
19 @param tile - the tile to find the path from (should be next tile the RV is about to enter) |
|
20 @param enterdir - diagonal direction which the RV will enter this new tile from |
|
21 @param tracks - available tracks on the new tile (to choose from) |
|
22 @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found |
|
23 */ |
9 Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir); |
24 Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir); |
|
25 |
|
26 /** Finds the best path for given train. |
|
27 @param v - the train that needs to find a path |
|
28 @param tile - the tile to find the path from (should be next tile the train is about to enter) |
|
29 @param enterdir - diagonal direction which the RV will enter this new tile from |
|
30 @param tracks - available tracks on the new tile (to choose from) |
|
31 @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found |
|
32 */ |
10 Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs); |
33 Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs); |
11 |
34 |
|
35 /** Used by RV multistop feature to find the nearest road stop that has a free slot. |
|
36 @param v - RV (its current tile will be the origin) |
|
37 @param tile - destination tile |
|
38 @return - distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found |
|
39 */ |
12 uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile); |
40 uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile); |
13 |
41 |
|
42 /** Used when user sends RV to the nearest depot or if RV needs servicing. |
|
43 Returns the nearest depot (or NULL if depot was not found). |
|
44 */ |
14 Depot* YapfFindNearestRoadDepot(const Vehicle *v); |
45 Depot* YapfFindNearestRoadDepot(const Vehicle *v); |
|
46 |
|
47 /** Used when user sends train to the nearest depot or if train needs servicing. |
|
48 @v - train that needs to go to some depot |
|
49 @max_distance - max distance (number of track tiles) from the current train position |
|
50 (used also as optimization - the pathfinder can stop path finding if max_distance |
|
51 was reached and no depot was seen) |
|
52 @reverse_penalty - penalty that should be added for the path that requires reversing the train first |
|
53 @depot_tile - receives the depot tile if depot was found |
|
54 @reversed - receives true if train needs to reversed first |
|
55 @return - the true if depot was found. |
|
56 */ |
15 bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed); |
57 bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed); |
16 |
58 |
|
59 /** Returns true if it is better to reverse the train before leaving station */ |
17 bool YapfCheckReverseTrain(Vehicle* v); |
60 bool YapfCheckReverseTrain(Vehicle* v); |
18 |
61 |
|
62 /** Use this function to notify YAPF that track layout (or signal configuration) has change */ |
19 void YapfNotifyTrackLayoutChange(TileIndex tile, Track track); |
63 void YapfNotifyTrackLayoutChange(TileIndex tile, Track track); |
20 |
64 |
21 |
65 /** performance measurement helpers */ |
22 void* NpfBeginInterval(void); |
66 void* NpfBeginInterval(void); |
23 int NpfEndInterval(void* perf); |
67 int NpfEndInterval(void* perf); |
|
68 |
24 |
69 |
25 extern int _aystar_stats_open_size; |
70 extern int _aystar_stats_open_size; |
26 extern int _aystar_stats_closed_size; |
71 extern int _aystar_stats_closed_size; |
27 |
72 |
28 |
73 |
|
74 /** Track followers. They should help whenever any new code will need to walk through |
|
75 tracks, road or water tiles (pathfinders, signal controllers, vehicle controllers). |
|
76 It is an attempt to introduce API that should simplify tasks listed above. |
|
77 If you will need to use it: |
|
78 1. allocate/declare FollowTrack_t structure; |
|
79 2. call FollowTrackInit() and provide vehicle (if relevant) |
|
80 3. call one of 6 FollowTrackXxxx() APIs below |
|
81 4. check return value (if true then continue else stop) |
|
82 5. look at FollowTrack_t structure for the result |
|
83 6. optionally repeat steps 3..5 |
|
84 7. in case of troubles contact KUDr |
|
85 */ |
|
86 |
29 /** Base struct for track followers. */ |
87 /** Base struct for track followers. */ |
30 typedef struct FollowTrack_t |
88 typedef struct FollowTrack_t |
31 { |
89 { |
32 const Vehicle* m_veh; |
90 const Vehicle* m_veh; ///< moving vehicle |
33 TileIndex m_old_tile; |
91 TileIndex m_old_tile; ///< the origin (vehicle moved from) before move |
34 Trackdir m_old_td; |
92 Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move |
35 TileIndex m_new_tile; |
93 TileIndex m_new_tile; ///< the new tile (the vehicle has entered) |
36 TrackdirBits m_new_td_bits; |
94 TrackdirBits m_new_td_bits; ///< the new set of available trackdirs |
37 // TrackdirBits m_red_td_bits; |
95 DiagDirection m_exitdir; ///< exit direction (leaving the old tile) |
38 DiagDirection m_exitdir; |
96 bool m_is_tunnel; ///< last turn passed tunnel |
39 bool m_is_tunnel; |
97 bool m_is_station; ///< last turn passed station |
40 bool m_is_station; |
98 int m_tiles_skipped; ///< number of skipped tunnel or station tiles |
41 int m_tiles_skipped; |
|
42 } FollowTrack_t; |
99 } FollowTrack_t; |
43 |
100 |
44 /** track followers */ |
101 /** Initializes FollowTrack_t structure */ |
|
102 void FollowTrackInit(FollowTrack_t *This, const Vehicle* v); |
|
103 |
|
104 /** Main track follower routines */ |
45 bool FollowTrackWater (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
105 bool FollowTrackWater (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
46 bool FollowTrackRoad (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
106 bool FollowTrackRoad (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
47 bool FollowTrackRail (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
107 bool FollowTrackRail (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
48 bool FollowTrackWaterNo90(FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
108 bool FollowTrackWaterNo90(FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
49 bool FollowTrackRoadNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
109 bool FollowTrackRoadNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
50 bool FollowTrackRailNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
110 bool FollowTrackRailNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); |
51 |
111 |
|
112 /** Base tile length units */ |
52 enum { |
113 enum { |
53 YAPF_TILE_LENGTH = 100, |
114 YAPF_TILE_LENGTH = 100, |
54 YAPF_TILE_CORNER_LENGTH = 71 |
115 YAPF_TILE_CORNER_LENGTH = 71 |
55 }; |
116 }; |
56 |
117 |