matthijs@1247: #ifndef NPF_H matthijs@1247: #define NPF_H matthijs@1247: matthijs@1247: #include "ttd.h" matthijs@1247: #include "aystar.h" matthijs@1247: #include "vehicle.h" matthijs@1247: matthijs@1247: //#define NPF_DEBUG matthijs@1247: //#define NPF_MARKROUTE //Mark the routes considered by the pathfinder by matthijs@1247: //mowing grass matthijs@1247: matthijs@1247: typedef struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */ matthijs@1247: TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */ matthijs@1247: int station_index; /* station index we're heading for, or -1 when we're heading for a tile */ matthijs@1247: } NPFFindStationOrTileData; matthijs@1247: matthijs@1247: enum { /* Indices into AyStar.userdata[] */ matthijs@1330: NPF_TYPE = 0, /* Contains a TransportTypes value */ matthijs@1330: NPF_OWNER, /* Contains an Owner value */ matthijs@1247: }; matthijs@1247: matthijs@1247: enum { /* Indices into AyStarNode.userdata[] */ matthijs@1247: NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */ matthijs@1247: NPF_NODE_FLAGS, matthijs@1247: }; matthijs@1247: enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]*/ matthijs@1247: NPF_FLAG_SEEN_SIGNAL = 1, /* Used to mark that a signal was seen on the way, for rail only */ matthijs@1247: NPF_FLAG_REVERSE = 2, /* Used to mark that this node was reached from the second start node, if applicable */ matthijs@1247: }; matthijs@1247: matthijs@1247: typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */ matthijs@1247: uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */ matthijs@1247: uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */ matthijs@1330: byte best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ matthijs@1247: AyStarNode node; /* The node within the target the search led us to */ matthijs@1247: } NPFFoundTargetData; matthijs@1247: matthijs@1247: /* These functions below are _not_ re-entrant, in favor of speed! */ matthijs@1247: matthijs@1247: /* Will search from the given tile and direction, for a route to the given matthijs@1247: * station for the given transport type. See the declaration of matthijs@1247: * NPFFoundTargetData above for the meaning of the result. */ matthijs@1330: NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner); matthijs@1247: /* Will search as above, but with two start nodes, the second being the matthijs@1247: * reverse. Look at the NPF_NODE_REVERSE flag in the result node to see which matthijs@1247: * direction was taken */ matthijs@1330: NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner); matthijs@1247: matthijs@1247: /* Will search a route to the closest depot. */ matthijs@1247: matthijs@1247: /* Search using breadth first. Good for little track choice and inaccurate matthijs@1247: * heuristic, such as railway/road */ matthijs@1330: NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type, Owner owner); matthijs@1247: /* Search by trying each depot in order of Manhattan Distance. Good for lots matthijs@1330: * of choices and accurate heuristics, such as water. */ matthijs@1330: NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type, Owner owner); matthijs@1247: matthijs@1247: void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v); matthijs@1247: matthijs@1247: /* matthijs@1247: * Some tables considering tracks, directions and signals. matthijs@1247: * XXX: Better place to but these? matthijs@1247: */ matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to the bit that stores its status in the map arrays, in the matthijs@1247: * direction along with the trackdir. matthijs@1247: */ matthijs@1247: const byte _signal_along_trackdir[14]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to the bit that stores its status in the map arrays, in the matthijs@1247: * direction against the trackdir. matthijs@1247: */ matthijs@1247: const byte _signal_against_trackdir[14]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to the trackdirs that can be reached from it (ie, when matthijs@1247: * entering the next tile. matthijs@1247: */ matthijs@1247: const uint16 _trackdir_reaches_trackdirs[14]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to all trackdirs that make 90 deg turns with it. matthijs@1247: */ matthijs@1247: const uint16 _trackdir_crosses_trackdirs[14]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a track to all tracks that make 90 deg turns with it. matthijs@1247: */ matthijs@1247: const byte _track_crosses_tracks[6]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to the (4-way) direction the tile is exited when following matthijs@1247: * that trackdir. matthijs@1247: */ matthijs@1247: const byte _trackdir_to_exitdir[14]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a track and an (4-way) dir to the trackdir that represents the track matthijs@1247: * with the exit in the given direction. matthijs@1247: */ matthijs@1247: const byte _track_exitdir_to_trackdir[6][4]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a track and a full (8-way) direction to the trackdir that represents matthijs@1247: * the track running in the given direction. matthijs@1247: */ matthijs@1247: const byte _track_direction_to_trackdir[6][8]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a (4-way) direction to the diagonal track that runs in that matthijs@1247: * direction. matthijs@1247: */ matthijs@1247: const byte _dir_to_diag_trackdir[4]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a (4-way) direction to the reverse. matthijs@1247: */ matthijs@1247: const byte _reverse_dir[4]; matthijs@1247: matthijs@1247: /** matthijs@1247: * Maps a trackdir to the reverse trackdir. matthijs@1247: */ matthijs@1247: const byte _reverse_trackdir[14]; matthijs@1247: matthijs@1247: #define REVERSE_TRACKDIR(trackdir) (trackdir ^ 0x8) matthijs@1247: matthijs@1247: #endif // NPF_H