|
OpenTTD Source 20251117-master-g7398d2e290
|
NewGRF handling of engines. More...
#include "stdafx.h"#include "debug.h"#include "train.h"#include "roadveh.h"#include "company_func.h"#include "newgrf_badge.h"#include "newgrf_cargo.h"#include "newgrf_spritegroup.h"#include "timer/timer_game_calendar.h"#include "vehicle_func.h"#include "core/random_func.hpp"#include "core/container_func.hpp"#include "aircraft.h"#include "station_base.h"#include "company_base.h"#include "newgrf_railtype.h"#include "newgrf_roadtype.h"#include "ship.h"#include "safeguards.h"Go to the source code of this file.
Data Structures | |
| struct | ListOrderChange |
Functions | |
| void | SetWagonOverrideSprites (EngineID engine, CargoType cargo, const SpriteGroup *group, std::span< EngineID > engine_ids) |
| const SpriteGroup * | GetWagonOverrideSpriteSet (EngineID engine, CargoType cargo, EngineID overriding_engine) |
| void | SetCustomEngineSprites (EngineID engine, CargoType cargo, const SpriteGroup *group) |
| 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. | |
| static int | MapOldSubType (const Vehicle *v) |
| static uint8_t | MapAircraftMovementState (const Aircraft *v) |
| Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2) | |
| static uint8_t | MapAircraftMovementAction (const Aircraft *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 Livery * | LiveryHelper (EngineID engine, const Vehicle *v) |
| Determines the livery of an engine. | |
| static uint32_t | PositionHelper (const Vehicle *v, bool consecutive) |
| Helper to get the position of a vehicle within a chain of vehicles. | |
| static uint32_t | VehicleGetVariable (Vehicle *v, const VehicleScopeResolver *object, uint8_t variable, uint32_t parameter, bool &available) |
| static const GRFFile * | GetEngineGrfFile (EngineID engine_type) |
| Get the grf file associated with an engine type. | |
| static void | GetCustomEngineSprite (EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) |
| void | GetCustomVehicleSprite (const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) |
| void | GetCustomVehicleIcon (EngineID engine, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result) |
| static void | GetRotorOverrideSprite (EngineID engine, const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result) |
| void | GetCustomRotorSprite (const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result) |
| void | GetCustomRotorIcon (EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result) |
| bool | UsesWagonOverride (const Vehicle *v) |
| Check if a wagon is currently using a wagon override. | |
| uint16_t | GetVehicleCallback (CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100) |
| 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, std::span< int32_t > regs100) |
| Evaluate a newgrf callback for vehicles with a different vehicle for parent scope. | |
| int | GetVehicleProperty (const Vehicle *v, PropertyID property, int orig_value, bool is_signed) |
| int | GetEngineProperty (EngineID engine, PropertyID property, int orig_value, const Vehicle *v, bool is_signed) |
| std::optional< bool > | TestVehicleBuildProbability (Vehicle *v, EngineID engine, BuildProbabilityType type) |
| Test for vehicle build probability type. | |
| static void | DoTriggerVehicleRandomisation (Vehicle *v, VehicleRandomTrigger trigger, uint16_t base_random_bits, bool first) |
| void | TriggerVehicleRandomisation (Vehicle *v, VehicleRandomTrigger trigger) |
| void | AlterVehicleListOrder (EngineID engine, uint16_t target) |
| Record a vehicle ListOrderChange. | |
| static bool | EnginePreSort (const EngineID &a, const EngineID &b) |
| Comparator function to sort engines via scope-GRFID and local ID. | |
| void | CommitVehicleListOrderChanges () |
| Determine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder. | |
| void | FillNewGRFVehicleCache (const Vehicle *v) |
| Fill the grf_cache of the given vehicle. | |
Variables | |
| static std::vector< ListOrderChange > | _list_order_changes |
NewGRF handling of engines.
Definition in file newgrf_engine.cpp.
| enum TTDPAircraftMovementActions : uint8_t |
Definition at line 232 of file newgrf_engine.cpp.
| enum TTDPAircraftMovementStates : uint8_t |
Definition at line 96 of file newgrf_engine.cpp.
| void AlterVehicleListOrder | ( | EngineID | engine, |
| uint16_t | target | ||
| ) |
Record a vehicle ListOrderChange.
| engine | Engine to move |
| target | Local engine ID to move engine in front of |
Definition at line 1345 of file newgrf_engine.cpp.
Referenced by AircraftVehicleChangeInfo(), RailVehicleChangeInfo(), RoadVehicleChangeInfo(), and ShipVehicleChangeInfo().
| void CommitVehicleListOrderChanges | ( | ) |
Determine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
Definition at line 1375 of file newgrf_engine.cpp.
References EnginePreSort(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), EngineOverrideManager::GetID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::GetNumItems(), Engine::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, Slide(), and Engine::type.
Referenced by AfterLoadGRFs().
|
static |
Definition at line 1260 of file newgrf_engine.cpp.
Comparator function to sort engines via scope-GRFID and local ID.
| a | left side |
| b | right side |
Definition at line 1357 of file newgrf_engine.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Engine::grf_prop, GRFFilePropsBase::grfid, GRFFilePropsBase::local_id, and Engine::type.
Referenced by CommitVehicleListOrderChanges().
| void FillNewGRFVehicleCache | ( | const Vehicle * | v | ) |
Fill the grf_cache of the given vehicle.
| v | The vehicle to fill the cache for. |
Definition at line 1419 of file newgrf_engine.cpp.
References NewGRFCache::cache_valid, Vehicle::engine_type, VehicleResolverObject::GetScope(), ScopeResolver::GetVariable(), Vehicle::grf_cache, HasBit(), lengthof, NCVV_COMPANY_INFORMATION, NCVV_CONSIST_CARGO_INFORMATION, NCVV_END, NCVV_POSITION_CONSIST_LENGTH, NCVV_POSITION_IN_VEHICLE, NCVV_POSITION_SAME_ID_LENGTH, VSG_SCOPE_SELF, and VehicleResolverObject::WO_NONE.
Referenced by CheckCaches().
|
static |
Definition at line 1105 of file newgrf_engine.cpp.
| void GetCustomRotorIcon | ( | EngineID | engine, |
| EngineImageType | image_type, | ||
| VehicleSpriteSeq * | result | ||
| ) |
Definition at line 1172 of file newgrf_engine.cpp.
| void GetCustomRotorSprite | ( | const struct Aircraft * | v, |
| EngineImageType | image_type, | ||
| VehicleSpriteSeq * | result | ||
| ) |
Definition at line 1167 of file newgrf_engine.cpp.
| void GetCustomVehicleIcon | ( | EngineID | engine, |
| Direction | direction, | ||
| EngineImageType | image_type, | ||
| VehicleSpriteSeq * | result | ||
| ) |
Definition at line 1130 of file newgrf_engine.cpp.
| void GetCustomVehicleSprite | ( | const Vehicle * | v, |
| Direction | direction, | ||
| EngineImageType | image_type, | ||
| VehicleSpriteSeq * | result | ||
| ) |
Definition at line 1125 of file newgrf_engine.cpp.
Get the grf file associated with an engine type.
| engine_type | Engine to query. |
Definition at line 1057 of file newgrf_engine.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), and Engine::GetGRF().
| int GetEngineProperty | ( | EngineID | engine, |
| PropertyID | property, | ||
| int | orig_value, | ||
| const Vehicle * | v, | ||
| bool | is_signed | ||
| ) |
Definition at line 1230 of file newgrf_engine.cpp.
|
static |
Definition at line 1135 of file newgrf_engine.cpp.
| uint16_t GetVehicleCallback | ( | CallbackID | callback, |
| uint32_t | param1, | ||
| uint32_t | param2, | ||
| EngineID | engine, | ||
| const Vehicle * | v, | ||
| std::span< int32_t > | regs100 | ||
| ) |
Evaluate a newgrf callback for vehicles.
| callback | The callback to evaluate | |
| 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 nullptr if it doesn't exist yet | |
| [out] | regs100 | Additional result values from registers 100+ |
Definition at line 1198 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().
| uint16_t GetVehicleCallbackParent | ( | CallbackID | callback, |
| uint32_t | param1, | ||
| uint32_t | param2, | ||
| EngineID | engine, | ||
| const Vehicle * | v, | ||
| const Vehicle * | parent, | ||
| std::span< int32_t > | regs100 | ||
| ) |
Evaluate a newgrf callback for vehicles with a different vehicle for parent scope.
| callback | The callback to evaluate | |
| 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 nullptr if it doesn't exist yet | |
| parent | The vehicle to use for parent scope | |
| [out] | regs100 | Additional result values from registers 100+ |
Definition at line 1215 of file newgrf_engine.cpp.
References VehicleResolverObject::WO_NONE.
Referenced by CheckTrainAttachment().
| int GetVehicleProperty | ( | const Vehicle * | v, |
| PropertyID | property, | ||
| int | orig_value, | ||
| bool | is_signed | ||
| ) |
Definition at line 1224 of file newgrf_engine.cpp.
| const SpriteGroup * GetWagonOverrideSpriteSet | ( | EngineID | engine, |
| CargoType | cargo, | ||
| EngineID | overriding_engine | ||
| ) |
Definition at line 43 of file newgrf_engine.cpp.
Determines the livery of an engine.
This always uses dual company colours independent of GUI settings. So it is desync-safe.
Definition at line 373 of file newgrf_engine.cpp.
References _current_company, Vehicle::engine_type, GroundVehicleCache::first_engine, GetEngineLivery(), Vehicle::GetGroundVehicleCache(), Vehicle::IsGroundVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), LIT_ALL, and Vehicle::owner.
Referenced by VehicleScopeResolver::GetVariable().
|
static |
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.
Definition at line 260 of file newgrf_engine.cpp.
References Vehicle::cur_speed, Vehicle::current_order, ENDLANDING, ENDTAKEOFF, FLYING, HANGAR, HELIENDLANDING, HELILANDING, HELIPAD1, HELIPAD2, HELIPAD3, HELITAKEOFF, Order::IsType(), LANDING, STARTTAKEOFF, Aircraft::state, TAKEOFF, TERM1, TERM2, TERM3, TERM4, TERM5, TERM6, TERM7, and TERM8.
|
static |
Map OTTD aircraft movement states to TTDPatch style movement states (VarAction 2 Variable 0xE2)
Definition at line 133 of file newgrf_engine.cpp.
References Station::airport, Brake, AirportFTAClass::delta_z, ENDLANDING, ENDTAKEOFF, ExactPosition, AirportMovingData::flags, FLYING, Airport::GetFTA(), GetTargetAirportIfValid(), HANGAR, HELIENDLANDING, HELILANDING, HeliLower, HELIPAD1, HELIPAD2, HELIPAD3, HeliRaise, HELITAKEOFF, Hold, LANDING, AirportFTAClass::MovingData(), Aircraft::pos, SlowTurn, STARTTAKEOFF, Aircraft::state, TAKEOFF, TERM1, TERM2, TERM3, TERM4, TERM5, TERM6, TERM7, TERM8, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().
|
static |
Definition at line 78 of file newgrf_engine.cpp.
|
static |
Helper to get the position of a vehicle within a chain of vehicles.
| v | the vehicle to get the position of. |
| consecutive | whether to look at the whole chain or the vehicles with the same 'engine type'. |
Definition at line 396 of file newgrf_engine.cpp.
References Vehicle::engine_type, Vehicle::First(), and Vehicle::Next().
| void SetCustomEngineSprites | ( | EngineID | engine, |
| CargoType | cargo, | ||
| const SpriteGroup * | group | ||
| ) |
Definition at line 54 of file newgrf_engine.cpp.
Tie a GRFFile entry to an engine, to allow us to retrieve GRF parameters etc during a game.
Definition at line 71 of file newgrf_engine.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Get(), Engine::grf_prop, and GRFFilePropsBase::SetGRFFile().
| void SetWagonOverrideSprites | ( | EngineID | engine, |
| CargoType | cargo, | ||
| const SpriteGroup * | group, | ||
| std::span< EngineID > | engine_ids | ||
| ) |
Definition at line 31 of file newgrf_engine.cpp.
| std::optional< bool > TestVehicleBuildProbability | ( | Vehicle * | v, |
| EngineID | engine, | ||
| BuildProbabilityType | type | ||
| ) |
Test for vehicle build probability type.
| v | Vehicle whose build probability to test. |
| type | Build probability type to test for. |
Definition at line 1251 of file newgrf_engine.cpp.
References CALLBACK_FAILED, CBID_VEHICLE_BUILD_PROBABILITY, GetVehicleCallback(), RandomRange(), and to_underlying().
Referenced by AddArticulatedParts(), BuildReplacementVehicle(), CmdBuildRailVehicle(), CmdBuildRailWagon(), and CmdCloneVehicle().
| void TriggerVehicleRandomisation | ( | Vehicle * | v, |
| VehicleRandomTrigger | trigger | ||
| ) |
Definition at line 1321 of file newgrf_engine.cpp.
| bool UsesWagonOverride | ( | const Vehicle * | v | ) |
Check if a wagon is currently using a wagon override.
| v | The wagon to check |
Definition at line 1182 of file newgrf_engine.cpp.
References SpecializedVehicle< T, Type >::From(), BaseVehicle::type, and VEH_TRAIN.
Referenced by Train::ConsistChanged(), and GetEngineLiveryScheme().
|
static |
Definition at line 415 of file newgrf_engine.cpp.
|
static |
Definition at line 1337 of file newgrf_engine.cpp.