engine_base.h
Go to the documentation of this file.00001
00002
00005 #ifndef ENGINE_BASE_H
00006 #define ENGINE_BASE_H
00007
00008 #include "engine_type.h"
00009 #include "oldpool.h"
00010
00011 DECLARE_OLD_POOL(Engine, Engine, 6, 10000)
00012
00013 struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
00014 char *name;
00015 Date intro_date;
00016 Date age;
00017 uint16 reliability;
00018 uint16 reliability_spd_dec;
00019 uint16 reliability_start, reliability_max, reliability_final;
00020 uint16 duration_phase_1, duration_phase_2, duration_phase_3;
00021 byte lifelength;
00022 byte flags;
00023 uint8 preview_company_rank;
00024 byte preview_wait;
00025 CompanyMask company_avail;
00026 uint8 image_index;
00027 VehicleType type;
00028
00029 EngineInfo info;
00030
00031 union {
00032 RailVehicleInfo rail;
00033 RoadVehicleInfo road;
00034 ShipVehicleInfo ship;
00035 AircraftVehicleInfo air;
00036 } u;
00037
00038
00039 const struct GRFFile *grffile;
00040 const struct SpriteGroup *group[NUM_CARGO + 2];
00041 uint16 internal_id;
00042 uint16 overrides_count;
00043 struct WagonOverride *overrides;
00044 uint16 list_position;
00045
00046 Engine();
00047 Engine(VehicleType type, EngineID base);
00048 ~Engine();
00049
00050 inline bool IsValid() const { return this->info.climates != 0; }
00051 };
00052
00053 static inline bool IsEngineIndex(uint index)
00054 {
00055 return index < GetEnginePoolSize();
00056 }
00057
00058 #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())
00059 #define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
00060
00061 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00062
00063 static inline const EngineInfo *EngInfo(EngineID e)
00064 {
00065 return &GetEngine(e)->info;
00066 }
00067
00068 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00069 {
00070 return &GetEngine(e)->u.rail;
00071 }
00072
00073 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00074 {
00075 return &GetEngine(e)->u.road;
00076 }
00077
00078 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00079 {
00080 return &GetEngine(e)->u.ship;
00081 }
00082
00083 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00084 {
00085 return &GetEngine(e)->u.air;
00086 }
00087
00088 #endif