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
00118 FORCEINLINE bool IsGroundVehicle() const
00119 {
00120 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
00121 }
00122
00128 const GRFFile *GetGRF() const
00129 {
00130 return this->grf_prop.grffile;
00131 }
00132
00133 uint32 GetGRFID() const;
00134 };
00135
00136 struct EngineIDMapping {
00137 uint32 grfid;
00138 uint16 internal_id;
00139 VehicleTypeByte type;
00140 uint8 substitute_id;
00141 };
00142
00147 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00148 static const uint NUM_DEFAULT_ENGINES;
00149
00150 void ResetToDefaultMapping();
00151 EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00152
00153 static bool ResetToCurrentNewGRFConfig();
00154 };
00155
00156 extern EngineOverrideManager _engine_mngr;
00157
00158 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
00159 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
00160
00161 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00162
00163 static inline const EngineInfo *EngInfo(EngineID e)
00164 {
00165 return &Engine::Get(e)->info;
00166 }
00167
00168 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00169 {
00170 return &Engine::Get(e)->u.rail;
00171 }
00172
00173 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00174 {
00175 return &Engine::Get(e)->u.road;
00176 }
00177
00178 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00179 {
00180 return &Engine::Get(e)->u.ship;
00181 }
00182
00183 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00184 {
00185 return &Engine::Get(e)->u.air;
00186 }
00187
00188 #endif