1
/* $Id: engine_base.h 15765 2009-03-18 19:50:34Z rubidium $ */
3
/** @file engine_base.h Base class for engines. */
8
#include "engine_type.h"
9
#include "economy_type.h"
11
#include "core/smallvec_type.hpp"
13
DECLARE_OLD_POOL(Engine, Engine, 6, 10000)
15
struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
16
char *name; ///< Custom name of engine
20
uint16 reliability_spd_dec;
21
uint16 reliability_start, reliability_max, reliability_final;
22
uint16 duration_phase_1, duration_phase_2, duration_phase_3;
25
uint8 preview_company_rank;
27
CompanyMask company_avail;
28
uint8 image_index; ///< Original vehicle image index
29
VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc.
37
AircraftVehicleInfo air;
40
/* NewGRF related data */
41
const struct GRFFile *grffile;
42
const struct SpriteGroup *group[NUM_CARGO + 2];
43
uint16 internal_id; ///< ID within the GRF file
44
uint16 overrides_count;
45
struct WagonOverride *overrides;
49
Engine(VehicleType type, EngineID base);
52
inline bool IsValid() const { return this->info.climates != 0; }
54
CargoID GetDefaultCargoType() const;
55
bool CanCarryCargo() const;
56
uint GetDisplayDefaultCapacity() const;
57
Money GetRunningCost() const;
58
Money GetCost() const;
59
uint GetDisplayMaxSpeed() const;
60
uint GetPower() const;
61
uint GetDisplayWeight() const;
62
uint GetDisplayMaxTractiveEffort() const;
65
struct EngineIDMapping {
66
uint32 grfid; ///< The GRF ID of the file the entity belongs to
67
uint16 internal_id; ///< The internal ID within the GRF file
68
VehicleTypeByte type; ///< The engine type
69
uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used)
73
* Stores the mapping of EngineID to the internal id of newgrfs.
74
* Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
76
struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
77
static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries
79
void ResetToDefaultMapping();
80
EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
83
extern EngineOverrideManager _engine_mngr;
85
static inline bool IsEngineIndex(uint index)
87
return index < GetEnginePoolSize();
90
#define FOR_ALL_ENGINES_FROM(e, start) for (e = GetEngine(start); e != NULL; e = (e->index + 1U < GetEnginePoolSize()) ? GetEngine(e->index + 1U) : NULL) if (e->IsValid())
91
#define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
93
#define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
95
static inline const EngineInfo *EngInfo(EngineID e)
97
return &GetEngine(e)->info;
100
static inline const RailVehicleInfo *RailVehInfo(EngineID e)
102
return &GetEngine(e)->u.rail;
105
static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
107
return &GetEngine(e)->u.road;
110
static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
112
return &GetEngine(e)->u.ship;
115
static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
117
return &GetEngine(e)->u.air;
120
#endif /* ENGINE_TYPE_H */