engine_base.h

Go to the documentation of this file.
00001 /* $Id: engine_base.h 15645 2009-03-08 16:51:08Z 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 #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   Money GetRunningCost() const;
00057   Money GetCost() const;
00058   uint GetDisplayMaxSpeed() const;
00059   uint GetPower() const;
00060   uint GetDisplayWeight() const;
00061   uint GetDisplayMaxTractiveEffort() const;
00062 };
00063 
00064 struct EngineIDMapping {
00065   uint32 grfid;          
00066   uint16 internal_id;    
00067   VehicleTypeByte type;  
00068   uint8  substitute_id;  
00069 };
00070 
00075 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00076   static const uint NUM_DEFAULT_ENGINES; 
00077 
00078   void ResetToDefaultMapping();
00079   EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00080 };
00081 
00082 extern EngineOverrideManager _engine_mngr;
00083 
00084 static inline bool IsEngineIndex(uint index)
00085 {
00086   return index < GetEnginePoolSize();
00087 }
00088 
00089 #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())
00090 #define FOR_ALL_ENGINES(e) FOR_ALL_ENGINES_FROM(e, 0)
00091 
00092 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00093 
00094 static inline const EngineInfo *EngInfo(EngineID e)
00095 {
00096   return &GetEngine(e)->info;
00097 }
00098 
00099 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00100 {
00101   return &GetEngine(e)->u.rail;
00102 }
00103 
00104 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00105 {
00106   return &GetEngine(e)->u.road;
00107 }
00108 
00109 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00110 {
00111   return &GetEngine(e)->u.ship;
00112 }
00113 
00114 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00115 {
00116   return &GetEngine(e)->u.air;
00117 }
00118 
00119 #endif /* ENGINE_TYPE_H */

Generated on Sun Mar 15 22:49:46 2009 for openttd by  doxygen 1.5.6