OpenTTD Source: src/engine.cpp File Reference

OpenTTD Source 15.0-RC2

Functions | Variables
engine.cpp File Reference

Base for all engine handling. More...

`#include "stdafx.h"`
`#include "core/container_func.hpp"`
`#include "company_func.h"`
`#include "command_func.h"`
`#include "news_func.h"`
`#include "aircraft.h"`
`#include "newgrf.h"`
`#include "newgrf_engine.h"`
`#include "strings_func.h"`
`#include "core/random_func.hpp"`
`#include "window_func.h"`
`#include "autoreplace_gui.h"`
`#include "string_func.h"`
`#include "ai/ai.hpp"`
`#include "core/pool_func.hpp"`
`#include "engine_gui.h"`
`#include "engine_func.h"`
`#include "engine_base.h"`
`#include "company_base.h"`
`#include "vehicle_func.h"`
`#include "articulated_vehicles.h"`
`#include "error.h"`
`#include "timer/timer.h"`
`#include "timer/timer_game_tick.h"`
`#include "timer/timer_game_calendar.h"`
`#include "table/strings.h"`
`#include "table/engines.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
void | SetupEngines ()
| Initialise the engine pool with the data from the original vehicles.
void | ShowEnginePreviewWindow (EngineID engine)
static bool | IsWagon (EngineID index)
| Determine whether an engine type is a wagon (and not a loco).
static void | ClearLastVariant (EngineID engine_id, VehicleType type)
| Ensure engine is not set as the last used variant for any other engine.
void | CalcEngineReliability (Engine *e, bool new_month)
| Update Engine::reliability and (if needed) update the engine GUIs.
void | SetYearEngineAgingStops ()
| Compute the value for _year_engine_aging_stops.
void | StartupOneEngine (Engine *e, const TimerGameCalendar::YearMonthDay &aging_ymd, uint32_t seed)
| Start/initialise one engine.
void | StartupEngines ()
| Start/initialise all our engines.
static void | EnableEngineForCompany (EngineID eid, CompanyID company)
| Allows engine eid to be used by a company company.
static void | DisableEngineForCompany (EngineID eid, CompanyID company)
| Forbids engine eid to be used by a company company.
static void | AcceptEnginePreview (EngineID eid, CompanyID company, int recursion_depth=0)
| Company company accepts engine eid for preview.
static CompanyID | GetPreviewCompany (Engine *e)
| Get the best company for an engine preview.
static bool | IsVehicleTypeDisabled (VehicleType type, bool ai)
| Checks if a vehicle type is disabled for all/ai companies.
void | ClearEnginesHiddenFlagOfCompany (CompanyID cid)
| Clear the 'hidden' flag for all engines of a new company.
CommandCost | CmdSetVehicleVisibility (DoCommandFlags flags, EngineID engine_id, bool hide)
| Set the visibility of an engine.
CommandCost | CmdWantEnginePreview (DoCommandFlags flags, EngineID engine_id)
| Accept an engine prototype.
CommandCost | CmdEngineCtrl (DoCommandFlags flags, EngineID engine_id, CompanyID company_id, bool allow)
| Allow or forbid a specific company to use an engine.
static void | NewVehicleAvailable (Engine *e)
| An engine has become available for general use.
void | CalendarEnginesMonthlyLoop ()
| Monthly update of the availability, reliability, and preview offers of the engines.
static bool | IsUniqueEngineName (const std::string &name)
| Is name still free as name for an engine?
CommandCost | CmdRenameEngine (DoCommandFlags flags, EngineID engine_id, const std::string &text)
| Rename an engine.
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 | CheckEngines ()
| Check for engines that have an appropriate availability.

## Variables
EnginePool | _engine_pool ("Engine")
EngineOverrideManager | _engine_mngr
static TimerGameCalendar::Year | _year_engine_aging_stops
| Year that engine aging stops.
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.
static const IntervalTimer< TimerGameCalendar > | _calendar_engines_daily ({TimerGameCalendar::DAY, TimerGameCalendar::Priority::ENGINE}, [](auto) { for(Company *c :Company::Iterate()) { c->avail_railtypes=AddDateIntroducedRailTypes(c->avail_railtypes, TimerGameCalendar::date);c->avail_roadtypes=AddDateIntroducedRoadTypes(c->avail_roadtypes, TimerGameCalendar::date);} if(TimerGameCalendar::year >=_year_engine_aging_stops) return;for(Engine *e :Engine::Iterate()) { EngineID i=e->index;if(e->flags.Test(EngineFlag::ExclusivePreview)) { if(e->preview_company !=CompanyID::Invalid()) { if(!--e->preview_wait) { CloseWindowById(WC_ENGINE_PREVIEW, i);e->preview_company=CompanyID::Invalid();} } else if(e->preview_asked.Count()< MAX_COMPANIES) { e->preview_company=GetPreviewCompany(e);if(e->preview_company==CompanyID::Invalid()) { e->preview_asked.Set();continue;} e->preview_asked.Set(e->preview_company);e->preview_wait=20;if(!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));if(IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);} } } })
| Daily check to offer an exclusive engine preview to the companies.
static const IntervalTimer< TimerGameCalendar > | _calendar_engines_monthly ({TimerGameCalendar::MONTH, TimerGameCalendar::Priority::ENGINE}, [](auto) { CalendarEnginesMonthlyLoop();})

## Detailed Description

Base for all engine handling.

Definition in file engine.cpp.

## Function Documentation

## ◆ AcceptEnginePreview()

static void AcceptEnginePreview | ( | EngineID | eid,
|  | CompanyID | company,
|  | int | recursion_depth = `0`
| ) |  |
| static

Company company accepts engine eid for preview.

Parameters

  eid | Engine being accepted (is under preview).
  company | Current company previewing the engine.
  recursion_depth | Recursion depth to avoid infinite loop.

Definition at line 882 of file engine.cpp.

References AcceptEnginePreview(), EnableEngineForCompany(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), InvalidateWindowData(), Engine::IterateType(), JoinPreview, Engine::preview_asked, Engine::preview_company, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), Engine::type, and WC_ENGINE_PREVIEW.

Referenced by AcceptEnginePreview(), and CmdWantEnginePreview().

## ◆ 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().

## ◆ CalendarEnginesMonthlyLoop()

void CalendarEnginesMonthlyLoop | ( |  | ) |

Monthly update of the availability, reliability, and preview offers of the engines.

Definition at line 1139 of file engine.cpp.

References _year_engine_aging_stops, Available, CalcEngineReliability(), TimerGameCalendar::date, TimerGameConst< struct Calendar >::DAYS_IN_YEAR, ExclusivePreview, InvalidateWindowClassesData(), IsVehicleTypeDisabled(), IsWagon(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), NewVehicleAvailable(), NoPreview, SetWindowClassesDirty(), WC_BUILD_VEHICLE, WC_REPLACE_VEHICLE, and TimerGameCalendar::year.

Referenced by ClickChangeDateCheat().

## ◆ 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.

## ◆ ClearEnginesHiddenFlagOfCompany()

void ClearEnginesHiddenFlagOfCompany | ( | CompanyID | cid | ) |

Clear the 'hidden' flag for all engines of a new company.

Parameters

  cid | Company being created.

Definition at line 1004 of file engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate().

Referenced by DoStartupNewCompany().

## ◆ ClearLastVariant()

static void ClearLastVariant | ( | EngineID | engine_id,
|  | VehicleType | type
| ) |  |
| static

Ensure engine is not set as the last used variant for any other engine.

Parameters

  engine_id | Engine being removed.
  type | Type of engine.

Definition at line 635 of file engine.cpp.

References Engine::IterateType().

Referenced by CalcEngineReliability(), and DisableEngineForCompany().

## ◆ CmdEngineCtrl()

CommandCost CmdEngineCtrl | ( | DoCommandFlags | flags,
|  | EngineID | engine_id,
|  | CompanyID | company_id,
|  | bool | allow
| ) |  |

Allow or forbid a specific company to use an engine.

Parameters

  flags | operation to perform
  engine_id | engine id
  company_id | Company to allow/forbid the use of an engine.
  allow | false to forbid, true to allow.

Returns
  the cost of this operation or an error

Definition at line 1057 of file engine.cpp.

References _current_company, CMD_ERROR, DisableEngineForCompany(), EnableEngineForCompany(), Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ CmdRenameEngine()

CommandCost CmdRenameEngine | ( | DoCommandFlags | flags,
|  | EngineID | engine_id,
|  | const std::string & | text
| ) |  |

Rename an engine.

Parameters

  flags | operation to perform
  engine_id | engine ID to rename
  text | the new name or an empty string when resetting to the default

Returns
  the cost of this operation or an error

Definition at line 1212 of file engine.cpp.

References CMD_ERROR, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), IsUniqueEngineName(), MarkWholeScreenDirty(), MAX_LENGTH_ENGINE_NAME_CHARS, Engine::name, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Utf8StringLength().

## ◆ CmdSetVehicleVisibility()

CommandCost CmdSetVehicleVisibility | ( | DoCommandFlags | flags,
|  | EngineID | engine_id,
|  | bool | hide
| ) |  |

Set the visibility of an engine.

Parameters

  flags | Operation to perform.
  engine_id | Engine id..
  hide | Set for hidden, unset for visible.

Returns
  The cost of this operation or an error.

Definition at line 1018 of file engine.cpp.

References _current_company, AddRemoveEngineFromAutoreplaceAndBuildWindows(), CMD_ERROR, Engine::company_hidden, Execute, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsEngineBuildable(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Engine::type.

## ◆ CmdWantEnginePreview()

CommandCost CmdWantEnginePreview | ( | DoCommandFlags | flags,
|  | EngineID | engine_id
| ) |  |

Accept an engine prototype.

XXX - it is possible that the top-company changes while you are waiting to accept the offer? Then it becomes invalid

Parameters

  flags | operation to perform
  engine_id | engine-prototype offered

Returns
  the cost of this operation or an error

Definition at line 1039 of file engine.cpp.

References _current_company, AcceptEnginePreview(), CMD_ERROR, ExclusivePreview, Execute, Engine::flags, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetIfValid(), Engine::preview_company, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

## ◆ DisableEngineForCompany()

static void DisableEngineForCompany | ( | EngineID | eid,
|  | CompanyID | company
| ) |  |
| static

Forbids engine eid to be used by a company company.

Parameters

  eid | The engine to disable.
  company | The company to forbid using the engine.

Definition at line 858 of file engine.cpp.

References _local_company, AddRemoveEngineFromAutoreplaceAndBuildWindows(), Company::avail_railtypes, Company::avail_roadtypes, ClearLastVariant(), Engine::company_avail, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetCompanyRailTypes(), GetCompanyRoadTypes(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), Engine::type, VEH_ROAD, and VEH_TRAIN.

Referenced by CmdEngineCtrl().

## ◆ EnableEngineForCompany()

static void EnableEngineForCompany | ( | EngineID | eid,
|  | CompanyID | company
| ) |  |
| static

Allows engine eid to be used by a company company.

Parameters

  eid | The engine to enable.
  company | The company to allow using the engine.

Definition at line 830 of file engine.cpp.

References _local_company, AddRemoveEngineFromAutoreplaceAndBuildWindows(), Company::avail_railtypes, Company::avail_roadtypes, Engine::company_avail, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), GetCompanyRailTypes(), GetCompanyRoadTypes(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, InvalidateWindowData(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), TRANSPORT_AIR, TRANSPORT_ROAD, TRANSPORT_WATER, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, WC_BUILD_TOOLBAR, and WC_MAIN_TOOLBAR.

Referenced by AcceptEnginePreview(), and CmdEngineCtrl().

## ◆ GetPreviewCompany()

static CompanyID GetPreviewCompany | ( | Engine * | e | ) |
| static

Get the best company for an engine preview.

Parameters

  e | Engine to preview.

Returns
  Best company if it exists, CompanyID::Invalid() otherwise.

Definition at line 914 of file engine.cpp.

References GetUnionOfArticulatedRefitMasks(), HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), Engine::preview_asked, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Engine::type, and VEH_TRAIN.

## ◆ 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().

## ◆ IsUniqueEngineName()

static bool IsUniqueEngineName | ( | const std::string & | name | ) |
| static

Is name still free as name for an engine?

Parameters

  name | New name of an engine.

Returns
  `false` if the name is being used already, else `true`.

Definition at line 1196 of file engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate().

Referenced by CmdRenameEngine().

## ◆ IsVehicleTypeDisabled()

static bool IsVehicleTypeDisabled | ( | VehicleType | type,
|  | bool | ai
| ) |  |
| static

Checks if a vehicle type is disabled for all/ai companies.

Parameters

  type | The vehicle type which shall be checked.
  ai | If true, check if the type is disabled for AI companies, otherwise check if the vehicle type is disabled for human companies.

Returns
  Whether or not a vehicle type is disabled.

Definition at line 948 of file engine.cpp.

References _settings_game, GameSettings::ai, AISettings::ai_disable_veh_aircraft, AISettings::ai_disable_veh_roadveh, AISettings::ai_disable_veh_ship, AISettings::ai_disable_veh_train, VehicleSettings::max_aircraft, VehicleSettings::max_roadveh, VehicleSettings::max_ships, VehicleSettings::max_trains, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, and GameSettings::vehicle.

Referenced by CalendarEnginesMonthlyLoop(), and NewVehicleAvailable().

## ◆ IsWagon()

static bool IsWagon | ( | EngineID | index | ) |
| static

Determine whether an engine type is a wagon (and not a loco).

Parameters

  index | Engine getting queried.

Returns
  Whether the queried engine is a wagon.

Definition at line 624 of file engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), RAILVEH_WAGON, Engine::type, and VEH_TRAIN.

Referenced by CalendarEnginesMonthlyLoop(), and NewVehicleAvailable().

## ◆ NewVehicleAvailable()

static void NewVehicleAvailable | ( | Engine * | e | ) |
| static

An engine has become available for general use.

Also handle the exclusive engine preview contract.

Parameters

  e | Engine generally available as of now.

Definition at line 1079 of file engine.cpp.

References AddDateIntroducedRailTypes(), AddDateIntroducedRoadTypes(), AddNewsItem(), AddRemoveEngineFromAutoreplaceAndBuildWindows(), ALL_GROUP, Available, AI::BroadcastNewEvent(), CloseWindowById(), Engine::company_avail, TimerGameCalendar::date, ExclusivePreview, Engine::flags, GetAllIntroducesRailTypes(), GetEncodedString(), GetEngineCategoryName(), GetGroupNumEngines(), GetRoadTypeInfo(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, RoadTypeInfo::introduces_roadtypes, InvalidateWindowData(), IsVehicleTypeDisabled(), IsWagon(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), NewVehicles, NoNews, PackEngineNameDParam(), PreviewNews, RailVehicleInfo::railtypes, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), RoadVehicleInfo::roadtype, ROADTYPE_END, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), TRANSPORT_AIR, TRANSPORT_ROAD, TRANSPORT_WATER, Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, VEH_TRAIN, Vehicle, WC_BUILD_TOOLBAR, and WC_ENGINE_PREVIEW.

Referenced by CalendarEnginesMonthlyLoop().

## ◆ 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().

## ◆ ShowEnginePreviewWindow()

void ShowEnginePreviewWindow | ( | EngineID | engine | ) |

Definition at line 152 of file engine_gui.cpp.

## ◆ 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]

Initial value:
= {
lengthof(_orig_rail_vehicle_info),
lengthof(_orig_road_vehicle_info),
lengthof(_orig_ship_vehicle_info),
lengthof(_orig_aircraft_vehicle_info),
}
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271

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_mngr

EngineOverrideManager _engine_mngr

Definition at line 45 of file engine.cpp.

## ◆ _engine_offsets

const uint8_t _engine_offsets[4]

Initial value:
= {
0,
lengthof(_orig_rail_vehicle_info),
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
}

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

Definition at line 62 of file engine.cpp.

Referenced by ParamSet().

## ◆ _year_engine_aging_stops

TimerGameCalendar::Year _year_engine_aging_stops
| static

Year that engine aging stops.

Engines will not reduce in reliability and no more engines will be introduced

Definition at line 51 of file engine.cpp.

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