Update readme.md
[openttd-joker.git] / src / engine_type.h
blob25cc067b25cea8215bb8d255a20bd37359424b20
1 /* $Id: engine_type.h 24810 2012-12-09 16:55:03Z frosch $ */
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_type.h Types related to engines. */
12 #ifndef ENGINE_TYPE_H
13 #define ENGINE_TYPE_H
15 #include "economy_type.h"
16 #include "rail_type.h"
17 #include "road_type.h"
18 #include "cargo_type.h"
19 #include "date_type.h"
20 #include "sound_type.h"
21 #include "strings_type.h"
23 typedef uint16 EngineID; ///< Unique identification number of an engine.
25 struct Engine;
26 struct RoadTypeIdentifier;
28 /** Available types of rail vehicles. */
29 enum RailVehicleTypes {
30 RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive
31 RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives
32 RAILVEH_WAGON, ///< simple wagon, not motorized
35 /** Type of rail engine. */
36 enum EngineClass {
37 EC_STEAM, ///< Steam rail engine.
38 EC_DIESEL, ///< Diesel rail engine.
39 EC_ELECTRIC, ///< Electric rail engine.
40 EC_MONORAIL, ///< Mono rail engine.
41 EC_MAGLEV, ///< Maglev engine.
44 /** Information about a rail vehicle. */
45 struct RailVehicleInfo {
46 byte image_index;
47 RailVehicleTypes railveh_type;
48 byte cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices.
49 RailTypeByte railtype;
50 uint16 max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h)
51 uint16 power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers.
52 uint16 weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine.
53 byte running_cost; ///< Running cost of engine; For multiheaded engines the sum of both running costs.
54 Price running_cost_class;
55 EngineClass engclass; ///< Class of engine for this vehicle
56 byte capacity; ///< Cargo capacity of vehicle; For multiheaded engines the capacity of each single engine.
57 byte ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only
58 uint16 pow_wag_power; ///< Extra power applied to consist if wagon should be powered
59 byte pow_wag_weight; ///< Extra weight applied to consist if wagon should be powered
60 byte visual_effect; ///< Bitstuffed NewGRF visual effect data
61 byte shorten_factor; ///< length on main map for this type is 8 - shorten_factor
62 byte tractive_effort; ///< Tractive effort coefficient
63 byte air_drag; ///< Coefficient of air drag
64 byte user_def_data; ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles
67 /** Information about a ship vehicle. */
68 struct ShipVehicleInfo {
69 byte image_index;
70 byte cost_factor;
71 uint16 max_speed; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
72 uint16 capacity;
73 byte running_cost;
74 SoundID sfx;
75 bool old_refittable; ///< Is ship refittable; only used during initialisation. Later use EngineInfo::refit_mask.
76 byte visual_effect; ///< Bitstuffed NewGRF visual effect data
77 byte ocean_speed_frac; ///< Fraction of maximum speed for ocean tiles.
78 byte canal_speed_frac; ///< Fraction of maximum speed for canal/river tiles.
80 /** Apply ocean/canal speed fraction to a velocity */
81 uint ApplyWaterClassSpeedFrac(uint raw_speed, bool is_ocean) const
83 /* speed_frac == 0 means no reduction while 0xFF means reduction to 1/256. */
84 return raw_speed * (256 - (is_ocean ? this->ocean_speed_frac : this->canal_speed_frac)) / 256;
88 /**
89 * AircraftVehicleInfo subtypes, bitmask type.
90 * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
91 * in which case bit 1 tells us whether it's a big(fast) plane or not.
93 enum AircraftSubTypeBits {
94 AIR_HELI = 0,
95 AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes
96 AIR_FAST = 2
99 /** Information about a aircraft vehicle. */
100 struct AircraftVehicleInfo {
101 byte image_index;
102 byte cost_factor;
103 byte running_cost;
104 byte subtype; ///< Type of aircraft. @see AircraftSubTypeBits
105 SoundID sfx;
106 byte acceleration;
107 uint16 max_speed; ///< Maximum speed (1 unit = 8 mph = 12.8 km-ish/h)
108 byte mail_capacity; ///< Mail capacity (bags).
109 uint16 passenger_capacity; ///< Passenger capacity (persons).
110 uint16 max_range; ///< Maximum range of this aircraft.
113 /** Information about a road vehicle. */
114 struct RoadVehicleInfo {
115 byte image_index;
116 byte cost_factor;
117 byte running_cost;
118 Price running_cost_class;
119 SoundID sfx;
120 uint16 max_speed; ///< Maximum speed (1 unit = 1/3.2 mph = 0.5 km-ish/h)
121 byte capacity;
122 uint8 weight; ///< Weight in 1/4t units
123 uint8 power; ///< Power in 10hp units
124 uint8 tractive_effort; ///< Coefficient of tractive effort
125 uint8 air_drag; ///< Coefficient of air drag
126 byte visual_effect; ///< Bitstuffed NewGRF visual effect data
127 byte shorten_factor; ///< length on main map for this type is 8 - shorten_factor
128 RoadSubType roadsubtype;
132 * Information about a vehicle
133 * @see table/engines.h
135 struct EngineInfo {
136 Date base_intro; ///< Basic date of engine introduction (without random parts).
137 Year lifelength; ///< Lifetime of a single vehicle
138 Year base_life; ///< Basic duration of engine availability (without random parts). \c 0xFF means infinite life.
139 byte decay_speed;
140 byte load_amount;
141 byte climates; ///< Climates supported by the engine.
142 CargoID cargo_type;
143 uint32 refit_mask;
144 byte refit_cost;
145 byte misc_flags; ///< Miscellaneous flags. @see EngineMiscFlags
146 byte callback_mask; ///< Bitmask of vehicle callbacks that have to be called
147 int8 retire_early; ///< Number of years early to retire vehicle
148 StringID string_id; ///< Default name of engine
149 uint16 cargo_age_period; ///< Number of ticks before carried cargo is aged.
153 * EngineInfo.misc_flags is a bitmask, with the following values
155 enum EngineMiscFlags {
156 EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves
157 EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle
158 EF_USES_2CC = 1, ///< Vehicle uses two company colours
159 EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU)
160 EF_RAIL_FLIPS = 3, ///< Rail vehicle can be flipped in the depot
161 EF_AUTO_REFIT = 4, ///< Automatic refitting is allowed
162 EF_NO_DEFAULT_CARGO_MULTIPLIER = 5, ///< Use the new capacity algorithm. The default cargotype of the vehicle does not affect capacity multipliers. CB 15 is also called in purchase list.
163 EF_NO_BREAKDOWN_SMOKE = 6, ///< Do not show black smoke during a breakdown.
164 EF_SPRITE_STACK = 7, ///< Draw vehicle by stacking multiple sprites.
168 * Engine.flags is a bitmask, with the following values.
170 enum EngineFlags {
171 ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone.
172 ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a company.
175 static const uint MAX_LENGTH_ENGINE_NAME_CHARS = 32; ///< The maximum length of an engine name in characters including '\0'
177 static const EngineID INVALID_ENGINE = 0xFFFF; ///< Constant denoting an invalid engine.
179 #endif /* ENGINE_TYPE_H */