OpenTTD Source: src/newgrf_engine.h Source File

OpenTTD Source 15.0-beta1

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 <http://www.gnu.org/licenses/>.
6 */
7
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 "gfx_type.h"
19#include "newgrf_spritegroup.h"
20
22 struct VehicleScopeResolver : public ScopeResolver {
23 const struct Vehicle *v;
24 EngineID self_type;
25 bool rotor_in_gui;
26
34 VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool rotor_in_gui)
35 : ScopeResolver(ro), v(v), self_type(engine_type), rotor_in_gui(rotor_in_gui)
36 {
37 }
38
39 void SetVehicle(const Vehicle *v) { this->v = v; }
40
41 uint32_t GetRandomBits() const override;
42 uint32_t GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const override;
43 uint32_t GetTriggers() const override;
44};
45
47 struct VehicleResolverObject : public ResolverObject {
49 enum WagonOverride {
50 WO_NONE,
51 WO_UNCACHED,
52 WO_CACHED,
53 WO_SELF,
54 };
55
56 VehicleScopeResolver self_scope;
57 VehicleScopeResolver parent_scope;
58
59 VehicleScopeResolver relative_scope;
60 uint8_t cached_relative_count;
61
62 VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool rotor_in_gui = false,
63 CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0);
64
65 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, uint8_t relative = 0) override;
66
67 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
68
69 GrfSpecFeature GetFeature() const override;
70 uint32_t GetDebugID() const override;
71};
72
73static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
74static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
75static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
76
77struct VehicleSpriteSeq;
78
79void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, std::span<EngineID> engine_ids);
80const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
81void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const struct SpriteGroup *group);
82
83void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
84#define GetCustomVehicleSprite(v, direction, image_type, result) GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)
85#define GetCustomVehicleIcon(et, direction, image_type, result) GetCustomEngineSprite(et, nullptr, direction, image_type, result)
86
87void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, EngineImageType image_type, VehicleSpriteSeq *result);
88#define GetCustomRotorSprite(v, image_type, result) GetRotorOverrideSprite(v->engine_type, v, image_type, result)
89#define GetCustomRotorIcon(et, image_type, result) GetRotorOverrideSprite(et, nullptr, image_type, result)
90
91/* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
92 * elsewhere... */
93struct GRFFile;
94
95void SetEngineGRF(EngineID engine, const struct GRFFile *file);
96
97uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v);
98uint16_t GetVehicleCallbackParent(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
99bool UsesWagonOverride(const Vehicle *v);
100
101/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
102 * time) orig_value is returned */
103int GetVehicleProperty(const Vehicle *v, PropertyID property, int orig_value, bool is_signed = false);
104int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, const Vehicle *v = nullptr, bool is_signed = false);
105
106enum class BuildProbabilityType {
107 Reversed = 0,
108};
109
110bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type);
111
112enum VehicleTrigger {
113 VEHICLE_TRIGGER_NEW_CARGO = 0x01,
114 /* Externally triggered only for the first vehicle in chain */
115 VEHICLE_TRIGGER_DEPOT = 0x02,
116 /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
117 VEHICLE_TRIGGER_EMPTY = 0x04,
118 /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
119 VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
120 /* Externally triggered for each vehicle in chain */
121 VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
122};
123void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
124
125void AlterVehicleListOrder(EngineID engine, uint16_t target);
126void CommitVehicleListOrderChanges();
127
128 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id);
129
130void FillNewGRFVehicleCache(const Vehicle *v);
131
132#endif /* NEWGRF_ENGINE_H */
CargoID
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
direction_type.h
Different types to 'show' directions.
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
engine_type.h
Types related to engines.
EngineID
uint16_t EngineID
Unique identification number of an engine.
Definition engine_type.h:21
gfx_type.h
Types related to the graphics and/or input devices.
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:67
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:20
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:22
SetEngineGRF
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.
Definition newgrf_engine.cpp:71
FillNewGRFVehicleCache
void FillNewGRFVehicleCache(const Vehicle *v)
Fill the grf_cache of the given vehicle.
Definition newgrf_engine.cpp:1376
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.
Definition newgrf_engine.cpp:1166
UsesWagonOverride
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
Definition newgrf_engine.cpp:1135
GetNewEngineID
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16_t internal_id)
Return the ID of a new engine.
Definition newgrf.cpp:711
TestVehicleBuildProbability
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
Test for vehicle build probablity type.
Definition newgrf_engine.cpp:1202
GetVehicleCallback
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition newgrf_engine.cpp:1150
CommitVehicleListOrderChanges
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
Definition newgrf_engine.cpp:1332
AlterVehicleListOrder
void AlterVehicleListOrder(EngineID engine, uint16_t target)
Record a vehicle ListOrderChange.
Definition newgrf_engine.cpp:1302
newgrf_properties.h
Properties of NewGRF Action 0.
PropertyID
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
Definition newgrf_properties.h:18
newgrf_spritegroup.h
Action 2 handling.
VarSpriteGroupScope
VarSpriteGroupScope
Definition newgrf_spritegroup.h:97
VSG_SCOPE_SELF
@ VSG_SCOPE_SELF
Resolved object itself.
Definition newgrf_spritegroup.h:100
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition aircraft.h:72
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:108
RealSpriteGroup
Definition newgrf_spritegroup.h:79
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:296
ResolverObject::callback_param2
uint32_t callback_param2
Second parameter (var 18) of the callback.
Definition newgrf_spritegroup.h:316
ResolverObject::callback
CallbackID callback
Callback being resolved.
Definition newgrf_spritegroup.h:314
ResolverObject::callback_param1
uint32_t callback_param1
First parameter (var 10) of the callback.
Definition newgrf_spritegroup.h:315
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
Definition newgrf_spritegroup.h:277
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:278
SpriteGroup
Definition newgrf_spritegroup.h:57
VehicleResolverObject
Resolver for a vehicle (chain)
Definition newgrf_engine.h:47
VehicleResolverObject::self_scope
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
Definition newgrf_engine.h:56
VehicleResolverObject::GetScope
ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, uint8_t relative=0) override
Get a resolver for the scope.
Definition newgrf_engine.cpp:319
VehicleResolverObject::ResolveReal
const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const override
Get the real sprites of the grf.
Definition newgrf_engine.cpp:980
VehicleResolverObject::parent_scope
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
Definition newgrf_engine.h:57
VehicleResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_engine.cpp:1002
VehicleResolverObject::relative_scope
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
Definition newgrf_engine.h:59
VehicleResolverObject::WO_NONE
@ WO_NONE
Resolve no wagon overrides.
Definition newgrf_engine.h:50
VehicleResolverObject::WO_SELF
@ WO_SELF
Resolve self-override (helicopter rotors and such).
Definition newgrf_engine.h:53
VehicleResolverObject::WO_UNCACHED
@ WO_UNCACHED
Resolve wagon overrides.
Definition newgrf_engine.h:51
VehicleResolverObject::WO_CACHED
@ WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
Definition newgrf_engine.h:52
VehicleResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_engine.cpp:1013
VehicleResolverObject::cached_relative_count
uint8_t cached_relative_count
Relative position of the other vehicle.
Definition newgrf_engine.h:60
VehicleScopeResolver
Resolver for a vehicle scope.
Definition newgrf_engine.h:22
VehicleScopeResolver::rotor_in_gui
bool rotor_in_gui
Helicopter rotor is drawn in GUI.
Definition newgrf_engine.h:25
VehicleScopeResolver::GetTriggers
uint32_t GetTriggers() const override
Get the triggers.
Definition newgrf_engine.cpp:313
VehicleScopeResolver::v
const struct Vehicle * v
The vehicle being resolved.
Definition newgrf_engine.h:23
VehicleScopeResolver::self_type
EngineID self_type
Type of the vehicle.
Definition newgrf_engine.h:24
VehicleScopeResolver::GetVariable
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
Definition newgrf_engine.cpp:943
VehicleScopeResolver::VehicleScopeResolver
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool rotor_in_gui)
Scope resolver of a single vehicle.
Definition newgrf_engine.h:34
VehicleScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_engine.cpp:308
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition vehicle_base.h:135
Vehicle
Vehicle data structure.
Definition vehicle_base.h:244
WagonOverride
Definition engine_base.h:19
vehicle_type.h
Types related to vehicles.
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition vehicle_type.h:78
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:21