KUDr@3900: /* $Id$ */ KUDr@3900: KUDr@3900: #ifndef YAPF_H KUDr@3900: #define YAPF_H KUDr@3900: KUDr@3900: #include "../debug.h" KUDr@3900: KUDr@4462: /** Finds the best path for given ship. KUDr@4462: @param v - the ship that needs to find a path KUDr@4462: @param tile - the tile to find the path from (should be next tile the ship is about to enter) KUDr@4462: @param enterdir - diagonal direction which the ship will enter this new tile from KUDr@4462: @param tracks - available tracks on the new tile (to choose from) KUDr@4462: @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found KUDr@4462: */ KUDr@3900: Trackdir YapfChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); KUDr@4462: KUDr@4462: /** Finds the best path for given road vehicle. KUDr@4462: @param v - the RV that needs to find a path KUDr@4462: @param tile - the tile to find the path from (should be next tile the RV is about to enter) KUDr@4462: @param enterdir - diagonal direction which the RV will enter this new tile from KUDr@4462: @param tracks - available tracks on the new tile (to choose from) KUDr@4462: @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found KUDr@4462: */ KUDr@3900: Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir); KUDr@4462: KUDr@4462: /** Finds the best path for given train. KUDr@4462: @param v - the train that needs to find a path KUDr@4462: @param tile - the tile to find the path from (should be next tile the train is about to enter) KUDr@4462: @param enterdir - diagonal direction which the RV will enter this new tile from KUDr@4462: @param tracks - available tracks on the new tile (to choose from) KUDr@4462: @return - the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found KUDr@4462: */ KUDr@3900: Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs); KUDr@3900: KUDr@4462: /** Used by RV multistop feature to find the nearest road stop that has a free slot. KUDr@4462: @param v - RV (its current tile will be the origin) KUDr@4462: @param tile - destination tile KUDr@4462: @return - distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found KUDr@4462: */ KUDr@3915: uint YapfRoadVehDistanceToTile(const Vehicle* v, TileIndex tile); KUDr@3915: KUDr@4462: /** Used when user sends RV to the nearest depot or if RV needs servicing. KUDr@4462: Returns the nearest depot (or NULL if depot was not found). KUDr@4462: */ KUDr@3900: Depot* YapfFindNearestRoadDepot(const Vehicle *v); KUDr@4462: KUDr@4462: /** Used when user sends train to the nearest depot or if train needs servicing. KUDr@4462: @v - train that needs to go to some depot KUDr@4462: @max_distance - max distance (number of track tiles) from the current train position KUDr@4462: (used also as optimization - the pathfinder can stop path finding if max_distance KUDr@4462: was reached and no depot was seen) KUDr@4462: @reverse_penalty - penalty that should be added for the path that requires reversing the train first KUDr@4462: @depot_tile - receives the depot tile if depot was found KUDr@4462: @reversed - receives true if train needs to reversed first KUDr@4462: @return - the true if depot was found. KUDr@4462: */ KUDr@3900: bool YapfFindNearestRailDepotTwoWay(Vehicle *v, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed); KUDr@3900: KUDr@4462: /** Returns true if it is better to reverse the train before leaving station */ KUDr@3900: bool YapfCheckReverseTrain(Vehicle* v); KUDr@3900: KUDr@4462: /** Use this function to notify YAPF that track layout (or signal configuration) has change */ KUDr@3900: void YapfNotifyTrackLayoutChange(TileIndex tile, Track track); KUDr@3900: KUDr@4462: /** performance measurement helpers */ KUDr@3900: void* NpfBeginInterval(void); KUDr@3900: int NpfEndInterval(void* perf); KUDr@3900: KUDr@4462: KUDr@3900: extern int _aystar_stats_open_size; KUDr@3900: extern int _aystar_stats_closed_size; KUDr@3900: KUDr@3900: KUDr@4462: /** Track followers. They should help whenever any new code will need to walk through KUDr@4462: tracks, road or water tiles (pathfinders, signal controllers, vehicle controllers). KUDr@4462: It is an attempt to introduce API that should simplify tasks listed above. KUDr@4462: If you will need to use it: KUDr@4462: 1. allocate/declare FollowTrack_t structure; KUDr@4462: 2. call FollowTrackInit() and provide vehicle (if relevant) KUDr@4462: 3. call one of 6 FollowTrackXxxx() APIs below KUDr@4462: 4. check return value (if true then continue else stop) KUDr@4462: 5. look at FollowTrack_t structure for the result KUDr@4462: 6. optionally repeat steps 3..5 KUDr@4462: 7. in case of troubles contact KUDr KUDr@4462: */ KUDr@4462: KUDr@3900: /** Base struct for track followers. */ KUDr@3900: typedef struct FollowTrack_t KUDr@3900: { KUDr@4462: const Vehicle* m_veh; ///< moving vehicle KUDr@4462: TileIndex m_old_tile; ///< the origin (vehicle moved from) before move KUDr@4462: Trackdir m_old_td; ///< the trackdir (the vehicle was on) before move KUDr@4462: TileIndex m_new_tile; ///< the new tile (the vehicle has entered) KUDr@4462: TrackdirBits m_new_td_bits; ///< the new set of available trackdirs KUDr@4462: DiagDirection m_exitdir; ///< exit direction (leaving the old tile) KUDr@4462: bool m_is_tunnel; ///< last turn passed tunnel KUDr@4462: bool m_is_station; ///< last turn passed station KUDr@4462: int m_tiles_skipped; ///< number of skipped tunnel or station tiles KUDr@3900: } FollowTrack_t; KUDr@3900: KUDr@4462: /** Initializes FollowTrack_t structure */ KUDr@4462: void FollowTrackInit(FollowTrack_t *This, const Vehicle* v); KUDr@4462: KUDr@4462: /** Main track follower routines */ KUDr@3900: bool FollowTrackWater (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: bool FollowTrackRoad (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: bool FollowTrackRail (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: bool FollowTrackWaterNo90(FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: bool FollowTrackRoadNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: bool FollowTrackRailNo90 (FollowTrack_t *This, TileIndex old_tile, Trackdir old_td); KUDr@3900: KUDr@4462: /** Base tile length units */ KUDr@3900: enum { KUDr@3900: YAPF_TILE_LENGTH = 100, KUDr@3900: YAPF_TILE_CORNER_LENGTH = 71 KUDr@3900: }; KUDr@3900: KUDr@3900: #endif /* YAPF_H */