OpenTTD Source 20241224-master-gf74b0cf984
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"
18#include "sound_type.h"
19#include "strings_type.h"
20
21typedef uint16_t EngineID;
22
23struct Engine;
24
31
40
43 uint8_t image_index;
44 RailVehicleTypes railveh_type;
45 uint8_t cost_factor;
49 uint16_t max_speed;
50 uint16_t power;
51 uint16_t weight;
52 uint8_t running_cost;
53 Price running_cost_class;
55 uint8_t capacity;
56 uint16_t pow_wag_power;
58 uint8_t visual_effect;
61 uint8_t air_drag;
62 uint8_t user_def_data;
64};
65
68 uint8_t image_index;
69 uint8_t cost_factor;
70 uint8_t running_cost;
71 uint8_t acceleration;
72 uint16_t max_speed;
73 uint16_t capacity;
74 SoundID sfx;
76 uint8_t visual_effect;
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
94 AIR_HELI = 0,
96 AIR_FAST = 2
97};
98
101 uint8_t image_index;
102 uint8_t cost_factor;
103 uint8_t running_cost;
104 uint8_t subtype;
105 SoundID sfx;
106 uint16_t max_speed;
107 uint8_t acceleration;
110 uint16_t max_range;
111};
112
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;
121 uint8_t capacity;
122 uint8_t weight;
123 uint8_t power;
125 uint8_t air_drag;
129};
130
135enum class ExtraEngineFlags : uint16_t {
136 None = 0,
137 NoNews = (1U << 0),
138 NoPreview = (1U << 1),
139 JoinPreview = (1U << 2),
140 SyncReliability = (1U << 3),
141};
143
152 uint8_t decay_speed;
153 uint8_t load_amount;
154 uint8_t climates;
155 CargoID cargo_type;
156 std::variant<CargoLabel, MixedCargoType> cargo_label;
157 CargoTypes refit_mask;
158 uint8_t refit_cost;
159 uint8_t misc_flags;
160 uint16_t callback_mask;
162 ExtraEngineFlags extra_flags;
166};
167
182
190
201
203inline uint64_t PackEngineNameDParam(EngineID engine_id, EngineNameContext context, uint32_t extra_data = 0)
204{
205 return engine_id | (static_cast<uint64_t>(context) << 32) | (static_cast<uint64_t>(extra_data) << 40);
206}
207
208static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32;
209
210static const EngineID INVALID_ENGINE = 0xFFFF;
211
212#endif /* ENGINE_TYPE_H */
@ None
Tile is not animated.
Types related to cargoes...
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
Types related to the economy.
Price
Enumeration of all base prices for use with Prices.
ExtraEngineFlags
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.
static const uint MAX_LENGTH_ENGINE_NAME_CHARS
The maximum length of an engine name in characters including '\0'.
static const EngineID INVALID_ENGINE
Constant denoting an invalid engine.
uint16_t EngineID
Unique identification number of an engine.
Definition engine_type.h:21
AircraftSubTypeBits
AircraftVehicleInfo subtypes, bitmask type.
Definition engine_type.h:93
@ AIR_CTOL
Conventional Take Off and Landing, i.e. planes.
Definition engine_type.h:95
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.
EngineClass
Type of rail engine.
Definition engine_type.h:33
@ EC_DIESEL
Diesel rail engine.
Definition engine_type.h:35
@ EC_STEAM
Steam rail engine.
Definition engine_type.h:34
@ EC_MAGLEV
Maglev engine.
Definition engine_type.h:38
@ EC_ELECTRIC
Electric rail engine.
Definition engine_type.h:36
@ EC_MONORAIL
Mono rail engine.
Definition engine_type.h:37
EngineFlags
Engine.flags is a bitmask, with the following values.
@ ENGINE_EXCLUSIVE_PREVIEW
This vehicle is in the exclusive preview stage, either being used or being offered to a company.
@ ENGINE_AVAILABLE
This vehicle is available to everyone.
EngineMiscFlags
EngineInfo.misc_flags is a bitmask, with the following values.
@ EF_USES_2CC
Vehicle uses two company colours.
@ EF_RAIL_TILTS
Rail vehicle tilts in curves.
@ EF_NO_DEFAULT_CARGO_MULTIPLIER
Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipl...
@ EF_ROAD_TRAM
Road vehicle is a tram/light rail vehicle.
@ EF_RAIL_IS_MU
Rail vehicle is a multiple-unit (DMU/EMU)
@ EF_NO_BREAKDOWN_SMOKE
Do not show black smoke during a breakdown.
@ EF_AUTO_REFIT
Automatic refitting is allowed.
@ EF_RAIL_FLIPS
Rail vehicle has old depot-flip handling.
@ EF_SPRITE_STACK
Draw vehicle by stacking multiple sprites.
EngineNameContext
Contexts an engine name can be shown in.
@ AutoreplaceVehicleInUse
Name is show in the autoreplace window 'Vehicles in use' panel.
@ Generic
No specific context available.
@ PreviewNews
Name is shown in exclusive preview or newspaper.
@ VehicleDetails
Name is shown in the vehicle details GUI.
@ PurchaseList
Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
RailVehicleTypes
Available types of rail vehicles.
Definition engine_type.h:26
@ RAILVEH_SINGLEHEAD
indicates a "standalone" locomotive
Definition engine_type.h:27
@ RAILVEH_WAGON
simple wagon, not motorized
Definition engine_type.h:29
@ RAILVEH_MULTIHEAD
indicates a combination of two locomotives
Definition engine_type.h:28
#define DECLARE_ENUM_AS_BIT_SET(enum_type)
Operators to allow to work with enum as with type safe bit set in C++.
Definition enum_type.hpp:35
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.
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.
EngineID variant_id
Engine variant ID. If set, will be treated specially in purchase lists.
uint8_t misc_flags
Miscellaneous flags.
StringID string_id
Default name of engine.
uint8_t climates
Climates supported by the engine.
TimerGameCalendar::Date base_intro
Basic date of engine introduction (without random parts).
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
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:42
uint16_t power
Power of engine (hp); For multiheaded engines the sum of both engine powers.
Definition engine_type.h:50
uint8_t user_def_data
Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles.
Definition engine_type.h:62
uint8_t running_cost
Running cost of engine; For multiheaded engines the sum of both running costs.
Definition engine_type.h:52
uint8_t cost_factor
Purchase cost factor; For multiheaded engines the sum of both engine prices.
Definition engine_type.h:45
uint8_t shorten_factor
length on main map for this type is 8 - shorten_factor
Definition engine_type.h:59
RailType intended_railtype
Intended railtype, regardless of elrail being enabled or disabled.
Definition engine_type.h:47
uint16_t pow_wag_power
Extra power applied to consist if wagon should be powered.
Definition engine_type.h:56
uint16_t max_speed
Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
Definition engine_type.h:49
int16_t curve_speed_mod
Modifier to maximum speed in curves (fixed-point binary with 8 fractional bits)
Definition engine_type.h:63
uint16_t weight
Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
Definition engine_type.h:51
uint8_t capacity
Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
Definition engine_type.h:55
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:58
uint8_t air_drag
Coefficient of air drag.
Definition engine_type.h:61
EngineClass engclass
Class of engine for this vehicle.
Definition engine_type.h:54
uint8_t ai_passenger_only
Bit value to tell AI that this engine is for passenger use only.
Definition engine_type.h:48
RailType railtype
Railtype, mangled if elrail is disabled.
Definition engine_type.h:46
uint8_t tractive_effort
Tractive effort coefficient.
Definition engine_type.h:60
uint8_t pow_wag_weight
Extra weight applied to consist if wagon should be powered.
Definition engine_type.h:57
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:67
bool old_refittable
Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
Definition engine_type.h:75
uint8_t ocean_speed_frac
Fraction of maximum speed for ocean tiles.
Definition engine_type.h:77
uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
Apply ocean/canal speed fraction to a velocity.
Definition engine_type.h:81
uint8_t visual_effect
Bitstuffed NewGRF visual effect data.
Definition engine_type.h:76
uint16_t max_speed
Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
Definition engine_type.h:72
uint8_t acceleration
Acceleration (1 unit = 1/3.2 mph per tick = 0.5 km-ish/h per tick)
Definition engine_type.h:71
uint8_t canal_speed_frac
Fraction of maximum speed for canal/river tiles.
Definition engine_type.h:78
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition of the game-calendar-timer.