# engine_base.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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 "engine_type.h"
    00016 #include "economy_type.h"
    00017 #include "core/pool_type.hpp"
    00018 #include "core/smallvec_type.hpp"
    00019
    00020 typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
    00021 extern EnginePool _engine_pool;
    00022
    00023 struct Engine : EnginePool::PoolItem<&_engine_pool> {
    00024   char *name;
    00025   Date intro_date;
    00026   Date age;
    00027   uint16 reliability;
    00028   uint16 reliability_spd_dec;
    00029   uint16 reliability_start, reliability_max, reliability_final;
    00030   uint16 duration_phase_1, duration_phase_2, duration_phase_3;
    00031   byte flags;
    00032   uint8 preview_company_rank;
    00033   byte preview_wait;
    00034   CompanyMask company_avail;
    00035   uint8 original_image_index;
    00036   VehicleType type;
    00037
    00038   EngineInfo info;
    00039
    00040   union {
    00041     RailVehicleInfo rail;
    00042     RoadVehicleInfo road;
    00043     ShipVehicleInfo ship;
    00044     AircraftVehicleInfo air;
    00045   } u;
    00046
    00047   /* NewGRF related data */
    00048   const struct GRFFile *grffile;
    00049   const struct SpriteGroup *group[NUM_CARGO + 2];
    00050   uint16 internal_id;
    00051   uint16 overrides_count;
    00052   struct WagonOverride *overrides;
    00053   uint16 list_position;
    00054
    00055   Engine();
    00056   Engine(VehicleType type, EngineID base);
    00057   ~Engine();
    00058
    00070   CargoID GetDefaultCargoType() const
    00071   {
    00072     return this->info.cargo_type;
    00073   }
    00074
    00075   bool CanCarryCargo() const;
    00076   uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const;
    00077   Money GetRunningCost() const;
    00078   Money GetCost() const;
    00079   uint GetDisplayMaxSpeed() const;
    00080   uint GetPower() const;
    00081   uint GetDisplayWeight() const;
    00082   uint GetDisplayMaxTractiveEffort() const;
    00083   Date GetLifeLengthInDays() const;
    00084 };
    00085
    00086 struct EngineIDMapping {
    00087   uint32 grfid;
    00088   uint16 internal_id;
    00089   VehicleTypeByte type;
    00090   uint8  substitute_id;
    00091 };
    00092
    00097 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
    00098   static const uint NUM_DEFAULT_ENGINES;
    00099
    00100   void ResetToDefaultMapping();
    00101   EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
    00102 };
    00103
    00104 extern EngineOverrideManager _engine_mngr;
    00105
    00106 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
    00107 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
    00108
    00109 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
    00110
    00111 static inline const EngineInfo *EngInfo(EngineID e)
    00112 {
    00113   return &Engine::Get(e)->info;
    00114 }
    00115
    00116 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
    00117 {
    00118   return &Engine::Get(e)->u.rail;
    00119 }
    00120
    00121 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
    00122 {
    00123   return &Engine::Get(e)->u.road;
    00124 }
    00125
    00126 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
    00127 {
    00128   return &Engine::Get(e)->u.ship;
    00129 }
    00130
    00131 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
    00132 {
    00133   return &Engine::Get(e)->u.air;
    00134 }
    00135
    00136 #endif /* ENGINE_TYPE_H */