OpenTTD Source 20250205-master-gfd85ab1e2c
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"
18#include "core/enum_type.hpp"
19#include "newgrf.h"
20#include "economy_func.h"
21
22
23enum RoadTramType : bool {
24 RTT_ROAD,
25 RTT_TRAM,
26};
27
28enum RoadTramTypes : uint8_t {
29 RTTB_ROAD = 1 << RTT_ROAD,
30 RTTB_TRAM = 1 << RTT_TRAM,
31};
32DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
33
34static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM };
35
37enum class RoadTypeFlag : uint8_t {
38 Catenary = 0,
39 NoLevelCrossing = 1,
40 NoHouses = 2,
41 Hidden = 3,
42 TownBuild = 4,
43};
45
46struct SpriteGroup;
47
64
66typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
67
189
191
192inline bool RoadTypeIsRoad(RoadType roadtype)
193{
194 return !HasBit(_roadtypes_type, roadtype);
195}
196
197inline bool RoadTypeIsTram(RoadType roadtype)
198{
199 return HasBit(_roadtypes_type, roadtype);
200}
201
202inline RoadTramType GetRoadTramType(RoadType roadtype)
203{
204 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
205}
206
207inline RoadTramType OtherRoadTramType(RoadTramType rtt)
208{
209 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
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 HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
235}
236
243{
244 assert(roadtype < ROADTYPE_END);
245 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
246}
247
254{
255 assert(roadtype < ROADTYPE_END);
256
257 /* Flat fee for removing road. */
258 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
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[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
263}
264
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;
299extern RoadTypes _roadtypes_hidden_mask;
300
301#endif /* ROAD_H */
Functions related to bit mathematics.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool Test(Tenum value) const
Test if the enum value is set.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:137
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:95
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:97
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:142
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:107
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:112
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:167
CursorID autoroad
Cursor for autorail tool.
Definition road.h:86
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:156
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition road.h:182
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:172
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:108
uint16_t maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition road.h:127
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:117
StringID err_build_road
Building a normal piece of road.
Definition road.h:100
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:101
uint8_t map_colour
Colour on mini-map.
Definition road.h:147
CursorID depot
Cursor for building a depot.
Definition road.h:87
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition road.h:177
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:85
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:132
StringID name
Name of this rail type.
Definition road.h:93
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:94
struct RoadTypeInfo::@26 cursor
Cursors associated with the road type.
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:76
struct RoadTypeInfo::@27 strings
Strings associated with the rail type.
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:88
SpriteID auto_road
button for the autoroad construction
Definition road.h:77
SpriteID convert_road
button for converting road types
Definition road.h:80
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:84
StringID err_convert_road
Converting a road type.
Definition road.h:105
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:98
StringID err_depot
Building a depot.
Definition road.h:102
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:75
SpriteID build_depot
button for building depots
Definition road.h:78
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition road.h:162
SpriteID build_tunnel
button for building a tunnel
Definition road.h:79
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:103
uint16_t cost_multiplier
Cost multiplier for building this road type.
Definition road.h:122
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:104
struct RoadTypeInfo::@25 gui_sprites
struct containing the sprites for the road GUI.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition road.h:96
Owner
Enum for all companies/owners.
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++.
Definition enum_type.hpp:68
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.
void ResetRoadTypes()
Reset all road type information to its default values.
Definition road_cmd.cpp:67
void InitRoadTypes()
Resolve sprites of custom road types.
Definition road_cmd.cpp:114
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
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition road_cmd.cpp:62
RoadTypeFlag
Roadtype flag bit numbers.
Definition road.h:37
@ 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.
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:143
std::vector< RoadTypeLabel > RoadTypeLabelList
List of road type labels.
Definition road.h:66
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:254
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition road.h:49
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition road.h:61
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition road.h:51
@ ROTSG_reserved2
Placeholder, if we need specific level crossing sprites.
Definition road.h:57
@ ROTSG_ROADSTOP
Required: Bay stop surface.
Definition road.h:60
@ ROTSG_GROUND
Required: Main group of ground images.
Definition road.h:52
@ ROTSG_DEPOT
Optional: Depot images.
Definition road.h:58
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition road.h:50
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition road.h:55
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition road.h:56
@ ROTSG_reserved3
Placeholder, if we add road fences (for highways).
Definition road.h:59
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition road.h:54
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition road.h:53
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:134
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:242
Enums and other types related to roads.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition road_type.h:38
RoadType
The different roadtypes we support.
Definition road_type.h:25
@ ROADTYPE_END
Used for iterations.
Definition road_type.h:29
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:109
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.