2006-05-27 18:12:16 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file yapf.h Entry point for OpenTTD to YAPF. */
|
2007-02-23 09:37:33 +01:00
|
|
|
|
2006-05-27 18:12:16 +02:00
|
|
|
#ifndef YAPF_H
|
|
|
|
#define YAPF_H
|
|
|
|
|
2009-12-01 23:45:39 +01:00
|
|
|
#include "../../direction_type.h"
|
|
|
|
#include "../../station_type.h"
|
2009-12-02 10:57:17 +01:00
|
|
|
#include "../pathfinder_type.h"
|
2006-05-27 18:12:16 +02:00
|
|
|
|
2009-12-02 01:01:07 +01:00
|
|
|
/**
|
|
|
|
* Finds the best path for given ship using YAPF.
|
2006-09-04 22:40:33 +02: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)
|
2009-12-02 00:56:04 +01:00
|
|
|
* @return the best trackdir for next turn or INVALID_TRACK if the path could not be found
|
2006-08-30 23:10:25 +02:00
|
|
|
*/
|
2009-12-02 10:31:38 +01:00
|
|
|
Track YapfChooseShipTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks);
|
2006-08-30 23:10:25 +02:00
|
|
|
|
|
|
|
/** Finds the best path for given road vehicle.
|
2006-09-04 22:40:33 +02: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
|
|
|
|
*/
|
2009-12-02 11:13:49 +01:00
|
|
|
Trackdir YapfChooseRoadTrack(const RoadVehicle *v, TileIndex tile, DiagDirection enterdir);
|
2006-08-30 23:10:25 +02:00
|
|
|
|
2009-12-02 10:57:17 +01:00
|
|
|
/**
|
|
|
|
* Finds the best path for given train using YAPF.
|
2006-09-04 22:40:33 +02: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 02:41:09 +02: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-03 00:50:52 +02: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
|
2009-12-02 10:57:17 +01:00
|
|
|
* @return the best track for next turn
|
2006-09-04 22:40:33 +02:00
|
|
|
*/
|
2009-12-02 10:57:17 +01:00
|
|
|
Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, struct PBSTileInfo *target);
|
2006-05-27 18:12:16 +02:00
|
|
|
|
2006-08-30 23:10:25 +02:00
|
|
|
/** Used by RV multistop feature to find the nearest road stop that has a free slot.
|
2006-09-04 22:40:33 +02: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-12-02 11:13:49 +01:00
|
|
|
uint YapfRoadVehDistanceToTile(const RoadVehicle *v, TileIndex tile);
|
2006-05-30 12:53:27 +02:00
|
|
|
|
2009-09-09 23:01:45 +02:00
|
|
|
/** Used to determinine the closest reachable compatible road stop for a given vehicle.
|
|
|
|
* @param v vehicle that needs to go to the road stop
|
|
|
|
* @param station the station the road stop must belong to
|
|
|
|
* @param stop_tile receives the stop tile if a stop was found
|
|
|
|
* @return true if stop was found.
|
|
|
|
*/
|
|
|
|
bool YapfFindNearestRoadVehicleCompatibleStop(const RoadVehicle *v, StationID station, TileIndex *stop_tile);
|
|
|
|
|
2009-08-31 21:16:18 +02:00
|
|
|
/** Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing.
|
|
|
|
* @param v vehicle that needs to go to some depot
|
|
|
|
* @param max_distance max distance (number of track tiles) from the current vehicle position
|
|
|
|
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
|
|
|
* was reached and no depot was seen)
|
|
|
|
* @param depot_tile receives the depot tile if depot was found
|
|
|
|
* @return true if depot was found.
|
2006-09-04 22:40:33 +02:00
|
|
|
*/
|
2009-12-02 11:13:49 +01:00
|
|
|
bool YapfFindNearestRoadDepot(const RoadVehicle *v, int max_distance, TileIndex *depot_tile);
|
2006-08-30 23:10:25 +02:00
|
|
|
|
2009-12-02 10:57:17 +01:00
|
|
|
/**
|
|
|
|
* Used when user sends train to the nearest depot or if train needs servicing using YAPF.
|
2007-04-18 02:41:09 +02: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
|
2009-08-31 21:16:18 +02:00
|
|
|
* (used also as optimization - the pathfinder can stop path finding if max_distance
|
|
|
|
* was reached and no depot was seen)
|
2009-12-02 10:57:17 +01:00
|
|
|
* @return the data about the depot
|
2006-09-04 22:40:33 +02:00
|
|
|
*/
|
2009-12-02 10:57:17 +01:00
|
|
|
FindDepotData YapfTrainFindNearestDepot(const Train *v, int max_distance);
|
2006-05-27 18:12:16 +02:00
|
|
|
|
2009-12-02 10:57:17 +01:00
|
|
|
/**
|
|
|
|
* Returns true if it is better to reverse the train before leaving station using YAPF.
|
|
|
|
* @param v the train leaving the station
|
|
|
|
* @return true if reversing is better
|
|
|
|
*/
|
|
|
|
bool YapfTrainCheckReverse(const Train *v);
|
2006-05-27 18:12:16 +02:00
|
|
|
|
2008-08-03 00:51:53 +02:00
|
|
|
/**
|
2009-12-02 10:57:17 +01:00
|
|
|
* Try to extend the reserved path of a train to the nearest safe tile using YAPF.
|
2008-08-03 00:51:53 +02:00
|
|
|
*
|
|
|
|
* @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.
|
2009-12-02 10:57:17 +01:00
|
|
|
* @param override_railtype Should all physically compatible railtypes be searched, even if the vehicle can't run on them on its own?
|
2008-08-03 00:51:53 +02:00
|
|
|
* @return True if the path could be extended to a safe tile.
|
|
|
|
*/
|
2009-12-02 10:57:17 +01:00
|
|
|
bool YapfTrainFindNearestSafeTile(const Train *v, TileIndex tile, Trackdir td, bool override_railtype);
|
2008-08-03 00:51:53 +02:00
|
|
|
|
2006-08-30 23:10:25 +02:00
|
|
|
/** Use this function to notify YAPF that track layout (or signal configuration) has change */
|
2006-05-27 18:12:16 +02:00
|
|
|
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track);
|
|
|
|
|
2006-08-30 23:10:25 +02:00
|
|
|
/** performance measurement helpers */
|
2009-01-10 01:31:47 +01:00
|
|
|
void *NpfBeginInterval();
|
2008-06-02 08:44:06 +02:00
|
|
|
int NpfEndInterval(void *perf);
|
2006-05-27 18:12:16 +02:00
|
|
|
|
2006-08-30 23:10:25 +02:00
|
|
|
|
2006-05-27 18:12:16 +02:00
|
|
|
extern int _aystar_stats_open_size;
|
|
|
|
extern int _aystar_stats_closed_size;
|
|
|
|
|
|
|
|
|
2006-08-30 23:10:25 +02:00
|
|
|
/** Base tile length units */
|
2006-05-27 18:12:16 +02:00
|
|
|
enum {
|
|
|
|
YAPF_TILE_LENGTH = 100,
|
2009-12-02 10:57:17 +01:00
|
|
|
YAPF_TILE_CORNER_LENGTH = 71,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This penalty is the equivalent of "infite", which means that paths that
|
|
|
|
* get this penalty will be chosen, but only if there is no other route
|
|
|
|
* without it. Be careful with not applying this penalty to often, or the
|
|
|
|
* total path cost might overflow..
|
|
|
|
* For now, this is just a Very Big Penalty, we might actually implement
|
|
|
|
* this in a nicer way :-)
|
|
|
|
*/
|
|
|
|
YAPF_INFINITE_PENALTY = 1000 * YAPF_TILE_LENGTH,
|
2006-05-27 18:12:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* YAPF_H */
|