OpenTTD Source: src/engine_func.h File Reference

OpenTTD Source 15.3

Functions | Variables
engine_func.h File Reference

Functions related to engines. More...

`#include "engine_type.h"`
`#include "vehicle_type.h"`
`#include "company_type.h"`
`#include "timer/timer_game_calendar.h"`

Go to the source code of this file.

## Functions
void | SetupEngines ()
| Initialise the engine pool with the data from the original vehicles.
void | StartupEngines ()
| Start/initialise all our engines.
void | CheckEngines ()
| Check for engines that have an appropriate availability.
bool | IsEngineBuildable (EngineID engine, VehicleType type, CompanyID company)
| Check if an engine is buildable.
bool | IsEngineRefittable (EngineID engine)
| Check if an engine is refittable.
void | SetYearEngineAgingStops ()
| Compute the value for _year_engine_aging_stops.
void | CalcEngineReliability (Engine *e, bool new_month)
| Update Engine::reliability and (if needed) update the engine GUIs.
void | StartupOneEngine (Engine *e, const TimerGameCalendar::YearMonthDay &aging_ymd, uint32_t seed)
| Start/initialise one engine.
uint | GetTotalCapacityOfArticulatedParts (EngineID engine)
| Get the capacity of an engine with articulated parts.

## Variables
const uint8_t | _engine_counts [4]
| Number of engines of each vehicle type in original engine data.
const uint8_t | _engine_offsets [4]
| Offset of the first engine of each vehicle type in original engine data.

## Detailed Description

Functions related to engines.

Definition in file engine_func.h.

## Function Documentation

## ◆ CalcEngineReliability()

void CalcEngineReliability | ( | Engine * | e,
|  | bool | new_month
| ) |  |

Update Engine::reliability and (if needed) update the engine GUIs.

Parameters

  e | Engine to update.

Definition at line 646 of file engine.cpp.

References _settings_game, AddRemoveEngineFromAutoreplaceAndBuildWindows(), Engine::age, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), EngineInfo::base_life, ClearLastVariant(), Engine::company_avail, Engine::duration_phase_1, Engine::duration_phase_2, Engine::duration_phase_3, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, VehicleSettings::never_expire_vehicles, Engine::reliability, Engine::reliability_final, Engine::reliability_max, Engine::reliability_start, EngineInfo::retire_early, SyncReliability, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Engine::type, EngineInfo::variant_id, and GameSettings::vehicle.

Referenced by CalendarEnginesMonthlyLoop(), FixTTOEngines(), and StartupEngines().

## ◆ CheckEngines()

void CheckEngines | ( |  | ) |

Check for engines that have an appropriate availability.

Definition at line 1313 of file engine.cpp.

References Available, GetEncodedString(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), RAILVEH_WAGON, ShowErrorMessage(), VEH_TRAIN, and WL_WARNING.

## ◆ GetTotalCapacityOfArticulatedParts()

uint GetTotalCapacityOfArticulatedParts | ( | EngineID | engine | ) |

Get the capacity of an engine with articulated parts.

Parameters

  engine | The engine to get the capacity of.

Returns
  The capacity.

Definition at line 162 of file engine_gui.cpp.

References GetCapacityOfArticulatedParts(), and CargoArray::GetSum().

Referenced by RoadVehEngineCapacitySorter(), and TrainEngineCapacitySorter().

## ◆ IsEngineBuildable()

bool IsEngineBuildable | ( | EngineID | engine,
|  | VehicleType | type,
|  | CompanyID | company
| ) |  |

Check if an engine is buildable.

Parameters

  engine | index of the engine to check.
  type | the type the engine should be.
  company | index of the company.

Returns
  True if an engine is valid, of the specified type, and buildable by the given company.

Definition at line 1246 of file engine.cpp.

References BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Any(), Company::avail_railtypes, Company::avail_roadtypes, Available, Engine::company_avail, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetAllCompatibleRailTypes(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), GetRoadTypeInfo(), Engine::IsEnabled(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::None(), OWNER_DEITY, RoadTypeInfo::powered_roadtypes, RailVehicleInfo::railtypes, RoadVehicleInfo::roadtype, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Engine::type, VEH_ROAD, and VEH_TRAIN.

Referenced by CheckAutoreplaceValidity(), CmdBuildVehicle(), CmdSetVehicleVisibility(), and GetNewEngineType().

## ◆ IsEngineRefittable()

bool IsEngineRefittable | ( | EngineID | engine | ) |

Check if an engine is refittable.

Note: Likely you want to use IsArticulatedVehicleRefittable().

Parameters

  engine | index of the engine to check.

Returns
  true if the engine is refittable.

Definition at line 1287 of file engine.cpp.

References EngineInfo::callback_mask, Engine::CanCarryCargo(), CargoSuffix, Engine::GetDefaultCargoType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), IsValidCargoType(), SetBit(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by IsArticulatedVehicleRefittable(), IsVehicleRefittable(), and OrdersWindow::UpdateAutoRefitState().

## ◆ SetupEngines()

void SetupEngines | ( |  | ) |

Initialise the engine pool with the data from the original vehicles.

Definition at line 600 of file engine.cpp.

References _engine_counts, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::CleanPool(), CloseWindowByClass(), VEH_COMPANY_END, and WC_ENGINE_PREVIEW.

Referenced by ResetNewGRFData().

## ◆ SetYearEngineAgingStops()

void SetYearEngineAgingStops | ( |  | ) |

Compute the value for _year_engine_aging_stops.

Definition at line 692 of file engine.cpp.

References _settings_game, _year_engine_aging_stops, EngineInfo::base_intro, EngineInfo::climates, TimerGameCalendar::ConvertDateToYMD(), TimerGameConst< struct Calendar >::DAYS_IN_LEAP_YEAR, GameSettings::game_creation, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), GameCreationSettings::landscape, EngineInfo::lifelength, RAILVEH_WAGON, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and VEH_TRAIN.

Referenced by AfterLoadGRFs().

## ◆ StartupEngines()

void StartupEngines | ( |  | ) |

Start/initialise all our engines.

Must be called whenever there are changes to the NewGRF config.

Definition at line 798 of file engine.cpp.

References _year_engine_aging_stops, CalcEngineReliability(), TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate(), TimerGameCalendar::date, GetCompanyRailTypes(), GetCompanyRoadTypes(), InvalidateWindowClassesData(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), Random, SetWindowClassesDirty(), StartupOneEngine(), WC_BUILD_VEHICLE, and WC_REPLACE_VEHICLE.

Referenced by _GenerateWorld(), AfterLoadGame(), ConResetEngines(), SaveLoadWindow::OnTimeout(), and ReloadNewGRFData().

## ◆ StartupOneEngine()

void StartupOneEngine | ( | Engine * | e,
|  | const TimerGameCalendar::YearMonthDay & | aging_ymd,
|  | uint32_t | seed
| ) |  |

Start/initialise one engine.

Parameters

  e | The engine to initialise.
  aging_date | The date used for age calculations.
  seed | Random seed.

Definition at line 717 of file engine.cpp.

References _settings_game, Engine::age, Available, EngineInfo::base_intro, EngineInfo::base_life, EngineInfo::climates, Engine::company_avail, Engine::company_hidden, TimerGameCalendar::ConvertDateToYMD(), TimerGameCalendar::ConvertYMDToDate(), TimerGameCalendar::date, Engine::duration_phase_1, Engine::duration_phase_2, Engine::duration_phase_3, Engine::flags, GameSettings::game_creation, GB(), GameCreationSettings::generation_seed, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Engine::GetGRFID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Engine::intro_date, GameCreationSettings::landscape, EngineInfo::lifelength, Random, Engine::reliability_final, Engine::reliability_max, Engine::reliability_spd_dec, Engine::reliability_start, RestoreRandomSeeds(), EngineInfo::retire_early, SaveRandomSeeds(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetRandomSeed(), GameCreationSettings::starting_year, SyncReliability, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Engine::type, and EngineInfo::variant_id.

Referenced by FixTTOEngines(), and StartupEngines().

## Variable Documentation

## ◆ _engine_counts

const uint8_t _engine_counts[4]
| extern

Number of engines of each vehicle type in original engine data.

Definition at line 54 of file engine.cpp.

Referenced by GetNewEngine(), ParamSet(), EngineOverrideManager::ResetToDefaultMapping(), and SetupEngines().

## ◆ _engine_offsets

const uint8_t _engine_offsets[4]
| extern

Offset of the first engine of each vehicle type in original engine data.

Definition at line 62 of file engine.cpp.

Referenced by ParamSet().