OpenTTD Source 20250312-master-gcdcc6b491d
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 "landscape_type.h"
15#include "newgrf_callbacks.h"
16#include "rail_type.h"
17#include "road_type.h"
18#include "cargo_type.h"
20#include "sound_type.h"
21#include "strings_type.h"
22#include "newgrf_badge_type.h"
23
26
27struct Engine;
28
35
44
47 uint8_t image_index = 0;
48 RailVehicleTypes railveh_type{};
49 uint8_t cost_factor = 0;
52 uint8_t ai_passenger_only = 0;
53 uint16_t max_speed = 0;
54 uint16_t power = 0;
55 uint16_t weight = 0;
56 uint8_t running_cost = 0;
57 Price running_cost_class{};
59 uint8_t capacity = 0;
60 uint16_t pow_wag_power = 0;
61 uint8_t pow_wag_weight = 0;
62 uint8_t visual_effect = 0;
63 uint8_t shorten_factor = 0;
64 uint8_t tractive_effort = 0;
65 uint8_t air_drag = 0;
66 uint8_t user_def_data = 0;
67 int16_t curve_speed_mod = 0;
68};
69
72 uint8_t image_index = 0;
73 uint8_t cost_factor = 0;
74 uint8_t running_cost = 0;
75 uint8_t acceleration = 0;
76 uint16_t max_speed = 0;
77 uint16_t capacity = 0;
78 SoundID sfx{};
79 bool old_refittable = 0;
80 uint8_t visual_effect = 0;
81 uint8_t ocean_speed_frac = 0;
82 uint8_t canal_speed_frac = 0;
83
85 uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
86 {
87 /* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
88 return raw_speed * (256 - (is_ocean ? this->ocean_speed_frac : this->canal_speed_frac)) / 256;
89 }
90};
91
97enum AircraftSubTypeBits : uint8_t {
98 AIR_HELI = 0,
100 AIR_FAST = 2
101};
102
105 uint8_t image_index = 0;
106 uint8_t cost_factor = 0;
107 uint8_t running_cost = 0;
108 uint8_t subtype = 0;
109 SoundID sfx{};
110 uint16_t max_speed = 0;
111 uint8_t acceleration = 0;
112 uint8_t mail_capacity = 0;
113 uint16_t passenger_capacity = 0;
114 uint16_t max_range = 0;
115};
116
119 uint8_t image_index = 0;
120 uint8_t cost_factor = 0;
121 uint8_t running_cost = 0;
122 Price running_cost_class{};
123 SoundID sfx{};
124 uint16_t max_speed = 0;
125 uint8_t capacity = 0;
126 uint8_t weight = 0;
127 uint8_t power = 0;
128 uint8_t tractive_effort = 0;
129 uint8_t air_drag = 0;
130 uint8_t visual_effect = 0;
131 uint8_t shorten_factor = 0;
133};
134
139enum class ExtraEngineFlag : uint8_t {
140 NoNews = 0,
141 NoPreview = 1,
142 JoinPreview = 2,
143 SyncReliability = 3,
144};
146
150enum class EngineMiscFlag : uint8_t {
151 RailTilts = 0,
152 RoadIsTram = 0,
153
154 Uses2CC = 1,
155
156 RailIsMU = 2,
157 RailFlips = 3,
158
159 AutoRefit = 4,
161 NoBreakdownSmoke = 6,
162 SpriteStack = 7,
163};
165
174 uint8_t decay_speed = 0;
175 uint8_t load_amount = 0;
177 CargoType cargo_type{};
178 std::variant<CargoLabel, MixedCargoType> cargo_label{};
179 CargoTypes refit_mask{};
180 uint8_t refit_cost = 0;
183 int8_t retire_early = 0;
184 ExtraEngineFlags extra_flags{};
186 uint16_t cargo_age_period = 0;
188};
189
193enum class EngineFlag : uint8_t {
194 Available = 0,
195 ExclusivePreview = 1,
196};
198
202enum class EngineNameContext : uint8_t {
203 Generic = 0x00,
204 VehicleDetails = 0x11,
205 PurchaseList = 0x20,
206 PreviewNews = 0x21,
208};
209
211inline uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data = 0)
212{
213 return engine_id.base() | (static_cast<uint64_t>(context) << 32) | (static_cast<uint64_t>(extra_data) << 40);
214}
215
216static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32;
217
218#endif /* ENGINE_TYPE_H */
Types related to cargoes...
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:23
Types related to the economy.
Price
Enumeration of all base prices for use with Prices.
AircraftSubTypeBits
AircraftVehicleInfo subtypes, bitmask type.
Definition engine_type.h:97
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition engine_type.h:99
ExtraEngineFlag
Extra engine flags for NewGRF features.
@ SyncReliability
Engine reliability will be synced with variant parent.
@ NoNews
No 'new vehicle' news will be generated.
@ JoinPreview
Engine will join exclusive preview with variant parent.
@ NoPreview
No exclusive preview will be offered.
EngineMiscFlag
EngineInfo.misc_flags is a bitmask, with the following values.
@ NoDefaultCargoMultiplier
Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipl...
@ RailFlips
Rail vehicle has old depot-flip handling.
@ RoadIsTram
Road vehicle is a tram/light rail vehicle.
@ RailTilts
Rail vehicle tilts in curves.
@ NoBreakdownSmoke
Do not show black smoke during a breakdown.
@ Uses2CC
Vehicle uses two company colours.
@ SpriteStack
Draw vehicle by stacking multiple sprites.
@ RailIsMU
Rail vehicle is a multiple-unit (DMU/EMU)
@ AutoRefit
Automatic refitting is allowed.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
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.
EngineFlag
Engine.flags is a bitmask, with the following values.
@ Available
This vehicle is available to everyone.
@ ExclusivePreview
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
EngineClass
Type of rail engine.
Definition engine_type.h:37
@ EC_DIESEL
Diesel rail engine.
Definition engine_type.h:39
@ EC_STEAM
Steam rail engine.
Definition engine_type.h:38
@ EC_MAGLEV
Maglev engine.
Definition engine_type.h:42
@ EC_ELECTRIC
Electric rail engine.
Definition engine_type.h:40
@ EC_MONORAIL
Mono rail engine.
Definition engine_type.h:41
EngineNameContext
Contexts an engine name can be shown in.
@ VehicleDetails
Name is shown in the vehicle details GUI.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
@ Generic
No specific context available.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
@ PreviewNews
Name is shown in exclusive preview or newspaper.
RailVehicleTypes
Available types of rail vehicles.
Definition engine_type.h:30
@ RAILVEH_SINGLEHEAD
indicates a "standalone" locomotive
Definition engine_type.h:31
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:33
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition engine_type.h:32
Types related to the landscape.
Types related to NewGRF badges.
Callbacks that NewGRFs could implement.
The different types of rail.
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:27
Enums and other types related to roads.
RoadType
The different roadtypes we support.
Definition road_type.h:25
Types related to sounds.
Types related to strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Information about a aircraft vehicle.
uint16_t max_speed
Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
uint8_t mail_capacity
Mail capacity (bags).
uint8_t subtype
Type of aircraft.
uint16_t passenger_capacity
Passenger capacity (persons).
uint16_t max_range
Maximum range of this aircraft.
Information about a vehicle.
uint16_t cargo_age_period
Number of ticks before carried cargo is aged.
TimerGameCalendar::Year base_life
Basic duration of engine availability (without random parts). 0xFF means infinite life.
LandscapeTypes climates
Climates supported by the engine.
EngineMiscFlags misc_flags
Miscellaneous flags.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
StringID string_id
Default name of engine.
VehicleCallbackMasks callback_mask
Bitmask of vehicle callbacks that have to be called.
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
int8_t retire_early
Number of years early to retire vehicle.
TimerGameCalendar::Year lifelength
Lifetime of a single vehicle.
Information about a rail vehicle.
Definition engine_type.h:46
uint16_t power
Power of engine (hp); For multiheaded engines the sum of both engine powers.
Definition engine_type.h:54
uint8_t user_def_data
Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles.
Definition engine_type.h:66
uint8_t running_cost
Running cost of engine; For multiheaded engines the sum of both running costs.
Definition engine_type.h:56
uint8_t cost_factor
Purchase cost factor; For multiheaded engines the sum of both engine prices.
Definition engine_type.h:49
uint8_t shorten_factor
length on main map for this type is 8 - shorten_factor
Definition engine_type.h:63
RailType intended_railtype
Intended railtype, regardless of elrail being enabled or disabled.
Definition engine_type.h:51
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition engine_type.h:60
uint16_t max_speed
Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition engine_type.h:53
int16_t curve_speed_mod
Modifier to maximum speed in curves (fixed-point binary with 8 fractional bits)
Definition engine_type.h:67
uint16_t weight
Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
Definition engine_type.h:55
uint8_t capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
Definition engine_type.h:59
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:62
uint8_t air_drag
Coefficient of air drag.
Definition engine_type.h:65
EngineClass engclass
Class of engine for this vehicle.
Definition engine_type.h:58
uint8_t ai_passenger_only
Bit value to tell AI that this engine is for passenger use only.
Definition engine_type.h:52
RailType railtype
Railtype, mangled if elrail is disabled.
Definition engine_type.h:50
uint8_t tractive_effort
Tractive effort coefficient.
Definition engine_type.h:64
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition engine_type.h:61
Information about a road vehicle.
uint8_t tractive_effort
Coefficient of tractive effort.
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
uint8_t air_drag
Coefficient of air drag.
uint8_t power
Power in 10hp units.
RoadType roadtype
Road type.
uint8_t weight
Weight in 1/4t units.
uint8_t shorten_factor
length on main map for this type is 8 - shorten_factor
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Information about a ship vehicle.
Definition engine_type.h:71
bool old_refittable
Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
Definition engine_type.h:79
uint8_t ocean_speed_frac
Fraction of maximum speed for ocean tiles.
Definition engine_type.h:81
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition engine_type.h:85
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:80
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition engine_type.h:76
uint8_t acceleration
Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick)
Definition engine_type.h:75
uint8_t canal_speed_frac
Fraction of maximum speed for canal/river tiles.
Definition engine_type.h:82
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.