2005-07-24 14:12:37 +00:00
/* $Id$ */
2005-01-31 11:23:10 +00:00
# ifndef NPF_H
# define NPF_H
2005-06-02 19:30:21 +00:00
# include "openttd.h"
2005-01-31 11:23:10 +00:00
# include "aystar.h"
2006-03-03 20:54:54 +00:00
# include "station.h"
2005-01-31 11:23:10 +00:00
# include "vehicle.h"
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
# include "tile.h"
2005-07-21 22:15:02 +00:00
# include "variables.h"
2005-01-31 11:23:10 +00:00
//mowing grass
2005-04-07 19:19:16 +00:00
enum {
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. */
/* Do no change below values */
NPF_HASH_SIZE = 1 < < NPF_HASH_BITS ,
NPF_HASH_HALFBITS = NPF_HASH_BITS / 2 ,
NPF_HASH_HALFMASK = ( 1 < < NPF_HASH_HALFBITS ) - 1
} ;
2005-01-31 11:23:10 +00:00
2005-05-07 22:00:36 +00:00
enum {
/** This penalty is the equivalent of "inifite", which means that paths that
* get this penalty will be chosen , but only if there is no other route
* without it . Be careful with not applying this penalty to often , or the
* total path cost might overflow . .
* For now , this is just a Very Big Penalty , we might actually implement
* this in a nicer way : - )
*/
NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
} ;
2005-01-31 11:23:10 +00:00
typedef struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */
TileIndex dest_coords ; /* An indication of where the station is, for heuristic purposes, or the target tile */
2006-03-03 20:54:54 +00:00
StationID station_index ; /* station index we're heading for, or INVALID_STATION when we're heading for a tile */
2005-01-31 11:23:10 +00:00
} NPFFindStationOrTileData ;
enum { /* Indices into AyStar.userdata[] */
2005-02-06 22:36:08 +00:00
NPF_TYPE = 0 , /* Contains a TransportTypes value */
NPF_OWNER , /* Contains an Owner value */
2005-07-03 13:02:54 +00:00
NPF_RAILTYPE , /* Contains the RailType value of the engine when NPF_TYPE == TRANSPORT_RAIL. Unused otherwise. */
2005-01-31 11:23:10 +00:00
} ;
enum { /* Indices into AyStarNode.userdata[] */
NPF_TRACKDIR_CHOICE = 0 , /* The trackdir chosen to get here */
NPF_NODE_FLAGS ,
} ;
2005-07-04 14:58:55 +00:00
2005-03-08 19:54:10 +00:00
typedef enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
NPF_FLAG_SEEN_SIGNAL , /* Used to mark that a signal was seen on the way, for rail only */
NPF_FLAG_REVERSE , /* Used to mark that this node was reached from the second start node, if applicable */
NPF_FLAG_LAST_SIGNAL_RED , /* Used to mark that the last signal on this path was red */
} NPFNodeFlag ;
2005-01-31 11:23:10 +00:00
typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */
uint best_bird_dist ; /* The best heuristic found. Is 0 if the target was found */
uint best_path_dist ; /* The shortest path. Is (uint)-1 if no path is found */
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
Trackdir best_trackdir ; /* The trackdir that leads to the shortest path/closest birds dist */
2005-01-31 11:23:10 +00:00
AyStarNode node ; /* The node within the target the search led us to */
} NPFFoundTargetData ;
/* These functions below are _not_ re-entrant, in favor of speed! */
/* Will search from the given tile and direction, for a route to the given
* station for the given transport type . See the declaration of
* NPFFoundTargetData above for the meaning of the result . */
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
NPFFoundTargetData NPFRouteToStationOrTile ( TileIndex tile , Trackdir trackdir , NPFFindStationOrTileData * target , TransportType type , Owner owner , RailType railtype ) ;
2006-02-01 06:32:03 +00:00
2005-01-31 11:23:10 +00:00
/* Will search as above, but with two start nodes, the second being the
2005-03-08 19:54:10 +00:00
* reverse . Look at the NPF_FLAG_REVERSE flag in the result node to see which
* direction was taken ( NPFGetBit ( result . node , NPF_FLAG_REVERSE ) ) */
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
NPFFoundTargetData NPFRouteToStationOrTileTwoWay ( TileIndex tile1 , Trackdir trackdir1 , TileIndex tile2 , Trackdir trackdir2 , NPFFindStationOrTileData * target , TransportType type , Owner owner , RailType railtype ) ;
2005-01-31 11:23:10 +00:00
/* Will search a route to the closest depot. */
/* Search using breadth first. Good for little track choice and inaccurate
2005-05-07 22:00:36 +00:00
* heuristic , such as railway / road . */
2005-07-03 13:02:54 +00:00
NPFFoundTargetData NPFRouteToDepotBreadthFirst ( TileIndex tile , Trackdir trackdir , TransportType type , Owner owner , RailType railtype ) ;
2005-05-07 22:00:36 +00:00
/* Same as above but with two start nodes, the second being the reverse. Call
* NPFGetBit ( result . node , NPF_FLAG_REVERSE ) to see from which node the path
* orginated . All pathfs from the second node will have the given
* reverse_penalty applied ( NPF_TILE_LENGTH is the equivalent of one full
* tile ) .
*/
2005-07-03 13:02:54 +00:00
NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay ( TileIndex tile1 , Trackdir trackdir1 , TileIndex tile2 , Trackdir trackdir2 , TransportType type , Owner owner , RailType railtype , uint reverse_penalty ) ;
2005-01-31 11:23:10 +00:00
/* Search by trying each depot in order of Manhattan Distance. Good for lots
2005-02-06 22:36:08 +00:00
* of choices and accurate heuristics , such as water . */
2005-07-03 13:02:54 +00:00
NPFFoundTargetData NPFRouteToDepotTrialError ( TileIndex tile , Trackdir trackdir , TransportType type , Owner owner , RailType railtype ) ;
2005-01-31 11:23:10 +00:00
void NPFFillWithOrderData ( NPFFindStationOrTileData * fstd , Vehicle * v ) ;
2005-03-08 19:54:10 +00:00
/*
* Functions to manipulate the various NPF related flags on an AyStarNode .
*/
/**
* Returns the current value of the given flag on the given AyStarNode .
*/
static inline bool NPFGetFlag ( const AyStarNode * node , NPFNodeFlag flag )
{
return HASBIT ( node - > user_data [ NPF_NODE_FLAGS ] , flag ) ;
}
/**
* Sets the given flag on the given AyStarNode to the given value .
*/
static inline void NPFSetFlag ( AyStarNode * node , NPFNodeFlag flag , bool value )
{
if ( value )
SETBIT ( node - > user_data [ NPF_NODE_FLAGS ] , flag ) ;
else
CLRBIT ( node - > user_data [ NPF_NODE_FLAGS ] , flag ) ;
}
2005-09-18 20:56:44 +00:00
# endif /* NPF_H */