OpenTTD
engine_base.h
Go to the documentation of this file.
1 /* $Id: engine_base.h 26802 2014-09-07 16:12:58Z alberth $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef ENGINE_BASE_H
13 #define ENGINE_BASE_H
14 
15 #include "engine_type.h"
16 #include "vehicle_type.h"
17 #include "core/pool_type.hpp"
18 #include "newgrf_commons.h"
19 
21 extern EnginePool _engine_pool;
22 
23 struct Engine : EnginePool::PoolItem<&_engine_pool> {
24  char *name;
26  Date age;
27  uint16 reliability;
30  uint16 reliability_max;
35  byte flags;
36  CompanyMask preview_asked;
38  byte preview_wait;
39  CompanyMask company_avail;
40  CompanyMask company_hidden;
43 
44  EngineInfo info;
45 
46  union {
47  RailVehicleInfo rail;
48  RoadVehicleInfo road;
49  ShipVehicleInfo ship;
51  } u;
52 
53  /* NewGRF related data */
61  uint16 overrides_count;
62  struct WagonOverride *overrides;
63  uint16 list_position;
64 
65  Engine();
67  ~Engine();
68  bool IsEnabled() const;
69 
82  {
83  return this->info.cargo_type;
84  }
85 
86  uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = NULL) const;
87 
88  bool CanCarryCargo() const;
89 
101  uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const
102  {
103  return this->DetermineCapacity(NULL, mail_capacity);
104  }
105 
106  Money GetRunningCost() const;
107  Money GetCost() const;
108  uint GetDisplayMaxSpeed() const;
109  uint GetPower() const;
110  uint GetDisplayWeight() const;
111  uint GetDisplayMaxTractiveEffort() const;
112  Date GetLifeLengthInDays() const;
113  uint16 GetRange() const;
114 
120  inline bool IsHidden(CompanyByte c) const
121  {
122  return c < MAX_COMPANIES && HasBit(this->company_hidden, c);
123  }
124 
129  inline bool IsGroundVehicle() const
130  {
131  return this->type == VEH_TRAIN || this->type == VEH_ROAD;
132  }
133 
139  const GRFFile *GetGRF() const
140  {
141  return this->grf_prop.grffile;
142  }
143 
144  uint32 GetGRFID() const;
145 };
146 
148  uint32 grfid;
149  uint16 internal_id;
152 };
153 
158 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
159  static const uint NUM_DEFAULT_ENGINES;
160 
161  void ResetToDefaultMapping();
162  EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
163 
164  static bool ResetToCurrentNewGRFConfig();
165 };
166 
167 extern EngineOverrideManager _engine_mngr;
168 
169 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
170 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
171 
172 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
173 
174 static inline const EngineInfo *EngInfo(EngineID e)
175 {
176  return &Engine::Get(e)->info;
177 }
178 
179 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
180 {
181  return &Engine::Get(e)->u.rail;
182 }
183 
184 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
185 {
186  return &Engine::Get(e)->u.road;
187 }
188 
189 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
190 {
191  return &Engine::Get(e)->u.ship;
192 }
193 
194 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
195 {
196  return &Engine::Get(e)->u.air;
197 }
198 
199 #endif /* ENGINE_BASE_H */