Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / newgrf_engine.h
blob90d755d3c45ac1de4abe0a820b2ab7989b7eb53e
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 */
8 /** @file newgrf_engine.h Functions for NewGRF engines. */
10 #ifndef NEWGRF_ENGINE_H
11 #define NEWGRF_ENGINE_H
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"
21 /** Resolver for a vehicle scope. */
22 struct VehicleScopeResolver : public ScopeResolver {
23 const struct Vehicle *v; ///< The vehicle being resolved.
24 EngineID self_type; ///< Type of the vehicle.
25 bool info_view; ///< Indicates if the item is being drawn in an info window.
27 /**
28 * Scope resolver of a single vehicle.
29 * @param ro Surrounding resolver.
30 * @param engine_type Engine type
31 * @param v %Vehicle being resolved.
32 * @param info_view Indicates if the item is being drawn in an info window.
34 VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
35 : ScopeResolver(ro), v(v), self_type(engine_type), info_view(info_view)
39 void SetVehicle(const Vehicle *v) { this->v = v; }
41 uint32 GetRandomBits() const override;
42 uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override;
43 uint32 GetTriggers() const override;
46 /** Resolver for a vehicle (chain) */
47 struct VehicleResolverObject : public ResolverObject {
48 /** Application of 'wagon overrides'. */
49 enum WagonOverride {
50 WO_NONE, //!< Resolve no wagon overrides.
51 WO_UNCACHED, //!< Resolve wagon overrides.
52 WO_CACHED, //!< Resolve wagon overrides using TrainCache::cached_override.
53 WO_SELF, //!< Resolve self-override (helicopter rotors and such).
56 VehicleScopeResolver self_scope; ///< Scope resolver for the indicated vehicle.
57 VehicleScopeResolver parent_scope; ///< Scope resolver for its parent vehicle.
59 VehicleScopeResolver relative_scope; ///< Scope resolver for an other vehicle in the chain.
60 byte cached_relative_count; ///< Relative position of the other vehicle.
62 VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view = false,
63 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
65 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override;
67 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
69 GrfSpecFeature GetFeature() const override;
70 uint32 GetDebugID() const override;
73 static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
74 static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
75 static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
77 struct VehicleSpriteSeq;
79 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
80 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
81 void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
83 void 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)
87 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result);
88 #define GetCustomRotorSprite(v, i, image_type, result) GetRotorOverrideSprite(v->engine_type, v, i, image_type, result)
89 #define GetCustomRotorIcon(et, image_type, result) GetRotorOverrideSprite(et, nullptr, true, image_type, result)
91 /* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
92 * elsewhere... */
93 struct GRFFile;
95 void SetEngineGRF(EngineID engine, const struct GRFFile *file);
97 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
98 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
99 bool UsesWagonOverride(const Vehicle *v);
101 /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
102 * time) orig_value is returned */
103 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
104 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = nullptr);
106 enum VehicleTrigger {
107 VEHICLE_TRIGGER_NEW_CARGO = 0x01,
108 /* Externally triggered only for the first vehicle in chain */
109 VEHICLE_TRIGGER_DEPOT = 0x02,
110 /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
111 VEHICLE_TRIGGER_EMPTY = 0x04,
112 /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
113 VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
114 /* Externally triggered for each vehicle in chain */
115 VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
117 void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
119 void AlterVehicleListOrder(EngineID engine, uint target);
120 void CommitVehicleListOrderChanges();
122 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
124 #endif /* NEWGRF_ENGINE_H */