OpenTTD Source 20250312-master-gcdcc6b491d
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 "newgrf_badge_type.h"
21#include "economy_func.h"
22
23
24enum RoadTramType : bool {
25 RTT_ROAD,
26 RTT_TRAM,
27};
28
29enum RoadTramTypes : uint8_t {
30 RTTB_ROAD = 1 << RTT_ROAD,
31 RTTB_TRAM = 1 << RTT_TRAM,
32};
33DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
34
35static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM };
36
38enum class RoadTypeFlag : uint8_t {
39 Catenary = 0,
40 NoLevelCrossing = 1,
41 NoHouses = 2,
42 Hidden = 3,
43 TownBuild = 4,
44};
46
47struct SpriteGroup;
48
65
67typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
68
192
194
195inline bool RoadTypeIsRoad(RoadType roadtype)
196{
197 return !HasBit(_roadtypes_type, roadtype);
198}
199
200inline bool RoadTypeIsTram(RoadType roadtype)
201{
202 return HasBit(_roadtypes_type, roadtype);
203}
204
205inline RoadTramType GetRoadTramType(RoadType roadtype)
206{
207 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
208}
209
210inline RoadTramType OtherRoadTramType(RoadTramType rtt)
211{
212 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
213}
214
220inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
221{
222 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
223 assert(roadtype < ROADTYPE_END);
224 return &_roadtypes[roadtype];
225}
226
235inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
236{
237 return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
238}
239
246{
247 assert(roadtype < ROADTYPE_END);
248 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
249}
250
257{
258 assert(roadtype < ROADTYPE_END);
259
260 /* Flat fee for removing road. */
261 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
262
263 /* Clearing tram earns a little money, but also incurs the standard clear road cost,
264 * so no profit can be made. */
265 return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
266}
267
275{
276 /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
277 if (from == to) return (Money)0;
278
279 /* Same cost as removing and then building. */
280 return RoadBuildCost(to) + RoadClearCost(from);
281}
282
288inline bool RoadNoLevelCrossing(RoadType roadtype)
289{
290 assert(roadtype < ROADTYPE_END);
292}
293
294RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
295
296void ResetRoadTypes();
297void InitRoadTypes();
298RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
299bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
300
301extern std::vector<RoadType> _sorted_roadtypes;
302extern RoadTypes _roadtypes_hidden_mask;
303
304#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(Tvalue_type value) const
Test if the value-th bit is set.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:138
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:96
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:98
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:143
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:108
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:113
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:168
CursorID autoroad
Cursor for autorail tool.
Definition road.h:87
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:157
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition road.h:183
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:173
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:109
uint16_t maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition road.h:128
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:118
StringID err_build_road
Building a normal piece of road.
Definition road.h:101
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:102
uint8_t map_colour
Colour on mini-map.
Definition road.h:148
CursorID depot
Cursor for building a depot.
Definition road.h:88
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition road.h:178
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:86
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:133
StringID name
Name of this rail type.
Definition road.h:94
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:95
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:77
struct RoadTypeInfo::@27 strings
Strings associated with the rail type.
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:89
SpriteID auto_road
button for the autoroad construction
Definition road.h:78
SpriteID convert_road
button for converting road types
Definition road.h:81
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:85
StringID err_convert_road
Converting a road type.
Definition road.h:106
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:99
StringID err_depot
Building a depot.
Definition road.h:103
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:76
SpriteID build_depot
button for building depots
Definition road.h:79
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition road.h:163
SpriteID build_tunnel
button for building a tunnel
Definition road.h:80
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:104
uint16_t cost_multiplier
Cost multiplier for building this road type.
Definition road.h:123
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:105
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:97
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:70
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: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:235
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition road_cmd.cpp:62
RoadTypeFlag
Roadtype flag bit numbers.
Definition road.h:38
@ 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:256
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:67
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:220
Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition road.h:274
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:50
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition road.h:62
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition road.h:52
@ ROTSG_reserved2
Placeholder, if we need specific level crossing sprites.
Definition road.h:58
@ ROTSG_ROADSTOP
Required: Bay stop surface.
Definition road.h:61
@ ROTSG_GROUND
Required: Main group of ground images.
Definition road.h:53
@ ROTSG_DEPOT
Optional: Depot images.
Definition road.h:59
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition road.h:51
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition road.h:56
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition road.h:57
@ ROTSG_reserved3
Placeholder, if we add road fences (for highways).
Definition road.h:60
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition road.h:55
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition road.h:54
bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition road.h:288
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:245
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:111
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.