2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file newgrf_engine.h Functions for NewGRF engines. */
|
2007-03-21 03:06:21 +00:00
|
|
|
|
2006-02-03 12:55:21 +00:00
|
|
|
#ifndef NEWGRF_ENGINE_H
|
|
|
|
#define NEWGRF_ENGINE_H
|
|
|
|
|
2007-12-18 19:52:14 +00:00
|
|
|
#include "direction_type.h"
|
2009-06-24 22:38:47 +00:00
|
|
|
#include "newgrf_callbacks.h"
|
2009-09-22 19:28:57 +00:00
|
|
|
#include "newgrf_properties.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "vehicle_type.h"
|
|
|
|
#include "engine_type.h"
|
|
|
|
#include "gfx_type.h"
|
2012-11-10 20:45:04 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Resolver for a vehicle scope. */
|
2012-11-10 20:45:04 +00:00
|
|
|
struct VehicleScopeResolver : public ScopeResolver {
|
2012-11-10 20:46:39 +00:00
|
|
|
const struct Vehicle *v; ///< The vehicle being resolved.
|
|
|
|
EngineID self_type; ///< Type of the vehicle.
|
|
|
|
bool info_view; ///< Indicates if the item is being drawn in an info window.
|
2012-11-10 20:45:04 +00:00
|
|
|
|
2018-03-11 13:19:41 +00:00
|
|
|
/**
|
|
|
|
* Scope resolver of a single vehicle.
|
|
|
|
* @param ro Surrounding resolver.
|
|
|
|
* @param engine_type Engine type
|
|
|
|
* @param v %Vehicle being resolved.
|
|
|
|
* @param info_view Indicates if the item is being drawn in an info window.
|
|
|
|
*/
|
|
|
|
VehicleScopeResolver(ResolverObject &ro, EngineID engine_type, const Vehicle *v, bool info_view)
|
|
|
|
: ScopeResolver(ro), v(v), self_type(engine_type), info_view(info_view)
|
|
|
|
{
|
|
|
|
}
|
2012-11-10 20:45:04 +00:00
|
|
|
|
|
|
|
void SetVehicle(const Vehicle *v) { this->v = v; }
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
uint32 GetRandomBits() const override;
|
2020-08-25 00:26:44 +00:00
|
|
|
uint32 GetVariable(byte variable, uint32 parameter, GetVariableExtra *extra) const override;
|
2019-03-03 22:25:13 +00:00
|
|
|
uint32 GetTriggers() const override;
|
2012-11-10 20:45:04 +00:00
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
/** Resolver for a vehicle (chain) */
|
2012-11-10 20:45:04 +00:00
|
|
|
struct VehicleResolverObject : public ResolverObject {
|
2014-03-03 20:02:31 +00:00
|
|
|
/** Application of 'wagon overrides'. */
|
|
|
|
enum WagonOverride {
|
|
|
|
WO_NONE, //!< Resolve no wagon overrides.
|
|
|
|
WO_UNCACHED, //!< Resolve wagon overrides.
|
|
|
|
WO_CACHED, //!< Resolve wagon overrides using TrainCache::cached_override.
|
|
|
|
WO_SELF, //!< Resolve self-override (helicopter rotors and such).
|
|
|
|
};
|
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
VehicleScopeResolver self_scope; ///< Scope resolver for the indicated vehicle.
|
|
|
|
VehicleScopeResolver parent_scope; ///< Scope resolver for its parent vehicle.
|
2012-11-10 20:45:04 +00:00
|
|
|
|
2012-11-10 20:46:39 +00:00
|
|
|
VehicleScopeResolver relative_scope; ///< Scope resolver for an other vehicle in the chain.
|
|
|
|
byte cached_relative_count; ///< Relative position of the other vehicle.
|
2012-11-10 20:45:04 +00:00
|
|
|
|
2014-03-03 20:02:31 +00:00
|
|
|
VehicleResolverObject(EngineID engine_type, const Vehicle *v, WagonOverride wagon_override, bool info_view = false,
|
2012-11-10 20:45:04 +00:00
|
|
|
CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
|
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0) override;
|
2012-11-10 20:45:04 +00:00
|
|
|
|
2019-03-03 22:25:13 +00:00
|
|
|
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
2020-01-26 12:45:51 +00:00
|
|
|
|
|
|
|
GrfSpecFeature GetFeature() const override;
|
|
|
|
uint32 GetDebugID() const override;
|
2012-11-10 20:45:04 +00:00
|
|
|
};
|
2006-03-08 06:55:33 +00:00
|
|
|
|
2010-05-13 09:44:44 +00:00
|
|
|
static const uint TRAININFO_DEFAULT_VEHICLE_WIDTH = 29;
|
2012-06-07 15:58:59 +00:00
|
|
|
static const uint ROADVEHINFO_DEFAULT_VEHICLE_WIDTH = 32;
|
2010-05-13 09:44:44 +00:00
|
|
|
static const uint VEHICLEINFO_FULL_VEHICLE_WIDTH = 32;
|
2006-02-03 12:55:21 +00:00
|
|
|
|
2016-10-16 14:57:56 +00:00
|
|
|
struct VehicleSpriteSeq;
|
|
|
|
|
2008-01-05 15:39:22 +00:00
|
|
|
void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, EngineID *train_id, uint trains);
|
|
|
|
const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, EngineID overriding_engine);
|
2006-04-30 18:19:37 +00:00
|
|
|
void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group);
|
2016-10-16 14:57:56 +00:00
|
|
|
|
|
|
|
void GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction direction, EngineImageType image_type, VehicleSpriteSeq *result);
|
|
|
|
#define GetCustomVehicleSprite(v, direction, image_type, result) GetCustomEngineSprite(v->engine_type, v, direction, image_type, result)
|
2019-04-10 21:07:06 +00:00
|
|
|
#define GetCustomVehicleIcon(et, direction, image_type, result) GetCustomEngineSprite(et, nullptr, direction, image_type, result)
|
2016-10-16 14:57:56 +00:00
|
|
|
|
|
|
|
void GetRotorOverrideSprite(EngineID engine, const struct Aircraft *v, bool info_view, EngineImageType image_type, VehicleSpriteSeq *result);
|
|
|
|
#define GetCustomRotorSprite(v, i, image_type, result) GetRotorOverrideSprite(v->engine_type, v, i, image_type, result)
|
2019-04-10 21:07:06 +00:00
|
|
|
#define GetCustomRotorIcon(et, image_type, result) GetRotorOverrideSprite(et, nullptr, true, image_type, result)
|
2006-04-23 22:25:33 +00:00
|
|
|
|
2006-05-31 17:31:08 +00:00
|
|
|
/* Forward declaration of GRFFile, to avoid unnecessary inclusion of newgrf.h
|
|
|
|
* elsewhere... */
|
|
|
|
struct GRFFile;
|
|
|
|
|
|
|
|
void SetEngineGRF(EngineID engine, const struct GRFFile *file);
|
2006-04-23 22:25:33 +00:00
|
|
|
|
2007-07-25 19:06:29 +00:00
|
|
|
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v);
|
|
|
|
uint16 GetVehicleCallbackParent(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v, const Vehicle *parent);
|
2006-02-03 12:55:21 +00:00
|
|
|
bool UsesWagonOverride(const Vehicle *v);
|
|
|
|
|
2007-04-18 18:37:40 +00:00
|
|
|
/* Handler to Evaluate callback 36. If the callback fails (i.e. most of the
|
|
|
|
* time) orig_value is returned */
|
2009-09-22 19:28:57 +00:00
|
|
|
uint GetVehicleProperty(const Vehicle *v, PropertyID property, uint orig_value);
|
2019-04-10 21:07:06 +00:00
|
|
|
uint GetEngineProperty(EngineID engine, PropertyID property, uint orig_value, const Vehicle *v = nullptr);
|
2007-04-18 18:37:40 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum VehicleTrigger {
|
2007-11-11 12:29:47 +00:00
|
|
|
VEHICLE_TRIGGER_NEW_CARGO = 0x01,
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Externally triggered only for the first vehicle in chain */
|
2007-11-11 12:29:47 +00:00
|
|
|
VEHICLE_TRIGGER_DEPOT = 0x02,
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Externally triggered only for the first vehicle in chain, only if whole chain is empty */
|
2007-11-11 12:29:47 +00:00
|
|
|
VEHICLE_TRIGGER_EMPTY = 0x04,
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Not triggered externally (called for the whole chain if we got NEW_CARGO) */
|
2007-11-11 12:29:47 +00:00
|
|
|
VEHICLE_TRIGGER_ANY_NEW_CARGO = 0x08,
|
2007-10-28 16:00:51 +00:00
|
|
|
/* Externally triggered for each vehicle in chain */
|
2007-11-11 12:29:47 +00:00
|
|
|
VEHICLE_TRIGGER_CALLBACK_32 = 0x10,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-02-03 12:55:21 +00:00
|
|
|
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
|
|
|
|
|
2008-04-29 21:31:29 +00:00
|
|
|
void UnloadWagonOverrides(Engine *e);
|
2006-02-03 12:55:21 +00:00
|
|
|
|
2012-06-03 15:07:27 +00:00
|
|
|
void AlterVehicleListOrder(EngineID engine, uint target);
|
2008-07-20 21:23:28 +00:00
|
|
|
void CommitVehicleListOrderChanges();
|
2006-02-04 21:48:46 +00:00
|
|
|
|
2008-04-30 17:42:08 +00:00
|
|
|
EngineID GetNewEngineID(const GRFFile *file, VehicleType type, uint16 internal_id);
|
|
|
|
|
2006-02-03 12:55:21 +00:00
|
|
|
#endif /* NEWGRF_ENGINE_H */
|