# newgrf_engine.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef NEWGRF_ENGINE_H
    00013 #define NEWGRF_ENGINE_H
    00014
    00015 #include "direction_type.h"
    00016 #include "newgrf_callbacks.h"
    00017 #include "newgrf_properties.h"
    00018 #include "vehicle_type.h"
    00019 #include "engine_type.h"
    00020 #include "gfx_type.h"
    00021 #include "newgrf_spritegroup.h"
    00022
    00024 struct VehicleScopeResolver : public ScopeResolver {
    00025   const struct Vehicle *v;
    00026   EngineID self_type;
    00027   bool info_view;
    00028
    00029   VehicleScopeResolver(ResolverObject *ro, EngineID engine_type, const Vehicle *v, bool info_view);
    00030
    00031   void SetVehicle(const Vehicle *v) { this->v = v; }
    00032
    00033   /* virtual */ uint32 GetRandomBits() const;
    00034   /* virtual */ uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
    00035   /* virtual */ uint32 GetTriggers() const;
    00036   /* virtual */ void SetTriggers(int triggers) const;
    00037 };
    00038
    00040 struct VehicleResolverObject : public ResolverObject {
    00041   VehicleScopeResolver self_scope;
    00042   VehicleScopeResolver parent_scope;
    00043
    00044   VehicleScopeResolver relative_scope;
    00045   byte cached_relative_count;
    00046
    00047   VehicleResolverObject(EngineID engine_type, const Vehicle *v, bool info_view = false,
    00048       CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
    00049
    00050   /* virtual */ ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0);
    00051
    00052   /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
    00053 };
    00054
    00055 static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH   = 29;
    00056 static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
    00057 static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH    = 32;
    00058
    00059 void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
    00060 const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
    00061 void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
    00062 SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type);
    00063 SpriteID GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type);
    00064 #define GetCustomRotorSprite(v, i, image_type) GetRotorOverrideSprite(v->engine_type, v, i, image_type)
    00065 #define GetCustomRotorIcon(et, image_type) GetRotorOverrideSprite(et, NULL, true, image_type)
    00066
    00067 /* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
    00068  * elsewhere... */
    00069 struct GRFFile;
    00070
    00071 void SetEngineGRF(EngineID engine, const struct GRFFile *file);
    00072
    00073 uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
    00074 uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
    00075 bool UsesWagonOverride(const Vehicle *v);
    00076 #define GetCustomVehicleSprite(v, direction, image_type) GetCustomEngineSprite(v->engine_type, v, direction, image_type)
    00077 #define GetCustomVehicleIcon(et, direction, image_type) GetCustomEngineSprite(et, NULL, direction, image_type)
    00078
    00079 /* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
    00080  * time) orig_value is returned */
    00081 uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
    00082 uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = NULL);
    00083
    00084 enum VehicleTrigger {
    00085   VEHICLE_TRIGGER_NEW_CARGO     = 0x01,
    00086   /* Externally triggered only for the first vehicle in chain */
    00087   VEHICLE_TRIGGER_DEPOT         = 0x02,
    00088   /* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
    00089   VEHICLE_TRIGGER_EMPTY         = 0x04,
    00090   /* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
    00091   VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
    00092   /* Externally triggered for each vehicle in chain */
    00093   VEHICLE_TRIGGER_CALLBACK_32   = 0x10,
    00094 };
    00095 void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
    00096
    00097 void UnloadWagonOverrides(Engine *e);
    00098
    00099 void AlterVehicleListOrder(EngineID engine, uint target);
    00100 void CommitVehicleListOrderChanges();
    00101
    00102 EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
    00103
    00104 #endif /* NEWGRF_ENGINE_H */