tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef PATHFIND_H truelight@0: #define PATHFIND_H truelight@0: tron@3153: #include "direction.h" tron@3153: Darkvater@4406: enum { Darkvater@4406: STR_FACTOR = 2, Darkvater@4406: DIAG_FACTOR = 3 Darkvater@4406: }; Darkvater@4406: matthijs@1247: //#define PF_BENCH // perform simple benchmarks on the train pathfinder (not matthijs@1247: //supported on all archs) matthijs@1247: truelight@0: typedef struct TrackPathFinder TrackPathFinder; tron@1977: typedef bool TPFEnumProc(TileIndex tile, void *data, int track, uint length, byte *state); truelight@0: typedef void TPFAfterProc(TrackPathFinder *tpf); truelight@0: ludde@2125: typedef bool NTPEnumProc(TileIndex tile, void *data, int track, uint length); truelight@0: truelight@0: #define PATHFIND_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links) truelight@0: #define PATHFIND_GET_LINK_PTR(tpf, link_offs) (TrackPathFinderLink*)((byte*)tpf->links + (link_offs)) truelight@0: truelight@0: /* y7 y6 y5 y4 y3 y2 y1 y0 x7 x6 x5 x4 x3 x2 x1 x0 truelight@0: * y7 y6 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0 0 0 0 truelight@0: * 0 0 y7 y6 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0 0 truelight@0: * 0 0 0 0 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0 0 truelight@0: */ tron@926: #define PATHFIND_HASH_TILE(tile) (TileX(tile) & 0x1F) + ((TileY(tile) & 0x1F) << 5) truelight@0: truelight@0: typedef struct TrackPathFinderLink { truelight@0: TileIndex tile; truelight@0: uint16 flags; truelight@0: uint16 next; truelight@0: } TrackPathFinderLink; truelight@0: truelight@0: typedef struct RememberData { truelight@0: uint16 cur_length; truelight@0: byte depth; truelight@0: byte pft_var6; truelight@0: } RememberData; truelight@0: truelight@0: struct TrackPathFinder { truelight@0: int num_links_left; truelight@0: TrackPathFinderLink *new_link; truelight@0: truelight@0: TPFEnumProc *enum_proc; truelight@0: truelight@0: void *userdata; truelight@201: truelight@0: RememberData rd; truelight@0: truelight@0: int the_dir; truelight@0: truelight@0: byte tracktype; truelight@0: byte var2; truelight@0: bool disable_tile_hash; truelight@0: bool hasbit_13; truelight@0: truelight@0: uint16 hash_head[0x400]; truelight@0: TileIndex hash_tile[0x400]; /* stores the link index when multi link. */ truelight@0: truelight@0: TrackPathFinderLink links[0x400]; /* hopefully, this is enough. */ truelight@0: }; truelight@0: tron@3153: void FollowTrack(TileIndex tile, uint16 flags, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data); truelight@0: truelight@0: typedef struct { tron@1977: TileIndex tile; truelight@0: int length; truelight@0: } FindLengthOfTunnelResult; belugas@3323: FindLengthOfTunnelResult FindLengthOfTunnel(TileIndex tile, DiagDirection direction); truelight@0: celestar@3355: void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypeMask railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data); truelight@0: truelight@0: #endif /* PATHFIND_H */