npf.h

Go to the documentation of this file.
00001 /* $Id: npf.h 12085 2008-02-08 16:25:55Z frosch $ */
00002 
00005 #ifndef NPF_H
00006 #define NPF_H
00007 
00008 #include "aystar.h"
00009 #include "station.h"
00010 #include "vehicle_type.h"
00011 #include "tile_type.h"
00012 #include "track_type.h"
00013 #include "core/bitmath_func.hpp"
00014 
00015 /* mowing grass */
00016 enum {
00017   NPF_HASH_BITS = 12, 
00018   /* Do no change below values */
00019   NPF_HASH_SIZE = 1 << NPF_HASH_BITS,
00020   NPF_HASH_HALFBITS = NPF_HASH_BITS / 2,
00021   NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1
00022 };
00023 
00024 /* For new pathfinding. Define here so it is globally available without having
00025  * to include npf.h */
00026 enum {
00027   NPF_TILE_LENGTH = 100
00028 };
00029 
00030 enum {
00038   NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
00039 };
00040 
00041 /* Meant to be stored in AyStar.targetdata */
00042 struct NPFFindStationOrTileData {
00043   TileIndex dest_coords;   
00044   StationID station_index; 
00045 };
00046 
00047 /* Indices into AyStar.userdata[] */
00048 enum {
00049   NPF_TYPE = 0,  
00050   NPF_SUB_TYPE,  
00051   NPF_OWNER,     
00052   NPF_RAILTYPES, 
00053 };
00054 
00055 /* Indices into AyStarNode.userdata[] */
00056 enum {
00057   NPF_TRACKDIR_CHOICE = 0, 
00058   NPF_NODE_FLAGS,
00059 };
00060 
00061 /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
00062 enum NPFNodeFlag {
00063   NPF_FLAG_SEEN_SIGNAL,       
00064   NPF_FLAG_REVERSE,           
00065   NPF_FLAG_LAST_SIGNAL_RED,   
00066   NPF_FLAG_IGNORE_START_TILE, 
00067 };
00068 
00069 /* Meant to be stored in AyStar.userpath */
00070 struct NPFFoundTargetData {
00071   uint best_bird_dist;    
00072   uint best_path_dist;    
00073   Trackdir best_trackdir; 
00074   AyStarNode node;        
00075 };
00076 
00077 /* These functions below are _not_ re-entrant, in favor of speed! */
00078 
00079 /* Will search from the given tile and direction, for a route to the given
00080  * station for the given transport type. See the declaration of
00081  * NPFFoundTargetData above for the meaning of the result. */
00082 NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, bool ignore_start_tile, NPFFindStationOrTileData* target, TransportType type, uint sub_type, Owner owner, RailTypes railtypes);
00083 
00084 /* Will search as above, but with two start nodes, the second being the
00085  * reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which
00086  * direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */
00087 NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, NPFFindStationOrTileData* target, TransportType type, uint sub_type, Owner owner, RailTypes railtypes);
00088 
00089 /* Will search a route to the closest depot. */
00090 
00091 /* Search using breadth first. Good for little track choice and inaccurate
00092  * heuristic, such as railway/road.*/
00093 NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, Trackdir trackdir, bool ignore_start_tile, TransportType type, uint sub_type, Owner owner, RailTypes railtypes);
00094 /* Same as above but with two start nodes, the second being the reverse. Call
00095  * NPFGetBit(result.node, NPF_FLAG_REVERSE) to see from which node the path
00096  * orginated. All pathfs from the second node will have the given
00097  * reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full
00098  * tile).
00099  */
00100 NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, bool ignore_start_tile1, TileIndex tile2, Trackdir trackdir2, bool ignore_start_tile2, TransportType type, uint sub_type, Owner owner, RailTypes railtypes, uint reverse_penalty);
00101 /* Search by trying each depot in order of Manhattan Distance. Good for lots
00102  * of choices and accurate heuristics, such as water. */
00103 NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir, bool ignore_start_tile, TransportType type, uint sub_type, Owner owner, RailTypes railtypes);
00104 
00105 void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v);
00106 
00107 
00108 /*
00109  * Functions to manipulate the various NPF related flags on an AyStarNode.
00110  */
00111 
00115 static inline bool NPFGetFlag(const AyStarNode* node, NPFNodeFlag flag)
00116 {
00117   return HasBit(node->user_data[NPF_NODE_FLAGS], flag);
00118 }
00119 
00123 static inline void NPFSetFlag(AyStarNode* node, NPFNodeFlag flag, bool value)
00124 {
00125   if (value)
00126     SetBit(node->user_data[NPF_NODE_FLAGS], flag);
00127   else
00128     ClrBit(node->user_data[NPF_NODE_FLAGS], flag);
00129 }
00130 
00131 #endif /* NPF_H */

Generated on Wed Oct 1 17:03:22 2008 for openttd by  doxygen 1.5.6