OpenTTD Source: src/pathfinder/npf/npf_func.h File Reference

OpenTTD Source 12.0-beta1

Functions
npf_func.h File Reference
`#include "../../track_type.h"`
`#include "../../direction_type.h"`
`#include "../../vehicle_type.h"`
`#include "../pathfinder_type.h"`

Go to the source code of this file.

## Functions
FindDepotData | NPFRoadVehicleFindNearestDepot (const RoadVehicle *v, int max_penalty)
| Used when user sends road vehicle to the nearest depot or if road vehicle needs servicing using NPF. More...
Trackdir | NPFRoadVehicleChooseTrack (const RoadVehicle *v, TileIndex tile, DiagDirection enterdir, bool &path_found)
| Finds the best path for given road vehicle using NPF. More...
Track | NPFShipChooseTrack (const Ship *v, bool &path_found)
| Finds the best path for given ship using NPF. More...
bool | NPFShipCheckReverse (const Ship *v)
| Returns true if it is better to reverse the ship before leaving depot using NPF. More...
FindDepotData | NPFTrainFindNearestDepot (const Train *v, int max_penalty)
| Used when user sends train to the nearest depot or if train needs servicing using NPF. More...
bool | NPFTrainFindNearestSafeTile (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 NPF. More...
bool | NPFTrainCheckReverse (const Train *v)
| Returns true if it is better to reverse the train before leaving station using NPF. More...
Track | NPFTrainChooseTrack (const Train *v, bool &path_found, bool reserve_track, struct PBSTileInfo *target)
| Finds the best path for given train using NPF. More...

## Detailed Description

Functions to access the new pathfinder.

Definition in file npf_func.h.

## Function Documentation

## ◆ NPFRoadVehicleChooseTrack()

Trackdir NPFRoadVehicleChooseTrack | ( | const RoadVehicle * | v,
|  | TileIndex | tile,
|  | DiagDirection | enterdir,
|  | bool & | path_found
| ) |  |

Finds the best path for given road vehicle using NPF.

Parameters

  v | the RV that needs to find a path
  tile | the tile to find the path from (should be next tile the RV is about to enter)
  enterdir | diagonal direction which the RV will enter this new tile 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 1171 of file npf.cpp.

## ◆ NPFRoadVehicleFindNearestDepot()

FindDepotData NPFRoadVehicleFindNearestDepot | ( | const RoadVehicle * | v,
|  | int | max_penalty
| ) |  |

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

Parameters

  v | vehicle that needs to go to some depot
  max_penalty | max 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 1154 of file npf.cpp.

References RoadVehicle::compatible_roadtypes, RoadVehicle::GetVehicleTrackdir(), Vehicle::owner, RAILTYPES_NONE, and TRANSPORT_ROAD.

## ◆ NPFShipCheckReverse()

bool NPFShipCheckReverse | ( | const Ship * | v | ) |

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

Parameters

  v | the ship leaving the depot

Returns
  true if reversing is better

Definition at line 1214 of file npf.cpp.

## ◆ NPFShipChooseTrack()

Track NPFShipChooseTrack | ( | const Ship * | v,
|  | bool & | path_found
| ) |  |

Finds the best path for given ship using NPF.

Parameters

  v | the ship that needs to find a path
  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

Definition at line 1193 of file npf.cpp.

References Ship::GetVehicleTrackdir(), and INVALID_TRACKDIR.

Referenced by ChooseShipTrack().

## ◆ NPFTrainCheckReverse()

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

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

Parameters

  v | the train leaving the station

Returns
  true if reversing is better

Definition at line 1277 of file npf.cpp.

References SpecializedVehicle< T, Type >::Last().

## ◆ NPFTrainChooseTrack()

Track NPFTrainChooseTrack | ( | const Train * | v,
|  | bool & | path_found,
|  | bool | reserve_track,
|  | struct PBSTileInfo * | target
| ) |  |

Finds the best path for given train using NPF.

Parameters

  v | the train that needs to find a path
  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

Returns
  the best track for next turn

Definition at line 1296 of file npf.cpp.

Referenced by DoTrainPathfind().

## ◆ NPFTrainFindNearestDepot()

FindDepotData NPFTrainFindNearestDepot | ( | const Train * | v,
|  | int | max_penalty
| ) |  |

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

Parameters

  v | train that needs to go to some depot
  max_penalty | max max_penalty (in 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 1234 of file npf.cpp.

References Train::GetVehicleTrackdir(), INVALID_TRACKDIR, SpecializedVehicle< T, Type >::Last(), Vehicle::owner, NPFFindStationOrTileData::reserve_path, ReverseTrackdir(), ROADTYPES_NONE, TRANSPORT_RAIL, and NPFFindStationOrTileData::v.

Referenced by FindClosestTrainDepot().

## ◆ NPFTrainFindNearestSafeTile()

bool NPFTrainFindNearestSafeTile | ( | 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 NPF.

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 1256 of file npf.cpp.

References RailtypeInfo::compatible_railtypes, GetRailTypeInfo(), Vehicle::owner, NPFFindStationOrTileData::reserve_path, ROADTYPES_NONE, TRANSPORT_RAIL, BaseVehicle::type, NPFFindStationOrTileData::v, and VEH_TRAIN.

Referenced by TryReserveSafeTrack().