pathfind.h

Go to the documentation of this file.
00001 /* $Id: pathfind.h 12193 2008-02-20 15:13:42Z frosch $ */
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 //#define PF_BENCH // perform simple benchmarks on the train pathfinder (not
00016 //supported on all archs)
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 /* y7 y6 y5 y4 y3 y2 y1 y0 x7 x6 x5 x4 x3 x2 x1 x0
00028  * y7 y6 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0  0  0  0
00029  *  0  0 y7 y6 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0  0
00030  *  0  0  0  0 y5 y4 y3 y2 y1 y0 x4 x3 x2 x1 x0  0
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   byte var2;
00062   bool disable_tile_hash;
00063 
00064   uint16 hash_head[0x400];
00065   TileIndex hash_tile[0x400];       
00066 
00067   TrackPathFinderLink links[0x400]; 
00068 };
00069 
00070 void FollowTrack(TileIndex tile, uint16 flags, uint sub_type, DiagDirection direction, TPFEnumProc* enum_proc, TPFAfterProc* after_proc, void* data);
00071 void NewTrainPathfind(TileIndex tile, TileIndex dest, RailTypes railtypes, DiagDirection direction, NTPEnumProc* enum_proc, void* data);
00072 
00073 #endif /* PATHFIND_H */

Generated on Mon Sep 22 20:34:17 2008 for openttd by  doxygen 1.5.6