# engine_base.h

Go to the documentation of this file.

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