Update readme.md
[openttd-joker.git] / src / road_type.h
blob309e2eb670fe3a242d010f429f80e54a573318c2
1 /* $Id: road_type.h 23595 2011-12-19 17:48:04Z rubidium $ */
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 */
10 /** @file road_type.h Enums and other types related to roads. */
12 #ifndef ROAD_TYPE_H
13 #define ROAD_TYPE_H
15 #include "core/enum_type.hpp"
16 #include "core/math_func.hpp"
18 typedef uint32 RoadTypeLabel;
20 /**
21 * The different roadtypes we support
23 * @note currently only ROADTYPE_ROAD and ROADTYPE_TRAM are supported.
25 enum RoadType {
26 ROADTYPE_BEGIN = 0, ///< Used for iterations
27 ROADTYPE_ROAD = 0, ///< Basic road type
28 ROADTYPE_TRAM = 1, ///< Trams
29 ROADTYPE_END, ///< Used for iterations
30 INVALID_ROADTYPE = 0xFF, ///< flag for invalid roadtype
32 DECLARE_POSTFIX_INCREMENT(RoadType)
33 template <> struct EnumPropsT<RoadType> : MakeEnumPropsT<RoadType, byte, ROADTYPE_BEGIN, ROADTYPE_END, INVALID_ROADTYPE, 2> {};
34 typedef TinyEnumT<RoadType> RoadTypeByte;
36 enum RoadSubType {
37 ROADSUBTYPE_BEGIN = 0, ///< Used for iterations
38 ROADSUBTYPE_NORMAL = 0, ///< Plain road/tram
39 ROADSUBTYPE_ELECTRIC = 1, ///< Electrified road/tram
40 ROADSUBTYPE_END = 31, ///< Used for iterations
41 INVALID_ROADSUBTYPE = 0x1F, ///< flag for invalid roadsubtype
43 DECLARE_POSTFIX_INCREMENT(RoadSubType);
45 /**
46 * The different roadtypes we support, but then a bitmask of them.
48 enum RoadTypes {
49 ROADTYPES_NONE = 0, ///< No roadtypes
50 ROADTYPES_ROAD = 1 << ROADTYPE_ROAD, ///< Road
51 ROADTYPES_TRAM = 1 << ROADTYPE_TRAM, ///< Trams
52 ROADTYPES_ALL = ROADTYPES_ROAD | ROADTYPES_TRAM, ///< Road + trams
53 ROADTYPES_END, ///< Used for iterations?
54 INVALID_ROADTYPES = 0xFF, ///< Invalid roadtypes
56 DECLARE_ENUM_AS_BIT_SET(RoadTypes)
57 template <> struct EnumPropsT<RoadTypes> : MakeEnumPropsT<RoadTypes, byte, ROADTYPES_NONE, ROADTYPES_END, INVALID_ROADTYPES, 2> {};
58 typedef SimpleTinyEnumT<RoadTypes, byte> RoadTypesByte;
60 /**
61 * The different roadsubtypes which exist, but then a bitmask of them.
63 enum RoadSubTypes {
64 ROADSUBTYPES_NONE = 0, ///< No roadsubtypes
65 ROADSUBTYPES_NORMAL = 1 << ROADSUBTYPE_NORMAL, ///< Plain road/tram
66 ROADSUBTYPES_ELECTRIC = 1 << ROADSUBTYPE_ELECTRIC, ///< Electrified road/tram
68 DECLARE_ENUM_AS_BIT_SET(RoadSubTypes)
70 /**
71 * Identifier for road and tram types.
73 struct RoadTypeIdentifier {
74 RoadType basetype;
75 RoadSubType subtype;
77 bool operator==(const RoadTypeIdentifier &other) const
79 return this->basetype == other.basetype && this->subtype == other.subtype;
82 bool operator!=(const RoadTypeIdentifier &other) const
84 return this->basetype != other.basetype || this->subtype != other.subtype;
87 uint8 Pack() const;
88 bool UnpackIfValid(uint32 data);
89 static RoadTypeIdentifier Unpack(uint32 data);
91 bool IsValid() const
93 return (this->basetype == ROADTYPE_ROAD || this->basetype == ROADTYPE_TRAM) && IsInsideMM(this->subtype, ROADSUBTYPE_BEGIN, ROADSUBTYPE_END);
96 bool IsRoad() const
98 return (this->basetype == ROADTYPE_ROAD) && IsInsideMM(this->subtype, ROADSUBTYPE_BEGIN, ROADSUBTYPE_END);
101 bool IsTram() const
103 return (this->basetype == ROADTYPE_TRAM) && IsInsideMM(this->subtype, ROADSUBTYPE_BEGIN, ROADSUBTYPE_END);
106 RoadTypeIdentifier(RoadType basetype, RoadSubType subtype) : basetype(basetype), subtype(subtype) {}
107 RoadTypeIdentifier() : basetype(INVALID_ROADTYPE), subtype(INVALID_ROADSUBTYPE) {}
111 * Enumeration for the road parts on a tile.
113 * This enumeration defines the possible road parts which
114 * can be build on a tile.
116 enum RoadBits {
117 ROAD_NONE = 0U, ///< No road-part is build
118 ROAD_NW = 1U, ///< North-west part
119 ROAD_SW = 2U, ///< South-west part
120 ROAD_SE = 4U, ///< South-east part
121 ROAD_NE = 8U, ///< North-east part
122 ROAD_X = ROAD_SW | ROAD_NE, ///< Full road along the x-axis (south-west + north-east)
123 ROAD_Y = ROAD_NW | ROAD_SE, ///< Full road along the y-axis (north-west + south-east)
125 ROAD_N = ROAD_NE | ROAD_NW, ///< Road at the two northern edges
126 ROAD_E = ROAD_NE | ROAD_SE, ///< Road at the two eastern edges
127 ROAD_S = ROAD_SE | ROAD_SW, ///< Road at the two southern edges
128 ROAD_W = ROAD_NW | ROAD_SW, ///< Road at the two western edges
130 ROAD_ALL = ROAD_X | ROAD_Y, ///< Full 4-way crossing
132 ROAD_END = ROAD_ALL + 1, ///< Out-of-range roadbits, used for iterations
134 DECLARE_ENUM_AS_BIT_SET(RoadBits)
135 template <> struct EnumPropsT<RoadBits> : MakeEnumPropsT<RoadBits, byte, ROAD_NONE, ROAD_END, ROAD_NONE, 4> {};
137 #endif /* ROAD_TYPE_H */