pathfind.h
Go to the documentation of this file.00001
00002
00005 #ifndef PATHFIND_H
00006 #define PATHFIND_H
00007
00008 #include "direction_type.h"
00009
00010 enum {
00011 STR_FACTOR = 2,
00012 DIAG_FACTOR = 3
00013 };
00014
00015
00016
00017
00018 struct TrackPathFinder;
00019 typedef bool TPFEnumProc(TileIndex tile, void *data, Trackdir trackdir, uint length);
00020 typedef void TPFAfterProc(TrackPathFinder *tpf);
00021
00022 typedef bool NTPEnumProc(TileIndex tile, void *data, int track, uint length);
00023
00024 #define PATHFIND_GET_LINK_OFFS(tpf, link) ((byte*)(link) - (byte*)tpf->links)
00025 #define PATHFIND_GET_LINK_PTR(tpf, link_offs) (TrackPathFinderLink*)((byte*)tpf->links + (link_offs))
00026
00027
00028
00029
00030
00031
00032 #define PATHFIND_HASH_TILE(tile) (TileX(tile) & 0x1F) + ((TileY(tile) & 0x1F) << 5)
00033
00034 struct TrackPathFinderLink {
00035 TileIndex tile;
00036 uint16 flags;
00037 uint16 next;
00038 };
00039
00040 struct RememberData {
00041 uint16 cur_length;
00042 byte depth;
00043 Track last_choosen_track;
00044 };
00045
00046 struct TrackPathFinder {
00047 int num_links_left;
00048 TrackPathFinderLink *new_link;
00049
00050 TPFEnumProc *enum_proc;
00051
00052 void *userdata;
00053
00054 RememberData rd;
00055
00056 TrackdirByte the_dir;
00057
00058 TransportType tracktype;
00059 uint sub_type;
00060
00061 bool disable_tile_hash;
00062
00063 uint16 hash_head[0x400];
00064 TileIndex hash_tile[0x400];
00065
00066 TrackPathFinderLink links[0x400];
00067 };
00068
00070 enum PathfindFlags {
00071 PATHFIND_FLAGS_NONE = 0,
00072 PATHFIND_FLAGS_SHIP_MODE = 0x0800,
00073 PATHFIND_FLAGS_DISABLE_TILE_HASH = 0x1000,
00074 };
00075 DECLARE_ENUM_AS_BIT_SET(PathfindFlags)
00076
00077 void FollowTrack(TileIndex tile, PathfindFlags flags, TransportType tt, uint sub_type, DiagDirection direction, TPFEnumProc *enum_proc, TPFAfterProc *after_proc, void *data);
00078 void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc *enum_proc, void *data);
00079
00080 #endif