# pathfind.cpp File Reference

Implementation of the oldest supported pathfinder. More...

`#include "stdafx.h"`
`#include "station_map.h"`
`#include "settings_type.h"`
`#include "pathfind.h"`
`#include "debug.h"`
`#include "tunnelbridge_map.h"`
`#include "core/random_func.hpp"`
`#include "core/alloc_type.hpp"`
`#include "tunnelbridge.h"`

Go to the source code of this file.

## Data Structures
struct | StackedItem
struct | HashLink
struct | NewTrackPathFinder
## Defines
#define | NTP_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links)
#define | NTP_GET_LINK_PTR(tpf, link_offs) (HashLink*)((byte*)tpf->links + (link_offs))
#define | ARR(i) tpf->stack[(i)-1]
## Functions
static bool | TPFSetTileBit (TrackPathFinder *tpf, TileIndex tile, int dir)
static void | TPFModeShip (TrackPathFinder *tpf, TileIndex tile, DiagDirection direction)
static bool | CanAccessTileInDir (TileIndex tile, DiagDirection side, TransportType tracktype)
| Checks if any vehicle can enter/leave tile in given diagdir Checks only for rail/road depots and road non-drivethrough stations.
static void | TPFModeNormal (TrackPathFinder *tpf, TileIndex tile, DiagDirection direction)
void | FollowTrack (TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
static void | HeapifyUp (NewTrackPathFinder *tpf)
| called after a new element was added in the queue at the last index.
static void | HeapifyDown (NewTrackPathFinder *tpf)
| called after the element 0 was eaten.
static bool | NtpVisit (NewTrackPathFinder *tpf, TileIndex tile, DiagDirection dir, uint length)
| mark a tile as visited and store the length of the path.
static bool | NtpCheck (NewTrackPathFinder *tpf, TileIndex tile, uint dir, uint length)
| Checks if the shortest path to the given tile/dir so far is still the given length.
static uint | DistanceMoo (TileIndex t0, TileIndex t1)
static void | NTPEnum (NewTrackPathFinder *tpf, TileIndex tile, DiagDirection direction)
void | NewTrainPathfind (TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc *enum_proc, void *data)
| new pathfinder for trains.
## Variables
static const byte | _length_of_track [16]

## Detailed Description

Implementation of the oldest supported pathfinder.

Definition in file pathfind.cpp.

## Function Documentation

static bool CanAccessTileInDir | ( | TileIndex | tile,
|  | DiagDirection | side,
|  | TransportType | tracktype |
| ) |  |  | `[inline, static]`

Checks if any vehicle can enter/leave tile in given diagdir Checks only for rail/road depots and road non-drivethrough stations.

Parameters:

  | tile | tile to check
  | side | side of tile we are trying to leave/enter
  | tracktype | type of transport

Precondition:
  tile has trackbit at that diagdir

Returns:
  true iff vehicle can enter/leve the tile in given side

Definition at line 180 of file pathfind.cpp.

References GetRailDepotDirection(), GetRoadStopDir(), IsRailDepotTile(), TRANSPORT_RAIL, and TRANSPORT_ROAD.

static void HeapifyDown | ( | NewTrackPathFinder * | tpf | ) | `[inline, static]`

called after the element 0 was eaten.

fill it with a new element

Definition at line 361 of file pathfind.cpp.

static void HeapifyUp | ( | NewTrackPathFinder * | tpf | ) | `[inline, static]`

called after a new element was added in the queue at the last index.

move it down to the proper position

Definition at line 347 of file pathfind.cpp.

void NewTrainPathfind | ( | TileIndex | tile,
|  | TileIndex | dest,
|  | RailTypes | railtypes,
|  | DiagDirection | direction,
|  | NTPEnumProc * | enum_proc,
|  | void * | data |
| ) |  |  |

new pathfinder for trains.

better and faster.

Definition at line 785 of file pathfind.cpp.

References _settings_game, lengthof, min(), PathfinderSettings::opf, GameSettings::pf, OPFSettings::pf_maxlength, and TRANSPORT_RAIL.

Referenced by DoTrainPathfind(), and FindClosestTrainDepot().

static bool NtpCheck | ( | NewTrackPathFinder * | tpf,
|  | TileIndex | tile,
|  | uint | dir,
|  | uint | length |
| ) |  |  | `[static]`

Checks if the shortest path to the given tile/dir so far is still the given length.

Returns:
  true if the length is still the same

Precondition:
  The given tile/dir combination should be present in the hash, by a previous call to NtpVisit().

Definition at line 479 of file pathfind.cpp.

static bool NtpVisit | ( | NewTrackPathFinder * | tpf,
|  | TileIndex | tile,
|  | DiagDirection | dir,
|  | uint | length |
| ) |  |  | `[static]`

mark a tile as visited and store the length of the path.

if we already had a better path to this tile, return false. otherwise return true.

Definition at line 393 of file pathfind.cpp.

## Variable Documentation

const byte _length_of_track[16]`[static]`

Initial value:

     {
      DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0,
      DIAG_FACTOR, DIAG_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, STR_FACTOR, 0, 0
    }

Definition at line 526 of file pathfind.cpp.