# engine.h File Reference

`#include "rail_type.h"`
`#include "cargo_type.h"`
`#include "vehicle_type.h"`
`#include "gfx_type.h"`
`#include "date_type.h"`
`#include "sound_type.h"`
`#include "player_type.h"`
`#include "strings_type.h"`

Go to the source code of this file.

## Data Structures

struct | RailVehicleInfo
struct | ShipVehicleInfo
struct | AircraftVehicleInfo
struct | RoadVehicleInfo
struct | EngineInfo
| Information about a vehicle. More...
struct | Engine

## Defines

#define | FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
#define | FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)

## Typedefs

typedef int CDECL | EngList_SortTypeFunction (const void *, const void *)
| argument type for EngList_Sort()

## Enumerations

enum | RailVehicleTypes { RAILVEH_SINGLEHEAD, RAILVEH_MULTIHEAD, RAILVEH_WAGON }
enum | EngineClass { EC_STEAM, EC_DIESEL, EC_ELECTRIC, EC_MONORAIL, EC_MAGLEV }
enum | { AIR_HELI = 0, AIR_CTOL = 1, AIR_FAST = 2 }
enum | { EF_RAIL_TILTS = 0, EF_ROAD_TRAM = 0, EF_USES_2CC = 1, EF_RAIL_IS_MU = 2 }
| EngineInfo.misc_flags is a bitmask, with the following values. More...
enum | { ENGINE_AVAILABLE = 1, ENGINE_EXCLUSIVE_PREVIEW = 2, ENGINE_OFFER_WINDOW_OPEN = 4 }
| Engine.flags is a bitmask, with the following values. More...
enum | { NUM_VEHICLE_TYPES = 6 }

enum

{
NUM_NORMAL_RAIL_ENGINES = 54, NUM_MONORAIL_ENGINES = 30, NUM_MAGLEV_ENGINES = 32, NUM_TRAIN_ENGINES = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
NUM_ROAD_ENGINES = 88, NUM_SHIP_ENGINES = 11, NUM_AIRCRAFT_ENGINES = 41, TOTAL_NUM_ENGINES = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
AIRCRAFT_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES, SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES, ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES
}

## Functions

void | SetupEngines ()
void | StartupEngines ()
void | DrawTrainEngine (int x, int y, EngineID engine, SpriteID pal)
void | DrawRoadVehEngine (int x, int y, EngineID engine, SpriteID pal)
void | DrawShipEngine (int x, int y, EngineID engine, SpriteID pal)
void | DrawAircraftEngine (int x, int y, EngineID engine, SpriteID pal)
void | LoadCustomEngineNames ()
void | DeleteCustomEngineNames ()
bool | IsEngineBuildable (EngineID engine, VehicleType type, PlayerID player)
| Check if an engine is buildable.
CargoID | GetEngineCargoType (EngineID engine)
| Get the default cargo type for a certain engine type.
static EngineID | GetFirstEngineOfType (VehicleType type)
static EngineID | GetLastEngineOfType (VehicleType type)
static Engine * | GetEngine (EngineID i)
static bool | IsEngineIndex (uint index)
static const EngineInfo * | EngInfo (EngineID e)
static const RailVehicleInfo * | RailVehInfo (EngineID e)
static const ShipVehicleInfo * | ShipVehInfo (EngineID e)
static const AircraftVehicleInfo * | AircraftVehInfo (EngineID e)
static const RoadVehicleInfo * | RoadVehInfo (EngineID e)
void | EngList_Create (EngineList *el)
| Creates engine list.
void | EngList_Destroy (EngineList *el)
| Deallocate and destroy engine list.
uint | EngList_Count (const EngineList *el)
| Returns number of items in the engine list.
void | EngList_Add (EngineList *el, EngineID eid)
| Append one item at the end of engine list.
EngineID * | EngList_Items (EngineList *el)
| Returns engine list items as C array.
void | EngList_RemoveAll (EngineList *el)
| Removes all items from engine list.
void | EngList_Sort (EngineList *el, EngList_SortTypeFunction compare)
| qsort of the engine list
void | EngList_SortPartial (EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
| qsort of specified portion of the engine list

## Variables

static const EngineID | INVALID_ENGINE = 0xFFFF
Engine | _engines [TOTAL_NUM_ENGINES]
const EngineInfo | _orig_engine_info [TOTAL_NUM_ENGINES]
const RailVehicleInfo | _orig_rail_vehicle_info [NUM_TRAIN_ENGINES]
const ShipVehicleInfo | _orig_ship_vehicle_info [NUM_SHIP_ENGINES]
const AircraftVehicleInfo | _orig_aircraft_vehicle_info [NUM_AIRCRAFT_ENGINES]
const RoadVehicleInfo | _orig_road_vehicle_info [NUM_ROAD_ENGINES]
EngineInfo | _engine_info [TOTAL_NUM_ENGINES]
RailVehicleInfo | _rail_vehicle_info [NUM_TRAIN_ENGINES]
ShipVehicleInfo | _ship_vehicle_info [NUM_SHIP_ENGINES]
AircraftVehicleInfo | _aircraft_vehicle_info [NUM_AIRCRAFT_ENGINES]
RoadVehicleInfo | _road_vehicle_info [NUM_ROAD_ENGINES]

## Detailed Description

Definition in file engine.h.

## Enumeration Type Documentation

anonymous enum

Enumerator:

  AIR_CTOL | Conventional Take Off and Landing, i.e. planes.

Definition at line 71 of file engine.h.

anonymous enum

EngineInfo.misc_flags is a bitmask, with the following values.

Enumerator:

  EF_RAIL_TILTS | Rail vehicle tilts in curves.
  EF_ROAD_TRAM | Road vehicle is a tram/light rail vehicle.
  EF_USES_2CC | Vehicle uses two company colours.
  EF_RAIL_IS_MU | Rail vehicle is a multiple-unit (DMU/EMU).

Definition at line 137 of file engine.h.

anonymous enum

Engine.flags is a bitmask, with the following values.

Enumerator:

  ENGINE_AVAILABLE | This vehicle is available to everyone.
  ENGINE_EXCLUSIVE_PREVIEW | This vehicle is in the exclusive preview stage, either being used or being offered to a player.
  ENGINE_OFFER_WINDOW_OPEN | The exclusive offer window is currently open for a player.

Definition at line 147 of file engine.h.

enum RailVehicleTypes

Enumerator:

  RAILVEH_SINGLEHEAD | indicates a "standalone" locomotive
  RAILVEH_MULTIHEAD | indicates a combination of two locomotives
  RAILVEH_WAGON | simple wagon, not motorized

Definition at line 17 of file engine.h.

## Function Documentation

void EngList_Add | ( | EngineList * | el,
|  | EngineID | eid |
| ) |  |  |

Append one item at the end of engine list.

Append one item at the end of engine list.

Parameters:

  | el | list o which to add an engine
  | eid | engine to add to the list

Definition at line 49 of file helpers.cpp.

Referenced by GenerateReplaceVehList().

uint EngList_Count | ( | const EngineList * | el | ) |

Returns number of items in the engine list.

Returns number of items in the engine list.

Parameters:

  | el | list for count inquiry

Returns:
  the desired count

Definition at line 40 of file helpers.cpp.

Referenced by DrawEngineList(), and GenerateLists().

void EngList_Create | ( | EngineList * | el | ) |

Creates engine list.

Creates engine list.

Parameters:

  | el | list to be created

Definition at line 21 of file helpers.cpp.

void EngList_Destroy | ( | EngineList * | el | ) |

Deallocate and destroy engine list.

Deallocate and destroy engine list.

Parameters:

  | el | list to be destroyed

Definition at line 30 of file helpers.cpp.

EngineID* EngList_Items | ( | EngineList * | el | ) |

Returns engine list items as C array.

Returns engine list items as C array.

Parameters:

  | el | list from which the array pointer has to be returned

Returns:
  the pointer required

Definition at line 58 of file helpers.cpp.

void EngList_RemoveAll | ( | EngineList * | el | ) |

Removes all items from engine list.

Removes all items from engine list.

Parameters:

  | el | list to be cleared

Definition at line 66 of file helpers.cpp.

Referenced by GenerateLists(), and GenerateReplaceVehList().

void EngList_Sort | ( | EngineList * | el,
|  | EngList_SortTypeFunction | compare |
| ) |  |  |

qsort of the engine list

qsort of the engine list

Parameters:

  | el | list to be sorted
  | compare | function for evaluation of the quicksort

Definition at line 75 of file helpers.cpp.

Referenced by GenerateReplaceVehList().

void EngList_SortPartial | ( | EngineList * | el,
|  | EngList_SortTypeFunction | compare,
|  | uint | begin,
|  | uint | num_items |
| ) |  |  |

qsort of specified portion of the engine list

qsort of specified portion of the engine list

Parameters:

  | el | list to be sorted
  | compare | function for evaluation of the quicksort
  | begin | start of sorting
  | num_items | count of items to be sorted

Definition at line 86 of file helpers.cpp.

CargoID GetEngineCargoType | ( | EngineID | engine | ) |

Get the default cargo type for a certain engine type.

Parameters:

  | engine | The ID to get the cargo for

Returns:
  The cargo type. CT_INVALID means no cargo capacity

Definition at line 446 of file engine.cpp.

Referenced by CmdCloneVehicle().

bool IsEngineBuildable | ( | EngineID | engine,
|  | VehicleType | type,
|  | PlayerID | player |
| ) |  |  |

Check if an engine is buildable.

Parameters:

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

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

Definition at line 420 of file engine.cpp.

References HasBit().

Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), and GenerateReplaceVehList().