OpenTTD Source: src/engine_type.h Source File

OpenTTD Source 14.1

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