OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf_engine.h
Go to the documentation of this file.
1 /* $Id: newgrf_engine.h 26388 2014-03-03 20:02:31Z 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
29 VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view);
30
31 void SetVehicle(const Vehicle *v) { this->v = v; }
32
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;
37 };
38
40 struct VehicleResolverObject : public ResolverObject {
42 enum WagonOverride {
43 WO_NONE,
44 WO_UNCACHED,
45 WO_CACHED,
46 WO_SELF,
47 };
48
49 VehicleScopeResolver self_scope;
50 VehicleScopeResolver parent_scope;
51
52 VehicleScopeResolver relative_scope;
53 byte cached_relative_count;
54
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);
57
58 /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
59
60 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
61 };
62
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;
66
67 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
68 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
69 void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
70 SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type);
71 SpriteID GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type);
72 #define GetCustomRotorSprite(v, i, image_type) GetRotorOverrideSprite(v->engine_type, v, i, image_type)
73 #define GetCustomRotorIcon(et, image_type) GetRotorOverrideSprite(et, NULL, true, image_type)
74
75 /* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
76 * elsewhere... */
77 struct GRFFile;
78
79 void SetEngineGRF(EngineID engine, const struct GRFFile *file);
80
81 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
82 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
83 bool UsesWagonOverride(const Vehicle *v);
84 #define GetCustomVehicleSprite(v, direction, image_type) GetCustomEngineSprite(v->engine_type, v, direction, image_type)
85 #define GetCustomVehicleIcon(et, direction, image_type) GetCustomEngineSprite(et, NULL, direction, image_type)
86
87 /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
88 * time) orig_value is returned */
89 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
90 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = NULL);
91
92 enum VehicleTrigger {
93 VEHICLE_TRIGGER_NEW_CARGO = 0x01,
94 /* Externally triggered only for the first vehicle in chain */
95 VEHICLE_TRIGGER_DEPOT = 0x02,
96 /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
97 VEHICLE_TRIGGER_EMPTY = 0x04,
98 /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
99 VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
100 /* Externally triggered for each vehicle in chain */
101 VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
102 };
103 void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
104
105 void UnloadWagonOverrides(Engine *e);
106
107 void AlterVehicleListOrder(EngineID engine, uint target);
108 void CommitVehicleListOrderChanges();
109
110 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
111
112 #endif /* NEWGRF_ENGINE_H */