KUDr@3900: /* $Id$ */ KUDr@3900: celestar@6121: /** @file yapf.h */ celestar@6121: 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. rubidium@4549: * @param v the ship that needs to find a path rubidium@4549: * @param tile the tile to find the path from (should be next tile the ship is about to enter) rubidium@4549: * @param enterdir diagonal direction which the ship will enter this new tile from rubidium@4549: * @param tracks available tracks on the new tile (to choose from) rubidium@4549: * @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. rubidium@4549: * @param v the RV that needs to find a path rubidium@4549: * @param tile the tile to find the path from (should be next tile the RV is about to enter) rubidium@4549: * @param enterdir diagonal direction which the RV will enter this new tile from rubidium@4549: * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found rubidium@4549: */ KUDr@3900: Trackdir YapfChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir); KUDr@4462: KUDr@4462: /** Finds the best path for given train. rubidium@4549: * @param v the train that needs to find a path rubidium@4549: * @param tile the tile to find the path from (should be next tile the train is about to enter) rubidium@4549: * @param enterdir diagonal direction which the RV will enter this new tile from belugas@6484: * @param tracks available trackdirs on the new tile (to choose from) belugas@6484: * @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess') rubidium@4549: * @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found rubidium@4549: */ rubidium@5587: Trackdir YapfChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found); KUDr@3900: KUDr@4462: /** Used by RV multistop feature to find the nearest road stop that has a free slot. rubidium@4549: * @param v RV (its current tile will be the origin) rubidium@4549: * @param tile destination tile rubidium@4549: * @return distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found rubidium@4549: */ 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. rubidium@4549: * Returns the nearest depot (or NULL if depot was not found). rubidium@4549: */ 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. belugas@6484: * @param v train that needs to go to some depot belugas@6484: * @param max_distance max distance (number of track tiles) from the current train position rubidium@4549: * (used also as optimization - the pathfinder can stop path finding if max_distance rubidium@4549: * was reached and no depot was seen) belugas@6484: * @param reverse_penalty penalty that should be added for the path that requires reversing the train first belugas@6484: * @param depot_tile receives the depot tile if depot was found belugas@6484: * @param reversed receives true if train needs to reversed first rubidium@4549: * @return the true if depot was found. rubidium@4549: */ 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 */ rubidium@6247: void* NpfBeginInterval(); 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 rubidium@4549: * tracks, road or water tiles (pathfinders, signal controllers, vehicle controllers). rubidium@4549: * It is an attempt to introduce API that should simplify tasks listed above. rubidium@4549: * If you will need to use it: rubidium@4549: * 1. allocate/declare FollowTrack_t structure; rubidium@4549: * 2. call FollowTrackInit() and provide vehicle (if relevant) rubidium@4549: * 3. call one of 6 FollowTrackXxxx() APIs below rubidium@4549: * 4. check return value (if true then continue else stop) rubidium@4549: * 5. look at FollowTrack_t structure for the result rubidium@4549: * 6. optionally repeat steps 3..5 rubidium@4549: * 7. in case of troubles contact KUDr rubidium@4549: */ KUDr@4462: KUDr@3900: /** Base struct for track followers. */ rubidium@6248: struct FollowTrack_t KUDr@3900: { KUDr@7211: enum ErrorCode { KUDr@7211: EC_NONE, KUDr@7211: EC_OWNER, KUDr@7211: EC_RAIL_TYPE, KUDr@7211: EC_90DEG, KUDr@7211: EC_NO_WAY, KUDr@7211: }; KUDr@7211: 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 celestar@5385: bool m_is_bridge; ///< last turn passed bridge ramp KUDr@4462: bool m_is_station; ///< last turn passed station KUDr@4462: int m_tiles_skipped; ///< number of skipped tunnel or station tiles KUDr@7211: ErrorCode m_err; rubidium@6248: }; 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 */