(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / newgrf_engine.h
blob3c8108737c247a837b21881719b93cb0252e41b9
1 /* $Id$ */
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 */
10 /** @file newgrf_engine.h Functions for NewGRF engines. */
12 #ifndef NEWGRF_ENGINE_H
13 #define NEWGRF_ENGINE_H
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"
23 /** Resolver for a vehicle scope. */
24 struct VehicleScopeResolver : public ScopeResolver {
25 const struct Vehicle *v; ///< The vehicle being resolved.
26 EngineID self_type; ///< Type of the vehicle.
27 bool info_view; ///< Indicates if the item is being drawn in an info window.
29 VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view);
31 void SetVehicle(const Vehicle *v) { this->v = v; }
33 /* virtual */ uint32 GetRandomBits() const;
34 /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
35 /* virtual */ uint32 GetTriggers() const;
36 /* virtual */ void SetTriggers(int triggers) const;
39 /** Resolver for a vehicle (chain) */
40 struct VehicleResolverObject : public ResolverObject {
41 /** Application of 'wagon overrides'. */
42 enum WagonOverride {
43 WO_NONE, //!< Resolve no wagon overrides.
44 WO_UNCACHED, //!< Resolve wagon overrides.
45 WO_CACHED, //!< Resolve wagon overrides using TrainCache::cached_override.
46 WO_SELF, //!< Resolve self-override (helicopter rotors and such).
49 VehicleScopeResolver self_scope; ///< Scope resolver for the indicated vehicle.
50 VehicleScopeResolver parent_scope; ///< Scope resolver for its parent vehicle.
52 VehicleScopeResolver relative_scope; ///< Scope resolver for an other vehicle in the chain.
53 byte cached_relative_count; ///< Relative position of the other vehicle.
55 VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view = false,
56 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
58 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
60 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
63 static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
64 static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
65 static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
67 struct VehicleSpriteSeq;
69 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
70 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
71 void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
73 void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
74 #define GetCustomVehicleSprite(v, direction, image_type, result) GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)
75 #define GetCustomVehicleIcon(et, direction, image_type, result) GetCustomEngineSprite(et, NULL, direction, image_type, result)
77 void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result);
78 #define GetCustomRotorSprite(v, i, image_type, result) GetRotorOverrideSprite(v->engine_type, v, i, image_type, result)
79 #define GetCustomRotorIcon(et, image_type, result) GetRotorOverrideSprite(et, NULL, true, image_type, result)
81 /* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
82 * elsewhere... */
83 struct GRFFile;
85 void SetEngineGRF(EngineID engine, const struct GRFFile *file);
87 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
88 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
89 bool UsesWagonOverride(const Vehicle *v);
91 /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
92 * time) orig_value is returned */
93 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
94 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = NULL);
96 enum VehicleTrigger {
97 VEHICLE_TRIGGER_NEW_CARGO = 0x01,
98 /* Externally triggered only for the first vehicle in chain */
99 VEHICLE_TRIGGER_DEPOT = 0x02,
100 /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
101 VEHICLE_TRIGGER_EMPTY = 0x04,
102 /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
103 VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
104 /* Externally triggered for each vehicle in chain */
105 VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
107 void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
109 void UnloadWagonOverrides(Engine *e);
111 void AlterVehicleListOrder(EngineID engine, uint target);
112 void CommitVehicleListOrderChanges();
114 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
116 #endif /* NEWGRF_ENGINE_H */