engine_base.h

Go to the documentation of this file.
00001 /* $Id: engine_base.h 21593 2010-12-22 10:50:32Z alberth $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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, reliability_max, reliability_final;
00032   uint16 duration_phase_1, duration_phase_2, duration_phase_3;
00033   byte flags;
00034   uint8 preview_company_rank;
00035   byte preview_wait;
00036   CompanyMask company_avail;
00037   uint8 original_image_index; 
00038   VehicleType type; 
00039 
00040   EngineInfo info;
00041 
00042   union {
00043     RailVehicleInfo rail;
00044     RoadVehicleInfo road;
00045     ShipVehicleInfo ship;
00046     AircraftVehicleInfo air;
00047   } u;
00048 
00049   /* NewGRF related data */
00056   GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
00057   uint16 overrides_count;
00058   struct WagonOverride *overrides;
00059   uint16 list_position;
00060 
00061   Engine();
00062   Engine(VehicleType type, EngineID base);
00063   ~Engine();
00064 
00076   CargoID GetDefaultCargoType() const
00077   {
00078     return this->info.cargo_type;
00079   }
00080 
00081   bool CanCarryCargo() const;
00082   uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const;
00083   Money GetRunningCost() const;
00084   Money GetCost() const;
00085   uint GetDisplayMaxSpeed() const;
00086   uint GetPower() const;
00087   uint GetDisplayWeight() const;
00088   uint GetDisplayMaxTractiveEffort() const;
00089   Date GetLifeLengthInDays() const;
00090 
00095   FORCEINLINE bool IsGroundVehicle() const
00096   {
00097     return this->type == VEH_TRAIN || this->type == VEH_ROAD;
00098   }
00099 };
00100 
00101 struct EngineIDMapping {
00102   uint32 grfid;          
00103   uint16 internal_id;    
00104   VehicleTypeByte type;  
00105   uint8  substitute_id;  
00106 };
00107 
00112 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00113   static const uint NUM_DEFAULT_ENGINES; 
00114 
00115   void ResetToDefaultMapping();
00116   EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00117 };
00118 
00119 extern EngineOverrideManager _engine_mngr;
00120 
00121 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
00122 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
00123 
00124 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00125 
00126 static inline const EngineInfo *EngInfo(EngineID e)
00127 {
00128   return &Engine::Get(e)->info;
00129 }
00130 
00131 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00132 {
00133   return &Engine::Get(e)->u.rail;
00134 }
00135 
00136 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00137 {
00138   return &Engine::Get(e)->u.road;
00139 }
00140 
00141 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00142 {
00143   return &Engine::Get(e)->u.ship;
00144 }
00145 
00146 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00147 {
00148   return &Engine::Get(e)->u.air;
00149 }
00150 
00151 #endif /* ENGINE_BASE_H */

Generated on Sun Jan 9 16:01:54 2011 for OpenTTD by  doxygen 1.6.1