OpenTTD Source: src/pathfinder/yapf/yapf_rail.cpp File Reference

OpenTTD Source 14.0-beta1

Data Structures | Functions
yapf_rail.cpp File Reference
`#include "../../stdafx.h"`
`#include "yapf.hpp"`
`#include "yapf_cache.h"`
`#include "yapf_node_rail.hpp"`
`#include "yapf_costrail.hpp"`
`#include "yapf_destrail.hpp"`
`#include "../../viewport_func.h"`
`#include "../../newgrf_station.h"`
`#include "../../safeguards.h"`

Go to the source code of this file.

## Data Structures
class | CYapfReserveTrack< Types >
class | CYapfFollowAnyDepotRailT< Types >
class | CYapfFollowAnySafeTileRailT< Types >
class | CYapfFollowRailT< Types >
struct | CYapfRail_TypesT< Tpf_, Ttrack_follower, Tnode_list, TdestinationT, TfollowT >
struct | CYapfRail1
struct | CYapfRail2
struct | CYapfAnyDepotRail1
struct | CYapfAnyDepotRail2
struct | CYapfAnySafeTileRail1
struct | CYapfAnySafeTileRail2

## Functions
template<typename Tpf >
void | DumpState (Tpf &pf1, Tpf &pf2)
Track | YapfTrainChooseTrack (const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target, TileIndex *dest)
| Finds the best path for given train using YAPF. More...
bool | YapfTrainCheckReverse (const Train *v)
| Returns true if it is better to reverse the train before leaving station using YAPF. More...
FindDepotData | YapfTrainFindNearestDepot (const Train *v, int max_penalty)
| Used when user sends train to the nearest depot or if train needs servicing 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...
void | YapfNotifyTrackLayoutChange (TileIndex tile, Track track)
| Use this function to notify YAPF that track layout (or signal configuration) has change. More...

## Detailed Description

The rail pathfinding.

Definition in file yapf_rail.cpp.

## Function Documentation

## ◆ YapfNotifyTrackLayoutChange()

void YapfNotifyTrackLayoutChange | ( | TileIndex | tile,
|  | Track | track
| ) |  |

Use this function to notify YAPF that track layout (or signal configuration) has change.

Parameters

  tile | the tile that is changed
  track | what piece of track is changed

Definition at line 644 of file yapf_rail.cpp.

Referenced by CmdConvertRail(), and CYapfReserveTrack< Types >::TryReservePath().

## ◆ YapfTrainCheckReverse()

bool YapfTrainCheckReverse | ( | const Train * | v | ) |

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

Parameters

  v | the train leaving the station

Returns
  true if reversing is better

Definition at line 550 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

  v | the train that needs to find a path
  tile | the tile to find the path from (should be next tile the train is about to enter)
  enterdir | diagonal direction which the RV will enter this new tile from
  tracks | available trackdirs on the new tile (to choose from)
  path_found | [out] Whether a path has been found (true) or has been guessed (false)
  reserve_track | indicates 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 535 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

  v | train that needs to go to some depot
  max_distance | max 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 609 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

  v | The train that needs to find a safe tile.
  tile | Last tile of the current reserved path.
  td | Last trackdir of the current reserved path.
  override_railtype | Should 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 628 of file yapf_rail.cpp.

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

Referenced by TryReserveSafeTrack().