# npf.h

Go to the documentation of this file.

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