OpenTTD
Public Member Functions | Data Fields
Engine Struct Reference
Inheritance diagram for Engine:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >

Public Member Functions

 Engine (VehicleType type, EngineID base)
 
bool IsEnabled () const
 Checks whether the engine is a valid (non-articulated part of an) engine. More...
 
CargoID GetDefaultCargoType () const
 Determines the default cargo type of an engine. More...
 
uint DetermineCapacity (const Vehicle *v, uint16 *mail_capacity=NULL) const
 Determines capacity of a given vehicle from scratch. More...
 
bool CanCarryCargo () const
 Determines whether an engine can carry something. More...
 
uint GetDisplayDefaultCapacity (uint16 *mail_capacity=NULL) const
 Determines the default cargo capacity of an engine for display purposes. More...
 
Money GetRunningCost () const
 Return how much the running costs of this engine are. More...
 
Money GetCost () const
 Return how much a new engine costs. More...
 
uint GetDisplayMaxSpeed () const
 Returns max speed of the engine for display purposes. More...
 
uint GetPower () const
 Returns the power of the engine for display and sorting purposes. More...
 
uint GetDisplayWeight () const
 Returns the weight of the engine for display purposes. More...
 
uint GetDisplayMaxTractiveEffort () const
 Returns the tractive effort of the engine for display purposes. More...
 
Date GetLifeLengthInDays () const
 Returns the vehicle's (not model's!) life length in days. More...
 
uint16 GetRange () const
 Get the range of an aircraft type. More...
 
StringID GetAircraftTypeText () const
 Get the name of the aircraft type for display purposes. More...
 
bool IsHidden (CompanyByte c) const
 Check whether the engine is hidden in the GUI for the given company. More...
 
bool IsGroundVehicle () const
 Check if the engine is a ground vehicle. More...
 
const GRFFileGetGRF () const
 Retrieve the NewGRF the engine is tied to. More...
 
uint32 GetGRFID () const
 Retrieve the GRF ID of the NewGRF the engine is tied to. More...
 
- Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >
void * operator new (size_t size)
 Allocates space for new Titem. More...
 
void * operator new (size_t size, size_t index)
 Allocates space for new Titem with given index. More...
 
void * operator new (size_t size, void *ptr)
 Allocates space for new Titem at given memory address. More...
 
void operator delete (void *p)
 Marks Titem as free. More...
 

Data Fields

char * name
 Custom name of engine.
 
Date intro_date
 Date of introduction of the engine.
 
Date age
 
uint16 reliability
 Current reliability of the engine.
 
uint16 reliability_spd_dec
 Speed of reliability decay between services (per day).
 
uint16 reliability_start
 Initial reliability of the engine.
 
uint16 reliability_max
 Maximal reliability of the engine.
 
uint16 reliability_final
 Final reliability of the engine.
 
uint16 duration_phase_1
 First reliability phase in months, increasing reliability from reliability_start to reliability_max.
 
uint16 duration_phase_2
 Second reliability phase in months, keeping reliability_max.
 
uint16 duration_phase_3
 Third reliability phase on months, decaying to reliability_final.
 
byte flags
 Flags of the engine. More...
 
CompanyMask preview_asked
 Bit for each company which has already been offered a preview.
 
CompanyByte preview_company
 Company which is currently being offered a preview INVALID_COMPANY means no company.
 
byte preview_wait
 Daily countdown timer for timeout of offering the engine to the preview_company company.
 
CompanyMask company_avail
 Bit for each company whether the engine is available for that company.
 
CompanyMask company_hidden
 Bit for each company whether the engine is normally hidden in the build gui for that company.
 
uint8 original_image_index
 Original vehicle image index, thus the image index of the overridden vehicle.
 
VehicleType type
 Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
 
EngineInfo info
 
union {
   RailVehicleInfo   rail
 
   RoadVehicleInfo   road
 
   ShipVehicleInfo   ship
 
   AircraftVehicleInfo   air
 
u
 
GRFFilePropsBase< NUM_CARGO+2 > grf_prop
 Properties related the the grf file. More...
 
uint16 overrides_count
 
struct WagonOverrideoverrides
 
uint16 list_position
 
- Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >
Tindex index
 Index of this pool item.
 

Additional Inherited Members

- Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >
static bool CanAllocateItem (size_t n=1)
 Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() More...
 
static bool CleaningPool ()
 Returns current state of pool cleaning - yes or no. More...
 
static bool IsValidID (size_t index)
 Tests whether given index can be used to get valid (non-NULL) Titem. More...
 
static Titem * Get (size_t index)
 Returns Titem with given index. More...
 
static Titem * GetIfValid (size_t index)
 Returns Titem with given index. More...
 
static size_t GetPoolSize ()
 Returns first unused index. More...
 
static size_t GetNumItems ()
 Returns number of valid items in the pool. More...
 
static void PostDestructor (size_t index)
 Dummy function called after destructor of each member. More...
 

Detailed Description

Definition at line 23 of file engine_base.h.

Member Function Documentation

◆ CanCarryCargo()

bool Engine::CanCarryCargo ( ) const

Determines whether an engine can carry something.

A vehicle cannot carry anything if its capacity is zero, or none of the possible cargoes is available in the climate.

Returns
true if the vehicle can carry something.

Definition at line 173 of file engine.cpp.

References type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by RefitWindow::BuildRefitList(), GetAvailableVehicleCargoTypes(), GetBestFittingSubType(), GetCargoSummaryOfArticulatedVehicle(), GetDefaultCargoType(), GetNewCargoTypeForReplace(), GetVehicleDefaultCapacity(), IsArticulatedVehicleCarryingDifferentCargoes(), and IsEngineRefittable().

◆ DetermineCapacity()

uint Engine::DetermineCapacity ( const Vehicle v,
uint16 *  mail_capacity = NULL 
) const

Determines capacity of a given vehicle from scratch.

For aircraft the main capacity is determined. Mail might be present as well.

Parameters
vVehicle of interest; NULL in purchase list
mail_capacityreturns secondary cargo (mail) capacity of aircraft
Returns
Capacity

Definition at line 206 of file engine.cpp.

Referenced by GetDefaultCargoType(), GetDisplayDefaultCapacity(), and LinkRefresher::HandleRefit().

◆ GetAircraftTypeText()

StringID Engine::GetAircraftTypeText ( ) const

Get the name of the aircraft type for display purposes.

Returns
Aircraft type string.

Definition at line 470 of file engine.cpp.

References type, and VEH_AIRCRAFT.

Referenced by GetDisplayDefaultCapacity().

◆ GetCost()

Money Engine::GetCost ( ) const

Return how much a new engine costs.

Returns
Cost of the engine.

Definition at line 321 of file engine.cpp.

References type, and VEH_ROAD.

Referenced by CmdBuildVehicle(), and GetDisplayDefaultCapacity().

◆ GetDefaultCargoType()

CargoID Engine::GetDefaultCargoType ( ) const
inline

Determines the default cargo type of an engine.

Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used for livery selection etc..

Vehicles with CT_INVALID as default cargo are usually not available, but it can appear as default cargo of articulated parts.

Returns
The default cargo type.
See also
CanCarryCargo

Definition at line 81 of file engine_base.h.

References CanCarryCargo(), and DetermineCapacity().

Referenced by CmdBuildVehicle(), GetAvailableVehicleCargoTypes(), VehicleScopeResolver::GetVariable(), GetVehicleDefaultCapacity(), and IsEngineRefittable().

◆ GetDisplayDefaultCapacity()

uint Engine::GetDisplayDefaultCapacity ( uint16 *  mail_capacity = NULL) const
inline

Determines the default cargo capacity of an engine for display purposes.

For planes carrying both passenger and mail this is the passenger capacity. For multiheaded engines this is the capacity of both heads. For articulated engines use GetCapacityOfArticulatedParts

Parameters
mail_capacityreturns secondary cargo (mail) capacity of aircraft
Returns
The default capacity
See also
GetDefaultCargoType

Definition at line 101 of file engine_base.h.

References DetermineCapacity(), GetAircraftTypeText(), GetCost(), GetDisplayMaxSpeed(), GetDisplayMaxTractiveEffort(), GetDisplayWeight(), GetLifeLengthInDays(), GetPower(), GetRange(), and GetRunningCost().

Referenced by AircraftEngineCargoSorter(), GetVehicleDefaultCapacity(), and ShipEngineCapacitySorter().

◆ GetDisplayMaxSpeed()

uint Engine::GetDisplayMaxSpeed ( ) const

Returns max speed of the engine for display purposes.

Returns
max speed in km-ish/h

Definition at line 361 of file engine.cpp.

References type, and VEH_TRAIN.

Referenced by GetDisplayDefaultCapacity().

◆ GetDisplayMaxTractiveEffort()

uint Engine::GetDisplayMaxTractiveEffort ( ) const

Returns the tractive effort of the engine for display purposes.

For dual-headed train-engines this is the tractive effort of both heads

Returns
tractive effort in display units kN

Definition at line 429 of file engine.cpp.

References GetDisplayWeight(), type, and VEH_TRAIN.

Referenced by GetDisplayDefaultCapacity().

◆ GetDisplayWeight()

uint Engine::GetDisplayWeight ( ) const

Returns the weight of the engine for display purposes.

For dual-headed train-engines this is the weight of both heads

Returns
weight in display units metric tons

Definition at line 411 of file engine.cpp.

References type, and VEH_TRAIN.

Referenced by GetDisplayDefaultCapacity(), and GetDisplayMaxTractiveEffort().

◆ GetGRF()

const GRFFile* Engine::GetGRF ( ) const
inline

Retrieve the NewGRF the engine is tied to.

This is the GRF providing the Action 3.

Returns
NewGRF associated to the engine.

Definition at line 140 of file engine_base.h.

References GetGRFID(), and GRFFilePropsBase< Tcnt >::grffile.

Referenced by GetEngineGrfFile(), GetGRFID(), GetLoadAmount(), GetRefitCostFactor(), GetRoadVehLength(), and Vehicle::UpdateVisualEffect().

◆ GetGRFID()

uint32 Engine::GetGRFID ( ) const

Retrieve the GRF ID of the NewGRF the engine is tied to.

This is the GRF providing the Action 3.

Returns
GRF ID of the associated NewGRF.

Definition at line 162 of file engine.cpp.

References GetGRF().

Referenced by GetGRF(), ShowNewGrfVehicleError(), and Vehicle::UpdateVisualEffect().

◆ GetLifeLengthInDays()

Date Engine::GetLifeLengthInDays ( ) const

Returns the vehicle's (not model's!) life length in days.

Returns
the life length

Definition at line 446 of file engine.cpp.

References _settings_game, DAYS_IN_LEAP_YEAR, VehicleSettings::extend_vehicle_life, EngineInfo::lifelength, and GameSettings::vehicle.

Referenced by GetDisplayDefaultCapacity().

◆ GetPower()

uint Engine::GetPower ( ) const

Returns the power of the engine for display and sorting purposes.

Only trains and road vehicles have power

Returns
power in display units hp

Definition at line 393 of file engine.cpp.

References type, and VEH_TRAIN.

Referenced by EnginePowerVsRunningCostSorter(), and GetDisplayDefaultCapacity().

◆ GetRange()

uint16 Engine::GetRange ( ) const

Get the range of an aircraft type.

Returns
Range of the aircraft type in tiles or 0 if unlimited range.

Definition at line 456 of file engine.cpp.

References type, and VEH_AIRCRAFT.

Referenced by GetDisplayDefaultCapacity().

◆ GetRunningCost()

Money Engine::GetRunningCost ( ) const

Return how much the running costs of this engine are.

Returns
Yearly running cost of the engine.

Definition at line 284 of file engine.cpp.

References type, and VEH_ROAD.

Referenced by EnginePowerVsRunningCostSorter(), and GetDisplayDefaultCapacity().

◆ IsEnabled()

bool Engine::IsEnabled ( ) const

Checks whether the engine is a valid (non-articulated part of an) engine.

Returns
true if enabled

Definition at line 152 of file engine.cpp.

References _settings_game, EngineInfo::climates, GameSettings::game_creation, HasBit(), GameCreationSettings::landscape, and EngineInfo::string_id.

Referenced by IsEngineBuildable().

◆ IsGroundVehicle()

bool Engine::IsGroundVehicle ( ) const
inline

Check if the engine is a ground vehicle.

Returns
True iff the engine is a train or a road vehicle.

Definition at line 130 of file engine_base.h.

References VEH_ROAD, and VEH_TRAIN.

Referenced by GetArticulatedVehicleCargoesAndRefits(), GetCapacityOfArticulatedParts(), and IsArticulatedVehicleRefittable().

◆ IsHidden()

bool Engine::IsHidden ( CompanyByte  c) const
inline

Check whether the engine is hidden in the GUI for the given company.

Parameters
cCompany to check.
Returns
true iff the engine is hidden in the GUI for the given company.

Definition at line 121 of file engine_base.h.

References HasBit(), and MAX_COMPANIES.

Referenced by BuildVehicleWindow::OnClick(), and BuildVehicleWindow::SetStringParameters().

Field Documentation

◆ flags

byte Engine::flags

Flags of the engine.

See also
EngineFlags

Definition at line 35 of file engine_base.h.

Referenced by CmdWantEnginePreview(), IsEngineBuildable(), NewVehicleAvailable(), and StartupOneEngine().

◆ grf_prop

GRFFilePropsBase<NUM_CARGO + 2> Engine::grf_prop

Properties related the the grf file.

NUM_CARGO real cargo plus two pseudo cargo sprite groups. Used for obtaining the sprite offset of custom sprites, and for evaluating callbacks.

Definition at line 60 of file engine_base.h.

Referenced by SetEngineGRF(), and VehicleLengthChanged().


The documentation for this struct was generated from the following files: