OpenTTD Source 20251019-master-g9f7f314f81
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 "core/flatset_type.hpp"
17#include "strings_type.h"
19#include "core/enum_type.hpp"
20#include "newgrf.h"
21#include "newgrf_badge_type.h"
22#include "economy_func.h"
23
24
25enum RoadTramType : bool {
26 RTT_ROAD,
27 RTT_TRAM,
28};
29
30enum RoadTramTypes : uint8_t {
31 RTTB_ROAD = 1 << RTT_ROAD,
32 RTTB_TRAM = 1 << RTT_TRAM,
33};
34DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
35
36static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM };
37
39enum class RoadTypeFlag : uint8_t {
40 Catenary = 0,
41 NoLevelCrossing = 1,
42 NoHouses = 2,
43 Hidden = 3,
44 TownBuild = 4,
45};
47
48struct SpriteGroup;
49
66
68public:
73 struct {
81
82 struct {
90
91 struct {
98
105
109
112
117
122
127
131 uint16_t max_speed;
132
136 RoadTypeLabel label;
137
142
147
156
162
167
172
176 const GRFFile *grffile[ROTSG_END];
177
181 const SpriteGroup *group[ROTSG_END];
182
183 std::vector<BadgeID> badges;
184
185 inline bool UsesOverlay() const
186 {
187 return this->group[ROTSG_GROUND] != nullptr;
188 }
189
190 RoadType Index() const;
191};
192
198inline RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
199{
202 return rtt == RTT_ROAD ? _roadtypes_road : _roadtypes_tram;
203}
204
205inline bool RoadTypeIsRoad(RoadType roadtype)
206{
207 return GetMaskForRoadTramType(RTT_ROAD).Test(roadtype);
208}
209
210inline bool RoadTypeIsTram(RoadType roadtype)
211{
212 return GetMaskForRoadTramType(RTT_TRAM).Test(roadtype);
213}
214
215inline RoadTramType GetRoadTramType(RoadType roadtype)
216{
217 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
218}
219
220inline RoadTramType OtherRoadTramType(RoadTramType rtt)
221{
222 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
223}
224
230inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
231{
232 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
233 assert(roadtype < ROADTYPE_END);
234 return &_roadtypes[roadtype];
235}
236
245inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
246{
247 return GetRoadTypeInfo(enginetype)->powered_roadtypes.Test(tiletype);
248}
249
256{
257 assert(roadtype < ROADTYPE_END);
258 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
259}
260
267{
268 assert(roadtype < ROADTYPE_END);
269
270 /* Flat fee for removing road. */
271 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
272
273 /* Clearing tram earns a little money, but also incurs the standard clear road cost,
274 * so no profit can be made. */
275 return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
276}
277
285{
286 /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
287 if (from == to) return (Money)0;
288
289 /* Same cost as removing and then building. */
290 return RoadBuildCost(to) + RoadClearCost(from);
291}
292
298inline bool RoadNoLevelCrossing(RoadType roadtype)
299{
300 assert(roadtype < ROADTYPE_END);
302}
303
304RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
305
306void ResetRoadTypes();
307void InitRoadTypes();
308RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
309bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
310
311extern std::vector<RoadType> _sorted_roadtypes;
313
314#endif /* ROAD_H */
Functions related to bit mathematics.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Flat set implementation that uses a sorted vector for storage.
struct RoadTypeInfo::@25 strings
Strings associated with the rail type.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:136
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:94
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:96
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:106
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:111
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:166
RoadType Index() const
Get the RoadType for this RoadTypeInfo.
Definition road.cpp:30
CursorID autoroad
Cursor for autorail tool.
Definition road.h:85
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:155
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition road.h:181
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:171
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:107
uint16_t maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition road.h:126
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:116
StringID err_build_road
Building a normal piece of road.
Definition road.h:99
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:100
FlatSet< RoadTypeLabel > alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:141
CursorID depot
Cursor for building a depot.
Definition road.h:86
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition road.h:176
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:84
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:131
StringID name
Name of this rail type.
Definition road.h:92
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:93
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:75
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:87
SpriteID auto_road
button for the autoroad construction
Definition road.h:76
SpriteID convert_road
button for converting road types
Definition road.h:79
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:83
StringID err_convert_road
Converting a road type.
Definition road.h:104
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:97
StringID err_depot
Building a depot.
Definition road.h:101
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:74
SpriteID build_depot
button for building depots
Definition road.h:77
struct RoadTypeInfo::@24 cursor
Cursors associated with the road type.
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition road.h:161
struct RoadTypeInfo::@23 gui_sprites
struct containing the sprites for the road GUI.
SpriteID build_tunnel
button for building a tunnel
Definition road.h:78
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:102
uint16_t cost_multiplier
Cost multiplier for building this road type.
Definition road.h:121
PixelColour map_colour
Colour on mini-map.
Definition road.h:146
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:103
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition road.h:95
Functions related to the economy.
Type (helpers) for enums.
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Flat set container implementation.
Types related to the graphics and/or input devices.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:19
Base for the NewGRF implementation.
Types related to NewGRF badges.
void ResetRoadTypes()
Reset all road type information to its default values.
Definition road_cmd.cpp:63
void InitRoadTypes()
Resolve sprites of custom road types.
Definition road_cmd.cpp:111
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:245
RoadTypeFlag
Roadtype flag bit numbers.
Definition road.h:39
@ Catenary
Bit number for adding catenary.
@ NoHouses
Bit number for setting this roadtype as not house friendly.
@ Hidden
Bit number for hidden from construction.
@ NoLevelCrossing
Bit number for disabling level crossing.
@ TownBuild
Bit number for allowing towns to build this roadtype.
RoadTypes _roadtypes_hidden_mask
Bitset of hidden roadtypes.
Definition road_cmd.cpp:56
Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition road.h:266
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
Test if any buildable RoadType is available for a company.
Definition road.cpp:152
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:198
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:230
Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition road.h:284
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels=true)
Get the road type for a given label.
Definition road.cpp:265
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:55
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition road.h:51
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition road.h:63
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition road.h:53
@ ROTSG_reserved2
Placeholder, if we need specific level crossing sprites.
Definition road.h:59
@ ROTSG_ROADSTOP
Required: Bay stop surface.
Definition road.h:62
@ ROTSG_GROUND
Required: Main group of ground images.
Definition road.h:54
@ ROTSG_DEPOT
Optional: Depot images.
Definition road.h:60
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition road.h:52
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition road.h:57
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition road.h:58
@ ROTSG_reserved3
Placeholder, if we add road fences (for highways).
Definition road.h:61
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition road.h:56
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition road.h:55
bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition road.h:298
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition road_cmd.cpp:129
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:255
RoadTypes _roadtypes_road
Bitset of road roadtypes.
Definition road_cmd.cpp:57
RoadTypes _roadtypes_tram
Bitset of tram roadtypes.
Definition road_cmd.cpp:58
Enums and other types related to roads.
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:27
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dynamic data of a loaded NewGRF.
Definition newgrf.h:115
Colour for pixel/line drawing.
Definition gfx_type.h:405
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.