OpenTTD Source 20241224-master-gf74b0cf984
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
44
55
56struct SpriteGroup;
57
74
76typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
77
199
201
202inline bool RoadTypeIsRoad(RoadType roadtype)
203{
204 return !HasBit(_roadtypes_type, roadtype);
205}
206
207inline bool RoadTypeIsTram(RoadType roadtype)
208{
209 return HasBit(_roadtypes_type, roadtype);
210}
211
212inline RoadTramType GetRoadTramType(RoadType roadtype)
213{
214 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
215}
216
217inline RoadTramType OtherRoadTramType(RoadTramType rtt)
218{
219 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
220}
221
227inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
228{
229 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
230 assert(roadtype < ROADTYPE_END);
231 return &_roadtypes[roadtype];
232}
233
242inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
243{
244 return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
245}
246
253{
254 assert(roadtype < ROADTYPE_END);
255 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
256}
257
264{
265 assert(roadtype < ROADTYPE_END);
266
267 /* Flat fee for removing road. */
268 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
269
270 /* Clearing tram earns a little money, but also incurs the standard clear road cost,
271 * so no profit can be made. */
272 return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
273}
274
282{
283 /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
284 if (from == to) return (Money)0;
285
286 /* Same cost as removing and then building. */
287 return RoadBuildCost(to) + RoadClearCost(from);
288}
289
295inline bool RoadNoLevelCrossing(RoadType roadtype)
296{
297 assert(roadtype < ROADTYPE_END);
298 return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_NO_LEVEL_CROSSING);
299}
300
301RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
302
303void ResetRoadTypes();
304void InitRoadTypes();
305RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
306bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
307
308extern std::vector<RoadType> _sorted_roadtypes;
309extern RoadTypes _roadtypes_hidden_mask;
310
311#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.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition road.h:147
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:105
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:107
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition road.h:152
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:117
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power
Definition road.h:122
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced.
Definition road.h:177
struct RoadTypeInfo::@28 cursor
Cursors associated with the road type.
CursorID autoroad
Cursor for autorail tool.
Definition road.h:96
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:166
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition road.h:192
uint8_t sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition road.h:182
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:118
uint16_t maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition road.h:137
RoadTypeFlags flags
Bit mask of road type flags.
Definition road.h:127
struct RoadTypeInfo::@29 strings
Strings associated with the rail type.
StringID err_build_road
Building a normal piece of road.
Definition road.h:110
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:111
uint8_t map_colour
Colour on mini-map.
Definition road.h:157
CursorID depot
Cursor for building a depot.
Definition road.h:97
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition road.h:187
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:95
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:142
StringID name
Name of this rail type.
Definition road.h:103
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:104
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:86
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:98
SpriteID auto_road
button for the autoroad construction
Definition road.h:87
struct RoadTypeInfo::@27 gui_sprites
struct containing the sprites for the road GUI.
SpriteID convert_road
button for converting road types
Definition road.h:90
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:94
StringID err_convert_road
Converting a road type.
Definition road.h:115
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition road.h:108
StringID err_depot
Building a depot.
Definition road.h:112
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:85
SpriteID build_depot
button for building depots
Definition road.h:88
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition road.h:172
SpriteID build_tunnel
button for building a tunnel
Definition road.h:89
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:113
uint16_t cost_multiplier
Cost multiplier for building this road type.
Definition road.h:132
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:114
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition road.h:106
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:35
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:18
uint32_t CursorID
The number of the cursor (sprite)
Definition gfx_type.h:20
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:242
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition road_cmd.cpp:62
RoadTypeFlag
Roadtype flag bit numbers.
Definition road.h:37
@ ROTF_NO_HOUSES
Bit number for setting this roadtype as not house friendly.
Definition road.h:40
@ ROTF_HIDDEN
Bit number for hidden from construction.
Definition road.h:41
@ ROTF_NO_LEVEL_CROSSING
Bit number for disabling level crossing.
Definition road.h:39
@ ROTF_TOWN_BUILD
Bit number for allowing towns to build this roadtype.
Definition road.h:42
@ ROTF_CATENARY
Bit number for adding catenary.
Definition road.h:38
Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition road.h:263
RoadTypeFlags
Roadtype flags.
Definition road.h:46
@ ROTFB_NO_HOUSES
Value for for setting this roadtype as not house friendly.
Definition road.h:50
@ ROTFB_NONE
All flags cleared.
Definition road.h:47
@ ROTFB_HIDDEN
Value for hidden from construction.
Definition road.h:51
@ ROTFB_CATENARY
Value for drawing a catenary.
Definition road.h:48
@ ROTFB_TOWN_BUILD
Value for allowing towns to build this roadtype.
Definition road.h:52
@ ROTFB_NO_LEVEL_CROSSING
Value for disabling a level crossing.
Definition road.h:49
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:76
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:227
Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition road.h:281
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:59
@ ROTSG_ONEWAY
Optional: One-way indicator images.
Definition road.h:71
@ ROTSG_OVERLAY
Optional: Images for overlaying track.
Definition road.h:61
@ ROTSG_reserved2
Placeholder, if we need specific level crossing sprites.
Definition road.h:67
@ ROTSG_ROADSTOP
Required: Bay stop surface.
Definition road.h:70
@ ROTSG_GROUND
Required: Main group of ground images.
Definition road.h:62
@ ROTSG_DEPOT
Optional: Depot images.
Definition road.h:68
@ ROTSG_CURSORS
Optional: Cursor and toolbar icon images.
Definition road.h:60
@ ROTSG_CATENARY_BACK
Optional: Catenary back.
Definition road.h:65
@ ROTSG_BRIDGE
Required: Bridge surface images.
Definition road.h:66
@ ROTSG_reserved3
Placeholder, if we add road fences (for highways).
Definition road.h:69
@ ROTSG_CATENARY_FRONT
Optional: Catenary front.
Definition road.h:64
@ ROTSG_TUNNEL
Optional: Ground images for tunnels.
Definition road.h:63
bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition road.h:295
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:252
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:108
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.