OpenTTD
road.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef ROAD_H
13 #define ROAD_H
14 
15 #include "road_type.h"
16 #include "gfx_type.h"
17 #include "core/bitmath_func.hpp"
18 #include "strings_type.h"
19 #include "date_type.h"
20 #include "core/enum_type.hpp"
21 #include "newgrf.h"
22 #include "economy_func.h"
23 
24 #include <vector>
25 
26 enum RoadTramType : bool {
27  RTT_ROAD,
28  RTT_TRAM,
29 };
30 
31 enum RoadTramTypes : uint8 {
32  RTTB_ROAD = 1 << RTT_ROAD,
33  RTTB_TRAM = 1 << RTT_TRAM,
34 };
35 DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
36 
37 #define FOR_ALL_ROADTRAMTYPES(x) for (RoadTramType x : { RTT_ROAD, RTT_TRAM })
38 
46 
47  ROTFB_NONE = 0,
53 };
55 
56 struct SpriteGroup;
57 
71  ROTSG_END,
72 };
73 
75 typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
76 
77 class RoadTypeInfo {
78 public:
83  struct {
90  } gui_sprites;
91 
92  struct {
99  } cursor;
100 
101  struct {
108 
115 
118  } strings;
119 
122 
127 
132 
137 
141  uint16 max_speed;
142 
146  RoadTypeLabel label;
147 
151  RoadTypeLabelList alternate_labels;
152 
157 
166 
172 
177 
182 
186  const GRFFile *grffile[ROTSG_END];
187 
191  const SpriteGroup *group[ROTSG_END];
192 
193  inline bool UsesOverlay() const
194  {
195  return this->group[ROTSG_GROUND] != nullptr;
196  }
197 };
198 
200 
201 static inline bool RoadTypeIsRoad(RoadType roadtype)
202 {
203  return !HasBit(_roadtypes_type, roadtype);
204 }
205 
206 static inline bool RoadTypeIsTram(RoadType roadtype)
207 {
208  return HasBit(_roadtypes_type, roadtype);
209 }
210 
211 static inline RoadTramType GetRoadTramType(RoadType roadtype)
212 {
213  return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
214 }
215 
216 static inline RoadTramType OtherRoadTramType(RoadTramType rtt)
217 {
218  return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
219 }
220 
226 static inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
227 {
228  extern RoadTypeInfo _roadtypes[ROADTYPE_END];
229  assert(roadtype < ROADTYPE_END);
230  return &_roadtypes[roadtype];
231 }
232 
241 static inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
242 {
243  return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
244 }
245 
251 static inline Money RoadBuildCost(RoadType roadtype)
252 {
253  assert(roadtype < ROADTYPE_END);
254  return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
255 }
256 
262 static inline Money RoadClearCost(RoadType roadtype)
263 {
264  assert(roadtype < ROADTYPE_END);
265 
266  /* Flat fee for removing road. */
267  if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
268 
269  /* Clearing tram earns a little money, but also incurs the standard clear road cost,
270  * so no profit can be made. */
271  return _price[PR_CLEAR_ROAD] - RoadBuildCost(roadtype) * 3 / 4;
272 }
273 
280 static inline Money RoadConvertCost(RoadType from, RoadType to)
281 {
282  /* Don't apply convert costs when converting to the same roadtype (ex. building a roadstop over existing road) */
283  if (from == to) return (Money)0;
284 
285  /* Same cost as removing and then building. */
286  return RoadBuildCost(to) + RoadClearCost(from);
287 }
288 
294 static inline bool RoadNoLevelCrossing(RoadType roadtype)
295 {
296  assert(roadtype < ROADTYPE_END);
298 }
299 
300 RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
301 
302 void ResetRoadTypes();
303 void InitRoadTypes();
304 RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
305 bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
306 
307 extern std::vector<RoadType> _sorted_roadtypes;
308 extern RoadTypes _roadtypes_hidden_mask;
309 
314 #define FOR_ALL_SORTED_ROADTYPES(var) for (uint8 index = 0; index < _sorted_roadtypes.size() && (var = _sorted_roadtypes[index], true) ; index++)
315 
316 #endif /* ROAD_H */
Owner
Enum for all companies/owners.
Definition: company_type.h:20
void ResetRoadTypes()
Reset all road type information to its default values.
Definition: road_cmd.cpp:64
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Placeholder, if we need specific tunnel sprites.
Definition: road.h:63
Enums and other types related to roads.
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:59
CursorID autoroad
Cursor for autorail tool.
Definition: road.h:95
byte map_colour
Colour on mini-map.
Definition: road.h:156
RoadTypeSpriteGroup
Sprite groups for a roadtype.
Definition: road.h:59
CursorID depot
Cursor for building a depot.
Definition: road.h:96
SpriteID build_depot
button for building depots
Definition: road.h:87
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:41
bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt)
Test if any buildable RoadType is available for a company.
Definition: road.cpp:134
RoadTypeFlags flags
Bit mask of road type flags.
Definition: road.h:126
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition: road.h:103
RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt)
Allocate a new road type label.
Definition: road_cmd.cpp:140
Used for iterations.
Definition: road_type.h:31
SpriteID build_x_road
button for building single rail in X direction
Definition: road.h:84
SpriteID build_tunnel
button for building a tunnel
Definition: road.h:88
StringID new_engine
Name of an engine for this type of road in the engine preview GUI.
Definition: road.h:107
RoadTypeFlags
Roadtype flags.
Definition: road.h:40
Value for allowing towns to build this roadtype.
Definition: road.h:52
Functions related to bit mathematics.
StringID build_caption
Caption of the build vehicle GUI for this rail type.
Definition: road.h:105
Bit number for hidden from construction.
Definition: road.h:44
Required: Drive-in stop surface.
Definition: road.h:70
Value for hidden from construction.
Definition: road.h:51
RoadType
The different roadtypes we support.
Definition: road_type.h:27
StringID err_convert_road
Converting a road type.
Definition: road.h:114
const SpriteGroup * group[ROTSG_END]
Sprite groups for resolving sprites.
Definition: road.h:191
Type (helpers) for enums.
Bit number for adding catenary.
Definition: road.h:41
StringID replace_text
Text used in the autoreplace GUI.
Definition: road.h:106
Bit number for setting this roadtype as not house friendly.
Definition: road.h:43
StringID name
Name of this rail type.
Definition: road.h:102
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:226
Bit number for allowing towns to build this roadtype.
Definition: road.h:45
RoadTypes powered_roadtypes
bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power ...
Definition: road.h:121
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition: road.h:113
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition: road.h:117
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition: road.h:116
static Money RoadClearCost(RoadType roadtype)
Returns the cost of clearing the specified roadtype.
Definition: road.h:262
uint16 maintenance_multiplier
Cost multiplier for maintenance of this road type.
Definition: road.h:136
Value for for setting this roadtype as not house friendly.
Definition: road.h:50
RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels=true)
Get the road type for a given label.
Definition: road.cpp:247
Optional: Catenary front.
Definition: road.h:64
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition: road.h:104
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:141
static Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition: road.h:251
Optional: Cursor and toolbar icon images.
Definition: road.h:60
StringID err_remove_road
Removing a normal piece of road.
Definition: road.h:110
Optional: Depot images.
Definition: road.h:68
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
struct RoadTypeInfo::@40 gui_sprites
struct containing the sprites for the road GUI.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
std::vector< RoadTypeLabel > RoadTypeLabelList
List of road type labels.
Definition: road.h:75
byte sorting_order
The sorting order of this roadtype for the toolbar dropdown.
Definition: road.h:181
CursorID road_nwse
Cursor for building rail in Y direction.
Definition: road.h:94
StringID err_depot
Building a depot.
Definition: road.h:111
void InitRoadTypes()
Resolve sprites of custom road types.
Definition: road_cmd.cpp:120
static 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:241
Required: Bridge surface images.
Definition: road.h:66
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
All flags cleared.
Definition: road.h:47
uint16 cost_multiplier
Cost multiplier for building this road type.
Definition: road.h:131
CursorID road_swne
Cursor for building rail in X direction.
Definition: road.h:93
Value for disabling a level crossing.
Definition: road.h:49
static bool RoadNoLevelCrossing(RoadType roadtype)
Test if road disallows level crossings.
Definition: road.h:294
Functions related to the economy.
Date introduction_date
Introduction date.
Definition: road.h:165
StringID err_build_road
Building a normal piece of road.
Definition: road.h:109
Optional: Catenary back.
Definition: road.h:65
Value for drawing a catenary.
Definition: road.h:48
SpriteID build_y_road
button for building single rail in Y direction
Definition: road.h:85
Placeholder, if we add road fences (for highways).
Definition: road.h:69
uint32 CursorID
The number of the cursor (sprite)
Definition: gfx_type.h:21
CursorID tunnel
Cursor for building a tunnel.
Definition: road.h:97
Types related to strings.
Types related to the dates in OpenTTD.
Placeholder, if we need specific level crossing sprites.
Definition: road.h:67
int32 Date
The type to store our dates in.
Definition: date_type.h:16
Bit number for disabling level crossing.
Definition: road.h:42
RoadTypes introduction_required_roadtypes
Bitmask of roadtypes that are required for this roadtype to be introduced at a given introduction_dat...
Definition: road.h:171
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static Money RoadConvertCost(RoadType from, RoadType to)
Calculates the cost of road conversion.
Definition: road.h:280
Required: Main group of ground images.
Definition: road.h:62
RoadTypes introduces_roadtypes
Bitmask of which other roadtypes are introduced when this roadtype is introduced. ...
Definition: road.h:176
RoadTypeLabelList alternate_labels
Road type labels this type provides in addition to the main label.
Definition: road.h:151
const GRFFile * grffile[ROTSG_END]
NewGRF providing the Action3 for the roadtype.
Definition: road.h:186
SpriteID auto_road
button for the autoroad construction
Definition: road.h:86
struct RoadTypeInfo::@41 cursor
Cursors associated with the road type.
SpriteID convert_road
button for converting road types
Definition: road.h:89
StringID err_build_station[2]
Building a bus or truck station.
Definition: road.h:112
Optional: Images for overlaying track.
Definition: road.h:61
Types related to the graphics and/or input devices.
RoadTypeLabel label
Unique 32 bit road type identifier.
Definition: road.h:146
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:107
Base for the NewGRF implementation.