engine_base.h

Go to the documentation of this file.
00001 /* $Id: engine_base.h 21986 2011-02-05 20:37:00Z frosch $ */
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   bool IsEnabled() const;
00065 
00077   CargoID GetDefaultCargoType() const
00078   {
00079     return this->info.cargo_type;
00080   }
00081 
00082   bool CanCarryCargo() const;
00083   uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const;
00084   Money GetRunningCost() const;
00085   Money GetCost() const;
00086   uint GetDisplayMaxSpeed() const;
00087   uint GetPower() const;
00088   uint GetDisplayWeight() const;
00089   uint GetDisplayMaxTractiveEffort() const;
00090   Date GetLifeLengthInDays() const;
00091 
00096   FORCEINLINE bool IsGroundVehicle() const
00097   {
00098     return this->type == VEH_TRAIN || this->type == VEH_ROAD;
00099   }
00100 };
00101 
00102 struct EngineIDMapping {
00103   uint32 grfid;          
00104   uint16 internal_id;    
00105   VehicleTypeByte type;  
00106   uint8  substitute_id;  
00107 };
00108 
00113 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
00114   static const uint NUM_DEFAULT_ENGINES; 
00115 
00116   void ResetToDefaultMapping();
00117   EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
00118 
00119   static bool ResetToCurrentNewGRFConfig();
00120 };
00121 
00122 extern EngineOverrideManager _engine_mngr;
00123 
00124 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
00125 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
00126 
00127 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
00128 
00129 static inline const EngineInfo *EngInfo(EngineID e)
00130 {
00131   return &Engine::Get(e)->info;
00132 }
00133 
00134 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
00135 {
00136   return &Engine::Get(e)->u.rail;
00137 }
00138 
00139 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
00140 {
00141   return &Engine::Get(e)->u.road;
00142 }
00143 
00144 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
00145 {
00146   return &Engine::Get(e)->u.ship;
00147 }
00148 
00149 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
00150 {
00151   return &Engine::Get(e)->u.air;
00152 }
00153 
00154 #endif /* ENGINE_BASE_H */

Generated on Fri Mar 18 23:17:35 2011 for OpenTTD by  doxygen 1.6.1