# newgrf_engine.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "variables.h"`
`#include "debug.h"`
`#include "engine.h"`
`#include "train.h"`
`#include "player_func.h"`
`#include "player_base.h"`
`#include "station.h"`
`#include "airport.h"`
`#include "newgrf.h"`
`#include "newgrf_callbacks.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_station.h"`
`#include "newgrf_spritegroup.h"`
`#include "newgrf_cargo.h"`
`#include "cargotype.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "core/random_func.hpp"`
`#include "direction_func.h"`
`#include "rail_map.h"`
`#include "rail.h"`
`#include "aircraft.h"`

Go to the source code of this file.

## Data Structures

struct | WagonOverride
struct | WagonOverrides

## Enumerations

enum

{
AMS_TTDP_HANGAR, AMS_TTDP_TO_HANGAR, AMS_TTDP_TO_PAD1, AMS_TTDP_TO_PAD2,
AMS_TTDP_TO_PAD3, AMS_TTDP_TO_ENTRY_2_AND_3, AMS_TTDP_TO_ENTRY_2_AND_3_AND_H, AMS_TTDP_TO_JUNCTION,
AMS_TTDP_LEAVE_RUNWAY, AMS_TTDP_TO_INWAY, AMS_TTDP_TO_RUNWAY, AMS_TTDP_TO_OUTWAY,
AMS_TTDP_WAITING, AMS_TTDP_TAKEOFF, AMS_TTDP_TO_TAKEOFF, AMS_TTDP_CLIMBING,
AMS_TTDP_FLIGHT_APPROACH, AMS_TTDP_UNUSED_0x11, AMS_TTDP_FLIGHT_TO_TOWER, AMS_TTDP_UNUSED_0x13,
AMS_TTDP_FLIGHT_FINAL, AMS_TTDP_FLIGHT_DESCENT, AMS_TTDP_BRAKING, AMS_TTDP_HELI_TAKEOFF_AIRPORT,
AMS_TTDP_HELI_TO_TAKEOFF_AIRPORT, AMS_TTDP_HELI_LAND_AIRPORT, AMS_TTDP_HELI_TAKEOFF_HELIPORT, AMS_TTDP_HELI_TO_TAKEOFF_HELIPORT,
AMS_TTDP_HELI_LAND_HELIPORT
}

enum

{
AMA_TTDP_IN_HANGAR, AMA_TTDP_ON_PAD1, AMA_TTDP_ON_PAD2, AMA_TTDP_ON_PAD3,
AMA_TTDP_HANGAR_TO_PAD1, AMA_TTDP_HANGAR_TO_PAD2, AMA_TTDP_HANGAR_TO_PAD3, AMA_TTDP_LANDING_TO_PAD1,
AMA_TTDP_LANDING_TO_PAD2, AMA_TTDP_LANDING_TO_PAD3, AMA_TTDP_PAD1_TO_HANGAR, AMA_TTDP_PAD2_TO_HANGAR,
AMA_TTDP_PAD3_TO_HANGAR, AMA_TTDP_PAD1_TO_TAKEOFF, AMA_TTDP_PAD2_TO_TAKEOFF, AMA_TTDP_PAD3_TO_TAKEOFF,
AMA_TTDP_HANGAR_TO_TAKOFF, AMA_TTDP_LANDING_TO_HANGAR, AMA_TTDP_IN_FLIGHT
}

enum | { ATP_TTDP_SMALL, ATP_TTDP_LARGE, ATP_TTDP_HELIPORT, ATP_TTDP_OILRIG }

## Functions

void | SetWagonOverrideSprites (EngineID engine, CargoID cargo, const SpriteGroup *group, EngineID *train_id, uint trains)
const SpriteGroup * | GetWagonOverrideSpriteSet (EngineID engine, CargoID cargo, EngineID overriding_engine)
void | UnloadWagonOverrides ()
| Unload all wagon override sprite groups.
void | SetCustomEngineSprites (EngineID engine, byte cargo, const SpriteGroup *group)
void | UnloadCustomEngineSprites ()
| Unload all engine sprite groups.
void | SetEngineGRF (EngineID engine, const GRFFile *file)
| Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game.
const GRFFile * | GetEngineGRF (EngineID engine)
| Retrieve the GRFFile tied to an engine.
uint32 | GetEngineGRFID (EngineID engine)
| Retrieve the GRF ID of the GRFFile tied to an engine.
static int | MapOldSubType (const Vehicle *v)
static byte | MapAircraftMovementState (const Vehicle *v)
| Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2).
static byte | MapAircraftMovementAction (const Vehicle *v)
| Map OTTD aircraft movement states to TTDPatch style movement actions (VarAction 2 Variable 0xE6) This is not fully supported yet but it's enough for Planeset.
static const Vehicle * | GRV (const ResolverObject *object)
static uint32 | VehicleGetRandomBits (const ResolverObject *object)
static uint32 | VehicleGetTriggers (const ResolverObject *object)
static void | VehicleSetTriggers (const ResolverObject *object, int triggers)
static uint32 | GetGRFParameter (EngineID engine_type, byte parameter)
static uint8 | LiveryHelper (EngineID engine, const Vehicle *v)
static uint32 | VehicleGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
static const SpriteGroup * | VehicleResolveReal (const ResolverObject *object, const SpriteGroup *group)
static void | NewVehicleResolver (ResolverObject *res, EngineID engine_type, const Vehicle *v)
static const SpriteGroup * | GetVehicleSpriteGroup (EngineID engine, const Vehicle *v, bool use_cache=true)
| Retrieve the SpriteGroup for the specified vehicle.
SpriteID | GetCustomEngineSprite (EngineID engine, const Vehicle *v, Direction direction)
SpriteID | GetRotorOverrideSprite (EngineID engine, const Vehicle *v, bool info_view)
bool | UsesWagonOverride (const Vehicle *v)
| Check if a wagon is currently using a wagon override.
uint16 | GetVehicleCallback (CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
| Evaluate a newgrf callback for vehicles.
uint16 | GetVehicleCallbackParent (CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
| Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
uint | GetVehicleProperty (const Vehicle *v, uint8 property, uint orig_value)
uint | GetEngineProperty (EngineID engine, uint8 property, uint orig_value)
static void | DoTriggerVehicle (Vehicle *v, VehicleTrigger trigger, byte base_random_bits, bool first)
void | TriggerVehicle (Vehicle *v, VehicleTrigger trigger)
void | ResetEngineListOrder ()
EngineID | GetRailVehAtPosition (EngineID pos)
| Get the EngineID at position pos.
uint16 | ListPositionOfEngine (EngineID engine)
| Get the list position of an engine.
void | AlterRailVehListOrder (EngineID engine, EngineID target)

## Variables

int | _traininfo_vehicle_pitch = 0
int | _traininfo_vehicle_width = 29
static WagonOverrides | _engine_wagon_overrides [TOTAL_NUM_ENGINES]
static const SpriteGroup * | _engine_custom_sprites [TOTAL_NUM_ENGINES][NUM_CARGO+2]
const GRFFile * | _engine_grf [TOTAL_NUM_ENGINES]
static EngineID | _engine_list_order [NUM_TRAIN_ENGINES]
static byte | _engine_list_position [NUM_TRAIN_ENGINES]

## Detailed Description

Definition in file newgrf_engine.cpp.

## Function Documentation

const GRFFile* GetEngineGRF | ( | EngineID | engine | ) | `[read]`

Retrieve the GRFFile tied to an engine.

Parameters:

  | engine | Engine ID to retrieve.

Returns:
  Pointer to GRFFile.

Definition at line 151 of file newgrf_engine.cpp.

Referenced by CalculateRefitMasks().

uint32 GetEngineGRFID | ( | EngineID | engine | ) |

Retrieve the GRF ID of the GRFFile tied to an engine.

Parameters:

  | engine | Engine ID to retrieve.

Returns:
  32 bit GRFID value.

Definition at line 163 of file newgrf_engine.cpp.

Referenced by CmdMoveRailVehicle(), CmdStartStopAircraft(), CmdStartStopRoadVeh(), CmdStartStopShip(), CmdStartStopTrain(), DrawVehicleRefitWindow(), and ShowAdditionalText().

EngineID GetRailVehAtPosition | ( | EngineID | pos | ) |

Get the EngineID at position pos.

Used when drawing a(n unsorted) list of engines.

Parameters:

  | pos | List position/

Returns:
  The EngineID at the requested position.

Definition at line 1084 of file newgrf_engine.cpp.

uint16 GetVehicleCallback | ( | CallbackID | callback,
|  | uint32 | param1,
|  | uint32 | param2,
|  | EngineID | engine,
|  | const Vehicle * | v |
| ) |  |  |

Evaluate a newgrf callback for vehicles.

Parameters:

  | callback | The callback to evalute
  | param1 | First parameter of the callback
  | param2 | Second parameter of the callback
  | engine | Engine type of the vehicle to evaluate the callback for
  | v | The vehicle to evaluate the callback for, or NULL if it doesnt exist yet

Returns:
  The value the callback returned, or CALLBACK_FAILED if it failed

Definition at line 926 of file newgrf_engine.cpp.

References CALLBACK_FAILED, and GetVehicleSpriteGroup().

Referenced by CmdBuildAircraft(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdStartStopAircraft(), CmdStartStopRoadVeh(), CmdStartStopShip(), CmdStartStopTrain(), LoadUnloadVehicle(), ShowAdditionalText(), and TrainConsistChanged().

uint16 GetVehicleCallbackParent | ( | CallbackID | callback,
|  | uint32 | param1,
|  | uint32 | param2,
|  | EngineID | engine,
|  | const Vehicle * | v,
|  | const Vehicle * | parent |
| ) |  |  |

Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.

Parameters:

  | callback | The callback to evalute
  | param1 | First parameter of the callback
  | param2 | Second parameter of the callback
  | engine | Engine type of the vehicle to evaluate the callback for
  | v | The vehicle to evaluate the callback for, or NULL if it doesnt exist yet
  | parent | The vehicle to use for parent scope

Returns:
  The value the callback returned, or CALLBACK_FAILED if it failed

Definition at line 953 of file newgrf_engine.cpp.

References CALLBACK_FAILED, and GetVehicleSpriteGroup().

Referenced by CmdMoveRailVehicle().

static const SpriteGroup* GetVehicleSpriteGroup | ( | EngineID | engine,
|  | const Vehicle * | v,
|  | bool | use_cache = `true` |
| ) |  |  | `[static]`

Retrieve the SpriteGroup for the specified vehicle.

If the vehicle is not specified, the purchase list group for the engine is chosen. For trains, an additional engine override lookup is performed.

Parameters:

  | engine | Engine type of the vehicle.
  | v | The vehicle itself.
  | use_cache | Use cached override

Returns:
  The selected SpriteGroup for the vehicle.

Definition at line 839 of file newgrf_engine.cpp.

Referenced by GetVehicleCallback(), and GetVehicleCallbackParent().

uint16 ListPositionOfEngine | ( | EngineID | engine | ) |

Get the list position of an engine.

Used when sorting a list of engines.

Parameters:

  | engine | ID of the engine.

Returns:
  The list position of the engine.

Definition at line 1096 of file newgrf_engine.cpp.

void SetEngineGRF | ( | EngineID | engine,
|  | const GRFFile * | file |
| ) |  |  |

Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game.

Parameters:

  | engine | Engine ID to tie the GRFFile to.
  | file | Pointer of GRFFile to tie.

Definition at line 139 of file newgrf_engine.cpp.

bool UsesWagonOverride | ( | const Vehicle * | v | ) |

Check if a wagon is currently using a wagon override.

Parameters:

  | v | The wagon to check

Returns:
  true if it is using an override, false otherwise

Definition at line 911 of file newgrf_engine.cpp.

Referenced by GetVehiclePalette(), and TrainConsistChanged().