OpenTTD Source: src/engine_type.h Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef ENGINE_TYPE_H
11#define ENGINE_TYPE_H
12
13#include "core/pool_type.hpp"
14#include "economy_type.h"
15#include "landscape_type.h"
16#include "newgrf_callbacks.h"
17#include "rail_type.h"
18#include "road_type.h"
19#include "cargo_type.h"
20#include "timer/timer_game_calendar.h"
21#include "sound_type.h"
22#include "strings_type.h"
23#include "newgrf_badge_type.h"
24
26 using EngineID = PoolID<uint16_t, struct EngineIDTag, 64000, 0xFFFF>;
27
28class Engine;
29
31 enum RailVehicleTypes : uint8_t {
32 RAILVEH_SINGLEHEAD,
33 RAILVEH_MULTIHEAD,
34 RAILVEH_WAGON,
35};
36
38 enum EngineClass : uint8_t {
39 EC_STEAM,
40 EC_DIESEL,
41 EC_ELECTRIC,
42 EC_MONORAIL,
43 EC_MAGLEV,
44};
45
47 enum class VehicleAccelerationModel : uint8_t {
48 Normal,
49 Monorail,
50 Maglev,
51};
52
54 enum VisualEffect : uint8_t {
55 VE_OFFSET_START = 0,
56 VE_OFFSET_COUNT = 4,
57 VE_OFFSET_CENTRE = 8,
58
59 VE_TYPE_START = 4,
60 VE_TYPE_COUNT = 2,
61 VE_TYPE_DEFAULT = 0,
62 VE_TYPE_STEAM = 1,
63 VE_TYPE_DIESEL = 2,
64 VE_TYPE_ELECTRIC = 3,
65
66 VE_DISABLE_EFFECT = 6,
67 VE_ADVANCED_EFFECT = VE_DISABLE_EFFECT,
68 VE_DISABLE_WAGON_POWER = 7,
69
70 VE_DEFAULT = 0xFF,
71};
72
74 struct RailVehicleInfo {
75 uint8_t image_index = 0;
76 RailVehicleTypes railveh_type = RAILVEH_WAGON;
77 uint8_t cost_factor = 0;
78 RailTypes railtypes{RAILTYPE_RAIL};
79 RailTypes intended_railtypes{RAILTYPE_RAIL};
80 uint8_t ai_passenger_only = 0;
81 uint16_t max_speed = 0;
82 uint16_t power = 0;
83 uint16_t weight = 0;
84 uint8_t running_cost = 0;
85 Price running_cost_class{};
86 EngineClass engclass{};
87 uint8_t capacity = 0;
88 uint16_t pow_wag_power = 0;
89 uint8_t pow_wag_weight = 0;
90 uint8_t visual_effect = VE_DEFAULT;
91 uint8_t shorten_factor = 0;
92 uint8_t tractive_effort = 0;
93 uint8_t air_drag = 0;
94 uint8_t user_def_data = 0;
95 int16_t curve_speed_mod = 0;
96};
97
99 struct ShipVehicleInfo {
100 uint8_t image_index = 0;
101 uint8_t cost_factor = 0;
102 uint8_t running_cost = 0;
103 uint8_t acceleration = 1;
104 uint16_t max_speed = 0;
105 uint16_t capacity = 0;
106 SoundID sfx{};
107 bool old_refittable = 0;
108 uint8_t visual_effect = VE_DEFAULT;
109 uint8_t ocean_speed_frac = 0;
110 uint8_t canal_speed_frac = 0;
111
113 uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
114 {
115 /* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
116 return raw_speed * (256 - (is_ocean ? this->ocean_speed_frac : this->canal_speed_frac)) / 256;
117 }
118};
119
125 enum AircraftSubTypeBits : uint8_t {
126 AIR_HELI = 0,
127 AIR_CTOL = 1,
128 AIR_FAST = 2
129};
130
132 struct AircraftVehicleInfo {
133 uint8_t image_index = 0;
134 uint8_t cost_factor = 0;
135 uint8_t running_cost = 0;
136 uint8_t subtype = 0;
137 SoundID sfx{};
138 uint16_t max_speed = 0;
139 uint8_t acceleration = 0;
140 uint8_t mail_capacity = 0;
141 uint16_t passenger_capacity = 0;
142 uint16_t max_range = 0;
143};
144
146 struct RoadVehicleInfo {
147 uint8_t image_index = 0;
148 uint8_t cost_factor = 0;
149 uint8_t running_cost = 0;
150 Price running_cost_class{};
151 SoundID sfx{};
152 uint16_t max_speed = 0;
153 uint8_t capacity = 0;
154 uint8_t weight = 0;
155 uint8_t power = 0;
156 uint8_t tractive_effort = 0x4C;
157 uint8_t air_drag = 0;
158 uint8_t visual_effect = VE_DEFAULT;
159 uint8_t shorten_factor = 0;
160 RoadType roadtype{};
161};
162
167 enum class ExtraEngineFlag : uint8_t {
168 NoNews = 0,
169 NoPreview = 1,
170 JoinPreview = 2,
171 SyncReliability = 3,
172};
173using ExtraEngineFlags = EnumBitSet<ExtraEngineFlag, uint8_t>;
174
178 enum class EngineMiscFlag : uint8_t {
179 RailTilts = 0,
180 RoadIsTram = 0,
181
182 Uses2CC = 1,
183
184 RailIsMU = 2,
185 RailFlips = 3,
186
187 AutoRefit = 4,
188 NoDefaultCargoMultiplier = 5,
189 NoBreakdownSmoke = 6,
190 SpriteStack = 7,
191};
192using EngineMiscFlags = EnumBitSet<EngineMiscFlag, uint8_t>;
193
198 struct EngineInfo {
199 TimerGameCalendar::Date base_intro{};
200 TimerGameCalendar::Year lifelength{};
201 TimerGameCalendar::Year base_life{};
202 uint8_t decay_speed = 0;
203 uint8_t load_amount = 0;
204 LandscapeTypes climates{};
205 CargoType cargo_type{};
206 std::variant<CargoLabel, MixedCargoType> cargo_label{};
207 CargoTypes refit_mask{};
208 uint8_t refit_cost = 0;
209 EngineMiscFlags misc_flags{};
210 VehicleCallbackMasks callback_mask{};
211 int8_t retire_early = 0;
212 ExtraEngineFlags extra_flags{};
213 StringID string_id = INVALID_STRING_ID;
214 uint16_t cargo_age_period = 0;
215 EngineID variant_id{};
216};
217
221 enum class EngineFlag : uint8_t {
222 Available = 0,
223 ExclusivePreview = 1,
224};
225using EngineFlags = EnumBitSet<EngineFlag, uint8_t>;
226
230 enum class EngineNameContext : uint8_t {
231 Generic = 0x00,
232 VehicleDetails = 0x11,
233 PurchaseList = 0x20,
234 PreviewNews = 0x21,
235 AutoreplaceVehicleInUse = 0x22,
236};
237
239 inline uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data = 0)
240{
241 return engine_id.base() | (static_cast<uint64_t>(context) << 32) | (static_cast<uint64_t>(extra_data) << 40);
242}
243
244 static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32;
245
246#endif /* ENGINE_TYPE_H */
cargo_type.h
Types related to cargoes...
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
Engine
Definition engine_base.h:38
EnumBitSet< RailType, uint64_t >
economy_type.h
Types related to the economy.
Price
Price
Enumeration of all base prices for use with Prices.
Definition economy_type.h:95
AircraftSubTypeBits
AircraftSubTypeBits
AircraftVehicleInfo subtypes, bitmask type.
Definition engine_type.h:125
AIR_CTOL
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition engine_type.h:127
ExtraEngineFlag
ExtraEngineFlag
Extra engine flags for NewGRF features.
Definition engine_type.h:167
ExtraEngineFlag::SyncReliability
@ SyncReliability
Engine reliability will be synced with variant parent.
ExtraEngineFlag::NoNews
@ NoNews
No 'new vehicle' news will be generated.
ExtraEngineFlag::JoinPreview
@ JoinPreview
Engine will join exclusive preview with variant parent.
ExtraEngineFlag::NoPreview
@ NoPreview
No exclusive preview will be offered.
EngineMiscFlag
EngineMiscFlag
EngineInfo.misc_flags is a bitmask, with the following values.
Definition engine_type.h:178
EngineMiscFlag::NoDefaultCargoMultiplier
@ NoDefaultCargoMultiplier
Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipl...
EngineMiscFlag::RailFlips
@ RailFlips
Rail vehicle has old depot-flip handling.
EngineMiscFlag::RoadIsTram
@ RoadIsTram
Road vehicle is a tram/light rail vehicle.
EngineMiscFlag::RailTilts
@ RailTilts
Rail vehicle tilts in curves.
EngineMiscFlag::NoBreakdownSmoke
@ NoBreakdownSmoke
Do not show black smoke during a breakdown.
EngineMiscFlag::Uses2CC
@ Uses2CC
Vehicle uses two company colours.
EngineMiscFlag::SpriteStack
@ SpriteStack
Draw vehicle by stacking multiple sprites.
EngineMiscFlag::RailIsMU
@ RailIsMU
Rail vehicle is a multiple-unit (DMU/EMU)
EngineMiscFlag::AutoRefit
@ AutoRefit
Automatic refitting is allowed.
VisualEffect
VisualEffect
Meaning of the various bits of the visual effect.
Definition engine_type.h:54
VE_TYPE_DEFAULT
@ VE_TYPE_DEFAULT
Use default from engine class.
Definition engine_type.h:61
VE_TYPE_COUNT
@ VE_TYPE_COUNT
Number of bits used for the effect type.
Definition engine_type.h:60
VE_OFFSET_CENTRE
@ VE_OFFSET_CENTRE
Value of offset corresponding to a position above the centre of the vehicle.
Definition engine_type.h:57
VE_TYPE_ELECTRIC
@ VE_TYPE_ELECTRIC
Electric sparks.
Definition engine_type.h:64
VE_TYPE_START
@ VE_TYPE_START
First bit used for the type of effect.
Definition engine_type.h:59
VE_OFFSET_COUNT
@ VE_OFFSET_COUNT
Number of bits used for the offset.
Definition engine_type.h:56
VE_ADVANCED_EFFECT
@ VE_ADVANCED_EFFECT
Flag for advanced effects.
Definition engine_type.h:67
VE_DISABLE_EFFECT
@ VE_DISABLE_EFFECT
Flag to disable visual effect.
Definition engine_type.h:66
VE_TYPE_STEAM
@ VE_TYPE_STEAM
Steam plumes.
Definition engine_type.h:62
VE_TYPE_DIESEL
@ VE_TYPE_DIESEL
Diesel fumes.
Definition engine_type.h:63
VE_DEFAULT
@ VE_DEFAULT
Default value to indicate that visual effect should be based on engine class.
Definition engine_type.h:70
VE_OFFSET_START
@ VE_OFFSET_START
First bit that contains the offset (0 = front, 8 = centre, 15 = rear)
Definition engine_type.h:55
VE_DISABLE_WAGON_POWER
@ VE_DISABLE_WAGON_POWER
Flag to disable wagon power.
Definition engine_type.h:68
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:244
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:239
EngineFlag
EngineFlag
Engine.flags is a bitmask, with the following values.
Definition engine_type.h:221
EngineFlag::Available
@ Available
This vehicle is available to everyone.
EngineFlag::ExclusivePreview
@ ExclusivePreview
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
EngineClass
EngineClass
Type of rail engine.
Definition engine_type.h:38
EC_DIESEL
@ EC_DIESEL
Diesel rail engine.
Definition engine_type.h:40
EC_STEAM
@ EC_STEAM
Steam rail engine.
Definition engine_type.h:39
EC_MAGLEV
@ EC_MAGLEV
Maglev engine.
Definition engine_type.h:43
EC_ELECTRIC
@ EC_ELECTRIC
Electric rail engine.
Definition engine_type.h:41
EC_MONORAIL
@ EC_MONORAIL
Mono rail engine.
Definition engine_type.h:42
EngineNameContext
EngineNameContext
Contexts an engine name can be shown in.
Definition engine_type.h:230
EngineNameContext::VehicleDetails
@ VehicleDetails
Name is shown in the vehicle details GUI.
EngineNameContext::PurchaseList
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
EngineNameContext::Generic
@ Generic
No specific context available.
EngineNameContext::AutoreplaceVehicleInUse
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
EngineNameContext::PreviewNews
@ PreviewNews
Name is shown in exclusive preview or newspaper.
VehicleAccelerationModel
VehicleAccelerationModel
Acceleration model of a vehicle.
Definition engine_type.h:47
VehicleAccelerationModel::Maglev
@ Maglev
Maglev acceleration model.
VehicleAccelerationModel::Normal
@ Normal
Default acceleration model.
VehicleAccelerationModel::Monorail
@ Monorail
Monorail acceleration model.
RailVehicleTypes
RailVehicleTypes
Available types of rail vehicles.
Definition engine_type.h:31
RAILVEH_SINGLEHEAD
@ RAILVEH_SINGLEHEAD
indicates a "standalone" locomotive
Definition engine_type.h:32
RAILVEH_WAGON
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:34
RAILVEH_MULTIHEAD
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition engine_type.h:33
landscape_type.h
Types related to the landscape.
newgrf_badge_type.h
Types related to NewGRF badges.
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
pool_type.hpp
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
rail_type.h
The different types of rail.
RAILTYPE_RAIL
@ RAILTYPE_RAIL
Standard non-electric rails.
Definition rail_type.h:27
road_type.h
Enums and other types related to roads.
RoadType
RoadType
The different roadtypes we support.
Definition road_type.h:23
sound_type.h
Types related to sounds.
strings_type.h
Types related to strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:20
AircraftVehicleInfo
Information about a aircraft vehicle.
Definition engine_type.h:132
AircraftVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
Definition engine_type.h:138
AircraftVehicleInfo::mail_capacity
uint8_t mail_capacity
Mail capacity (bags).
Definition engine_type.h:140
AircraftVehicleInfo::subtype
uint8_t subtype
Type of aircraft.
Definition engine_type.h:136
AircraftVehicleInfo::passenger_capacity
uint16_t passenger_capacity
Passenger capacity (persons).
Definition engine_type.h:141
AircraftVehicleInfo::max_range
uint16_t max_range
Maximum range of this aircraft.
Definition engine_type.h:142
EngineInfo
Information about a vehicle.
Definition engine_type.h:198
EngineInfo::cargo_age_period
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
Definition engine_type.h:214
EngineInfo::base_life
TimerGameCalendar::Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
Definition engine_type.h:201
EngineInfo::climates
LandscapeTypes climates
Climates supported by the engine.
Definition engine_type.h:204
EngineInfo::misc_flags
EngineMiscFlags misc_flags
Miscellaneous flags.
Definition engine_type.h:209
EngineInfo::variant_id
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
Definition engine_type.h:215
EngineInfo::string_id
StringID string_id
Default name of engine.
Definition engine_type.h:213
EngineInfo::callback_mask
VehicleCallbackMasks callback_mask
Bitmask of vehicle callbacks that have to be called.
Definition engine_type.h:210
EngineInfo::base_intro
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
Definition engine_type.h:199
EngineInfo::retire_early
int8_t retire_early
Number of years early to retire vehicle.
Definition engine_type.h:211
EngineInfo::lifelength
TimerGameCalendar::Year lifelength
Lifetime of a single vehicle.
Definition engine_type.h:200
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
RailVehicleInfo
Information about a rail vehicle.
Definition engine_type.h:74
RailVehicleInfo::power
uint16_t power
Power of engine (hp); For multiheaded engines the sum of both engine powers.
Definition engine_type.h:82
RailVehicleInfo::user_def_data
uint8_t user_def_data
Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles.
Definition engine_type.h:94
RailVehicleInfo::running_cost
uint8_t running_cost
Running cost of engine; For multiheaded engines the sum of both running costs.
Definition engine_type.h:84
RailVehicleInfo::cost_factor
uint8_t cost_factor
Purchase cost factor; For multiheaded engines the sum of both engine prices.
Definition engine_type.h:77
RailVehicleInfo::shorten_factor
uint8_t shorten_factor
length on main map for this type is 8 - shorten_factor
Definition engine_type.h:91
RailVehicleInfo::railtypes
RailTypes railtypes
Railtypes, mangled if elrail is disabled.
Definition engine_type.h:78
RailVehicleInfo::pow_wag_power
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition engine_type.h:88
RailVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition engine_type.h:81
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:95
RailVehicleInfo::weight
uint16_t weight
Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
Definition engine_type.h:83
RailVehicleInfo::capacity
uint8_t capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
Definition engine_type.h:87
RailVehicleInfo::visual_effect
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:90
RailVehicleInfo::air_drag
uint8_t air_drag
Coefficient of air drag.
Definition engine_type.h:93
RailVehicleInfo::intended_railtypes
RailTypes intended_railtypes
Intended railtypes, regardless of elrail being enabled or disabled.
Definition engine_type.h:79
RailVehicleInfo::engclass
EngineClass engclass
Class of engine for this vehicle.
Definition engine_type.h:86
RailVehicleInfo::ai_passenger_only
uint8_t ai_passenger_only
Bit value to tell AI that this engine is for passenger use only.
Definition engine_type.h:80
RailVehicleInfo::tractive_effort
uint8_t tractive_effort
Tractive effort coefficient.
Definition engine_type.h:92
RailVehicleInfo::pow_wag_weight
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition engine_type.h:89
RoadVehicleInfo
Information about a road vehicle.
Definition engine_type.h:146
RoadVehicleInfo::tractive_effort
uint8_t tractive_effort
Coefficient of tractive effort.
Definition engine_type.h:156
RoadVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition engine_type.h:152
RoadVehicleInfo::air_drag
uint8_t air_drag
Coefficient of air drag.
Definition engine_type.h:157
RoadVehicleInfo::power
uint8_t power
Power in 10hp units.
Definition engine_type.h:155
RoadVehicleInfo::roadtype
RoadType roadtype
Road type.
Definition engine_type.h:160
RoadVehicleInfo::weight
uint8_t weight
Weight in 1/4t units.
Definition engine_type.h:154
RoadVehicleInfo::shorten_factor
uint8_t shorten_factor
length on main map for this type is 8 - shorten_factor
Definition engine_type.h:159
RoadVehicleInfo::visual_effect
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:158
ShipVehicleInfo
Information about a ship vehicle.
Definition engine_type.h:99
ShipVehicleInfo::old_refittable
bool old_refittable
Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
Definition engine_type.h:107
ShipVehicleInfo::ocean_speed_frac
uint8_t ocean_speed_frac
Fraction of maximum speed for ocean tiles.
Definition engine_type.h:109
ShipVehicleInfo::ApplyWaterClassSpeedFrac
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition engine_type.h:113
ShipVehicleInfo::visual_effect
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:108
ShipVehicleInfo::max_speed
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition engine_type.h:104
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:103
ShipVehicleInfo::canal_speed_frac
uint8_t canal_speed_frac
Fraction of maximum speed for canal/river tiles.
Definition engine_type.h:110
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130
timer_game_calendar.h
Definition of the game-calendar-timer.