summaryrefslogtreecommitdiff
path: root/rail.c
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2005-06-16 18:04:02 +0000
committermatthijs <matthijs@openttd.org>2005-06-16 18:04:02 +0000
commit9cb58e0bb3799224f48a6c9e278b288551c59bec (patch)
tree13bfcb2e646ad2b6e44031f7353f93fe0551bc96 /rail.c
parentfc5784a3103d5e4fc0dbfec5f905a6ebbfd9c84b (diff)
downloadopenttd-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 'rail.c')
-rw-r--r--rail.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/rail.c b/rail.c
new file mode 100644
index 000000000..24f383b50
--- /dev/null
+++ b/rail.c
@@ -0,0 +1,93 @@
+#include "rail.h"
+
+/* 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[] = {
+ 0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0,
+ 0x40, 0x40, 0x40, 0x10, 0x80, 0x20
+};
+
+/* 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[] = {
+ 0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0,
+ 0x80, 0x80, 0x80, 0x20, 0x40, 0x10
+};
+
+/* Maps a Track to the bits that store the status of the two signals that can
+ * be present on the given track */
+const byte _signal_on_track[] = {
+ 0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30
+};
+
+/* Maps a diagonal direction to the all trackdirs that are connected to any
+ * track entering in this direction (including those making 90 degree turns)
+ */
+const TrackdirBits _exitdir_reaches_trackdirs[] = {
+ TRACKDIR_BIT_DIAG1_NE|TRACKDIR_BIT_LOWER_E|TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */
+ TRACKDIR_BIT_DIAG2_SE|TRACKDIR_BIT_LEFT_S |TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */
+ TRACKDIR_BIT_DIAG1_SW|TRACKDIR_BIT_UPPER_W|TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */
+ TRACKDIR_BIT_DIAG2_NW|TRACKDIR_BIT_RIGHT_N|TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */
+};
+
+/* TODO: Remove magic numbers from tables below just like
+ * _exitdir_reaches_trackdirs[] */
+
+const Trackdir _next_trackdir[14] = {
+ 0, 1, 3, 2, 5, 4, 0, 0,
+ 8, 9, 11, 10, 13, 12
+};
+
+/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
+const TrackdirBits _trackdir_crosses_trackdirs[] = {
+ 0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C, 0, 0,
+ 0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C
+};
+
+/* Maps a track to all tracks that make 90 deg turns with it. */
+const TrackBits _track_crosses_tracks[] = {
+ 0x2, /* Track 1 -> Track 2 */
+ 0x1, /* Track 2 -> Track 1 */
+ 0x30, /* Upper -> Left | Right */
+ 0x30, /* Lower -> Left | Right */
+ 0x0C, /* Left -> Upper | Lower */
+ 0x0C, /* Right -> Upper | Lower */
+};
+
+/* Maps a trackdir to the (4-way) direction the tile is exited when following
+ * that trackdir */
+const DiagDirection _trackdir_to_exitdir[] = {
+ 0,1,0,1,2,1, 0,0,
+ 2,3,3,2,3,0,
+};
+
+const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
+ {0, 0xff, 8, 0xff},
+ {0xff, 1, 0xff, 9},
+ {2, 0xff, 0xff, 10},
+ {0xff, 3, 11, 0xf},
+ {0xff, 0xff, 4, 12},
+ {13, 5, 0xff, 0xff}
+};
+
+const Trackdir _track_direction_to_trackdir[][DIR_END] = {
+ {0xff, 0, 0xff, 0xff, 0xff, 8, 0xff, 0xff},
+ {0xff, 0xff, 0xff, 1, 0xff, 0xff, 0xff, 9},
+ {0xff, 0xff, 2, 0xff, 0xff, 0xff, 10, 0xff},
+ {0xff, 0xff, 3, 0xff, 0xff, 0xff, 11, 0xff},
+ {12, 0xff, 0xff, 0xff, 4, 0xff, 0xff, 0xff},
+ {13, 0xff, 0xff, 0xff, 5, 0xff, 0xff, 0xff}
+};
+
+const Trackdir _dir_to_diag_trackdir[] = {
+ 0, 1, 8, 9,
+};
+
+const DiagDirection _reverse_diagdir[] = {
+ 2, 3, 0, 1
+};
+
+const Trackdir _reverse_trackdir[] = {
+ 8, 9, 10, 11, 12, 13, 0xFF, 0xFF,
+ 0, 1, 2, 3, 4, 5
+};