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 bool CanCarryCargo() const;
00087 uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const;
00088 Money GetRunningCost() const;
00089 Money GetCost() const;
00090 uint GetDisplayMaxSpeed() const;
00091 uint GetPower() const;
00092 uint GetDisplayWeight() const;
00093 uint GetDisplayMaxTractiveEffort() const;
00094 Date GetLifeLengthInDays() const;
00095
00100 FORCEINLINE bool IsGroundVehicle() const
00101 {
00102 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
00103 }
00104 };
00105
00106 struct EngineIDMapping {
00107 uint32 grfid;
00108 uint16 internal_id;
00109 VehicleTypeByte type;
00110 uint8 substitute_id;
00111 };
00112
00117 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00118 static const uint NUM_DEFAULT_ENGINES;
00119
00120 void ResetToDefaultMapping();
00121 EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00122
00123 static bool ResetToCurrentNewGRFConfig();
00124 };
00125
00126 extern EngineOverrideManager _engine_mngr;
00127
00128 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
00129 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
00130
00131 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00132
00133 static inline const EngineInfo *EngInfo(EngineID e)
00134 {
00135 return &Engine::Get(e)->info;
00136 }
00137
00138 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00139 {
00140 return &Engine::Get(e)->u.rail;
00141 }
00142
00143 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00144 {
00145 return &Engine::Get(e)->u.road;
00146 }
00147
00148 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00149 {
00150 return &Engine::Get(e)->u.ship;
00151 }
00152
00153 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00154 {
00155 return &Engine::Get(e)->u.air;
00156 }
00157
00158 #endif