OpenTTD Source: src/table/track_data.h Source File

OpenTTD Source 15.3

track_data.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10/* Maps a diagonal direction to the all trackdirs that are connected to any
11 * track entering in this direction (including those making 90 degree turns)
12 */
13extern const TrackdirBits _exitdir_reaches_trackdirs[] = {
14 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_LOWER_E | TRACKDIR_BIT_LEFT_N, // DIAGDIR_NE
15 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_LEFT_S | TRACKDIR_BIT_UPPER_E, // DIAGDIR_SE
16 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_RIGHT_S, // DIAGDIR_SW
17 TRACKDIR_BIT_Y_NW | TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_LOWER_W // DIAGDIR_NW
18};
19
20extern const Trackdir _next_trackdir[TRACKDIR_END] = {
21 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_LOWER_E, TRACKDIR_UPPER_E, TRACKDIR_RIGHT_S, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR,
22 TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_LOWER_W, TRACKDIR_UPPER_W, TRACKDIR_RIGHT_N, TRACKDIR_LEFT_N
23};
24
25/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
26extern const TrackdirBits _track_crosses_trackdirs[TRACK_END] = {
27 TRACKDIR_BIT_Y_SE | TRACKDIR_BIT_Y_NW, // TRACK_X
28 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_X_SW, // TRACK_Y
29 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, // TRACK_UPPER
30 TRACKDIR_BIT_RIGHT_N | TRACKDIR_BIT_RIGHT_S | TRACKDIR_BIT_LEFT_N | TRACKDIR_BIT_LEFT_S, // TRACK_LOWER
31 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E, // TRACK_LEFT
32 TRACKDIR_BIT_UPPER_W | TRACKDIR_BIT_UPPER_E | TRACKDIR_BIT_LOWER_W | TRACKDIR_BIT_LOWER_E // TRACK_RIGHT
33};
34
35/* Maps a track to all tracks that make 90 deg turns with it. */
36extern const TrackBits _track_crosses_tracks[] = {
37 TRACK_BIT_Y, // TRACK_X
38 TRACK_BIT_X, // TRACK_Y
39 TRACK_BIT_VERT, // TRACK_UPPER
40 TRACK_BIT_VERT, // TRACK_LOWER
41 TRACK_BIT_HORZ, // TRACK_LEFT
42 TRACK_BIT_HORZ // TRACK_RIGHT
43};
44
45/* Maps a trackdir to the (4-way) direction the tile is exited when following
46 * that trackdir */
47extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END] = {
48 DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_SE, DIAGDIR_NE, DIAGDIR_NE,
49 DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE,
50};
51
52extern const Trackdir _track_exitdir_to_trackdir[][DIAGDIR_END] = {
53 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
54 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
55 {TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W},
56 {INVALID_TRACKDIR, TRACKDIR_LOWER_E, TRACKDIR_LOWER_W, INVALID_TRACKDIR},
57 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, TRACKDIR_LEFT_N},
58 {TRACKDIR_RIGHT_N, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR}
59};
60
61extern const Trackdir _track_enterdir_to_trackdir[][DIAGDIR_END] = {
62 {TRACKDIR_X_NE, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR},
63 {INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, TRACKDIR_Y_NW},
64 {INVALID_TRACKDIR, TRACKDIR_UPPER_E, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
65 {TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W},
66 {TRACKDIR_LEFT_N, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR},
67 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, TRACKDIR_RIGHT_N}
68};
69
70extern const Trackdir _track_direction_to_trackdir[][DIR_END] = {
71 {INVALID_TRACKDIR, TRACKDIR_X_NE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_X_SW, INVALID_TRACKDIR, INVALID_TRACKDIR},
72 {INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_SE, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_Y_NW},
73 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_UPPER_W, INVALID_TRACKDIR},
74 {INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_E, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LOWER_W, INVALID_TRACKDIR},
75 {TRACKDIR_LEFT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_LEFT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR},
76 {TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR, TRACKDIR_RIGHT_S, INVALID_TRACKDIR, INVALID_TRACKDIR, INVALID_TRACKDIR}
77};
78
79extern const Trackdir _dir_to_diag_trackdir[] = {
80 TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
81};
82
83extern const TrackBits _corner_to_trackbits[] = {
84 TRACK_BIT_LEFT, TRACK_BIT_LOWER, TRACK_BIT_RIGHT, TRACK_BIT_UPPER,
85};
86
87extern const TrackdirBits _uphill_trackdirs[] = {
88 TRACKDIR_BIT_NONE ,
89 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW,
90 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE,
91 TRACKDIR_BIT_X_SW ,
92 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE,
93 TRACKDIR_BIT_NONE ,
94 TRACKDIR_BIT_Y_SE ,
95 TRACKDIR_BIT_NONE ,
96 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW,
97 TRACKDIR_BIT_Y_NW ,
98 TRACKDIR_BIT_NONE ,
99 TRACKDIR_BIT_NONE ,
100 TRACKDIR_BIT_X_NE ,
101 TRACKDIR_BIT_NONE ,
102 TRACKDIR_BIT_NONE ,
103 TRACKDIR_BIT_NONE ,
104 TRACKDIR_BIT_NONE ,
105 TRACKDIR_BIT_NONE ,
106 TRACKDIR_BIT_NONE ,
107 TRACKDIR_BIT_NONE ,
108 TRACKDIR_BIT_NONE ,
109 TRACKDIR_BIT_NONE ,
110 TRACKDIR_BIT_NONE ,
111 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_SE,
112 TRACKDIR_BIT_NONE ,
113 TRACKDIR_BIT_NONE ,
114 TRACKDIR_BIT_NONE ,
115 TRACKDIR_BIT_X_SW | TRACKDIR_BIT_Y_NW,
116 TRACKDIR_BIT_NONE ,
117 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_NW,
118 TRACKDIR_BIT_X_NE | TRACKDIR_BIT_Y_SE,
119};
DIR_END
@ DIR_END
Used to iterate.
Definition direction_type.h:34
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition direction_type.h:81
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition direction_type.h:84
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition direction_type.h:82
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition track_type.h:39
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition track_type.h:41
TRACK_BIT_Y
@ TRACK_BIT_Y
Y-axis track.
Definition track_type.h:38
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition track_type.h:44
TRACK_BIT_X
@ TRACK_BIT_X
X-axis track.
Definition track_type.h:37
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition track_type.h:40
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition track_type.h:42
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition track_type.h:45
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition track_type.h:66
TRACKDIR_X_NE
@ TRACKDIR_X_NE
X-axis and direction to north-east.
Definition track_type.h:68
TRACKDIR_LOWER_E
@ TRACKDIR_LOWER_E
Lower track and direction to east.
Definition track_type.h:71
TRACKDIR_RIGHT_N
@ TRACKDIR_RIGHT_N
Right track and direction to north.
Definition track_type.h:81
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition track_type.h:85
TRACKDIR_UPPER_E
@ TRACKDIR_UPPER_E
Upper track and direction to east.
Definition track_type.h:70
TRACKDIR_Y_SE
@ TRACKDIR_Y_SE
Y-axis and direction to south-east.
Definition track_type.h:69
TRACKDIR_LEFT_S
@ TRACKDIR_LEFT_S
Left track and direction to south.
Definition track_type.h:72
TRACKDIR_UPPER_W
@ TRACKDIR_UPPER_W
Upper track and direction to west.
Definition track_type.h:78
TRACKDIR_X_SW
@ TRACKDIR_X_SW
X-axis and direction to south-west.
Definition track_type.h:76
TRACKDIR_LOWER_W
@ TRACKDIR_LOWER_W
Lower track and direction to west.
Definition track_type.h:79
TRACKDIR_Y_NW
@ TRACKDIR_Y_NW
Y-axis and direction to north-west.
Definition track_type.h:77
TRACKDIR_END
@ TRACKDIR_END
Used for iterations.
Definition track_type.h:84
TRACKDIR_RIGHT_S
@ TRACKDIR_RIGHT_S
Right track and direction to south.
Definition track_type.h:73
TRACKDIR_LEFT_N
@ TRACKDIR_LEFT_N
Left track and direction to north.
Definition track_type.h:80
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition track_type.h:97
TRACKDIR_BIT_LEFT_S
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
Definition track_type.h:103
TRACKDIR_BIT_Y_NW
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
Definition track_type.h:107
TRACKDIR_BIT_UPPER_E
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
Definition track_type.h:101
TRACKDIR_BIT_X_NE
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
Definition track_type.h:99
TRACKDIR_BIT_LOWER_E
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
Definition track_type.h:102
TRACKDIR_BIT_LEFT_N
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
Definition track_type.h:110
TRACKDIR_BIT_RIGHT_S
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
Definition track_type.h:104
TRACKDIR_BIT_Y_SE
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
Definition track_type.h:100
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition track_type.h:98
TRACKDIR_BIT_RIGHT_N
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
Definition track_type.h:111
TRACKDIR_BIT_UPPER_W
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
Definition track_type.h:108
TRACKDIR_BIT_LOWER_W
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
Definition track_type.h:109
TRACKDIR_BIT_X_SW
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
Definition track_type.h:106
TRACK_END
@ TRACK_END
Used for iterations.
Definition track_type.h:27