OpenTTD

newgrf_engine.h
Go to the documentation of this file.
1 /* $Id: newgrf_engine.h 27984 2018-03-11 13:19:41Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef NEWGRF_ENGINE_H
13 #define NEWGRF_ENGINE_H
14
15 #include "direction_type.h"
16 #include "newgrf_callbacks.h"
17 #include "newgrf_properties.h"
18 #include "vehicle_type.h"
19 #include "engine_type.h"
20 #include "gfx_type.h"
21 #include "newgrf_spritegroup.h"
22
24 struct VehicleScopeResolver : public ScopeResolver {
25 const struct Vehicle *v;
26 EngineID self_type;
27 bool info_view;
28
36 VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
37 : ScopeResolver(ro), v(v), self_type(engine_type), info_view(info_view)
38 {
39 }
40
41 void SetVehicle(const Vehicle *v) { this->v = v; }
42
43 /* virtual */ uint32 GetRandomBits() const;
44 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
45 /* virtual */ uint32 GetTriggers() const;
46 };
47
49 struct VehicleResolverObject : public ResolverObject {
51 enum WagonOverride {
52 WO_NONE,
53 WO_UNCACHED,
54 WO_CACHED,
55 WO_SELF,
56 };
57
58 VehicleScopeResolver self_scope;
59 VehicleScopeResolver parent_scope;
60
61 VehicleScopeResolver relative_scope;
62 byte cached_relative_count;
63
64 VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view = false,
65 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
66
67 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
68
69 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
70 };
71
72 static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
73 static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
74 static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
75
76 struct VehicleSpriteSeq;
77
78 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
79 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
80 void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
81
82 void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
83 #define GetCustomVehicleSprite(v, direction, image_type, result) GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)
84 #define GetCustomVehicleIcon(et, direction, image_type, result) GetCustomEngineSprite(et, NULL, direction, image_type, result)
85
86 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result);
87 #define GetCustomRotorSprite(v, i, image_type, result) GetRotorOverrideSprite(v->engine_type, v, i, image_type, result)
88 #define GetCustomRotorIcon(et, image_type, result) GetRotorOverrideSprite(et, NULL, true, image_type, result)
89
90 /* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
91 * elsewhere... */
92 struct GRFFile;
93
94 void SetEngineGRF(EngineID engine, const struct GRFFile *file);
95
96 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
97 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
98 bool UsesWagonOverride(const Vehicle *v);
99
100 /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
101 * time) orig_value is returned */
102 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
103 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = NULL);
104
105 enum VehicleTrigger {
106 VEHICLE_TRIGGER_NEW_CARGO = 0x01,
107 /* Externally triggered only for the first vehicle in chain */
108 VEHICLE_TRIGGER_DEPOT = 0x02,
109 /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
110 VEHICLE_TRIGGER_EMPTY = 0x04,
111 /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
112 VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
113 /* Externally triggered for each vehicle in chain */
114 VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
115 };
116 void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
117
118 void UnloadWagonOverrides(Engine *e);
119
120 void AlterVehicleListOrder(EngineID engine, uint target);
121 void CommitVehicleListOrderChanges();
122
123 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
124
125 #endif /* NEWGRF_ENGINE_H */
WagonOverride
Definition: newgrf_engine.cpp:30
ScopeResolver
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
Definition: newgrf_spritegroup.h:291
direction_type.h
Different types to &#39;show&#39; directions.
VehicleScopeResolver
Resolver for a vehicle scope.
Definition: newgrf_engine.h:24
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:292
VarSpriteGroupScope
VarSpriteGroupScope
Definition: newgrf_spritegroup.h:100
VehicleResolverObject::cached_relative_count
byte cached_relative_count
Relative position of the other vehicle.
Definition: newgrf_engine.h:62
GetVehicleCallbackParent
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.
Definition: newgrf_engine.cpp:1083
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:310
engine_type.h
Types related to engines.
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:212
CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition: newgrf_callbacks.h:24
PropertyID
PropertyID
List of NewGRF properties used in Action 0 or Callback 0x36 (CBID_VEHICLE_MODIFY_PROPERTY).
Definition: newgrf_properties.h:20
EngineImageType
EngineImageType
Visualisation contexts of vehicles and engines.
Definition: vehicle_type.h:87
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:26
RealSpriteGroup
Definition: newgrf_spritegroup.h:79
VehicleResolverObject::WO_NONE
Resolve no wagon overrides.
Definition: newgrf_engine.h:52
newgrf_spritegroup.h
Action 2 handling.
VehicleResolverObject::WO_UNCACHED
Resolve wagon overrides.
Definition: newgrf_engine.h:53
VehicleResolverObject::self_scope
VehicleScopeResolver self_scope
Scope resolver for the indicated vehicle.
Definition: newgrf_engine.h:58
VehicleType
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
VehicleResolverObject
Resolver for a vehicle (chain)
Definition: newgrf_engine.h:49
CommitVehicleListOrderChanges
void CommitVehicleListOrderChanges()
Deternine default engine sorting and execute recorded ListOrderChanges from AlterVehicleListOrder.
Definition: newgrf_engine.cpp:1228
SpriteGroup
Definition: newgrf_spritegroup.h:58
VehicleResolverObject::relative_scope
VehicleScopeResolver relative_scope
Scope resolver for an other vehicle in the chain.
Definition: newgrf_engine.h:61
VehicleScopeResolver::self_type
EngineID self_type
Type of the vehicle.
Definition: newgrf_engine.h:26
UsesWagonOverride
bool UsesWagonOverride(const Vehicle *v)
Check if a wagon is currently using a wagon override.
Definition: newgrf_engine.cpp:1052
AlterVehicleListOrder
void AlterVehicleListOrder(EngineID engine, uint target)
Record a vehicle ListOrderChange.
Definition: newgrf_engine.cpp:1196
VehicleSpriteSeq
Sprite sequence for a vehicle part.
Definition: vehicle_base.h:130
VSG_SCOPE_SELF
Resolved object itself.
Definition: newgrf_spritegroup.h:103
VehicleResolverObject::parent_scope
VehicleScopeResolver parent_scope
Scope resolver for its parent vehicle.
Definition: newgrf_engine.h:59
Engine
Definition: engine_base.h:23
VehicleScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Definition: newgrf_engine.cpp:883
EngineID
uint16 EngineID
Unique identification number of an engine.
Definition: engine_type.h:22
VehicleScopeResolver::VehicleScopeResolver
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
Scope resolver of a single vehicle.
Definition: newgrf_engine.h:36
VehicleResolverObject::WO_SELF
Resolve self-override (helicopter rotors and such).
Definition: newgrf_engine.h:55
vehicle_type.h
Types related to vehicles.
UnloadWagonOverrides
void UnloadWagonOverrides(Engine *e)
Unload all wagon override sprite groups.
Definition: newgrf_engine.cpp:74
GetVehicleCallback
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Definition: newgrf_engine.cpp:1067
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:288
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:22
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
VehicleScopeResolver::v
const struct Vehicle * v
The vehicle being resolved.
Definition: newgrf_engine.h:25
VehicleScopeResolver::GetTriggers
uint32 GetTriggers() const
Get the triggers.
Definition: newgrf_engine.cpp:345
VehicleScopeResolver::info_view
bool info_view
Indicates if the item is being drawn in an info window.
Definition: newgrf_engine.h:27
GetNewEngineID
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id)
Return the ID of a new engine.
Definition: newgrf.cpp:695
newgrf_properties.h
Properties of NewGRF Action 0.
gfx_type.h
Types related to the graphics and/or input devices.
VehicleScopeResolver::GetRandomBits
uint32 GetRandomBits() const
Get a few random bits.
Definition: newgrf_engine.cpp:340
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:104
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:104
VehicleResolverObject::WO_CACHED
Resolve wagon overrides using TrainCache::cached_override.
Definition: newgrf_engine.h:54