OpenTTD: src/track_type.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

track_type.h
Go to the documentation of this file.
1 /* $Id: track_type.h 27833 2017-03-28 21:44:40Z peter1138 $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef TRACK_TYPE_H
13 #define TRACK_TYPE_H
14
15 #include "core/enum_type.hpp"
16
21 enum Track {
22 TRACK_BEGIN = 0,
23 TRACK_X = 0,
24 TRACK_Y = 1,
25 TRACK_UPPER = 2,
26 TRACK_LOWER = 3,
27 TRACK_LEFT = 4,
28 TRACK_RIGHT = 5,
29 TRACK_END,
30 INVALID_TRACK = 0xFF,
31 };
32
34 DECLARE_POSTFIX_INCREMENT(Track)
36 template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK, 3> {};
37 typedef TinyEnumT<Track> TrackByte;
38
39
41 enum TrackBits {
42 TRACK_BIT_NONE = 0U,
43 TRACK_BIT_X = 1U << TRACK_X,
44 TRACK_BIT_Y = 1U << TRACK_Y,
45 TRACK_BIT_UPPER = 1U << TRACK_UPPER,
46 TRACK_BIT_LOWER = 1U << TRACK_LOWER,
47 TRACK_BIT_LEFT = 1U << TRACK_LEFT,
48 TRACK_BIT_RIGHT = 1U << TRACK_RIGHT,
49 TRACK_BIT_CROSS = TRACK_BIT_X | TRACK_BIT_Y,
50 TRACK_BIT_HORZ = TRACK_BIT_UPPER | TRACK_BIT_LOWER,
51 TRACK_BIT_VERT = TRACK_BIT_LEFT | TRACK_BIT_RIGHT,
52 TRACK_BIT_3WAY_NE = TRACK_BIT_X | TRACK_BIT_UPPER | TRACK_BIT_RIGHT,
53 TRACK_BIT_3WAY_SE = TRACK_BIT_Y | TRACK_BIT_LOWER | TRACK_BIT_RIGHT,
54 TRACK_BIT_3WAY_SW = TRACK_BIT_X | TRACK_BIT_LOWER | TRACK_BIT_LEFT,
55 TRACK_BIT_3WAY_NW = TRACK_BIT_Y | TRACK_BIT_UPPER | TRACK_BIT_LEFT,
56 TRACK_BIT_ALL = TRACK_BIT_CROSS | TRACK_BIT_HORZ | TRACK_BIT_VERT,
57 TRACK_BIT_MASK = 0x3FU,
58 TRACK_BIT_WORMHOLE = 0x40U,
59 TRACK_BIT_DEPOT = 0x80U,
60 INVALID_TRACK_BIT = 0xFF,
61 };
62 DECLARE_ENUM_AS_BIT_SET(TrackBits)
63 typedef SimpleTinyEnumT<TrackBits, byte> TrackBitsByte;
64
74 enum Trackdir {
75 TRACKDIR_BEGIN = 0,
76 TRACKDIR_X_NE = 0,
77 TRACKDIR_Y_SE = 1,
78 TRACKDIR_UPPER_E = 2,
79 TRACKDIR_LOWER_E = 3,
80 TRACKDIR_LEFT_S = 4,
81 TRACKDIR_RIGHT_S = 5,
82 TRACKDIR_RVREV_NE = 6,
83 TRACKDIR_RVREV_SE = 7,
84 TRACKDIR_X_SW = 8,
85 TRACKDIR_Y_NW = 9,
86 TRACKDIR_UPPER_W = 10,
87 TRACKDIR_LOWER_W = 11,
88 TRACKDIR_LEFT_N = 12,
89 TRACKDIR_RIGHT_N = 13,
90 TRACKDIR_RVREV_SW = 14,
91 TRACKDIR_RVREV_NW = 15,
92 TRACKDIR_END,
93 INVALID_TRACKDIR = 0xFF,
94 };
95
97 template <> struct EnumPropsT<Trackdir> : MakeEnumPropsT<Trackdir, byte, TRACKDIR_BEGIN, TRACKDIR_END, INVALID_TRACKDIR, 4> {};
98 typedef TinyEnumT<Trackdir> TrackdirByte;
99
106 enum TrackdirBits {
107 TRACKDIR_BIT_NONE = 0U,
108 TRACKDIR_BIT_X_NE = 1U << TRACKDIR_X_NE,
109 TRACKDIR_BIT_Y_SE = 1U << TRACKDIR_Y_SE,
110 TRACKDIR_BIT_UPPER_E = 1U << TRACKDIR_UPPER_E,
111 TRACKDIR_BIT_LOWER_E = 1U << TRACKDIR_LOWER_E,
112 TRACKDIR_BIT_LEFT_S = 1U << TRACKDIR_LEFT_S,
113 TRACKDIR_BIT_RIGHT_S = 1U << TRACKDIR_RIGHT_S,
114 /* Again, note the two missing values here. This enables trackdir -> track conversion by doing (trackdir & 0xFF) */
115 TRACKDIR_BIT_X_SW = 1U << TRACKDIR_X_SW,
116 TRACKDIR_BIT_Y_NW = 1U << TRACKDIR_Y_NW,
117 TRACKDIR_BIT_UPPER_W = 1U << TRACKDIR_UPPER_W,
118 TRACKDIR_BIT_LOWER_W = 1U << TRACKDIR_LOWER_W,
119 TRACKDIR_BIT_LEFT_N = 1U << TRACKDIR_LEFT_N,
120 TRACKDIR_BIT_RIGHT_N = 1U << TRACKDIR_RIGHT_N,
121 TRACKDIR_BIT_MASK = 0x3F3F,
122 INVALID_TRACKDIR_BIT = 0xFFFF,
123 };
124 DECLARE_ENUM_AS_BIT_SET(TrackdirBits)
125 typedef SimpleTinyEnumT<TrackdirBits, uint16> TrackdirBitsShort;
126
127 typedef uint32 TrackStatus;
128
129 #endif /* TRACK_TYPE_H */