engine_base.h

Go to the documentation of this file.
00001 /* $Id: engine_base.h 15765 2009-03-18 19:50:34Z rubidium $ */
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 #include "core/smallvec_type.hpp"
00012 
00013 DECLARE_OLD_POOL(Engine, Engine, 6, 10000)
00014 
00015 struct Engine : PoolItem<Engine, EngineID, &_Engine_pool> {
00016   char *name;         
00017   Date intro_date;
00018   Date age;
00019   uint16 reliability;
00020   uint16 reliability_spd_dec;
00021   uint16 reliability_start, reliability_max, reliability_final;
00022   uint16 duration_phase_1, duration_phase_2, duration_phase_3;
00023   byte lifelength;
00024   byte flags;
00025   uint8 preview_company_rank;
00026   byte preview_wait;
00027   CompanyMask company_avail;
00028   uint8 image_index; 
00029   VehicleType type; 
00030 
00031   EngineInfo info;
00032 
00033   union {
00034     RailVehicleInfo rail;
00035     RoadVehicleInfo road;
00036     ShipVehicleInfo ship;
00037     AircraftVehicleInfo air;
00038   } u;
00039 
00040   /* NewGRF related data */
00041   const struct GRFFile *grffile;
00042   const struct SpriteGroup *group[NUM_CARGO + 2];
00043   uint16 internal_id;                             
00044   uint16 overrides_count;
00045   struct WagonOverride *overrides;
00046   uint16 list_position;
00047 
00048   Engine();
00049   Engine(VehicleType type, EngineID base);
00050   ~Engine();
00051 
00052   inline bool IsValid() const { return this->info.climates != 0; }
00053 
00054   CargoID GetDefaultCargoType() const;
00055   bool CanCarryCargo() const;
00056   uint GetDisplayDefaultCapacity() const;
00057   Money GetRunningCost() const;
00058   Money GetCost() const;
00059   uint GetDisplayMaxSpeed() const;
00060   uint GetPower() const;
00061   uint GetDisplayWeight() const;
00062   uint GetDisplayMaxTractiveEffort() const;
00063 };
00064 
00065 struct EngineIDMapping {
00066   uint32 grfid;          
00067   uint16 internal_id;    
00068   VehicleTypeByte type;  
00069   uint8  substitute_id;  
00070 };
00071 
00076 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00077   static const uint NUM_DEFAULT_ENGINES; 
00078 
00079   void ResetToDefaultMapping();
00080   EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00081 };
00082 
00083 extern EngineOverrideManager _engine_mngr;
00084 
00085 static inline bool IsEngineIndex(uint index)
00086 {
00087   return index < GetEnginePoolSize();
00088 }
00089 
00090 #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())
00091 #define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
00092 
00093 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00094 
00095 static inline const EngineInfo *EngInfo(EngineID e)
00096 {
00097   return &GetEngine(e)->info;
00098 }
00099 
00100 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00101 {
00102   return &GetEngine(e)->u.rail;
00103 }
00104 
00105 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00106 {
00107   return &GetEngine(e)->u.road;
00108 }
00109 
00110 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00111 {
00112   return &GetEngine(e)->u.ship;
00113 }
00114 
00115 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00116 {
00117   return &GetEngine(e)->u.air;
00118 }
00119 
00120 #endif /* ENGINE_TYPE_H */

Generated on Sun Nov 15 15:40:11 2009 for OpenTTD by  doxygen 1.5.6