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 
25  const struct Vehicle *v;
27  bool info_view;
28 
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 
56  };
57 
60 
63 
64  VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view = false,
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 
119 
120 void AlterVehicleListOrder(EngineID engine, uint target);
122 
123 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
124 
125 #endif /* NEWGRF_ENGINE_H */