src/npf.h
branchcpp_gui
changeset 6303 84c215fc8eb8
parent 6298 c30fe89622df
child 6719 4cc327ad39d5
equal deleted inserted replaced
6302:bd80897189ba 6303:84c215fc8eb8
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file npf.h */
     2 
     4 
     3 #ifndef NPF_H
     5 #ifndef NPF_H
     4 #define NPF_H
     6 #define NPF_H
     5 
     7 
     6 #include "openttd.h"
     8 #include "openttd.h"
     7 #include "aystar.h"
     9 #include "aystar.h"
     8 #include "station.h"
    10 #include "station.h"
     9 #include "vehicle.h"
    11 #include "vehicle.h"
    10 #include "tile.h"
    12 #include "tile.h"
    11 
    13 
    12 //mowing grass
    14 /* mowing grass */
    13 enum {
    15 enum {
    14 	NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */
    16 	NPF_HASH_BITS = 12, ///< The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value.
    15 	/* Do no change below values */
    17 	/* Do no change below values */
    16 	NPF_HASH_SIZE = 1 << NPF_HASH_BITS,
    18 	NPF_HASH_SIZE = 1 << NPF_HASH_BITS,
    17 	NPF_HASH_HALFBITS = NPF_HASH_BITS / 2,
    19 	NPF_HASH_HALFBITS = NPF_HASH_BITS / 2,
    18 	NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1
    20 	NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1
    19 };
    21 };
    33 	 * this in a nicer way :-)
    35 	 * this in a nicer way :-)
    34 	 */
    36 	 */
    35 	NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
    37 	NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
    36 };
    38 };
    37 
    39 
    38 struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */
    40 /* Meant to be stored in AyStar.targetdata */
    39 	TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */
    41 struct NPFFindStationOrTileData {
    40 	StationID station_index; /* station index we're heading for, or INVALID_STATION when we're heading for a tile */
    42 	TileIndex dest_coords;   ///< An indication of where the station is, for heuristic purposes, or the target tile
       
    43 	StationID station_index; ///< station index we're heading for, or INVALID_STATION when we're heading for a tile
    41 };
    44 };
    42 
    45 
    43 enum { /* Indices into AyStar.userdata[] */
    46 /* Indices into AyStar.userdata[] */
    44 	NPF_TYPE = 0, /* Contains a TransportTypes value */
    47 enum {
    45 	NPF_OWNER, /* Contains an Owner value */
    48 	NPF_TYPE = 0,  ///< Contains a TransportTypes value
    46 	NPF_RAILTYPES, /* Contains a bitmask the compatible RailTypes of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise. */
    49 	NPF_OWNER,     ///< Contains an Owner value
       
    50 	NPF_RAILTYPES, ///< Contains a bitmask the compatible RailTypes of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise.
    47 };
    51 };
    48 
    52 
    49 enum { /* Indices into AyStarNode.userdata[] */
    53 /* Indices into AyStarNode.userdata[] */
    50 	NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */
    54 enum {
       
    55 	NPF_TRACKDIR_CHOICE = 0, ///< The trackdir chosen to get here
    51 	NPF_NODE_FLAGS,
    56 	NPF_NODE_FLAGS,
    52 };
    57 };
    53 
    58 
    54 enum NPFNodeFlag { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
    59 /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
    55 	NPF_FLAG_SEEN_SIGNAL, /* Used to mark that a signal was seen on the way, for rail only */
    60 enum NPFNodeFlag {
    56 	NPF_FLAG_REVERSE, /* Used to mark that this node was reached from the second start node, if applicable */
    61 	NPF_FLAG_SEEN_SIGNAL,     ///< Used to mark that a signal was seen on the way, for rail only
    57 	NPF_FLAG_LAST_SIGNAL_RED, /* Used to mark that the last signal on this path was red */
    62 	NPF_FLAG_REVERSE,         ///< Used to mark that this node was reached from the second start node, if applicable
       
    63 	NPF_FLAG_LAST_SIGNAL_RED, ///< Used to mark that the last signal on this path was red
    58 };
    64 };
    59 
    65 
    60 struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */
    66 /* Meant to be stored in AyStar.userpath */
    61 	uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */
    67 struct NPFFoundTargetData {
    62 	uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */
    68 	uint best_bird_dist;    ///< The best heuristic found. Is 0 if the target was found
    63 	Trackdir best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */
    69 	uint best_path_dist;    ///< The shortest path. Is (uint)-1 if no path is found
    64 	AyStarNode node; /* The node within the target the search led us to */
    70 	Trackdir best_trackdir; ///< The trackdir that leads to the shortest path/closest birds dist
       
    71 	AyStarNode node;        ///< The node within the target the search led us to
    65 };
    72 };
    66 
    73 
    67 /* These functions below are _not_ re-entrant, in favor of speed! */
    74 /* These functions below are _not_ re-entrant, in favor of speed! */
    68 
    75 
    69 /* Will search from the given tile and direction, for a route to the given
    76 /* Will search from the given tile and direction, for a route to the given