OpenTTD Source: src/road.h Source File

OpenTTD Source 15.0-RC2

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