OpenTTD Source 20241224-master-gf74b0cf984
newgrf_engine.h File Reference

Functions for NewGRF engines. More...

#include "direction_type.h"
#include "newgrf_callbacks.h"
#include "newgrf_properties.h"
#include "vehicle_type.h"
#include "engine_type.h"
#include "gfx_type.h"
#include "newgrf_spritegroup.h"

Go to the source code of this file.

Data Structures

struct  VehicleScopeResolver
 Resolver for a vehicle scope. More...
 
struct  VehicleResolverObject
 Resolver for a vehicle (chain) More...
 

Macros

#define GetCustomVehicleSprite(v, direction, image_type, result)   GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)
 
#define GetCustomVehicleIcon(et, direction, image_type, result)   GetCustomEngineSprite(et, nullptr, direction, image_type, result)
 
#define GetCustomRotorSprite(v, image_type, result)   GetRotorOverrideSprite(v->engine_type, v, image_type, result)
 
#define GetCustomRotorIcon(et, image_type, result)   GetRotorOverrideSprite(et, nullptr, image_type, result)
 

Enumerations

enum class  BuildProbabilityType { Reversed = 0 }
 
enum  VehicleTrigger {
  VEHICLE_TRIGGER_NEW_CARGO = 0x01 , VEHICLE_TRIGGER_DEPOT = 0x02 , VEHICLE_TRIGGER_EMPTY = 0x04 , VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08 ,
  VEHICLE_TRIGGER_CALLBACK_32 = 0x10
}
 

Functions

void SetWagonOverrideSprites (EngineID engine, CargoID cargo, const struct SpriteGroup *group, std::span< EngineID > engine_ids)
 
const SpriteGroupGetWagonOverrideSpriteSet (EngineID engine, CargoID cargo, EngineID overriding_engine)
 
void SetCustomEngineSprites (EngineID engine, uint8_t cargo, const struct SpriteGroup *group)
 
void GetCustomEngineSprite (EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result)
 
void GetRotorOverrideSprite (EngineID engine, const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result)
 
void SetEngineGRF (EngineID engine, const struct GRFFile *file)
 
uint16_t GetVehicleCallback (CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
 Evaluate a newgrf callback for vehicles.
 
uint16_t GetVehicleCallbackParent (CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent)
 Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
 
bool UsesWagonOverride (const Vehicle *v)
 Check if a wagon is currently using a wagon override.
 
int GetVehicleProperty (const Vehicle *v, PropertyID property, int orig_value, bool is_signed=false)
 
int GetEngineProperty (EngineID engine, PropertyID property, int orig_value, const Vehicle *v=nullptr, bool is_signed=false)
 
bool TestVehicleBuildProbability (Vehicle *v, EngineID engine, BuildProbabilityType type)
 Test for vehicle build probablity type.
 
void TriggerVehicle (Vehicle *veh, VehicleTrigger trigger)
 
void AlterVehicleListOrder (EngineID engine, uint16_t target)
 Record a vehicle ListOrderChange.
 
void CommitVehicleListOrderChanges ()
 Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
 
EngineID GetNewEngineID (const GRFFile *file, VehicleType type, uint16_t internal_id)
 Return the ID of a new engine.
 
void FillNewGRFVehicleCache (const Vehicle *v)
 Fill the grf_cache of the given vehicle.
 

Variables

static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29
 
static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32
 
static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32
 

Detailed Description

Functions for NewGRF engines.

Definition in file newgrf_engine.h.

Macro Definition Documentation

◆ GetCustomRotorIcon

#define GetCustomRotorIcon (   et,
  image_type,
  result 
)    GetRotorOverrideSprite(et, nullptr, image_type, result)

Definition at line 89 of file newgrf_engine.h.

◆ GetCustomRotorSprite

#define GetCustomRotorSprite (   v,
  image_type,
  result 
)    GetRotorOverrideSprite(v->engine_type, v, image_type, result)

Definition at line 88 of file newgrf_engine.h.

◆ GetCustomVehicleIcon

#define GetCustomVehicleIcon (   et,
  direction,
  image_type,
  result 
)    GetCustomEngineSprite(et, nullptr, direction, image_type, result)

Definition at line 85 of file newgrf_engine.h.

◆ GetCustomVehicleSprite

#define GetCustomVehicleSprite (   v,
  direction,
  image_type,
  result 
)    GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)

Definition at line 84 of file newgrf_engine.h.

Enumeration Type Documentation

◆ BuildProbabilityType

enum class BuildProbabilityType
strong

Definition at line 106 of file newgrf_engine.h.

◆ VehicleTrigger

enum VehicleTrigger

Definition at line 112 of file newgrf_engine.h.

Function Documentation

◆ AlterVehicleListOrder()

void AlterVehicleListOrder ( EngineID  engine,
uint16_t  target 
)

Record a vehicle ListOrderChange.

Parameters
engineEngine to move
targetLocal engine ID to move engine in front of
Note
All sorting is done later in CommitVehicleListOrderChanges

Definition at line 1302 of file newgrf_engine.cpp.

Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), and ShipVehicleChangeInfo().

◆ CommitVehicleListOrderChanges()

◆ FillNewGRFVehicleCache()

◆ GetCustomEngineSprite()

void GetCustomEngineSprite ( EngineID  engine,
const Vehicle v,
Direction  direction,
EngineImageType  image_type,
VehicleSpriteSeq result 
)

Definition at line 1074 of file newgrf_engine.cpp.

◆ GetEngineProperty()

int GetEngineProperty ( EngineID  engine,
PropertyID  property,
int  orig_value,
const Vehicle v = nullptr,
bool  is_signed = false 
)

Definition at line 1181 of file newgrf_engine.cpp.

◆ GetNewEngineID()

EngineID GetNewEngineID ( const GRFFile file,
VehicleType  type,
uint16_t  internal_id 
)

Return the ID of a new engine.

Parameters
fileThe NewGRF file providing the engine.
typeThe Vehicle type.
internal_idNewGRF-internal ID of the engine.
Returns
The new EngineID.
Note
depending on the dynamic_engine setting and a possible override property the grfID may be unique or overwriting or partially re-defining properties of an existing engine.

Definition at line 711 of file newgrf.cpp.

References _settings_game, VehicleSettings::dynamic_engines, EngineOverrideManager::GetID(), and GameSettings::vehicle.

Referenced by FinaliseEngineArray(), and GetNextArticulatedPart().

◆ GetRotorOverrideSprite()

void GetRotorOverrideSprite ( EngineID  engine,
const struct Aircraft v,
EngineImageType  image_type,
VehicleSpriteSeq result 
)

Definition at line 1096 of file newgrf_engine.cpp.

◆ GetVehicleCallback()

uint16_t GetVehicleCallback ( CallbackID  callback,
uint32_t  param1,
uint32_t  param2,
EngineID  engine,
const Vehicle v 
)

Evaluate a newgrf callback for vehicles.

Parameters
callbackThe callback to evaluate
param1First parameter of the callback
param2Second parameter of the callback
engineEngine type of the vehicle to evaluate the callback for
vThe vehicle to evaluate the callback for, or nullptr if it doesn't exist yet
Returns
The value the callback returned, or CALLBACK_FAILED if it failed

Definition at line 1150 of file newgrf_engine.cpp.

References VehicleResolverObject::WO_UNCACHED.

Referenced by CalculateRefitMasks(), CmdStartStopVehicle(), Train::ConsistChanged(), Engine::DetermineCapacity(), FormatString(), GetCargoSubtypeText(), GetLoadAmount(), GetNewGRFAdditionalText(), GetNextArticulatedPart(), GetRefitCostFactor(), GetRoadVehLength(), PlayVehicleSound(), RunEconomyVehicleDayProc(), SpawnAdvancedVisualEffect(), TestVehicleBuildProbability(), and Vehicle::UpdateVisualEffect().

◆ GetVehicleCallbackParent()

uint16_t GetVehicleCallbackParent ( CallbackID  callback,
uint32_t  param1,
uint32_t  param2,
EngineID  engine,
const Vehicle v,
const Vehicle parent 
)

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

Parameters
callbackThe callback to evaluate
param1First parameter of the callback
param2Second parameter of the callback
engineEngine type of the vehicle to evaluate the callback for
vThe vehicle to evaluate the callback for, or nullptr if it doesn't exist yet
parentThe vehicle to use for parent scope
Returns
The value the callback returned, or CALLBACK_FAILED if it failed

Definition at line 1166 of file newgrf_engine.cpp.

References VehicleResolverObject::WO_NONE.

Referenced by CheckTrainAttachment().

◆ GetVehicleProperty()

int GetVehicleProperty ( const Vehicle v,
PropertyID  property,
int  orig_value,
bool  is_signed = false 
)

Definition at line 1175 of file newgrf_engine.cpp.

◆ GetWagonOverrideSpriteSet()

const SpriteGroup * GetWagonOverrideSpriteSet ( EngineID  engine,
CargoID  cargo,
EngineID  overriding_engine 
)

Definition at line 42 of file newgrf_engine.cpp.

◆ TestVehicleBuildProbability()

bool TestVehicleBuildProbability ( Vehicle v,
EngineID  engine,
BuildProbabilityType  type 
)

Test for vehicle build probablity type.

Parameters
vVehicle whose build probability to test.
typeBuild probability type to test for.
Returns
True iff the probability result says so.

Definition at line 1202 of file newgrf_engine.cpp.

References CALLBACK_FAILED, CBID_VEHICLE_BUILD_PROBABILITY, GetVehicleCallback(), RandomRange(), and to_underlying().

Referenced by AddArticulatedParts(), CmdBuildRailVehicle(), and CmdBuildRailWagon().

◆ TriggerVehicle()

void TriggerVehicle ( Vehicle veh,
VehicleTrigger  trigger 
)

Definition at line 1273 of file newgrf_engine.cpp.

◆ UsesWagonOverride()

bool UsesWagonOverride ( const Vehicle v)

Check if a wagon is currently using a wagon override.

Parameters
vThe wagon to check
Returns
true if it is using an override, false otherwise

Definition at line 1135 of file newgrf_engine.cpp.

References SpecializedVehicle< T, Type >::From(), BaseVehicle::type, and VEH_TRAIN.

Referenced by Train::ConsistChanged(), and GetEngineLiveryScheme().

Variable Documentation

◆ ROADVEHINFO_DEFAULT_VEHICLE_WIDTH

const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32
static

Definition at line 74 of file newgrf_engine.h.

◆ TRAININFO_DEFAULT_VEHICLE_WIDTH

const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29
static

Definition at line 73 of file newgrf_engine.h.

◆ VEHICLEINFO_FULL_VEHICLE_WIDTH

const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32
static

Definition at line 75 of file newgrf_engine.h.