Add: INR currency (#8136)
[openttd-github.git] / src / engine_base.h
blob203d35f20143d3cce2f7d9fe38e7b2a3efe543c3
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file engine_base.h Base class for engines. */
10 #ifndef ENGINE_BASE_H
11 #define ENGINE_BASE_H
13 #include "engine_type.h"
14 #include "vehicle_type.h"
15 #include "core/pool_type.hpp"
16 #include "newgrf_commons.h"
18 typedef Pool<Engine, EngineID, 64, 64000> EnginePool;
19 extern EnginePool _engine_pool;
21 struct Engine : EnginePool::PoolItem<&_engine_pool> {
22 char *name; ///< Custom name of engine.
23 Date intro_date; ///< Date of introduction of the engine.
24 Date age;
25 uint16 reliability; ///< Current reliability of the engine.
26 uint16 reliability_spd_dec; ///< Speed of reliability decay between services (per day).
27 uint16 reliability_start; ///< Initial reliability of the engine.
28 uint16 reliability_max; ///< Maximal reliability of the engine.
29 uint16 reliability_final; ///< Final reliability of the engine.
30 uint16 duration_phase_1; ///< First reliability phase in months, increasing reliability from #reliability_start to #reliability_max.
31 uint16 duration_phase_2; ///< Second reliability phase in months, keeping #reliability_max.
32 uint16 duration_phase_3; ///< Third reliability phase on months, decaying to #reliability_final.
33 byte flags; ///< Flags of the engine. @see EngineFlags
34 CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview.
35 CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company.
36 byte preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company.
37 CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company.
38 CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company.
39 uint8 original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle
40 VehicleType type; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc.
42 EngineInfo info;
44 union {
45 RailVehicleInfo rail;
46 RoadVehicleInfo road;
47 ShipVehicleInfo ship;
48 AircraftVehicleInfo air;
49 } u;
51 /* NewGRF related data */
52 /**
53 * Properties related the the grf file.
54 * NUM_CARGO real cargo plus two pseudo cargo sprite groups.
55 * Used for obtaining the sprite offset of custom sprites, and for
56 * evaluating callbacks.
58 GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
59 uint16 overrides_count;
60 struct WagonOverride *overrides;
61 uint16 list_position;
63 Engine();
64 Engine(VehicleType type, EngineID base);
65 ~Engine();
66 bool IsEnabled() const;
68 /**
69 * Determines the default cargo type of an engine.
71 * Usually a valid cargo is returned, even though the vehicle has zero capacity, and can therefore not carry anything. But the cargotype is still used
72 * for livery selection etc..
74 * Vehicles with CT_INVALID as default cargo are usually not available, but it can appear as default cargo of articulated parts.
76 * @return The default cargo type.
77 * @see CanCarryCargo
79 CargoID GetDefaultCargoType() const
81 return this->info.cargo_type;
84 uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = nullptr) const;
86 bool CanCarryCargo() const;
88 /**
89 * Determines the default cargo capacity of an engine for display purposes.
91 * For planes carrying both passenger and mail this is the passenger capacity.
92 * For multiheaded engines this is the capacity of both heads.
93 * For articulated engines use GetCapacityOfArticulatedParts
95 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
96 * @return The default capacity
97 * @see GetDefaultCargoType
99 uint GetDisplayDefaultCapacity(uint16 *mail_capacity = nullptr) const
101 return this->DetermineCapacity(nullptr, mail_capacity);
104 Money GetRunningCost() const;
105 Money GetCost() const;
106 uint GetDisplayMaxSpeed() const;
107 uint GetPower() const;
108 uint GetDisplayWeight() const;
109 uint GetDisplayMaxTractiveEffort() const;
110 Date GetLifeLengthInDays() const;
111 uint16 GetRange() const;
112 StringID GetAircraftTypeText() const;
115 * Check whether the engine is hidden in the GUI for the given company.
116 * @param c Company to check.
117 * @return \c true iff the engine is hidden in the GUI for the given company.
119 inline bool IsHidden(CompanyID c) const
121 return c < MAX_COMPANIES && HasBit(this->company_hidden, c);
125 * Check if the engine is a ground vehicle.
126 * @return True iff the engine is a train or a road vehicle.
128 inline bool IsGroundVehicle() const
130 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
134 * Retrieve the NewGRF the engine is tied to.
135 * This is the GRF providing the Action 3.
136 * @return NewGRF associated to the engine.
138 const GRFFile *GetGRF() const
140 return this->grf_prop.grffile;
143 uint32 GetGRFID() const;
145 struct EngineTypeFilter {
146 VehicleType vt;
148 bool operator() (size_t index) { return Engine::Get(index)->type == this->vt; }
152 * Returns an iterable ensemble of all valid engines of the given type
153 * @param vt the VehicleType for engines to be valid
154 * @param from index of the first engine to consider
155 * @return an iterable ensemble of all valid engines of the given type
157 static Pool::IterateWrapperFiltered<Engine, EngineTypeFilter> IterateType(VehicleType vt, size_t from = 0)
159 return Pool::IterateWrapperFiltered<Engine, EngineTypeFilter>(from, EngineTypeFilter{ vt });
163 struct EngineIDMapping {
164 uint32 grfid; ///< The GRF ID of the file the entity belongs to
165 uint16 internal_id; ///< The internal ID within the GRF file
166 VehicleType type; ///< The engine type
167 uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used)
171 * Stores the mapping of EngineID to the internal id of newgrfs.
172 * Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
174 struct EngineOverrideManager : std::vector<EngineIDMapping> {
175 static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries
177 void ResetToDefaultMapping();
178 EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
180 static bool ResetToCurrentNewGRFConfig();
183 extern EngineOverrideManager _engine_mngr;
185 static inline const EngineInfo *EngInfo(EngineID e)
187 return &Engine::Get(e)->info;
190 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
192 return &Engine::Get(e)->u.rail;
195 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
197 return &Engine::Get(e)->u.road;
200 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
202 return &Engine::Get(e)->u.ship;
205 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
207 return &Engine::Get(e)->u.air;
210 #endif /* ENGINE_BASE_H */