MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MaybeCrashAirplane

Function MaybeCrashAirplane

src/aircraft_cmd.cpp:1384–1408  ·  view source on GitHub ↗

* Decide whether aircraft \a v should crash. * @param v Aircraft to test. */

Source from the content-addressed store, hash-verified

1382 * @param v Aircraft to test.
1383 */
1384static void MaybeCrashAirplane(Aircraft *v)
1385{
1386
1387 Station *st = Station::Get(v->targetairport);
1388
1389 uint32_t prob;
1390 if (st->airport.GetFTA()->flags.Test(AirportFTAClass::Flag::ShortStrip) &&
1391 (AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
1392 !_cheats.no_jetcrash.value) {
1393 prob = 3276;
1394 } else {
1395 if (_settings_game.vehicle.plane_crashes == 0) return;
1396 prob = (0x4000 << _settings_game.vehicle.plane_crashes) / 1500;
1397 }
1398
1399 if (GB(Random(), 0, 22) > prob) return;
1400
1401 /* Crash the airplane. Remove all goods stored at the station. */
1402 for (GoodsEntry &ge : st->goods) {
1403 ge.rating = 1;
1404 if (ge.HasData()) ge.GetData().cargo.Truncate();
1405 }
1406
1407 CrashAirplane(v);
1408}
1409
1410/**
1411 * Aircraft arrives at a terminal. If it is the first aircraft, throw a party.

Callers 1

AircraftControllerFunction · 0.85

Calls 8

AircraftVehInfoFunction · 0.85
GBFunction · 0.85
CrashAirplaneFunction · 0.85
TestMethod · 0.80
GetFTAMethod · 0.80
TruncateMethod · 0.80
RandomFunction · 0.50
HasDataMethod · 0.45

Tested by

no test coverage detected