2009-08-21 20:21:05 +00:00
/*
* This file is part of OpenTTD .
* 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.
* 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 .
* 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/>.
*/
2008-03-28 18:00:38 +00:00
/** @file engine_type.h Types related to engines. */
# ifndef ENGINE_TYPE_H
# define ENGINE_TYPE_H
2009-11-07 22:47:54 +00:00
# include "economy_type.h"
2008-03-28 18:00:38 +00:00
# include "rail_type.h"
2019-04-06 06:46:15 +00:00
# include "road_type.h"
2008-03-28 18:00:38 +00:00
# include "cargo_type.h"
# include "date_type.h"
# include "sound_type.h"
# include "strings_type.h"
2024-01-07 16:41:53 +00:00
typedef uint16_t EngineID ; ///< Unique identification number of an engine.
2008-03-28 18:00:38 +00:00
2008-04-29 21:31:29 +00:00
struct Engine ;
2011-03-13 13:49:31 +00:00
/** Available types of rail vehicles. */
2008-03-28 18:00:38 +00:00
enum RailVehicleTypes {
RAILVEH_SINGLEHEAD , ///< indicates a "standalone" locomotive
RAILVEH_MULTIHEAD , ///< indicates a combination of two locomotives
RAILVEH_WAGON , ///< simple wagon, not motorized
} ;
2011-03-13 13:49:31 +00:00
/** Type of rail engine. */
2008-03-28 18:00:38 +00:00
enum EngineClass {
2011-03-13 13:49:31 +00:00
EC_STEAM , ///< Steam rail engine.
EC_DIESEL , ///< Diesel rail engine.
EC_ELECTRIC , ///< Electric rail engine.
EC_MONORAIL , ///< Mono rail engine.
EC_MAGLEV , ///< Maglev engine.
2008-03-28 18:00:38 +00:00
} ;
2011-03-13 13:49:31 +00:00
/** Information about a rail vehicle. */
2008-03-28 18:00:38 +00:00
struct RailVehicleInfo {
byte image_index ;
RailVehicleTypes railveh_type ;
2008-08-15 17:54:43 +00:00
byte cost_factor ; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices.
2023-01-06 00:44:57 +00:00
RailType railtype ; ///< Railtype, mangled if elrail is disabled.
RailType intended_railtype ; ///< Intended railtype, regardless of elrail being enabled or disabled.
2024-01-07 16:41:53 +00:00
uint16_t max_speed ; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
uint16_t power ; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers.
uint16_t weight ; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
2008-07-26 22:00:59 +00:00
byte running_cost ; ///< Running cost of engine; For multiheaded engines the sum of both running costs.
2009-11-07 22:47:54 +00:00
Price running_cost_class ;
2008-03-28 18:00:38 +00:00
EngineClass engclass ; ///< Class of engine for this vehicle
2008-07-26 22:00:59 +00:00
byte capacity ; ///< Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
2009-03-25 14:03:29 +00:00
byte ai_passenger_only ; ///< Bit value to tell AI that this engine is for passenger use only
2024-01-07 16:41:53 +00:00
uint16_t pow_wag_power ; ///< Extra power applied to consist if wagon should be powered
2009-03-25 14:03:29 +00:00
byte pow_wag_weight ; ///< Extra weight applied to consist if wagon should be powered
byte visual_effect ; ///< Bitstuffed NewGRF visual effect data
byte shorten_factor ; ///< length on main map for this type is 8 - shorten_factor
byte tractive_effort ; ///< Tractive effort coefficient
2010-08-02 14:50:26 +00:00
byte air_drag ; ///< Coefficient of air drag
2009-03-25 14:03:29 +00:00
byte user_def_data ; ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
2024-01-07 16:41:53 +00:00
int16_t curve_speed_mod ; ///< Modifier to maximum speed in curves (fixed-point binary with 8 fractional bits)
2008-03-28 18:00:38 +00:00
} ;
2011-03-13 13:49:31 +00:00
/** Information about a ship vehicle. */
2008-03-28 18:00:38 +00:00
struct ShipVehicleInfo {
byte image_index ;
2008-08-15 17:54:43 +00:00
byte cost_factor ;
2024-01-07 16:41:53 +00:00
uint16_t max_speed ; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
uint16_t capacity ;
2008-03-28 18:00:38 +00:00
byte running_cost ;
2009-05-17 17:17:48 +00:00
SoundID sfx ;
2009-10-04 20:33:18 +00:00
bool old_refittable ; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
2010-11-18 14:32:09 +00:00
byte visual_effect ; ///< Bitstuffed NewGRF visual effect data
2011-07-07 14:16:22 +00:00
byte ocean_speed_frac ; ///< Fraction of maximum speed for ocean tiles.
byte canal_speed_frac ; ///< Fraction of maximum speed for canal/river tiles.
2011-08-27 10:33:45 +00:00
/** Apply ocean/canal speed fraction to a velocity */
uint ApplyWaterClassSpeedFrac ( uint raw_speed , bool is_ocean ) const
{
/* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
return raw_speed * ( 256 - ( is_ocean ? this - > ocean_speed_frac : this - > canal_speed_frac ) ) / 256 ;
}
2008-03-28 18:00:38 +00:00
} ;
2011-03-13 13:49:31 +00:00
/**
* AircraftVehicleInfo subtypes , bitmask type .
2008-03-28 18:00:38 +00:00
* If bit 0 is 0 then it is a helicopter , otherwise it is a plane
2011-03-13 13:49:31 +00:00
* in which case bit 1 tells us whether it ' s a big ( fast ) plane or not .
*/
2010-05-13 09:44:44 +00:00
enum AircraftSubTypeBits {
2008-03-28 18:00:38 +00:00
AIR_HELI = 0 ,
AIR_CTOL = 1 , ///< Conventional Take Off and Landing, i.e. planes
AIR_FAST = 2
} ;
2011-03-13 13:49:31 +00:00
/** Information about a aircraft vehicle. */
2008-03-28 18:00:38 +00:00
struct AircraftVehicleInfo {
byte image_index ;
2008-08-15 17:54:43 +00:00
byte cost_factor ;
2008-03-28 18:00:38 +00:00
byte running_cost ;
2024-01-07 16:41:53 +00:00
byte subtype ; ///< Type of aircraft. @see AircraftSubTypeBits
2009-05-17 17:17:48 +00:00
SoundID sfx ;
2008-03-28 18:00:38 +00:00
byte acceleration ;
2024-01-07 16:41:53 +00:00
uint16_t max_speed ; ///< Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
byte mail_capacity ; ///< Mail capacity (bags).
uint16_t passenger_capacity ; ///< Passenger capacity (persons).
uint16_t max_range ; ///< Maximum range of this aircraft.
2008-03-28 18:00:38 +00:00
} ;
2011-03-13 13:49:31 +00:00
/** Information about a road vehicle. */
2008-03-28 18:00:38 +00:00
struct RoadVehicleInfo {
byte image_index ;
2008-08-15 17:54:43 +00:00
byte cost_factor ;
2008-03-28 18:00:38 +00:00
byte running_cost ;
2009-11-07 22:47:54 +00:00
Price running_cost_class ;
2009-05-17 17:17:48 +00:00
SoundID sfx ;
2024-01-07 16:41:53 +00:00
uint16_t max_speed ; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
2008-03-28 18:00:38 +00:00
byte capacity ;
2024-01-07 16:41:53 +00:00
uint8_t weight ; ///< Weight in 1/4t units
uint8_t power ; ///< Power in 10hp units
uint8_t tractive_effort ; ///< Coefficient of tractive effort
uint8_t air_drag ; ///< Coefficient of air drag
byte visual_effect ; ///< Bitstuffed NewGRF visual effect data
byte shorten_factor ; ///< length on main map for this type is 8 - shorten_factor
RoadType roadtype ; ///< Road type
2008-03-28 18:00:38 +00:00
} ;
2024-01-07 16:41:53 +00:00
enum class ExtraEngineFlags : uint8_t {
2022-12-09 01:40:55 +00:00
None = 0 ,
NoNews = ( 1U < < 0 ) , ///< No 'new vehicle' news will be generated.
NoPreview = ( 1U < < 1 ) , ///< No exclusive preview will be offered.
JoinPreview = ( 1U < < 2 ) , ///< Engine will join exclusive preview with variant parent.
SyncReliability = ( 1U < < 3 ) , ///< Engine reliability will be synced with variant parent.
} ;
DECLARE_ENUM_AS_BIT_SET ( ExtraEngineFlags ) ;
2010-08-01 19:22:34 +00:00
/**
* Information about a vehicle
2008-03-28 18:00:38 +00:00
* @ see table / engines . h
*/
struct EngineInfo {
2011-03-13 16:43:00 +00:00
Date base_intro ; ///< Basic date of engine introduction (without random parts).
2010-06-08 20:16:51 +00:00
Year lifelength ; ///< Lifetime of a single vehicle
2011-03-13 16:43:00 +00:00
Year base_life ; ///< Basic duration of engine availability (without random parts). \c 0xFF means infinite life.
2008-06-05 12:08:20 +00:00
byte decay_speed ;
2008-03-28 18:00:38 +00:00
byte load_amount ;
2011-03-13 16:43:00 +00:00
byte climates ; ///< Climates supported by the engine.
2009-08-17 18:33:48 +00:00
CargoID cargo_type ;
2018-05-21 21:08:39 +00:00
CargoTypes refit_mask ;
2008-03-28 18:00:38 +00:00
byte refit_cost ;
2024-01-07 16:41:53 +00:00
byte misc_flags ; ///< Miscellaneous flags. @see EngineMiscFlags
uint16_t callback_mask ; ///< Bitmask of vehicle callbacks that have to be called
int8_t retire_early ; ///< Number of years early to retire vehicle
StringID string_id ; ///< Default name of engine
uint16_t cargo_age_period ; ///< Number of ticks before carried cargo is aged.
EngineID variant_id ; ///< Engine variant ID. If set, will be treated specially in purchase lists.
2022-12-09 01:40:55 +00:00
ExtraEngineFlags extra_flags ;
2008-03-28 18:00:38 +00:00
} ;
/**
* EngineInfo . misc_flags is a bitmask , with the following values
*/
2010-05-13 09:44:44 +00:00
enum EngineMiscFlags {
2008-03-28 18:00:38 +00:00
EF_RAIL_TILTS = 0 , ///< Rail vehicle tilts in curves
EF_ROAD_TRAM = 0 , ///< Road vehicle is a tram/light rail vehicle
EF_USES_2CC = 1 , ///< Vehicle uses two company colours
EF_RAIL_IS_MU = 2 , ///< Rail vehicle is a multiple-unit (DMU/EMU)
2022-12-23 21:02:14 +00:00
EF_RAIL_FLIPS = 3 , ///< Rail vehicle has old depot-flip handling
2011-11-04 00:38:51 +00:00
EF_AUTO_REFIT = 4 , ///< Automatic refitting is allowed
2012-01-28 12:11:23 +00:00
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.
2012-04-17 19:43:04 +00:00
EF_NO_BREAKDOWN_SMOKE = 6 , ///< Do not show black smoke during a breakdown.
2016-10-16 14:59:44 +00:00
EF_SPRITE_STACK = 7 , ///< Draw vehicle by stacking multiple sprites.
2008-03-28 18:00:38 +00:00
} ;
/**
* Engine . flags is a bitmask , with the following values .
*/
2010-05-13 09:44:44 +00:00
enum EngineFlags {
2008-03-28 18:00:38 +00:00
ENGINE_AVAILABLE = 1 , ///< This vehicle is available to everyone.
2008-09-30 20:39:50 +00:00
ENGINE_EXCLUSIVE_PREVIEW = 2 , ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
2008-03-28 18:00:38 +00:00
} ;
2023-01-22 21:06:48 +00:00
/**
* Contexts an engine name can be shown in .
*/
2024-01-07 16:41:53 +00:00
enum EngineNameContext : uint8_t {
2023-04-16 22:02:32 +00:00
Generic = 0x00 , ///< No specific context available.
VehicleDetails = 0x11 , ///< Name is shown in the vehicle details GUI.
PurchaseList = 0x20 , ///< Name is shown in the purchase list (including autoreplace window 'Available vehicles' panel).
PreviewNews = 0x21 , ///< Name is shown in exclusive preview or newspaper.
AutoreplaceVehicleInUse = 0x22 , ///< Name is show in the autoreplace window 'Vehicles in use' panel.
2023-01-22 21:06:48 +00:00
} ;
/** Combine an engine ID and a name context to an engine name dparam. */
2024-01-07 16:41:53 +00:00
inline uint64_t PackEngineNameDParam ( EngineID engine_id , EngineNameContext context , uint32_t extra_data = 0 )
2023-01-22 21:06:48 +00:00
{
2024-01-07 16:41:53 +00:00
return engine_id | ( static_cast < uint64_t > ( context ) < < 32 ) | ( static_cast < uint64_t > ( extra_data ) < < 40 ) ;
2023-01-22 21:06:48 +00:00
}
2022-11-09 23:50:46 +00:00
static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 64 ; ///< The maximum length of an engine name in characters including '\0'
2008-03-28 18:00:38 +00:00
2011-03-13 13:49:31 +00:00
static const EngineID INVALID_ENGINE = 0xFFFF ; ///< Constant denoting an invalid engine.
2008-03-28 18:00:38 +00:00
# endif /* ENGINE_TYPE_H */