OpenTTD Source 20260621-master-g720d10536d
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef ROAD_H
11#define ROAD_H
12
13#include "road_type.h"
14#include "gfx_type.h"
15#include "core/flatset_type.hpp"
16#include "strings_type.h"
18#include "core/enum_type.hpp"
19#include "newgrf.h"
20#include "newgrf_badge_type.h"
21#include "economy_func.h"
22
24enum class RoadTypeFlag : uint8_t {
28 Hidden = 3,
30};
31
34
35struct SpriteGroup;
36
53
55public:
60 struct {
68
69 struct {
77
78 struct {
85
92
96
99
104
109
114
118 uint16_t max_speed;
119
123 RoadTypeLabel label;
124
129
134
143
149
154
159
164
169
170 std::vector<BadgeID> badges;
171
172 inline bool UsesOverlay() const
173 {
174 return this->group[RoadSpriteType::Ground] != nullptr;
175 }
176
177 RoadType Index() const;
178};
179
191
192inline bool RoadTypeIsRoad(RoadType roadtype)
193{
195}
196
197inline bool RoadTypeIsTram(RoadType roadtype)
198{
200}
201
202inline RoadTramType GetRoadTramType(RoadType roadtype)
203{
204 return RoadTypeIsTram(roadtype) ? RoadTramType::Tram : RoadTramType::Road;
205}
206
207inline RoadTramType OtherRoadTramType(RoadTramType rtt)
208{
210}
211
217inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
218{
219 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
220 assert(roadtype < ROADTYPE_END);
221 return &_roadtypes[roadtype];
222}
223
232inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
233{
234 return GetRoadTypeInfo(enginetype)->powered_roadtypes.Test(tiletype);
235}
236
242inline Money RoadBuildCost(RoadType roadtype)
243{
244 assert(roadtype < ROADTYPE_END);
245 return (_price[Price::BuildRoad] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
246}
247
253inline Money RoadClearCost(RoadType roadtype)
254{
255 assert(roadtype < ROADTYPE_END);
256
257 /* Flat fee for removing road. */
258 if (RoadTypeIsRoad(roadtype)) return _price[Price::ClearRoad];
259
260 /* Clearing tram earns a little money, but also incurs the standard clear road cost,
261 * so no profit can be made. */
262 return _price[Price::ClearRoad] - RoadBuildCost(roadtype) * 3 / 4;
263}
264
271inline Money RoadConvertCost(RoadType from, RoadType to)
272{
273 /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
274 if (from == to) return (Money)0;
275
276 /* Same cost as removing and then building. */
277 return RoadBuildCost(to) + RoadClearCost(from);
278}
279
285inline bool RoadNoLevelCrossing(RoadType roadtype)
286{
287 assert(roadtype < ROADTYPE_END);
289}
290
291RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
292
293void ResetRoadTypes();
294void InitRoadTypes();
295RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
296bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
297
298extern std::vector<RoadType> _sorted_roadtypes;
300
301#endif /* ROAD_H */
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Enum-as-bit-set wrapper.
Flat set implementation that uses a sorted vector for storage.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:123
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:81
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:83
EnumIndexArray< const SpriteGroup *, RoadSpriteType, RoadSpriteType::End > group
Sprite groups for resolving sprites.
Definition road.h:168
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_build_station
Building a bus or truck station.
Definition road.h:89
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:98
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:153
RoadType Index() const
Get the RoadType for this RoadTypeInfo.
Definition road.cpp:30
CursorID autoroad
Cursor for autorail tool.
Definition road.h:72
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:142
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:158
uint16_t maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition road.h:113
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:103
StringID err_build_road
Building a normal piece of road.
Definition road.h:86
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:87
FlatSet< RoadTypeLabel > alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:128
CursorID depot
Cursor for building a depot.
Definition road.h:73
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:71
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:118
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_title
Title for the station picker for bus or truck stations.
Definition road.h:93
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID name
Name of this rail type.
Definition road.h:79
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:80
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:62
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_tooltip
Tooltip for the station picker for bus or truck stations.
Definition road.h:94
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:74
SpriteID auto_road
button for the autoroad construction
Definition road.h:63
SpriteID convert_road
button for converting road types
Definition road.h:66
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:70
StringID err_convert_road
Converting a road type.
Definition road.h:91
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:84
StringID err_depot
Building a depot.
Definition road.h:88
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:61
SpriteID build_depot
button for building depots
Definition road.h:64
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition road.h:148
SpriteID build_tunnel
button for building a tunnel
Definition road.h:65
EnumIndexArray< const GRFFile *, RoadSpriteType, RoadSpriteType::End > grffile
NewGRF providing the Action3 for the roadtype.
Definition road.h:163
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_remove_station
Removing of a bus or truck station.
Definition road.h:90
uint16_t cost_multiplier
Cost multiplier for building this road type.
Definition road.h:108
PixelColour map_colour
Colour on mini-map.
Definition road.h:133
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition road.h:82
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Prices _price
Prices and also the fractional part.
Definition economy.cpp:106
Functions related to the economy.
@ ClearRoad
Price for destroying roads.
@ BuildRoad
Price for building roads.
Type (helpers) for enums.
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
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:232
RoadTypeFlag
Roadtype flag bit numbers.
Definition road.h:24
@ Catenary
Bit number for adding catenary.
Definition road.h:25
@ NoHouses
Bit number for setting this roadtype as not house friendly.
Definition road.h:27
@ Hidden
Bit number for hidden from construction.
Definition road.h:28
@ NoLevelCrossing
Bit number for disabling level crossing.
Definition road.h:26
@ TownBuild
Bit number for allowing towns to build this roadtype.
Definition road.h:29
EnumBitSet< RoadTypeFlag, uint8_t > RoadTypeFlags
Bitset of RoadTypeFlag elements.
Definition road.h:33
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:253
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
Test if any buildable RoadType is available for a company.
Definition road.cpp:153
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:185
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition road.h:271
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels=true)
Get the road type for a given label.
Definition road.cpp:265
RoadSpriteType
Sprite types for a roadtype.
Definition road.h:38
@ Roadstop
Required: Bay stop surface.
Definition road.h:49
@ Ground
Required: Main group of ground images.
Definition road.h:41
@ CatenaryFront
Optional: Catenary front.
Definition road.h:43
@ ReservedFence
Placeholder, if we add road fences (for highways).
Definition road.h:48
@ Overlay
Optional: Images for overlaying track.
Definition road.h:40
@ UI
Optional: Cursor and toolbar icon images.
Definition road.h:39
@ CatenaryRear
Optional: Catenary back.
Definition road.h:44
@ End
End marker.
Definition road.h:51
@ Oneway
Optional: One-way indicator images.
Definition road.h:50
@ ReservedCrossing
Placeholder, if we need specific level crossing sprites.
Definition road.h:46
@ Bridge
Required: Bridge surface images.
Definition road.h:45
@ Tunnel
Optional: Ground images for tunnels.
Definition road.h:42
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:55
bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition road.h:285
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition road_cmd.cpp:132
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:242
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.
EnumBitSet< RoadType, uint64_t > RoadTypes
Bitset of RoadType elements.
Definition road_type.h:32
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:27
RoadTramType
The different types of road type.
Definition road_type.h:37
@ Tram
Tram type.
Definition road_type.h:39
@ Road
Road type.
Definition road_type.h:38
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Colour for pixel/line drawing.
Definition gfx_type.h:308
Common wrapper for all the different sprite group types.
Definition of the game-calendar-timer.