Remove SIGTYPE_LAST_NOPBS
[openttd/fttd.git] / src / engine_base.h
blobc433755e64379756ae1672ec3fb1eaf48292a58f
1 /* $Id$ */
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 */
10 /** @file engine_base.h Base class for engines. */
12 #ifndef ENGINE_BASE_H
13 #define ENGINE_BASE_H
15 #include "engine_type.h"
16 #include "vehicle_type.h"
17 #include "core/pool_type.hpp"
18 #include "newgrf_commons.h"
20 struct Engine : PooledItem <Engine, EngineID, 64, 64000> {
21 char *name; ///< Custom name of engine.
22 Date intro_date; ///< Date of introduction of the engine.
23 Date age;
24 uint16 reliability; ///< Current reliability of the engine.
25 uint16 reliability_spd_dec; ///< Speed of reliability decay between services (per day).
26 uint16 reliability_start; ///< Initial reliability of the engine.
27 uint16 reliability_max; ///< Maximal reliability of the engine.
28 uint16 reliability_final; ///< Final reliability of the engine.
29 uint16 duration_phase_1; ///< First reliability phase in months, increasing reliability from #reliability_start to #reliability_max.
30 uint16 duration_phase_2; ///< Second reliability phase in months, keeping #reliability_max.
31 uint16 duration_phase_3; ///< Third reliability phase on months, decaying to #reliability_final.
32 byte flags; ///< Flags of the engine. @see EngineFlags
33 CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview.
34 CompanyByte preview_company;///< Company which is currently being offered a preview \c INVALID_COMPANY means no company.
35 byte preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company.
36 CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company.
37 uint8 original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle
38 VehicleType type; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc.
40 EngineInfo info;
42 union {
43 RailVehicleInfo rail;
44 RoadVehicleInfo road;
45 ShipVehicleInfo ship;
46 AircraftVehicleInfo air;
47 } u;
49 /* NewGRF related data */
50 /**
51 * Properties related the the grf file.
52 * NUM_CARGO real cargo plus two pseudo cargo sprite groups.
53 * Used for obtaining the sprite offset of custom sprites, and for
54 * evaluating callbacks.
56 GRFFilePropsBase<NUM_CARGO + 2> grf_prop;
57 uint16 overrides_count;
58 struct WagonOverride *overrides;
59 uint16 list_position;
61 Engine();
62 Engine(VehicleType type, EngineID base);
63 ~Engine();
64 bool IsEnabled() const;
66 /**
67 * Determines the default cargo type of an engine.
69 * 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
70 * for livery selection etc..
72 * Vehicles with CT_INVALID as default cargo are usually not available, but it can appear as default cargo of articulated parts.
74 * @return The default cargo type.
75 * @see CanCarryCargo
77 CargoID GetDefaultCargoType() const
79 return this->info.cargo_type;
82 uint DetermineCapacity(const Vehicle *v, uint16 *mail_capacity = NULL) const;
84 bool CanCarryCargo() const;
86 /**
87 * Determines the default cargo capacity of an engine for display purposes.
89 * For planes carrying both passenger and mail this is the passenger capacity.
90 * For multiheaded engines this is the capacity of both heads.
91 * For articulated engines use GetCapacityOfArticulatedParts
93 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
94 * @return The default capacity
95 * @see GetDefaultCargoType
97 uint GetDisplayDefaultCapacity(uint16 *mail_capacity = NULL) const
99 return this->DetermineCapacity(NULL, mail_capacity);
102 Money GetRunningCost() const;
103 Money GetCost() const;
104 uint GetDisplayMaxSpeed() const;
105 uint GetPower() const;
106 uint GetDisplayWeight() const;
107 uint GetDisplayMaxTractiveEffort() const;
108 Date GetLifeLengthInDays() const;
109 uint16 GetRange() const;
112 * Check if the engine is a ground vehicle.
113 * @return True iff the engine is a train or a road vehicle.
115 inline bool IsGroundVehicle() const
117 return this->type == VEH_TRAIN || this->type == VEH_ROAD;
121 * Retrieve the NewGRF the engine is tied to.
122 * This is the GRF providing the Action 3.
123 * @return NewGRF associated to the engine.
125 const GRFFile *GetGRF() const
127 return this->grf_prop.grffile;
130 uint32 GetGRFID() const;
133 struct EngineIDMapping {
134 uint32 grfid; ///< The GRF ID of the file the entity belongs to
135 uint16 internal_id; ///< The internal ID within the GRF file
136 VehicleTypeByte type; ///< The engine type
137 uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used)
141 * Stores the mapping of EngineID to the internal id of newgrfs.
142 * Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
144 struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
145 static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries
147 void ResetToDefaultMapping();
148 EngineID GetID(VehicleType type, uint16 grf_local_id, uint32 grfid);
150 static bool ResetToCurrentNewGRFConfig();
153 extern EngineOverrideManager _engine_mngr;
155 #define FOR_ALL_ENGINES_FROM(var, start) FOR_ALL_ITEMS_FROM(Engine, engine_index, var, start)
156 #define FOR_ALL_ENGINES(var) FOR_ALL_ENGINES_FROM(var, 0)
158 #define FOR_ALL_ENGINES_OF_TYPE(e, engine_type) FOR_ALL_ENGINES(e) if (e->type == engine_type)
160 static inline const EngineInfo *EngInfo(EngineID e)
162 return &Engine::Get(e)->info;
165 static inline const RailVehicleInfo *RailVehInfo(EngineID e)
167 return &Engine::Get(e)->u.rail;
170 static inline const RoadVehicleInfo *RoadVehInfo(EngineID e)
172 return &Engine::Get(e)->u.road;
175 static inline const ShipVehicleInfo *ShipVehInfo(EngineID e)
177 return &Engine::Get(e)->u.ship;
180 static inline const AircraftVehicleInfo *AircraftVehInfo(EngineID e)
182 return &Engine::Get(e)->u.air;
185 #endif /* ENGINE_BASE_H */