Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef ENGINE_BASE_H
00013 #define ENGINE_BASE_H
00014
00015 #include "company_type.h"
00016 #include "engine_type.h"
00017 #include "vehicle_type.h"
00018 #include "core/pool_type.hpp"
00019 #include "core/smallvec_type.hpp"
00020 #include "newgrf_commons.h"
00021
00022 typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
00023 extern EnginePool _engine_pool;
00024
00025 struct Engine : EnginePool::PoolItem<&_engine_pool> {
00026 char *name;
00027 Date intro_date;
00028 Date age;
00029 uint16 reliability;
00030 uint16 reliability_spd_dec;
00031 uint16 reliability_start;
00032 uint16 reliability_max;
00033 uint16 reliability_final;
00034 uint16 duration_phase_1;
00035 uint16 duration_phase_2;
00036 uint16 duration_phase_3;
00037 byte flags;
00038 uint8 preview_company_rank;
00039 byte preview_wait;
00040 CompanyMask company_avail;
00041 uint8 original_image_index;
00042 VehicleType type;
00043
00044 EngineInfo info;
00045
00046 union {
00047 RailVehicleInfo rail;
00048 RoadVehicleInfo road;
00049 ShipVehicleInfo ship;
00050 AircraftVehicleInfo air;
00051 } u;
00052
00053
00060 GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
00061 uint16 overrides_count;
00062 struct WagonOverride *overrides;
00063 uint16 list_position;
00064
00065 Engine();
00066 Engine(VehicleType type, EngineID base);
00067 ~Engine();
00068 bool IsEnabled() const;
00069
00081 CargoID GetDefaultCargoType() const
00082 {
00083 return this->info.cargo_type;
00084 }
00085
00086 uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = NULL) const;
00087
00088 bool CanCarryCargo() const;
00089
00101 uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const
00102 {
00103 return this->DetermineCapacity(NULL, mail_capacity);
00104 }
00105
00106 Money GetRunningCost() const;
00107 Money GetCost() const;
00108 uint GetDisplayMaxSpeed() const;
00109 uint GetPower() const;
00110 uint GetDisplayWeight() const;
00111 uint GetDisplayMaxTractiveEffort() const;
00112 Date GetLifeLengthInDays() const;
00113 uint16 GetRange() const;
00114
00119 FORCEINLINE bool IsGroundVehicle() const
00120 {
00121 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
00122 }
00123
00129 const GRFFile *GetGRF() const
00130 {
00131 return this->grf_prop.grffile;
00132 }
00133
00134 uint32 GetGRFID() const;
00135 };
00136
00137 struct EngineIDMapping {
00138 uint32 grfid;
00139 uint16 internal_id;
00140 VehicleTypeByte type;
00141 uint8 substitute_id;
00142 };
00143
00148 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00149 static const uint NUM_DEFAULT_ENGINES;
00150
00151 void ResetToDefaultMapping();
00152 EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00153
00154 static bool ResetToCurrentNewGRFConfig();
00155 };
00156
00157 extern EngineOverrideManager _engine_mngr;
00158
00159 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
00160 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
00161
00162 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00163
00164 static inline const EngineInfo *EngInfo(EngineID e)
00165 {
00166 return &Engine::Get(e)->info;
00167 }
00168
00169 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00170 {
00171 return &Engine::Get(e)->u.rail;
00172 }
00173
00174 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00175 {
00176 return &Engine::Get(e)->u.road;
00177 }
00178
00179 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00180 {
00181 return &Engine::Get(e)->u.ship;
00182 }
00183
00184 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00185 {
00186 return &Engine::Get(e)->u.air;
00187 }
00188
00189 #endif