2006-05-27 16:12:16 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file yapf.h Entry point for OpenTTD to YAPF. */
|
2007-02-23 08:37:33 +00:00
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
#ifndef YAPF_H
|
|
|
|
#define YAPF_H
|
|
|
|
|
|
|
|
#include "../debug.h"
|
2008-03-28 16:32:27 +00:00
|
|
|
#include "../depot_type.h"
|
2008-03-31 00:06:17 +00:00
|
|
|
#include "../direction_type.h"
|
2008-08-02 22:50:52 +00:00
|
|
|
#include "../pbs.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Finds the best path for given ship.
|
2006-09-04 20:40:33 +00:00
|
|
|
* @param v the ship that needs to find a path
|
|
|
|
* @param tile the tile to find the path from (should be next tile the ship is about to enter)
|
|
|
|
* @param enterdir diagonal direction which the ship will enter this new tile from
|
|
|
|
* @param tracks available tracks on the new tile (to choose from)
|
|
|
|
* @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
|
2006-08-30 21:10:25 +00:00
|
|
|
*/
|
2008-06-02 06:44:06 +00:00
|
|
|
Trackdir YapfChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
|
2006-08-30 21:10:25 +00:00
|
|
|
|
|
|
|
/** Finds the best path for given road vehicle.
|
2006-09-04 20:40:33 +00:00
|
|
|
* @param v the RV that needs to find a path
|
|
|
|
* @param tile the tile to find the path from (should be next tile the RV is about to enter)
|
|
|
|
* @param enterdir diagonal direction which the RV will enter this new tile from
|
|
|
|
* @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
|
|
|
|
*/
|
2008-06-02 06:44:06 +00:00
|
|
|
Trackdir YapfChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir);
|
2006-08-30 21:10:25 +00:00
|
|
|
|
|
|
|
/** Finds the best path for given train.
|
2006-09-04 20:40:33 +00:00
|
|
|
* @param v the train that needs to find a path
|
|
|
|
* @param tile the tile to find the path from (should be next tile the train is about to enter)
|
|
|
|
* @param enterdir diagonal direction which the RV will enter this new tile from
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param tracks available trackdirs on the new tile (to choose from)
|
|
|
|
* @param path_not_found [out] true is returned if no path can be found (returned Trackdir is only a 'guess')
|
2008-08-02 22:50:52 +00:00
|
|
|
* @param reserve_track indicates whether YAPF should try to reserve the found path
|
|
|
|
* @param target [out] the target tile of the reservation, free is set to true if path was reserved
|
2006-09-04 20:40:33 +00:00
|
|
|
* @return the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found
|
|
|
|
*/
|
2008-08-02 22:50:52 +00:00
|
|
|
Trackdir YapfChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Used by RV multistop feature to find the nearest road stop that has a free slot.
|
2006-09-04 20:40:33 +00:00
|
|
|
* @param v RV (its current tile will be the origin)
|
|
|
|
* @param tile destination tile
|
|
|
|
* @return distance from origin tile to the destination (number of road tiles) or UINT_MAX if path not found
|
|
|
|
*/
|
2009-01-10 00:31:47 +00:00
|
|
|
uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile);
|
2006-05-30 10:53:27 +00:00
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Used when user sends RV to the nearest depot or if RV needs servicing.
|
2006-09-04 20:40:33 +00:00
|
|
|
* Returns the nearest depot (or NULL if depot was not found).
|
|
|
|
*/
|
2009-01-10 00:31:47 +00:00
|
|
|
Depot *YapfFindNearestRoadDepot(const Vehicle *v);
|
2006-08-30 21:10:25 +00:00
|
|
|
|
|
|
|
/** Used when user sends train to the nearest depot or if train needs servicing.
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param v train that needs to go to some depot
|
|
|
|
* @param max_distance max distance (number of track tiles) from the current train position
|
2006-09-04 20:40:33 +00:00
|
|
|
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
|
|
|
* was reached and no depot was seen)
|
2007-04-18 00:41:09 +00:00
|
|
|
* @param reverse_penalty penalty that should be added for the path that requires reversing the train first
|
|
|
|
* @param depot_tile receives the depot tile if depot was found
|
|
|
|
* @param reversed receives true if train needs to reversed first
|
2006-09-04 20:40:33 +00:00
|
|
|
* @return the true if depot was found.
|
|
|
|
*/
|
2008-06-02 06:44:06 +00:00
|
|
|
bool YapfFindNearestRailDepotTwoWay(const Vehicle *v, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Returns true if it is better to reverse the train before leaving station */
|
2009-01-10 00:31:47 +00:00
|
|
|
bool YapfCheckReverseTrain(const Vehicle *v);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2008-08-02 22:51:53 +00:00
|
|
|
/**
|
|
|
|
* Try to extend the reserved path of a train to the nearest safe tile.
|
|
|
|
*
|
|
|
|
* @param v The train that needs to find a safe tile.
|
|
|
|
* @param tile Last tile of the current reserved path.
|
|
|
|
* @param td Last trackdir of the current reserved path.
|
|
|
|
* @param override_railtype Should all physically compabtible railtypes be searched, even if the vehicle can't on them on it own?
|
|
|
|
* @return True if the path could be extended to a safe tile.
|
|
|
|
*/
|
|
|
|
bool YapfRailFindNearestSafeTile(const Vehicle *v, TileIndex tile, Trackdir td, bool override_railtype);
|
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Use this function to notify YAPF that track layout (or signal configuration) has change */
|
2006-05-27 16:12:16 +00:00
|
|
|
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track);
|
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** performance measurement helpers */
|
2009-01-10 00:31:47 +00:00
|
|
|
void *NpfBeginInterval();
|
2008-06-02 06:44:06 +00:00
|
|
|
int NpfEndInterval(void *perf);
|
2006-05-27 16:12:16 +00:00
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
extern int _aystar_stats_open_size;
|
|
|
|
extern int _aystar_stats_closed_size;
|
|
|
|
|
|
|
|
|
2006-08-30 21:10:25 +00:00
|
|
|
/** Base tile length units */
|
2006-05-27 16:12:16 +00:00
|
|
|
enum {
|
|
|
|
YAPF_TILE_LENGTH = 100,
|
|
|
|
YAPF_TILE_CORNER_LENGTH = 71
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* YAPF_H */
|