# engine_base.h

Go to the documentation of this file.

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