Update: Translations from eints
[openttd-github.git] / src / road.h
blob44f4fcd198e2a8e79b8e68f49b7b752641999d3e
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 */
8 /** @file road.h Road specific functions. */
10 #ifndef ROAD_H
11 #define ROAD_H
13 #include "road_type.h"
14 #include "gfx_type.h"
15 #include "core/bitmath_func.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 "economy_func.h"
23 enum RoadTramType : bool {
24 RTT_ROAD,
25 RTT_TRAM,
28 enum RoadTramTypes : uint8_t {
29 RTTB_ROAD = 1 << RTT_ROAD,
30 RTTB_TRAM = 1 << RTT_TRAM,
32 DECLARE_ENUM_AS_BIT_SET(RoadTramTypes)
34 static const RoadTramType _roadtramtypes[] = { RTT_ROAD, RTT_TRAM };
36 /** Roadtype flag bit numbers. Starts with RO instead of R because R is used for rails */
37 enum RoadTypeFlag {
38 ROTF_CATENARY = 0, ///< Bit number for adding catenary
39 ROTF_NO_LEVEL_CROSSING, ///< Bit number for disabling level crossing
40 ROTF_NO_HOUSES, ///< Bit number for setting this roadtype as not house friendly
41 ROTF_HIDDEN, ///< Bit number for hidden from construction.
42 ROTF_TOWN_BUILD, ///< Bit number for allowing towns to build this roadtype.
45 /** Roadtype flags. Starts with RO instead of R because R is used for rails */
46 enum RoadTypeFlags : uint8_t {
47 ROTFB_NONE = 0, ///< All flags cleared.
48 ROTFB_CATENARY = 1 << ROTF_CATENARY, ///< Value for drawing a catenary.
49 ROTFB_NO_LEVEL_CROSSING = 1 << ROTF_NO_LEVEL_CROSSING, ///< Value for disabling a level crossing.
50 ROTFB_NO_HOUSES = 1 << ROTF_NO_HOUSES, ///< Value for for setting this roadtype as not house friendly.
51 ROTFB_HIDDEN = 1 << ROTF_HIDDEN, ///< Value for hidden from construction.
52 ROTFB_TOWN_BUILD = 1 << ROTF_TOWN_BUILD, ///< Value for allowing towns to build this roadtype.
54 DECLARE_ENUM_AS_BIT_SET(RoadTypeFlags)
56 struct SpriteGroup;
58 /** Sprite groups for a roadtype. */
59 enum RoadTypeSpriteGroup {
60 ROTSG_CURSORS, ///< Optional: Cursor and toolbar icon images
61 ROTSG_OVERLAY, ///< Optional: Images for overlaying track
62 ROTSG_GROUND, ///< Required: Main group of ground images
63 ROTSG_TUNNEL, ///< Optional: Ground images for tunnels
64 ROTSG_CATENARY_FRONT, ///< Optional: Catenary front
65 ROTSG_CATENARY_BACK, ///< Optional: Catenary back
66 ROTSG_BRIDGE, ///< Required: Bridge surface images
67 ROTSG_reserved2, ///< Placeholder, if we need specific level crossing sprites.
68 ROTSG_DEPOT, ///< Optional: Depot images
69 ROTSG_reserved3, ///< Placeholder, if we add road fences (for highways).
70 ROTSG_ROADSTOP, ///< Required: Bay stop surface
71 ROTSG_ONEWAY, ///< Optional: One-way indicator images
72 ROTSG_END,
75 /** List of road type labels. */
76 typedef std::vector<RoadTypeLabel> RoadTypeLabelList;
78 class RoadTypeInfo {
79 public:
80 /**
81 * struct containing the sprites for the road GUI. @note only sprites referred to
82 * directly in the code are listed
84 struct {
85 SpriteID build_x_road; ///< button for building single rail in X direction
86 SpriteID build_y_road; ///< button for building single rail in Y direction
87 SpriteID auto_road; ///< button for the autoroad construction
88 SpriteID build_depot; ///< button for building depots
89 SpriteID build_tunnel; ///< button for building a tunnel
90 SpriteID convert_road; ///< button for converting road types
91 } gui_sprites;
93 struct {
94 CursorID road_swne; ///< Cursor for building rail in X direction
95 CursorID road_nwse; ///< Cursor for building rail in Y direction
96 CursorID autoroad; ///< Cursor for autorail tool
97 CursorID depot; ///< Cursor for building a depot
98 CursorID tunnel; ///< Cursor for building a tunnel
99 SpriteID convert_road; ///< Cursor for converting road types
100 } cursor; ///< Cursors associated with the road type.
102 struct {
103 StringID name; ///< Name of this rail type.
104 StringID toolbar_caption; ///< Caption in the construction toolbar GUI for this rail type.
105 StringID menu_text; ///< Name of this rail type in the main toolbar dropdown.
106 StringID build_caption; ///< Caption of the build vehicle GUI for this rail type.
107 StringID replace_text; ///< Text used in the autoreplace GUI.
108 StringID new_engine; ///< Name of an engine for this type of road in the engine preview GUI.
110 StringID err_build_road; ///< Building a normal piece of road
111 StringID err_remove_road; ///< Removing a normal piece of road
112 StringID err_depot; ///< Building a depot
113 StringID err_build_station[2]; ///< Building a bus or truck station
114 StringID err_remove_station[2]; ///< Removing of a bus or truck station
115 StringID err_convert_road; ///< Converting a road type
117 StringID picker_title[2]; ///< Title for the station picker for bus or truck stations
118 StringID picker_tooltip[2]; ///< Tooltip for the station picker for bus or truck stations
119 } strings; ///< Strings associated with the rail type.
121 /** bitmask to the OTHER roadtypes on which a vehicle of THIS roadtype generates power */
122 RoadTypes powered_roadtypes;
125 * Bit mask of road type flags
127 RoadTypeFlags flags;
130 * Cost multiplier for building this road type
132 uint16_t cost_multiplier;
135 * Cost multiplier for maintenance of this road type
137 uint16_t maintenance_multiplier;
140 * Maximum speed for vehicles travelling on this road type
142 uint16_t max_speed;
145 * Unique 32 bit road type identifier
147 RoadTypeLabel label;
150 * Road type labels this type provides in addition to the main label.
152 RoadTypeLabelList alternate_labels;
155 * Colour on mini-map
157 uint8_t map_colour;
160 * Introduction date.
161 * When #INVALID_DATE or a vehicle using this roadtype gets introduced earlier,
162 * the vehicle's introduction date will be used instead for this roadtype.
163 * The introduction at this date is furthermore limited by the
164 * #introduction_required_types.
166 TimerGameCalendar::Date introduction_date;
169 * Bitmask of roadtypes that are required for this roadtype to be introduced
170 * at a given #introduction_date.
172 RoadTypes introduction_required_roadtypes;
175 * Bitmask of which other roadtypes are introduced when this roadtype is introduced.
177 RoadTypes introduces_roadtypes;
180 * The sorting order of this roadtype for the toolbar dropdown.
182 uint8_t sorting_order;
185 * NewGRF providing the Action3 for the roadtype. nullptr if not available.
187 const GRFFile *grffile[ROTSG_END];
190 * Sprite groups for resolving sprites
192 const SpriteGroup *group[ROTSG_END];
194 inline bool UsesOverlay() const
196 return this->group[ROTSG_GROUND] != nullptr;
200 extern RoadTypes _roadtypes_type;
202 inline bool RoadTypeIsRoad(RoadType roadtype)
204 return !HasBit(_roadtypes_type, roadtype);
207 inline bool RoadTypeIsTram(RoadType roadtype)
209 return HasBit(_roadtypes_type, roadtype);
212 inline RoadTramType GetRoadTramType(RoadType roadtype)
214 return RoadTypeIsTram(roadtype) ? RTT_TRAM : RTT_ROAD;
217 inline RoadTramType OtherRoadTramType(RoadTramType rtt)
219 return rtt == RTT_ROAD ? RTT_TRAM : RTT_ROAD;
223 * Returns a pointer to the Roadtype information for a given roadtype
224 * @param roadtype the road type which the information is requested for
225 * @return The pointer to the RoadTypeInfo
227 inline const RoadTypeInfo *GetRoadTypeInfo(RoadType roadtype)
229 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
230 assert(roadtype < ROADTYPE_END);
231 return &_roadtypes[roadtype];
235 * Checks if an engine of the given RoadType got power on a tile with a given
236 * RoadType. This would normally just be an equality check, but for electrified
237 * roads (which also support non-electric vehicles).
238 * @param enginetype The RoadType of the engine we are considering.
239 * @param tiletype The RoadType of the tile we are considering.
240 * @return Whether the engine got power on this tile.
242 inline bool HasPowerOnRoad(RoadType enginetype, RoadType tiletype)
244 return HasBit(GetRoadTypeInfo(enginetype)->powered_roadtypes, tiletype);
248 * Returns the cost of building the specified roadtype.
249 * @param roadtype The roadtype being built.
250 * @return The cost multiplier.
252 inline Money RoadBuildCost(RoadType roadtype)
254 assert(roadtype < ROADTYPE_END);
255 return (_price[PR_BUILD_ROAD] * GetRoadTypeInfo(roadtype)->cost_multiplier) >> 3;
259 * Returns the cost of clearing the specified roadtype.
260 * @param roadtype The roadtype being removed.
261 * @return The cost.
263 inline Money RoadClearCost(RoadType roadtype)
265 assert(roadtype < ROADTYPE_END);
267 /* Flat fee for removing road. */
268 if (RoadTypeIsRoad(roadtype)) return _price[PR_CLEAR_ROAD];
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;
276 * Calculates the cost of road conversion
277 * @param from The roadtype we are converting from
278 * @param to The roadtype we are converting to
279 * @return Cost per RoadBit
281 inline Money RoadConvertCost(RoadType from, RoadType to)
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;
286 /* Same cost as removing and then building. */
287 return RoadBuildCost(to) + RoadClearCost(from);
291 * Test if road disallows level crossings
292 * @param roadtype The roadtype we are testing
293 * @return True iff the roadtype disallows level crossings
295 inline bool RoadNoLevelCrossing(RoadType roadtype)
297 assert(roadtype < ROADTYPE_END);
298 return HasBit(GetRoadTypeInfo(roadtype)->flags, ROTF_NO_LEVEL_CROSSING);
301 RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels = true);
303 void ResetRoadTypes();
304 void InitRoadTypes();
305 RoadType AllocateRoadType(RoadTypeLabel label, RoadTramType rtt);
306 bool HasAnyRoadTypesAvail(CompanyID company, RoadTramType rtt);
308 extern std::vector<RoadType> _sorted_roadtypes;
309 extern RoadTypes _roadtypes_hidden_mask;
311 #endif /* ROAD_H */