OpenTTD Source: src/road.h Source File

OpenTTD Source 13.2.1

road.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 <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef ROAD_H
11 #define ROAD_H
12
13 #include "road_type.h"
14 #include "gfx_type.h"
15 #include "core/bitmath_func.hpp"
16 #include "strings_type.h"
17 #include "date_type.h"
18 #include "core/enum_type.hpp"
19 #include "newgrf.h"
20 #include "economy_func.h"
21
22 #include <vector>
23
24 enum RoadTramType : bool {
25 RTT_ROAD,
26 RTT_TRAM,
27 };
28
29 enum RoadTramTypes : uint8 {
30 RTTB_ROAD = 1 << RTT_ROAD,
31 RTTB_TRAM = 1 << RTT_TRAM,
32 };
33 DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
34
35 static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM };
36
38 enum RoadTypeFlags {
39 ROTF_CATENARY = 0,
40 ROTF_NO_LEVEL_CROSSING,
41 ROTF_NO_HOUSES,
42 ROTF_HIDDEN,
43 ROTF_TOWN_BUILD,
44
45 ROTFB_NONE = 0,
46 ROTFB_CATENARY = 1 << ROTF_CATENARY,
47 ROTFB_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING,
48 ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES,
49 ROTFB_HIDDEN = 1 << ROTF_HIDDEN,
50 ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD,
51 };
52 DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)
53
54 struct SpriteGroup;
55
57 enum RoadTypeSpriteGroup {
58 ROTSG_CURSORS,
59 ROTSG_OVERLAY,
60 ROTSG_GROUND,
61 ROTSG_TUNNEL,
62 ROTSG_CATENARY_FRONT,
63 ROTSG_CATENARY_BACK,
64 ROTSG_BRIDGE,
65 ROTSG_reserved2,
66 ROTSG_DEPOT,
67 ROTSG_reserved3,
68 ROTSG_ROADSTOP,
69 ROTSG_ONEWAY,
70 ROTSG_END,
71 };
72
74 typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
75
76 class RoadTypeInfo {
77 public:
82 struct {
83 SpriteID build_x_road;
84 SpriteID build_y_road;
85 SpriteID auto_road;
86 SpriteID build_depot;
87 SpriteID build_tunnel;
88 SpriteID convert_road;
89 } gui_sprites;
90
91 struct {
92 CursorID road_swne;
93 CursorID road_nwse;
94 CursorID autoroad;
95 CursorID depot;
96 CursorID tunnel;
97 SpriteID convert_road;
98 } cursor;
99
100 struct {
101 StringID name;
102 StringID toolbar_caption;
103 StringID menu_text;
104 StringID build_caption;
105 StringID replace_text;
106 StringID new_engine;
107
108 StringID err_build_road;
109 StringID err_remove_road;
110 StringID err_depot;
111 StringID err_build_station[2];
112 StringID err_remove_station[2];
113 StringID err_convert_road;
114
115 StringID picker_title[2];
116 StringID picker_tooltip[2];
117 } strings;
118
120 RoadTypes powered_roadtypes;
121
125 RoadTypeFlags flags;
126
130 uint16 cost_multiplier;
131
135 uint16 maintenance_multiplier;
136
140 uint16 max_speed;
141
145 RoadTypeLabel label;
146
150 RoadTypeLabelList alternate_labels;
151
155 byte map_colour;
156
164 Date introduction_date;
165
170 RoadTypes introduction_required_roadtypes;
171
175 RoadTypes introduces_roadtypes;
176
180 byte sorting_order;
181
185 const GRFFile *grffile[ROTSG_END];
186
190 const SpriteGroup *group[ROTSG_END];
191
192 inline bool UsesOverlay() const
193 {
194 return this->group[ROTSG_GROUND] != nullptr;
195 }
196 };
197
198 extern RoadTypes _roadtypes_type;
199
200 static inline bool RoadTypeIsRoad(RoadType roadtype)
201 {
202 return !HasBit(_roadtypes_type, roadtype);
203 }
204
205 static inline bool RoadTypeIsTram(RoadType roadtype)
206 {
207 return HasBit(_roadtypes_type, roadtype);
208 }
209
210 static inline RoadTramType GetRoadTramType(RoadType roadtype)
211 {
212 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
213 }
214
215 static inline RoadTramType OtherRoadTramType(RoadTramType rtt)
216 {
217 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
218 }
219
225 static inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
226 {
227 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
228 assert(roadtype < ROADTYPE_END);
229 return &_roadtypes[roadtype];
230 }
231
240 static inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
241 {
242 return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
243 }
244
250 static inline Money RoadBuildCost(RoadType roadtype)
251 {
252 assert(roadtype < ROADTYPE_END);
253 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
254 }
255
261 static inline Money RoadClearCost(RoadType roadtype)
262 {
263 assert(roadtype < ROADTYPE_END);
264
265 /* Flat fee for removing road. */
266 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
267
268 /* Clearing tram earns a little money, but also incurs the standard clear road cost,
269 * so no profit can be made. */
270 return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
271 }
272
279 static inline Money RoadConvertCost(RoadType from, RoadType to)
280 {
281 /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
282 if (from == to) return (Money)0;
283
284 /* Same cost as removing and then building. */
285 return RoadBuildCost(to) + RoadClearCost(from);
286 }
287
293 static inline bool RoadNoLevelCrossing(RoadType roadtype)
294 {
295 assert(roadtype < ROADTYPE_END);
296 return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_NO_LEVEL_CROSSING);
297 }
298
299 RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
300
301 void ResetRoadTypes();
302 void InitRoadTypes();
303 RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
304 bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
305
306 extern std::vector<RoadType> _sorted_roadtypes;
307 extern RoadTypes _roadtypes_hidden_mask;
308
309 #endif /* ROAD_H */
RoadTypeInfo::flags
RoadTypeFlags flags
Bit mask of road type flags.
Definition: road.h:125
RoadTypeInfo::new_engine
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition: road.h:106
ROTF_NO_LEVEL_CROSSING
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
Definition: road.h:40
RoadTypeInfo::toolbar_caption
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition: road.h:102
ROTSG_ONEWAY
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition: road.h:69
RoadTypeInfo
Definition: road.h:76
ROTSG_GROUND
@ ROTSG_GROUND
Required: Main group of ground images.
Definition: road.h:60
ROADTYPE_END
@ ROADTYPE_END
Used for iterations.
Definition: road_type.h:26
RoadTypeInfo::err_build_road
StringID err_build_road
Building a normal piece of road.
Definition: road.h:108
RoadTypeInfo::menu_text
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition: road.h:103
ROTF_CATENARY
@ ROTF_CATENARY
Bit number for adding catenary.
Definition: road.h:39
ROTFB_TOWN_BUILD
@ ROTFB_TOWN_BUILD
Value for allowing towns to build this roadtype.
Definition: road.h:50
RoadTypeInfo::build_y_road
SpriteID build_y_road
button for building single rail in Y direction
Definition: road.h:84
ROTSG_reserved2
@ ROTSG_reserved2
Placeholder, if we need specific level crossing sprites.
Definition: road.h:65
RoadTypeInfo::introduces_roadtypes
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition: road.h:175
ROTF_TOWN_BUILD
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
Definition: road.h:43
RoadTypeInfo::sorting_order
byte sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition: road.h:180
RoadConvertCost
static Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition: road.h:279
RoadTypeInfo::build_depot
SpriteID build_depot
button for building depots
Definition: road.h:86
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
RoadTypeInfo::err_remove_station
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition: road.h:112
economy_func.h
RoadTypeInfo::tunnel
CursorID tunnel
Cursor for building a tunnel.
Definition: road.h:96
RoadTypeInfo::replace_text
StringID replace_text
Text used in the autoreplace GUI.
Definition: road.h:105
strings_type.h
RoadTypeInfo::introduction_date
Date introduction_date
Introduction date.
Definition: road.h:164
RoadTypeInfo::err_remove_road
StringID err_remove_road
Removing a normal piece of road.
Definition: road.h:109
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
RoadTypeInfo::depot
CursorID depot
Cursor for building a depot.
Definition: road.h:95
ROTSG_CURSORS
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition: road.h:58
RoadTypeInfo::road_nwse
CursorID road_nwse
Cursor for building rail in Y direction.
Definition: road.h:93
RoadTypeInfo::road_swne
CursorID road_swne
Cursor for building rail in X direction.
Definition: road.h:92
RoadTypeLabelList
std::vector< RoadTypeLabel > RoadTypeLabelList
List of road type labels.
Definition: road.h:74
AllocateRoadType
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition: road_cmd.cpp:141
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
bitmath_func.hpp
RoadTypeSpriteGroup
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition: road.h:57
RoadTypeInfo::powered_roadtypes
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition: road.h:120
_roadtypes_type
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:60
CursorID
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:19
ROTF_HIDDEN
@ ROTF_HIDDEN
Bit number for hidden from construction.
Definition: road.h:42
HasAnyRoadTypesAvail
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
Test if any buildable RoadType is available for a company.
Definition: road.cpp:132
RoadTypeInfo::auto_road
SpriteID auto_road
button for the autoroad construction
Definition: road.h:85
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
RoadTypes
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
RoadTypeInfo::group
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition: road.h:190
RoadTypeInfo::alternate_labels
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition: road.h:150
ROTSG_ROADSTOP
@ ROTSG_ROADSTOP
Required: Drive-in stop surface.
Definition: road.h:68
ROTF_NO_HOUSES
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
Definition: road.h:41
ROTSG_BRIDGE
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition: road.h:64
ROTFB_CATENARY
@ ROTFB_CATENARY
Value for drawing a catenary.
Definition: road.h:46
RoadTypeInfo::name
StringID name
Name of this rail type.
Definition: road.h:101
RoadTypeInfo::build_tunnel
SpriteID build_tunnel
button for building a tunnel
Definition: road.h:87
date_type.h
RoadTypeInfo::picker_tooltip
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition: road.h:116
ROTFB_NO_HOUSES
@ ROTFB_NO_HOUSES
Value for for setting this roadtype as not house friendly.
Definition: road.h:48
RoadTypeInfo::build_x_road
SpriteID build_x_road
button for building single rail in X direction
Definition: road.h:83
RoadTypeInfo::convert_road
SpriteID convert_road
button for converting road types
Definition: road.h:88
RoadTypeInfo::grffile
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition: road.h:185
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
RoadTypeInfo::gui_sprites
struct RoadTypeInfo::@40 gui_sprites
struct containing the sprites for the road GUI.
RoadTypeInfo::label
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition: road.h:145
RoadTypeInfo::err_build_station
StringID err_build_station[2]
Building a bus or truck station.
Definition: road.h:111
RoadTypeInfo::cursor
struct RoadTypeInfo::@41 cursor
Cursors associated with the road type.
ROTSG_OVERLAY
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition: road.h:59
RoadTypeInfo::autoroad
CursorID autoroad
Cursor for autorail tool.
Definition: road.h:94
RoadClearCost
static Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition: road.h:261
RoadTypeInfo::err_convert_road
StringID err_convert_road
Converting a road type.
Definition: road.h:113
newgrf.h
RoadTypeInfo::map_colour
byte map_colour
Colour on mini-map.
Definition: road.h:155
ROTSG_CATENARY_FRONT
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition: road.h:62
GetRoadTypeInfo
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:225
RoadType
RoadType
The different roadtypes we support.
Definition: road_type.h:22
enum_type.hpp
ROTSG_TUNNEL
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition: road.h:61
DECLARE_ENUM_AS_BIT_SET
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Definition: company_manager_face.h:29
RoadTypeInfo::cost_multiplier
uint16 cost_multiplier
Cost multiplier for building this road type.
Definition: road.h:130
ROTSG_DEPOT
@ ROTSG_DEPOT
Optional: Depot images.
Definition: road.h:66
RoadTypeInfo::max_speed
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:140
road_type.h
OverflowSafeInt< int64 >
RoadBuildCost
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:250
HasPowerOnRoad
static bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
Checks if an engine of the given RoadType got power on a tile with a given RoadType.
Definition: road.h:240
RoadTypeFlags
RoadTypeFlags
Roadtype flags.
Definition: road.h:38
GetRoadTypeByLabel
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels=true)
Get the road type for a given label.
Definition: road.cpp:243
ResetRoadTypes
void ResetRoadTypes()
Reset all road type information to its default values.
Definition: road_cmd.cpp:65
ROTFB_NONE
@ ROTFB_NONE
All flags cleared.
Definition: road.h:45
RoadTypeInfo::err_depot
StringID err_depot
Building a depot.
Definition: road.h:110
RoadNoLevelCrossing
static bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition: road.h:293
gfx_type.h
InitRoadTypes
void InitRoadTypes()
Resolve sprites of custom road types.
Definition: road_cmd.cpp:121
RoadTypeInfo::build_caption
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: road.h:104
ROTSG_CATENARY_BACK
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition: road.h:63
RoadTypeInfo::introduction_required_roadtypes
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition: road.h:170
SpriteGroup
Definition: newgrf_spritegroup.h:57
RoadTypeInfo::picker_title
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition: road.h:115
ROTSG_reserved3
@ ROTSG_reserved3
Placeholder, if we add road fences (for highways).
Definition: road.h:67
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:106
RoadTypeInfo::maintenance_multiplier
uint16 maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition: road.h:135
ROTFB_NO_LEVEL_CROSSING
@ ROTFB_NO_LEVEL_CROSSING
Value for disabling a level crossing.
Definition: road.h:47
RoadTypeInfo::strings
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
ROTFB_HIDDEN
@ ROTFB_HIDDEN
Value for hidden from construction.
Definition: road.h:49