8 #include "tunnel_map.h" |
8 #include "tunnel_map.h" |
9 |
9 |
10 /* XXX: Below 3 tables store duplicate data. Maybe remove some? */ |
10 /* XXX: Below 3 tables store duplicate data. Maybe remove some? */ |
11 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
11 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
12 * direction along with the trackdir */ |
12 * direction along with the trackdir */ |
13 const byte _signal_along_trackdir[] = { |
13 extern const byte _signal_along_trackdir[] = { |
14 0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, |
14 0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0, |
15 0x40, 0x40, 0x40, 0x10, 0x80, 0x20 |
15 0x40, 0x40, 0x40, 0x10, 0x80, 0x20 |
16 }; |
16 }; |
17 |
17 |
18 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
18 /* Maps a trackdir to the bit that stores its status in the map arrays, in the |
19 * direction against the trackdir */ |
19 * direction against the trackdir */ |
20 const byte _signal_against_trackdir[] = { |
20 extern const byte _signal_against_trackdir[] = { |
21 0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, |
21 0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0, |
22 0x80, 0x80, 0x80, 0x20, 0x40, 0x10 |
22 0x80, 0x80, 0x80, 0x20, 0x40, 0x10 |
23 }; |
23 }; |
24 |
24 |
25 /* Maps a Track to the bits that store the status of the two signals that can |
25 /* Maps a Track to the bits that store the status of the two signals that can |
26 * be present on the given track */ |
26 * be present on the given track */ |
27 const byte _signal_on_track[] = { |
27 extern const byte _signal_on_track[] = { |
28 0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30 |
28 0xC0, 0xC0, 0xC0, 0x30, 0xC0, 0x30 |
29 }; |
29 }; |
30 |
30 |
31 /* Maps a diagonal direction to the all trackdirs that are connected to any |
31 /* Maps a diagonal direction to the all trackdirs that are connected to any |
32 * track entering in this direction (including those making 90 degree turns) |
32 * track entering in this direction (including those making 90 degree turns) |
33 */ |
33 */ |
34 const TrackdirBits _exitdir_reaches_trackdirs[] = { |
34 extern const TrackdirBits _exitdir_reaches_trackdirs[] = { |
35 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */ |
35 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, /* DIAGDIR_NE */ |
36 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ |
36 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, /* DIAGDIR_SE */ |
37 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ |
37 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, /* DIAGDIR_SW */ |
38 TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ |
38 TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W /* DIAGDIR_NW */ |
39 }; |
39 }; |
40 |
40 |
41 const Trackdir _next_trackdir[] = { |
41 extern const Trackdir _next_trackdir[] = { |
42 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, |
42 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, |
43 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N |
43 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N |
44 }; |
44 }; |
45 |
45 |
46 /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ |
46 /* Maps a trackdir to all trackdirs that make 90 deg turns with it. */ |
47 const TrackdirBits _track_crosses_trackdirs[] = { |
47 extern const TrackdirBits _track_crosses_trackdirs[] = { |
48 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ |
48 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, /* TRACK_X */ |
49 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ |
49 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, /* TRACK_Y */ |
50 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ |
50 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_UPPER */ |
51 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ |
51 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, /* TRACK_LOWER */ |
52 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ |
52 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, /* TRACK_LEFT */ |
53 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E /* TRACK_RIGHT */ |
53 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E /* TRACK_RIGHT */ |
54 }; |
54 }; |
55 |
55 |
56 /* Maps a track to all tracks that make 90 deg turns with it. */ |
56 /* Maps a track to all tracks that make 90 deg turns with it. */ |
57 const TrackBits _track_crosses_tracks[] = { |
57 extern const TrackBits _track_crosses_tracks[] = { |
58 TRACK_BIT_Y, /* TRACK_X */ |
58 TRACK_BIT_Y, /* TRACK_X */ |
59 TRACK_BIT_X, /* TRACK_Y */ |
59 TRACK_BIT_X, /* TRACK_Y */ |
60 TRACK_BIT_VERT, /* TRACK_UPPER */ |
60 TRACK_BIT_VERT, /* TRACK_UPPER */ |
61 TRACK_BIT_VERT, /* TRACK_LOWER */ |
61 TRACK_BIT_VERT, /* TRACK_LOWER */ |
62 TRACK_BIT_HORZ, /* TRACK_LEFT */ |
62 TRACK_BIT_HORZ, /* TRACK_LEFT */ |
63 TRACK_BIT_HORZ /* TRACK_RIGHT */ |
63 TRACK_BIT_HORZ /* TRACK_RIGHT */ |
64 }; |
64 }; |
65 |
65 |
66 /* Maps a trackdir to the (4-way) direction the tile is exited when following |
66 /* Maps a trackdir to the (4-way) direction the tile is exited when following |
67 * that trackdir */ |
67 * that trackdir */ |
68 const DiagDirection _trackdir_to_exitdir[] = { |
68 extern const DiagDirection _trackdir_to_exitdir[] = { |
69 DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE, |
69 DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_NE,DIAGDIR_SE,DIAGDIR_SW,DIAGDIR_SE, DIAGDIR_NE,DIAGDIR_NE, |
70 DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE, |
70 DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NW,DIAGDIR_SW,DIAGDIR_NW,DIAGDIR_NE, |
71 }; |
71 }; |
72 |
72 |
73 const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = { |
73 extern const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = { |
74 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR}, |
74 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR}, |
75 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
75 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
76 {TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W}, |
76 {TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W}, |
77 {INVALID_TRACKDIR, TRACKDIR_LOWER_E, TRACKDIR_LOWER_W, INVALID_TRACKDIR}, |
77 {INVALID_TRACKDIR, TRACKDIR_LOWER_E, TRACKDIR_LOWER_W, INVALID_TRACKDIR}, |
78 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, TRACKDIR_LEFT_N}, |
78 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, TRACKDIR_LEFT_N}, |
79 {TRACKDIR_RIGHT_N, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR} |
79 {TRACKDIR_RIGHT_N, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR} |
80 }; |
80 }; |
81 |
81 |
82 const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace magic with enums |
82 extern const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = { // TODO: replace magic with enums |
83 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR}, |
83 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR}, |
84 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
84 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
85 {INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR}, |
85 {INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR}, |
86 {TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W}, |
86 {TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W}, |
87 {TRACKDIR_LEFT_N, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
87 {TRACKDIR_LEFT_N, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
88 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N} |
88 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N} |
89 }; |
89 }; |
90 |
90 |
91 const Trackdir _track_direction_to_trackdir[][DIR_END] = { |
91 extern const Trackdir _track_direction_to_trackdir[][DIR_END] = { |
92 {INVALID_TRACKDIR, TRACKDIR_X_NE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
92 {INVALID_TRACKDIR, TRACKDIR_X_NE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
93 {INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
93 {INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_NW}, |
94 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W, INVALID_TRACKDIR}, |
94 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W, INVALID_TRACKDIR}, |
95 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W, INVALID_TRACKDIR}, |
95 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W, INVALID_TRACKDIR}, |
96 {TRACKDIR_LEFT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
96 {TRACKDIR_LEFT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR}, |
97 {TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR} |
97 {TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR} |
98 }; |
98 }; |
99 |
99 |
100 const Trackdir _dir_to_diag_trackdir[] = { |
100 extern const Trackdir _dir_to_diag_trackdir[] = { |
101 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW, |
101 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW, |
102 }; |
102 }; |
103 |
103 |
104 |
104 |
105 RailType GetTileRailType(TileIndex tile, Trackdir trackdir) |
105 RailType GetTileRailType(TileIndex tile, Track track) |
106 { |
106 { |
107 switch (GetTileType(tile)) { |
107 switch (GetTileType(tile)) { |
108 case MP_RAILWAY: |
108 case MP_RAILWAY: |
109 return GetRailType(tile); |
109 return GetRailType(tile); |
110 |
110 |