OpenTTD Source  20241120-master-g6d3adc6169
yapf.h File Reference

Entry point for OpenTTD to YAPF. More...

#include "../../direction_type.h"
#include "../../track_type.h"
#include "../../vehicle_type.h"
#include "../../ship.h"
#include "../../roadveh.h"
#include "../pathfinder_type.h"

Go to the source code of this file.

Functions

Track YapfShipChooseTrack (const Ship *v, TileIndex tile, bool &path_found, ShipPathCache &path_cache)
 Finds the best path for given ship using YAPF. More...
 
bool YapfShipCheckReverse (const Ship *v, Trackdir *trackdir)
 Returns true if it is better to reverse the ship before leaving depot using YAPF. More...
 
Trackdir YapfRoadVehicleChooseTrack (const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs, bool &path_found, RoadVehPathCache &path_cache)
 Finds the best path for given road vehicle using YAPF. More...
 
Track YapfTrainChooseTrack (const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, struct PBSTileInfo *target, TileIndex *dest)
 Finds the best path for given train using YAPF. More...
 
FindDepotData YapfRoadVehicleFindNearestDepot (const RoadVehicle *v, int max_penalty)
 Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF. More...
 
FindDepotData YapfTrainFindNearestDepot (const Train *v, int max_distance)
 Used when user sends train to the nearest depot or if train needs servicing using YAPF. More...
 
bool YapfTrainCheckReverse (const Train *v)
 Returns true if it is better to reverse the train before leaving station using YAPF. More...
 
bool YapfTrainFindNearestSafeTile (const Train *v, TileIndex tile, Trackdir td, bool override_railtype)
 Try to extend the reserved path of a train to the nearest safe tile using YAPF. More...
 

Detailed Description

Entry point for OpenTTD to YAPF.

Definition in file yapf.h.

Function Documentation

◆ YapfRoadVehicleChooseTrack()

Trackdir YapfRoadVehicleChooseTrack ( const RoadVehicle v,
TileIndex  tile,
DiagDirection  enterdir,
TrackdirBits  trackdirs,
bool &  path_found,
RoadVehPathCache &  path_cache 
)

Finds the best path for given road vehicle using YAPF.

Parameters
vthe RV that needs to find a path
tilethe tile to find the path from (should be next tile the RV is about to enter)
enterdirdiagonal direction which the RV will enter this new tile from
trackdirsavailable trackdirs on the new tile (to choose from)
path_found[out] Whether a path has been found (true) or has been guessed (false)
Returns
the best trackdir for next turn or INVALID_TRACKDIR if the path could not be found

Definition at line 529 of file yapf_road.cpp.

References _settings_game, YAPFSettings::disable_node_optimization, FindFirstBit(), INVALID_TRACKDIR, GameSettings::pf, and PathfinderSettings::yapf.

◆ YapfRoadVehicleFindNearestDepot()

FindDepotData YapfRoadVehicleFindNearestDepot ( const RoadVehicle v,
int  max_penalty 
)

Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using YAPF.

Parameters
vvehicle that needs to go to some depot
max_penaltymax distance (in pathfinder penalty) from the current vehicle position (used also as optimization - the pathfinder can stop path finding if max_penalty was reached and no depot was seen)
Returns
the data about the depot

Definition at line 538 of file yapf_road.cpp.

References GetTrackdirBitsForRoad(), RoadVehicle::GetVehicleTrackdir(), HasTrackdir(), and Vehicle::tile.

◆ YapfShipCheckReverse()

bool YapfShipCheckReverse ( const Ship v,
Trackdir trackdir 
)

Returns true if it is better to reverse the ship before leaving depot using YAPF.

Parameters
vthe ship leaving the depot
trackdir[out] the best of all possible reversed trackdirs
Returns
true if reversing is better

Definition at line 437 of file yapf_ship.cpp.

◆ YapfShipChooseTrack()

Track YapfShipChooseTrack ( const Ship v,
TileIndex  tile,
bool &  path_found,
ShipPathCache &  path_cache 
)

Finds the best path for given ship using YAPF.

Parameters
vthe ship that needs to find a path
tilethe tile to find the path from (should be next tile the ship is about to enter)
path_found[out] Whether a path has been found (true) or has been guessed (false)
Returns
the best trackdir for next turn or INVALID_TRACK if the path could not be found

Finds the best path for given ship using YAPF.

Definition at line 429 of file yapf_ship.cpp.

References ChooseShipTrack(), Ship::GetVehicleTrackdir(), INVALID_TRACK, INVALID_TRACKDIR, TRACKDIR_BIT_NONE, TrackdirToTrack(), and TrackdirToTrackdirBits().

Referenced by ChooseShipTrack().

◆ YapfTrainCheckReverse()

bool YapfTrainCheckReverse ( const Train v)

Returns true if it is better to reverse the train before leaving station using YAPF.

Parameters
vthe train leaving the station
Returns
true if reversing is better

Definition at line 559 of file yapf_rail.cpp.

References _settings_game, DistanceManhattan(), PathfinderSettings::forbid_90_deg, GetOtherTunnelBridgeEnd(), GetTunnelBridgeDirection(), Train::GetVehicleTrackdir(), SpecializedVehicle< T, Type >::Last(), GameSettings::pf, ReverseTrackdir(), Vehicle::tile, TileVirtXY(), TRACK_BIT_WORMHOLE, TrackdirToExitdir(), Vehicle::x_pos, Vehicle::y_pos, and YAPF_TILE_LENGTH.

◆ YapfTrainChooseTrack()

Track YapfTrainChooseTrack ( const Train v,
TileIndex  tile,
DiagDirection  enterdir,
TrackBits  tracks,
bool &  path_found,
bool  reserve_track,
struct PBSTileInfo target,
TileIndex dest 
)

Finds the best path for given train using YAPF.

Parameters
vthe train that needs to find a path
tilethe tile to find the path from (should be next tile the train is about to enter)
enterdirdiagonal direction which the RV will enter this new tile from
tracksavailable trackdirs on the new tile (to choose from)
path_found[out] Whether a path has been found (true) or has been guessed (false)
reserve_trackindicates whether YAPF should try to reserve the found path
target[out] the target tile of the reservation, free is set to true if path was reserved
dest[out] the final tile of the best path found
Returns
the best track for next turn

Definition at line 550 of file yapf_rail.cpp.

References _settings_game, FindFirstTrack(), PathfinderSettings::forbid_90_deg, INVALID_TRACKDIR, GameSettings::pf, and TrackdirToTrack().

Referenced by DoTrainPathfind().

◆ YapfTrainFindNearestDepot()

FindDepotData YapfTrainFindNearestDepot ( const Train v,
int  max_distance 
)

Used when user sends train to the nearest depot or if train needs servicing using YAPF.

Parameters
vtrain that needs to go to some depot
max_distancemax distance (int pathfinder penalty) from the current train position (used also as optimization - the pathfinder can stop path finding if max_penalty was reached and no depot was seen)
Returns
the data about the depot

Definition at line 612 of file yapf_rail.cpp.

References _settings_game, FollowTrainReservation(), PathfinderSettings::forbid_90_deg, Train::GetVehicleTrackdir(), SpecializedVehicle< T, Type >::Last(), GameSettings::pf, ReverseTrackdir(), PBSTileInfo::tile, Vehicle::tile, PBSTileInfo::trackdir, and YAPF_INFINITE_PENALTY.

Referenced by FindClosestTrainDepot().

◆ YapfTrainFindNearestSafeTile()

bool YapfTrainFindNearestSafeTile ( const Train v,
TileIndex  tile,
Trackdir  td,
bool  override_railtype 
)

Try to extend the reserved path of a train to the nearest safe tile using YAPF.

Parameters
vThe train that needs to find a safe tile.
tileLast tile of the current reserved path.
tdLast trackdir of the current reserved path.
override_railtypeShould all physically compatible railtypes be searched, even if the vehicle can't run on them on its own?
Returns
True if the path could be extended to a safe tile.

Definition at line 625 of file yapf_rail.cpp.

References _settings_game, PathfinderSettings::forbid_90_deg, and GameSettings::pf.

Referenced by TryReserveSafeTrack().