Update: Translations from eints
[openttd-github.git] / src / engine_type.h
blobd5a28ced3ea152181d08441b52764286b352e5f5
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 engine_type.h Types related to engines. */
10 #ifndef ENGINE_TYPE_H
11 #define ENGINE_TYPE_H
13 #include "economy_type.h"
14 #include "rail_type.h"
15 #include "road_type.h"
16 #include "cargo_type.h"
17 #include "timer/timer_game_calendar.h"
18 #include "sound_type.h"
19 #include "strings_type.h"
21 typedef uint16_t EngineID; ///< Unique identification number of an engine.
23 struct Engine;
25 /** Available types of rail vehicles. */
26 enum RailVehicleTypes {
27 RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive
28 RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives
29 RAILVEH_WAGON, ///< simple wagon, not motorized
32 /** Type of rail engine. */
33 enum EngineClass {
34 EC_STEAM, ///< Steam rail engine.
35 EC_DIESEL, ///< Diesel rail engine.
36 EC_ELECTRIC, ///< Electric rail engine.
37 EC_MONORAIL, ///< Mono rail engine.
38 EC_MAGLEV, ///< Maglev engine.
41 /** Information about a rail vehicle. */
42 struct RailVehicleInfo {
43 uint8_t image_index;
44 RailVehicleTypes railveh_type;
45 uint8_t cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices.
46 RailType railtype; ///< Railtype, mangled if elrail is disabled.
47 RailType intended_railtype; ///< Intended railtype, regardless of elrail being enabled or disabled.
48 uint16_t max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
49 uint16_t power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers.
50 uint16_t weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
51 uint8_t running_cost; ///< Running cost of engine; For multiheaded engines the sum of both running costs.
52 Price running_cost_class;
53 EngineClass engclass; ///< Class of engine for this vehicle
54 uint8_t capacity; ///< Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
55 uint8_t ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only
56 uint16_t pow_wag_power; ///< Extra power applied to consist if wagon should be powered
57 uint8_t pow_wag_weight; ///< Extra weight applied to consist if wagon should be powered
58 uint8_t visual_effect; ///< Bitstuffed NewGRF visual effect data
59 uint8_t shorten_factor; ///< length on main map for this type is 8 - shorten_factor
60 uint8_t tractive_effort; ///< Tractive effort coefficient
61 uint8_t air_drag; ///< Coefficient of air drag
62 uint8_t user_def_data; ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
63 int16_t curve_speed_mod; ///< Modifier to maximum speed in curves (fixed-point binary with 8 fractional bits)
66 /** Information about a ship vehicle. */
67 struct ShipVehicleInfo {
68 uint8_t image_index;
69 uint8_t cost_factor;
70 uint8_t acceleration; ///< Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick)
71 uint16_t max_speed; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
72 uint16_t capacity;
73 uint8_t running_cost;
74 SoundID sfx;
75 bool old_refittable; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
76 uint8_t visual_effect; ///< Bitstuffed NewGRF visual effect data
77 uint8_t ocean_speed_frac; ///< Fraction of maximum speed for ocean tiles.
78 uint8_t canal_speed_frac; ///< Fraction of maximum speed for canal/river tiles.
80 /** Apply ocean/canal speed fraction to a velocity */
81 uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
83 /* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
84 return raw_speed * (256 - (is_ocean ? this->ocean_speed_frac : this->canal_speed_frac)) / 256;
88 /**
89 * AircraftVehicleInfo subtypes, bitmask type.
90 * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
91 * in which case bit 1 tells us whether it's a big(fast) plane or not.
93 enum AircraftSubTypeBits {
94 AIR_HELI = 0,
95 AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes
96 AIR_FAST = 2
99 /** Information about a aircraft vehicle. */
100 struct AircraftVehicleInfo {
101 uint8_t image_index;
102 uint8_t cost_factor;
103 uint8_t running_cost;
104 uint8_t subtype; ///< Type of aircraft. @see AircraftSubTypeBits
105 SoundID sfx;
106 uint8_t acceleration;
107 uint16_t max_speed; ///< Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
108 uint8_t mail_capacity; ///< Mail capacity (bags).
109 uint16_t passenger_capacity; ///< Passenger capacity (persons).
110 uint16_t max_range; ///< Maximum range of this aircraft.
113 /** Information about a road vehicle. */
114 struct RoadVehicleInfo {
115 uint8_t image_index;
116 uint8_t cost_factor;
117 uint8_t running_cost;
118 Price running_cost_class;
119 SoundID sfx;
120 uint16_t max_speed; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
121 uint8_t capacity;
122 uint8_t weight; ///< Weight in 1/4t units
123 uint8_t power; ///< Power in 10hp units
124 uint8_t tractive_effort; ///< Coefficient of tractive effort
125 uint8_t air_drag; ///< Coefficient of air drag
126 uint8_t visual_effect; ///< Bitstuffed NewGRF visual effect data
127 uint8_t shorten_factor; ///< length on main map for this type is 8 - shorten_factor
128 RoadType roadtype; ///< Road type
131 enum class ExtraEngineFlags : uint32_t {
132 None = 0,
133 NoNews = (1U << 0), ///< No 'new vehicle' news will be generated.
134 NoPreview = (1U << 1), ///< No exclusive preview will be offered.
135 JoinPreview = (1U << 2), ///< Engine will join exclusive preview with variant parent.
136 SyncReliability = (1U << 3), ///< Engine reliability will be synced with variant parent.
138 DECLARE_ENUM_AS_BIT_SET(ExtraEngineFlags);
141 * Information about a vehicle
142 * @see table/engines.h
144 struct EngineInfo {
145 TimerGameCalendar::Date base_intro; ///< Basic date of engine introduction (without random parts).
146 TimerGameCalendar::Year lifelength; ///< Lifetime of a single vehicle
147 TimerGameCalendar::Year base_life; ///< Basic duration of engine availability (without random parts). \c 0xFF means infinite life.
148 uint8_t decay_speed;
149 uint8_t load_amount;
150 uint8_t climates; ///< Climates supported by the engine.
151 CargoID cargo_type;
152 std::variant<CargoLabel, MixedCargoType> cargo_label;
153 CargoTypes refit_mask;
154 uint8_t refit_cost;
155 uint8_t misc_flags; ///< Miscellaneous flags. @see EngineMiscFlags
156 uint16_t callback_mask; ///< Bitmask of vehicle callbacks that have to be called
157 int8_t retire_early; ///< Number of years early to retire vehicle
158 StringID string_id; ///< Default name of engine
159 uint16_t cargo_age_period; ///< Number of ticks before carried cargo is aged.
160 EngineID variant_id; ///< Engine variant ID. If set, will be treated specially in purchase lists.
161 ExtraEngineFlags extra_flags;
165 * EngineInfo.misc_flags is a bitmask, with the following values
167 enum EngineMiscFlags {
168 EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves
169 EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle
170 EF_USES_2CC = 1, ///< Vehicle uses two company colours
171 EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
172 EF_RAIL_FLIPS = 3, ///< Rail vehicle has old depot-flip handling
173 EF_AUTO_REFIT = 4, ///< Automatic refitting is allowed
174 EF_NO_DEFAULT_CARGO_MULTIPLIER = 5, ///< Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipliers. CB 15 is also called in purchase list.
175 EF_NO_BREAKDOWN_SMOKE = 6, ///< Do not show black smoke during a breakdown.
176 EF_SPRITE_STACK = 7, ///< Draw vehicle by stacking multiple sprites.
180 * Engine.flags is a bitmask, with the following values.
182 enum EngineFlags {
183 ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone.
184 ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
188 * Contexts an engine name can be shown in.
190 enum EngineNameContext : uint8_t {
191 Generic = 0x00, ///< No specific context available.
192 VehicleDetails = 0x11, ///< Name is shown in the vehicle details GUI.
193 PurchaseList = 0x20, ///< Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
194 PreviewNews = 0x21, ///< Name is shown in exclusive preview or newspaper.
195 AutoreplaceVehicleInUse = 0x22, ///< Name is show in the autoreplace window 'Vehicles in use' panel.
198 /** Combine an engine ID and a name context to an engine name dparam. */
199 inline uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data = 0)
201 return engine_id | (static_cast<uint64_t>(context) << 32) | (static_cast<uint64_t>(extra_data) << 40);
204 static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32; ///< The maximum length of an engine name in characters including '\0'
206 static const EngineID INVALID_ENGINE = 0xFFFF; ///< Constant denoting an invalid engine.
208 #endif /* ENGINE_TYPE_H */