rail.c
changeset 1942 c5d5cf5b0263
child 1944 dd9cba5fab2a
equal deleted inserted replaced
1941:ca268f8837df 1942:c5d5cf5b0263
       
     1 #include "rail.h"
       
     2 
       
     3 /* Maps a trackdir to the bit that stores its status in the map arrays, in the
       
     4  * direction along with the trackdir */
       
     5 const byte _signal_along_trackdir[] = {
       
     6 	0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0,
       
     7 	0x40, 0x40, 0x40, 0x10, 0x80, 0x20
       
     8 };
       
     9 
       
    10 /* Maps a trackdir to the bit that stores its status in the map arrays, in the
       
    11  * direction against the trackdir */
       
    12 const byte _signal_against_trackdir[] = {
       
    13 	0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0,
       
    14 	0x80, 0x80, 0x80, 0x20, 0x40, 0x10
       
    15 };
       
    16 
       
    17 /* Maps a Track to the bits that store the status of the two signals that can
       
    18  * be present on the given track */
       
    19 const byte _signal_on_track[] = {
       
    20 	0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30
       
    21 };
       
    22 
       
    23 /* Maps a diagonal direction to the all trackdirs that are connected to any
       
    24  * track entering in this direction (including those making 90 degree turns)
       
    25  */
       
    26 const TrackdirBits _exitdir_reaches_trackdirs[] = {
       
    27 	TRACKDIR_BIT_DIAG1_NE|TRACKDIR_BIT_LOWER_E|TRACKDIR_BIT_LEFT_N,  /* DIAGDIR_NE */
       
    28 	TRACKDIR_BIT_DIAG2_SE|TRACKDIR_BIT_LEFT_S |TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */
       
    29 	TRACKDIR_BIT_DIAG1_SW|TRACKDIR_BIT_UPPER_W|TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */
       
    30 	TRACKDIR_BIT_DIAG2_NW|TRACKDIR_BIT_RIGHT_N|TRACKDIR_BIT_LOWER_W  /* DIAGDIR_NW */
       
    31 };
       
    32 
       
    33 /* TODO: Remove magic numbers from tables below just like
       
    34  * _exitdir_reaches_trackdirs[] */
       
    35 
       
    36 const Trackdir _next_trackdir[14] = {
       
    37 	0,  1,  3,  2,  5,  4, 0, 0,
       
    38 	8,  9,  11, 10, 13, 12
       
    39 };
       
    40 
       
    41 /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
       
    42 const TrackdirBits _trackdir_crosses_trackdirs[] = {
       
    43 	0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C, 0, 0,
       
    44 	0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C
       
    45 };
       
    46 
       
    47 /* Maps a track to all tracks that make 90 deg turns with it. */
       
    48 const TrackBits _track_crosses_tracks[] = {
       
    49 	0x2, /* Track 1 -> Track 2 */
       
    50 	0x1, /* Track 2 -> Track 1 */
       
    51 	0x30, /* Upper -> Left | Right */
       
    52 	0x30, /* Lower -> Left | Right */
       
    53 	0x0C, /* Left -> Upper | Lower */
       
    54 	0x0C, /* Right -> Upper | Lower */
       
    55 };
       
    56 
       
    57 /* Maps a trackdir to the (4-way) direction the tile is exited when following
       
    58  * that trackdir */
       
    59 const DiagDirection _trackdir_to_exitdir[] = {
       
    60 	0,1,0,1,2,1, 0,0,
       
    61 	2,3,3,2,3,0,
       
    62 };
       
    63 
       
    64 const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
       
    65 	{0,    0xff, 8,    0xff},
       
    66 	{0xff, 1,    0xff, 9},
       
    67 	{2,    0xff, 0xff, 10},
       
    68 	{0xff, 3,    11,   0xf},
       
    69 	{0xff, 0xff, 4,    12},
       
    70 	{13,   5,    0xff, 0xff}
       
    71 };
       
    72 
       
    73 const Trackdir _track_direction_to_trackdir[][DIR_END] = {
       
    74 	{0xff, 0,    0xff, 0xff, 0xff, 8,    0xff, 0xff},
       
    75 	{0xff, 0xff, 0xff, 1,    0xff, 0xff, 0xff, 9},
       
    76 	{0xff, 0xff, 2,    0xff, 0xff, 0xff, 10,   0xff},
       
    77 	{0xff, 0xff, 3,    0xff, 0xff, 0xff, 11,   0xff},
       
    78 	{12,   0xff, 0xff, 0xff, 4,    0xff, 0xff, 0xff},
       
    79 	{13,   0xff, 0xff, 0xff, 5,    0xff, 0xff, 0xff}
       
    80 };
       
    81 
       
    82 const Trackdir _dir_to_diag_trackdir[] = {
       
    83 	0, 1, 8, 9,
       
    84 };
       
    85 
       
    86 const DiagDirection _reverse_diagdir[] = {
       
    87 	2, 3, 0, 1
       
    88 };
       
    89 
       
    90 const Trackdir _reverse_trackdir[] = {
       
    91 	8, 9, 10, 11, 12, 13, 0xFF, 0xFF,
       
    92 	0, 1, 2,  3,  4,  5
       
    93 };