OpenTTD Source 20261112-master-gbcbec5e63f
newgrf_engine.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NEWGRF_ENGINE_H
11#define NEWGRF_ENGINE_H
12
13#include "direction_type.h"
14#include "newgrf_callbacks.h"
15#include "newgrf_properties.h"
16#include "vehicle_type.h"
17#include "engine_type.h"
18#include "newgrf_spritegroup.h"
19
21struct VehicleScopeResolver : public ScopeResolver {
22 const struct Vehicle *v;
25
34 : ScopeResolver(ro), v(v), self_type(engine_type), rotor_in_gui(rotor_in_gui)
35 {
36 }
37
38 void SetVehicle(const Vehicle *v) { this->v = v; }
39
40 uint32_t GetRandomBits() const override;
41 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
42 uint32_t GetRandomTriggers() const override;
43};
44
46struct VehicleResolverObject : public SpecializedResolverObject<VehicleRandomTriggers> {
48 enum class WagonOverride : uint8_t {
53 };
54
57
60
61 VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui = false,
63
64 ScopeResolver *GetScope(VarSpriteGroupScope scope = VarSpriteGroupScope::Self, uint8_t relative = 0) override;
65
66 const SpriteGroup *ResolveReal(const RealSpriteGroup &group) const override;
67
68 GrfSpecFeature GetFeature() const override;
69 uint32_t GetDebugID() const override;
70};
71
72static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
73static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
74static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
75
76struct VehicleSpriteSeq;
77
78void SetWagonOverrideSprites(EngineID engine, CargoType cargo, const struct SpriteGroup *group, std::span<EngineID> engine_ids);
79const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoType cargo, EngineID overriding_engine);
80void SetCustomEngineSprites(EngineID engine, CargoType cargo, const struct SpriteGroup *group);
81
82void GetCustomVehicleSprite(const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
83void GetCustomVehicleIcon(EngineID engine, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
84
85void GetCustomRotorSprite(const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result);
86void GetCustomRotorIcon(EngineID engine, EngineImageType image_type, VehicleSpriteSeq *result);
87
88/* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
89 * elsewhere... */
90struct GRFFile;
91
92void SetEngineGRF(EngineID engine, const struct GRFFile *file);
93
94uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span<int32_t> regs100 = {});
95uint16_t GetVehicleCallbackParent(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent, std::span<int32_t> regs100 = {});
96bool UsesWagonOverride(const Vehicle *v);
97
98/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
99 * time) orig_value is returned */
100int GetVehicleProperty(const Vehicle *v, PropertyID property, int orig_value, bool is_signed = false);
101int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, const Vehicle *v = nullptr, bool is_signed = false);
102
104enum class BuildProbabilityType : uint8_t {
106};
107
108std::optional<bool> TestVehicleBuildProbability(Vehicle *v, BuildProbabilityType type);
109
110void TriggerVehicleRandomisation(Vehicle *veh, VehicleRandomTrigger trigger);
111
112void AlterVehicleListOrder(EngineID engine, uint16_t target);
114
115EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id);
116
117void FillNewGRFVehicleCache(const Vehicle *v);
118
119#endif /* NEWGRF_ENGINE_H */
CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
Different types to 'show' directions.
Direction
Defines the 8 directions on the map.
Types related to engines.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
Definition engine_type.h:25
GrfSpecFeature
Definition newgrf.h:81
Callbacks that NewGRFs could implement.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
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.
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
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.
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.
BuildProbabilityType
Different types of modifications during the purchase of a vehicle to request the chance for using a N...
@ Reversed
Change the rail vehicle should be reversed when purchased.
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Definition newgrf.cpp:300
std::optional< bool > TestVehicleBuildProbability(Vehicle *v, BuildProbabilityType type)
Test for vehicle build probability type.
void CommitVehicleListOrderChanges()
Determine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
void AlterVehicleListOrder(EngineID engine, uint16_t target)
Record a vehicle ListOrderChange.
Properties of NewGRF Action 0.
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
Action 2 handling.
VarSpriteGroupScope
Shared by deterministic and random groups.
@ Self
Resolved object itself.
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition aircraft.h:75
Dynamic data of a loaded NewGRF.
Definition newgrf.h:126
'Real' sprite groups contain a list of other result or callback sprite groups.
Interface for SpriteGroup-s to access the gamestate.
uint32_t callback_param2
Second parameter (var 18) of the callback.
CallbackID callback
Callback being resolved.
uint32_t callback_param1
First parameter (var 10) of the callback.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
ResolverObject & ro
Surrounding resolver object.
Specialization of ResolverObject with type-safe access to RandomTriggers.
Common wrapper for all the different sprite group types.
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0) override
Get a resolver for the scope.
WagonOverride
Application of 'wagon overrides'.
@ Cached
Resolve wagon overrides using TrainCache::cached_override.
@ None
Resolve no wagon overrides.
@ Uncached
Resolve wagon overrides.
@ Self
Resolve self-override (helicopter rotors and such).
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui=false, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Resolver of a vehicle (chain).
const SpriteGroup * ResolveReal(const RealSpriteGroup &group) const override
Get the real sprites of the grf.
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
uint8_t cached_relative_count
Relative position of the other vehicle.
Resolver for a vehicle scope.
uint32_t GetRandomTriggers() const override
Get the triggers.
bool rotor_in_gui
Helicopter rotor is drawn in GUI.
const struct Vehicle * v
The vehicle being resolved.
EngineID self_type
Type of the vehicle.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool rotor_in_gui)
Scope resolver of a single vehicle.
uint32_t GetRandomBits() const override
Get a few random bits.
Sprite sequence for a vehicle part.
Vehicle data structure.
Types related to vehicles.
EngineImageType
Visualisation contexts of vehicles and engines.
VehicleType
Available vehicle types.
VehicleRandomTrigger
Randomisation triggers for vehicles.