# pathfind.h File Reference

The oldest pathfinder that's supported. More...

`#include "direction_type.h"`

Go to the source code of this file.

## Data Structures

struct | TrackPathFinderLink
struct | RememberData
struct | TrackPathFinder

## Defines

#define | PATHFIND_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links)
#define | PATHFIND_GET_LINK_PTR(tpf, link_offs) (TrackPathFinderLink*)((byte*)tpf->links + (link_offs))
#define | PATHFIND_HASH_TILE(tile) (TileX(tile) & 0x1F) + ((TileY(tile) & 0x1F) << 5)

## Typedefs

typedef bool | TPFEnumProc (TileIndex tile, void *data, Trackdir trackdir, uint length)
typedef void | TPFAfterProc (TrackPathFinder *tpf)
typedef bool | NTPEnumProc (TileIndex tile, void *data, int track, uint length)

## Enumerations

enum | { STR_FACTOR = 2, DIAG_FACTOR = 3 }
enum | PathfindFlags { PATHFIND_FLAGS_NONE = 0, PATHFIND_FLAGS_SHIP_MODE = 0x0800, PATHFIND_FLAGS_DISABLE_TILE_HASH = 0x1000 }
| Some flags to modify the behaviour of original pathfinder. More...

## Functions

void | FollowTrack (TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data)
void | NewTrainPathfind (TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc *enum_proc, void *data)
| new pathfinder for trains.
static TileIndex | CalcClosestStationTile (StationID station, TileIndex tile)
| Calculates the tile of given station that is closest to a given tile for this we assume the station is a rectangle, as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h).

## Detailed Description

The oldest pathfinder that's supported.

Definition in file pathfind.h.

## Enumeration Type Documentation

enum PathfindFlags

Some flags to modify the behaviour of original pathfinder.

Enumerator:

  PATHFIND_FLAGS_SHIP_MODE | pathfinder with some optimizations for ships, but does not work for other types.
  PATHFIND_FLAGS_DISABLE_TILE_HASH | do not check for searching in circles

Definition at line 70 of file pathfind.h.

## Function Documentation

static TileIndex CalcClosestStationTile | ( | StationID | station,
|  | TileIndex | tile |
| ) |  |  | `[inline, static]`

Calculates the tile of given station that is closest to a given tile for this we assume the station is a rectangle, as defined by its top tile (st->train_tile) and its width/height (st->trainst_w, st->trainst_h).

Parameters:

  | station | The station to calculate the distance to
  | tile | The tile from where to calculate the distance

Returns:
  The closest station tile to the given tile.

Definition at line 89 of file pathfind.h.

References ClampU(), INVALID_TILE, TileX(), TileXY(), TileY(), Station::train_tile, Station::trainst_h, Station::trainst_w, and Station::xy.

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().