19 #include "player.h" |
19 #include "player.h" |
20 #include "airport.h" |
20 #include "airport.h" |
21 #include "vehicle_gui.h" |
21 #include "vehicle_gui.h" |
22 #include "table/sprites.h" |
22 #include "table/sprites.h" |
23 #include "newgrf_engine.h" |
23 #include "newgrf_engine.h" |
|
24 #include "newgrf_callbacks.h" |
24 |
25 |
25 static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport); |
26 static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport); |
26 static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
27 static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
27 static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
28 static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport); |
28 static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport); |
29 static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport); |
154 { |
155 { |
155 return AircraftVehInfo(engine_type)->base_cost * (_price.aircraft_base>>3)>>5; |
156 return AircraftVehInfo(engine_type)->base_cost * (_price.aircraft_base>>3)>>5; |
156 } |
157 } |
157 |
158 |
158 |
159 |
|
160 /** |
|
161 * Calculates cargo capacity based on an aircraft's passenger |
|
162 * and mail capacities. |
|
163 * @param cid Which cargo type to calculate a capacity for. |
|
164 * @param engine Which engine to find a cargo capacity for. |
|
165 * @return New cargo capacity value. |
|
166 */ |
|
167 static uint16 AircraftDefaultCargoCapacity(CargoID cid, EngineID engine_type) |
|
168 { |
|
169 const AircraftVehicleInfo *avi = AircraftVehInfo(engine_type); |
|
170 |
|
171 assert(cid != CT_INVALID); |
|
172 |
|
173 /* An aircraft can carry twice as much goods as normal cargo, |
|
174 * and four times as many passengers. */ |
|
175 switch (cid) { |
|
176 case CT_PASSENGERS: |
|
177 return avi->passenger_capacity; |
|
178 case CT_MAIL: |
|
179 return avi->passenger_capacity + avi->mail_capacity; |
|
180 case CT_GOODS: |
|
181 return (avi->passenger_capacity + avi->mail_capacity) / 2; |
|
182 default: |
|
183 return (avi->passenger_capacity + avi->mail_capacity) / 4; |
|
184 } |
|
185 } |
|
186 |
|
187 |
159 /** Build an aircraft. |
188 /** Build an aircraft. |
160 * @param tile tile of depot where aircraft is built |
189 * @param tile tile of depot where aircraft is built |
161 * @param p1 aircraft type being built (engine) |
190 * @param p1 aircraft type being built (engine) |
162 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
191 * @param p2 bit 0 when set, the unitnumber will be 0, otherwise it will be a free number |
163 */ |
192 */ |
253 |
283 |
254 v->subtype = (avi->subtype & 1) == 0 ? 0 : 2; |
284 v->subtype = (avi->subtype & 1) == 0 ? 0 : 2; |
255 v->value = value; |
285 v->value = value; |
256 |
286 |
257 u->subtype = 4; |
287 u->subtype = 4; |
|
288 |
|
289 /* Danger, Will Robinson! |
|
290 * If the aircraft is refittable, but cannot be refitted to |
|
291 * passengers, we select the cargo type from the refit mask. |
|
292 * This is a fairly nasty hack to get around the fact that TTD |
|
293 * has no default cargo type specifier for planes... */ |
|
294 cargo = FindFirstRefittableCargo(p1); |
|
295 if (cargo != CT_INVALID && cargo != CT_PASSENGERS) { |
|
296 uint16 callback = CALLBACK_FAILED; |
|
297 |
|
298 v->cargo_type = cargo; |
|
299 |
|
300 if (HASBIT(EngInfo(p1)->callbackmask, CBM_REFIT_CAPACITY)) { |
|
301 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
|
302 } |
|
303 |
|
304 if (callback == CALLBACK_FAILED) { |
|
305 /* Callback failed, or not executed; use the default cargo capacity */ |
|
306 v->cargo_cap = AircraftDefaultCargoCapacity(v->cargo_type, v->engine_type); |
|
307 } else { |
|
308 v->cargo_cap = callback; |
|
309 } |
|
310 |
|
311 /* Set the 'second compartent' capacity to none */ |
|
312 u->cargo_cap = 0; |
|
313 } |
258 |
314 |
259 e = GetEngine(p1); |
315 e = GetEngine(p1); |
260 v->reliability = e->reliability; |
316 v->reliability = e->reliability; |
261 v->reliability_spd_dec = e->reliability_spd_dec; |
317 v->reliability_spd_dec = e->reliability_spd_dec; |
262 v->max_age = e->lifelength * 366; |
318 v->max_age = e->lifelength * 366; |