diff options
author | tron <tron@openttd.org> | 2006-03-05 12:34:55 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2006-03-05 12:34:55 +0000 |
commit | 586388c9f17a39b4d3a7e7706fe6b40191a922b4 (patch) | |
tree | 113bde0444e78799f198050654eba4d96e28702e | |
parent | f007ad282c60cc1b2529b44c3e0b4c1bdab3d685 (diff) | |
download | openttd-586388c9f17a39b4d3a7e7706fe6b40191a922b4.tar.xz |
(svn r3767) Move all direction related enums and functions to a separate header
-rw-r--r-- | depot.h | 1 | ||||
-rw-r--r-- | direction.h | 49 | ||||
-rw-r--r-- | npf.c | 8 | ||||
-rw-r--r-- | rail.c | 4 | ||||
-rw-r--r-- | rail.h | 16 | ||||
-rw-r--r-- | ship_cmd.c | 6 | ||||
-rw-r--r-- | tile.h | 35 |
7 files changed, 58 insertions, 61 deletions
@@ -6,6 +6,7 @@ /** @file depot.h Header files for depots (not hangars) * @see depot.c */ +#include "direction.h" #include "pool.h" #include "tile.h" #include "variables.h" diff --git a/direction.h b/direction.h new file mode 100644 index 000000000..0300db8a9 --- /dev/null +++ b/direction.h @@ -0,0 +1,49 @@ +/* $Id$ */ + +#ifndef DIRECTION_H +#define DIRECTION_H + +/* Direction as commonly used in v->direction, 8 way. */ +typedef enum Direction { + DIR_N = 0, + DIR_NE = 1, /* Northeast, upper right on your monitor */ + DIR_E = 2, + DIR_SE = 3, + DIR_S = 4, + DIR_SW = 5, + DIR_W = 6, + DIR_NW = 7, + DIR_END, + INVALID_DIR = 0xFF, +} Direction; + + +/* Direction commonly used as the direction of entering and leaving tiles, 4-way */ +typedef enum DiagDirection { + DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ + DIAGDIR_SE = 1, + DIAGDIR_SW = 2, + DIAGDIR_NW = 3, + DIAGDIR_END, + INVALID_DIAGDIR = 0xFF, +} DiagDirection; + +static inline DiagDirection ReverseDiagDir(DiagDirection d) +{ + return 2 ^ d; +} + + +static inline DiagDirection DirToDiagdir(Direction dir) +{ + return (DiagDirection)(dir >> 1); +} + + +/* the 2 axis */ +typedef enum Axis { + AXIS_X = 0, + AXIS_Y = 1 +} Axis; + +#endif @@ -162,11 +162,11 @@ static uint NPFTunnelCost(AyStarNode* current) { DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction); TileIndex tile = current->tile; - if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagdir(exitdir)) { + if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagDir(exitdir)) { /* We just popped out if this tunnel, since were * facing the tunnel exit */ FindLengthOfTunnelResult flotr; - flotr = FindLengthOfTunnel(tile, ReverseDiagdir(exitdir)); + flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); return flotr.length * NPF_TILE_LENGTH; //TODO: Penalty for tunnels? } else { @@ -543,7 +543,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current) * otherwise (only for trains, since only with trains you can * (sometimes) reach tiles after reversing that you couldn't reach * without reversing. */ - if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL) { + if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir)) && type == TRANSPORT_RAIL) { /* We are headed inwards. We can only reverse here, so we'll not * consider this direction, but jump ahead to the reverse direction. * It would be nicer to return one neighbour here (the reverse @@ -596,7 +596,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current) * orientation. They are only "inwards", since we are reaching this tile * from some other tile. This prevents vehicles driving into depots from * the back */ - ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagdir(exitdir))); + ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagDir(exitdir))); } else { ts = GetTileTrackStatus(dst_tile, type); } @@ -99,10 +99,6 @@ const Trackdir _dir_to_diag_trackdir[] = { TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW, }; -const DiagDirection _reverse_diagdir[] = { - DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE -}; - const Trackdir _reverse_trackdir[] = { TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_UPPER_W, TRACKDIR_LOWER_W, TRACKDIR_LEFT_N, TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_UPPER_E, TRACKDIR_LOWER_E, TRACKDIR_LEFT_S, TRACKDIR_RIGHT_S @@ -5,6 +5,7 @@ #ifndef RAIL_H #define RAIL_H +#include "direction.h" #include "tile.h" /* @@ -464,21 +465,6 @@ static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) { return _track_crosses_trackdirs[TrackdirToTrack(trackdir)]; } -/** - * Maps a (4-way) direction to the reverse. - */ -static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) { - extern const DiagDirection _reverse_diagdir[DIAGDIR_END]; - return _reverse_diagdir[diagdir]; -} - -/** - * Maps a (8-way) direction to a (4-way) DiagDirection - */ -static inline DiagDirection DirToDiagdir(Direction dir) { - assert(dir < DIR_END); - return (DiagDirection)(dir >> 1); -} /* Checks if a given Track is diagonal */ static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); } diff --git a/ship_cmd.c b/ship_cmd.c index 31e195dd6..d12d36ae7 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -537,7 +537,7 @@ static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks if (_patches.new_pathfinding_all) { NPFFindStationOrTileData fstd; NPFFoundTargetData ftd; - TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagdir(enterdir))); + TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir))); byte trackdir = GetVehicleTrackdir(v); assert (trackdir != 0xFF); /* Check that we are not in a depot */ @@ -564,9 +564,9 @@ static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks tot_dist = (uint)-1; /* Let's find out how far it would be if we would reverse first */ - b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagdir(enterdir)] & v->u.ship.state; + b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagDir(enterdir)] & v->u.ship.state; if (b != 0) { - dist = FindShipTrack(v, tile2, ReverseDiagdir(enterdir), b, tile, &track); + dist = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track); if (dist != (uint)-1) tot_dist = dist + 1; } @@ -20,41 +20,6 @@ typedef enum TileTypes { MP_UNMOVABLE, } TileType; -/* Direction as commonly used in v->direction, 8 way. */ -typedef enum Directions { - DIR_N = 0, - DIR_NE = 1, /* Northeast, upper right on your monitor */ - DIR_E = 2, - DIR_SE = 3, - DIR_S = 4, - DIR_SW = 5, - DIR_W = 6, - DIR_NW = 7, - DIR_END, - INVALID_DIR = 0xFF, -} Direction; - -/* Direction commonly used as the direction of entering and leaving tiles, 4-way */ -typedef enum DiagonalDirections { - DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */ - DIAGDIR_SE = 1, - DIAGDIR_SW = 2, - DIAGDIR_NW = 3, - DIAGDIR_END, - INVALID_DIAGDIR = 0xFF, -} DiagDirection; - -static inline DiagDirection ReverseDiagDir(DiagDirection d) -{ - return 2 ^ d; -} - - -/* the 2 axis */ -typedef enum Axis { - AXIS_X = 0, - AXIS_Y = 1 -} Axis; void SetMapExtraBits(TileIndex tile, byte flags); uint GetMapExtraBits(TileIndex tile); |