3 /** @file engine.h */ |
3 /** @file engine.h */ |
4 |
4 |
5 #ifndef ENGINE_H |
5 #ifndef ENGINE_H |
6 #define ENGINE_H |
6 #define ENGINE_H |
7 |
7 |
8 #include "rail_type.h" |
8 #include "engine_type.h" |
9 #include "cargo_type.h" |
|
10 #include "vehicle_type.h" |
|
11 #include "gfx_type.h" |
|
12 #include "date_type.h" |
|
13 #include "sound_type.h" |
|
14 #include "player_type.h" |
|
15 #include "strings_type.h" |
|
16 |
|
17 enum RailVehicleTypes { |
|
18 RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive |
|
19 RAILVEH_MULTIHEAD, ///< indicates a combination of two locomotives |
|
20 RAILVEH_WAGON, ///< simple wagon, not motorized |
|
21 }; |
|
22 |
|
23 enum EngineClass { |
|
24 EC_STEAM, |
|
25 EC_DIESEL, |
|
26 EC_ELECTRIC, |
|
27 EC_MONORAIL, |
|
28 EC_MAGLEV, |
|
29 }; |
|
30 |
|
31 struct RailVehicleInfo { |
|
32 byte image_index; |
|
33 RailVehicleTypes railveh_type; |
|
34 byte base_cost; |
|
35 RailTypeByte railtype; |
|
36 uint16 max_speed; |
|
37 uint16 power; |
|
38 uint16 weight; |
|
39 byte running_cost; |
|
40 byte running_cost_class; |
|
41 EngineClass engclass; ///< Class of engine for this vehicle |
|
42 byte capacity; |
|
43 CargoID cargo_type; |
|
44 byte ai_rank; |
|
45 byte ai_passenger_only; ///< Bit value to tell AI that this engine is for passenger use only |
|
46 uint16 pow_wag_power; |
|
47 byte pow_wag_weight; |
|
48 byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value |
|
49 // for when the 'powered wagon' callback fails. But it should really also determine what |
|
50 // kind of visual effect to generate for a vehicle (default, steam, diesel, electric). |
|
51 // Same goes for the callback result, which atm is only used to check if a wagon is powered. |
|
52 byte shorten_factor; ///< length on main map for this type is 8 - shorten_factor |
|
53 byte tractive_effort; ///< Tractive effort coefficient |
|
54 byte user_def_data; ///< Property 0x25: "User-defined bit mask" Used only for (very few) NewGRF vehicles |
|
55 }; |
|
56 |
|
57 struct ShipVehicleInfo { |
|
58 byte image_index; |
|
59 byte base_cost; |
|
60 uint16 max_speed; |
|
61 CargoID cargo_type; |
|
62 uint16 capacity; |
|
63 byte running_cost; |
|
64 SoundFxByte sfx; |
|
65 bool refittable; |
|
66 }; |
|
67 |
|
68 /* AircraftVehicleInfo subtypes, bitmask type. |
|
69 * If bit 0 is 0 then it is a helicopter, otherwise it is a plane |
|
70 * in which case bit 1 tells us whether it's a big(fast) plane or not */ |
|
71 enum { |
|
72 AIR_HELI = 0, |
|
73 AIR_CTOL = 1, ///< Conventional Take Off and Landing, i.e. planes |
|
74 AIR_FAST = 2 |
|
75 }; |
|
76 |
|
77 struct AircraftVehicleInfo { |
|
78 byte image_index; |
|
79 byte base_cost; |
|
80 byte running_cost; |
|
81 byte subtype; |
|
82 SoundFxByte sfx; |
|
83 byte acceleration; |
|
84 uint16 max_speed; |
|
85 byte mail_capacity; |
|
86 uint16 passenger_capacity; |
|
87 }; |
|
88 |
|
89 struct RoadVehicleInfo { |
|
90 byte image_index; |
|
91 byte base_cost; |
|
92 byte running_cost; |
|
93 byte running_cost_class; |
|
94 SoundFxByte sfx; |
|
95 byte max_speed; |
|
96 byte capacity; |
|
97 CargoID cargo_type; |
|
98 }; |
|
99 |
|
100 /** Information about a vehicle |
|
101 * @see table/engines.h |
|
102 */ |
|
103 struct EngineInfo { |
|
104 Date base_intro; |
|
105 Year lifelength; |
|
106 Year base_life; |
|
107 byte unk2; ///< flag for carriage(bit 7) and decay speed(bits0..6) |
|
108 byte load_amount; |
|
109 byte climates; |
|
110 uint32 refit_mask; |
|
111 byte refit_cost; |
|
112 byte misc_flags; |
|
113 byte callbackmask; |
|
114 int8 retire_early; ///< Number of years early to retire vehicle |
|
115 StringID string_id; ///< Default name of engine |
|
116 }; |
|
117 |
|
118 struct Engine { |
|
119 char *name; ///< Custom name of engine |
|
120 Date intro_date; |
|
121 Date age; |
|
122 uint16 reliability; |
|
123 uint16 reliability_spd_dec; |
|
124 uint16 reliability_start, reliability_max, reliability_final; |
|
125 uint16 duration_phase_1, duration_phase_2, duration_phase_3; |
|
126 byte lifelength; |
|
127 byte flags; |
|
128 uint8 preview_player_rank; |
|
129 byte preview_wait; |
|
130 byte player_avail; |
|
131 VehicleType type; ///< type, ie VEH_ROAD, VEH_TRAIN, etc. |
|
132 }; |
|
133 |
|
134 /** |
|
135 * EngineInfo.misc_flags is a bitmask, with the following values |
|
136 */ |
|
137 enum { |
|
138 EF_RAIL_TILTS = 0, ///< Rail vehicle tilts in curves |
|
139 EF_ROAD_TRAM = 0, ///< Road vehicle is a tram/light rail vehicle |
|
140 EF_USES_2CC = 1, ///< Vehicle uses two company colours |
|
141 EF_RAIL_IS_MU = 2, ///< Rail vehicle is a multiple-unit (DMU/EMU) |
|
142 }; |
|
143 |
|
144 /** |
|
145 * Engine.flags is a bitmask, with the following values. |
|
146 */ |
|
147 enum { |
|
148 ENGINE_AVAILABLE = 1, ///< This vehicle is available to everyone. |
|
149 ENGINE_EXCLUSIVE_PREVIEW = 2, ///< This vehicle is in the exclusive preview stage, either being used or being offered to a player. |
|
150 ENGINE_OFFER_WINDOW_OPEN = 4, ///< The exclusive offer window is currently open for a player. |
|
151 }; |
|
152 |
|
153 enum { |
|
154 NUM_VEHICLE_TYPES = 6 |
|
155 }; |
|
156 |
|
157 static const EngineID INVALID_ENGINE = 0xFFFF; |
|
158 |
|
159 |
9 |
160 void SetupEngines(); |
10 void SetupEngines(); |
161 void StartupEngines(); |
11 void StartupEngines(); |
162 |
12 |
163 |
13 |
169 void LoadCustomEngineNames(); |
19 void LoadCustomEngineNames(); |
170 void DeleteCustomEngineNames(); |
20 void DeleteCustomEngineNames(); |
171 |
21 |
172 bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player); |
22 bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player); |
173 CargoID GetEngineCargoType(EngineID engine); |
23 CargoID GetEngineCargoType(EngineID engine); |
174 |
|
175 enum { |
|
176 NUM_NORMAL_RAIL_ENGINES = 54, |
|
177 NUM_MONORAIL_ENGINES = 30, |
|
178 NUM_MAGLEV_ENGINES = 32, |
|
179 NUM_TRAIN_ENGINES = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES, |
|
180 NUM_ROAD_ENGINES = 88, |
|
181 NUM_SHIP_ENGINES = 11, |
|
182 NUM_AIRCRAFT_ENGINES = 41, |
|
183 TOTAL_NUM_ENGINES = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES, |
|
184 AIRCRAFT_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES, |
|
185 SHIP_ENGINES_INDEX = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES, |
|
186 ROAD_ENGINES_INDEX = NUM_TRAIN_ENGINES, |
|
187 }; |
|
188 |
24 |
189 static inline EngineID GetFirstEngineOfType(VehicleType type) |
25 static inline EngineID GetFirstEngineOfType(VehicleType type) |
190 { |
26 { |
191 const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX}; |
27 const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX}; |
192 |
28 |
261 { |
97 { |
262 assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info)); |
98 assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info)); |
263 return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; |
99 return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; |
264 } |
100 } |
265 |
101 |
266 typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp) |
|
267 |
|
268 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */ |
102 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */ |
269 void EngList_Create(EngineList *el); ///< Creates engine list |
103 void EngList_Create(EngineList *el); ///< Creates engine list |
270 void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list |
104 void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list |
271 uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list |
105 uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list |
272 void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list |
106 void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list |