tron@2186: /* $Id$ */ tron@2186: rubidium@9111: /** @file pathfind.h The oldest pathfinder that's supported. */ belugas@6352: truelight@0: #ifndef PATHFIND_H truelight@0: #define PATHFIND_H truelight@0: rubidium@8100: #include "direction_type.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: rubidium@6248: struct TrackPathFinder; frosch@8611: typedef bool TPFEnumProc(TileIndex tile, void *data, Trackdir trackdir, uint length); 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: rubidium@6248: struct TrackPathFinderLink { truelight@0: TileIndex tile; truelight@0: uint16 flags; truelight@0: uint16 next; rubidium@6248: }; truelight@0: rubidium@6248: struct RememberData { truelight@0: uint16 cur_length; truelight@0: byte depth; frosch@8611: Track last_choosen_track; rubidium@6248: }; 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: rubidium@5587: TrackdirByte the_dir; truelight@0: rubidium@8263: TransportType tracktype; rubidium@6683: uint sub_type; rubidium@6683: truelight@0: bool disable_tile_hash; truelight@0: truelight@0: uint16 hash_head[0x400]; belugas@6352: TileIndex hash_tile[0x400]; ///< stores the link index when multi link. truelight@0: belugas@6352: TrackPathFinderLink links[0x400]; ///< hopefully, this is enough. truelight@0: }; truelight@0: frosch@8800: /** Some flags to modify the behaviour of original pathfinder */ frosch@8800: enum PathfindFlags { frosch@8800: PATHFIND_FLAGS_NONE = 0, frosch@8800: PATHFIND_FLAGS_SHIP_MODE = 0x0800, ///< pathfinder with some optimizations for ships, but does not work for other types. frosch@8800: PATHFIND_FLAGS_DISABLE_TILE_HASH = 0x1000, ///< do not check for searching in circles frosch@8800: }; frosch@8800: DECLARE_ENUM_AS_BIT_SET(PathfindFlags) frosch@8800: frosch@8800: void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data); rubidium@8236: void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data); truelight@0: truelight@0: #endif /* PATHFIND_H */