diff options
author | matthijs <matthijs@openttd.org> | 2005-06-16 18:04:02 +0000 |
---|---|---|
committer | matthijs <matthijs@openttd.org> | 2005-06-16 18:04:02 +0000 |
commit | 9cb58e0bb3799224f48a6c9e278b288551c59bec (patch) | |
tree | 13bfcb2e646ad2b6e44031f7353f93fe0551bc96 /npf.h | |
parent | fc5784a3103d5e4fc0dbfec5f905a6ebbfd9c84b (diff) | |
download | openttd-9cb58e0bb3799224f48a6c9e278b288551c59bec.tar.xz |
(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.
Diffstat (limited to 'npf.h')
-rw-r--r-- | npf.h | 107 |
1 files changed, 8 insertions, 99 deletions
@@ -1,11 +1,11 @@ #ifndef NPF_H #define NPF_H -/* Blaat */ - #include "openttd.h" #include "aystar.h" #include "vehicle.h" +#include "tile.h" +#include "rail.h" //mowing grass enum { @@ -50,7 +50,7 @@ typedef enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() 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 */ - byte best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ + Trackdir best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */ AyStarNode node; /* The node within the target the search led us to */ } NPFFoundTargetData; @@ -59,27 +59,27 @@ typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */ /* 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. */ -NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner); +NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, Trackdir trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner); /* Will search as above, but with two start nodes, the second being the * reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which * direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */ -NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner); +NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, Trackdir trackdir1, TileIndex tile2, Trackdir trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner); /* Will search a route to the closest depot. */ /* Search using breadth first. Good for little track choice and inaccurate * heuristic, such as railway/road.*/ -NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type, Owner owner); +NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner); /* 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). */ -NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, TransportType type, Owner owner, uint reverse_penalty); +NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, Trackdir trackdir1, TileIndex tile2, Trackdir trackdir2, TransportType type, Owner owner, uint reverse_penalty); /* Search by trying each depot in order of Manhattan Distance. Good for lots * of choices and accurate heuristics, such as water. */ -NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type, Owner owner); +NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, Trackdir trackdir, TransportType type, Owner owner); void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v); @@ -107,95 +107,4 @@ static inline void NPFSetFlag(AyStarNode* node, NPFNodeFlag flag, bool value) CLRBIT(node->user_data[NPF_NODE_FLAGS], flag); } -/* - * Some tables considering tracks, directions and signals. - * XXX: Better place to but these? - */ - -/** - * Maps a trackdir to the bit that stores its status in the map arrays, in the - * direction along with the trackdir. - */ -const byte _signal_along_trackdir[14]; - -/** - * Maps a trackdir to the bit that stores its status in the map arrays, in the - * direction against the trackdir. - */ -const byte _signal_against_trackdir[14]; - -/** - * Maps a trackdir to the trackdirs that can be reached from it (ie, when - * entering the next tile. - */ -const uint16 _trackdir_reaches_trackdirs[14]; - -/** - * Maps a trackdir to the trackdir that you will end up on if you go straight - * ahead. This will be the same trackdir for diagonal trackdirs, but a - * different (alternating) one for straight trackdirs */ -const uint16 _next_trackdir[14]; -/** - * Maps a trackdir to all trackdirs that make 90 deg turns with it. - */ -const uint16 _trackdir_crosses_trackdirs[14]; - -/** - * Maps a track to all tracks that make 90 deg turns with it. - */ -const byte _track_crosses_tracks[6]; - -/** - * Maps a trackdir to the (4-way) direction the tile is exited when following - * that trackdir. - */ -const byte _trackdir_to_exitdir[14]; - -/** - * Maps a track and an (4-way) dir to the trackdir that represents the track - * with the exit in the given direction. - */ -const byte _track_exitdir_to_trackdir[6][4]; - -/** - * Maps a track and a full (8-way) direction to the trackdir that represents - * the track running in the given direction. - */ -const byte _track_direction_to_trackdir[6][8]; - -/** - * Maps a (4-way) direction to the diagonal track that runs in that - * direction. - */ -const byte _dir_to_diag_trackdir[4]; - -/** - * Maps a (4-way) direction to the reverse. - */ -const byte _reverse_dir[4]; - -/** - * Maps a trackdir to the reverse trackdir. - */ -const byte _reverse_trackdir[14]; - -/* Returns the Track that a given Trackdir represents */ -static inline byte TrackdirToTrack(byte trackdir) { return trackdir & 0x7; } - -/* Returns a Trackdir for the given Track. Since every Track corresponds to - * two Trackdirs, we choose the one which points between N and SE. - * Note that the actual implementation is quite futile, but this might change - * in the future. - */ -static inline byte TrackToTrackdir(byte track) { return track; } - -/* Checks if a given Track is diagonal */ -static inline bool IsDiagonalTrack(byte track) { return track == 0x0 || track == 0x1; } - -/* Checks if a given Trackdir is diagonal. */ -static inline bool IsDiagonalTrackdir(byte trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); } - - -#define REVERSE_TRACKDIR(trackdir) (trackdir ^ 0x8) - #endif // NPF_H |