# engine.cpp File Reference

Base for all engine handling. More...

`#include "stdafx.h"`
`#include "debug.h"`
`#include "company_func.h"`
`#include "command_func.h"`
`#include "news_func.h"`
`#include "variables.h"`
`#include "aircraft.h"`
`#include "newgrf_engine.h"`
`#include "group.h"`
`#include "strings_func.h"`
`#include "gfx_func.h"`
`#include "core/random_func.hpp"`
`#include "window_func.h"`
`#include "date_func.h"`
`#include "autoreplace_gui.h"`
`#include "string_func.h"`
`#include "oldpool_func.h"`
`#include "ai/ai.hpp"`
`#include "vehicle_func.h"`
`#include "settings_type.h"`
`#include "table/strings.h"`
`#include "table/engines.h"`

Go to the source code of this file.

## Functions
void | SetCachedEngineCounts ()
| Sets cached values in Company::num_vehicles and Group::num_vehicles.
void | SetupEngines ()
void | ShowEnginePreviewWindow (EngineID engine)
static bool | IsWagon (EngineID index)
static void | CalcEngineReliability (Engine *e)
void | SetYearEngineAgingStops ()
void | StartupOneEngine (Engine *e, Date aging_date)
void | StartupEngines ()
static void | AcceptEnginePreview (EngineID eid, CompanyID company)
static CompanyID | GetBestCompany (uint8 pp)
void | EnginesDailyLoop ()
CommandCost | CmdWantEnginePreview (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Accept an engine prototype.
StringID | GetEngineCategoryName (EngineID engine)
static void | NewVehicleAvailable (Engine *e)
void | EnginesMonthlyLoop ()
static bool | IsUniqueEngineName (const char *name)
CommandCost | CmdRenameEngine (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *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.
## Variables
EngineOverrideManager | _engine_mngr
Year | _year_engine_aging_stops
| Year that engine aging stops.
const uint8 | _engine_counts [4]
| Number of engines of each vehicle type in original engine data.
const uint8 | _engine_offsets [4]
| Offset of the first engine of each vehicle type in original engine data.

## Detailed Description

Base for all engine handling.

Definition in file engine.cpp.

## Function Documentation

CommandCost CmdRenameEngine | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Rename an engine.

Parameters:

  | tile | unused
  | flags | operation to perfom
  | p1 | engine ID to rename
  | p2 | unused

Definition at line 735 of file engine.cpp.

References CMD_ERROR, DC_EXEC, MarkWholeScreenDirty(), MAX_LENGTH_ENGINE_NAME_BYTES, return_cmd_error, and StrEmpty().

CommandCost CmdWantEnginePreview | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

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:

  | tile | unused
  | flags | operation to perfom
  | p1 | engine-prototype offered
  | p2 | unused

Definition at line 621 of file engine.cpp.

References CMD_ERROR, and DC_EXEC.

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 770 of file engine.cpp.

References HasBit().

Referenced by CheckAutoreplaceValidity(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), and GetNewEngineType().

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 798 of file engine.cpp.

References EngineInfo::callbackmask, CBM_VEHICLE_CARGO_SUFFIX, HasBit(), and EngineInfo::refit_mask.

Referenced by IsArticulatedVehicleRefittable(), and IsVehicleRefitable().

## Variable Documentation

const uint8 _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),
    }

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

Definition at line 38 of file engine.cpp.

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

const uint8 _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 46 of file engine.cpp.

Year _year_engine_aging_stops

Year that engine aging stops.

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

Definition at line 35 of file engine.cpp.