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

Function CrashAirplane

src/aircraft_cmd.cpp:1348–1378  ·  view source on GitHub ↗

* Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash. * @param v Aircraft that crashed. */

Source from the content-addressed store, hash-verified

1346 * @param v Aircraft that crashed.
1347 */
1348static void CrashAirplane(Aircraft *v)
1349{
1350 CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
1351
1352 uint victims = v->Crash();
1353
1354 v->cargo.Truncate();
1355 v->Next()->cargo.Truncate();
1356 const Station *st = GetTargetAirportIfValid(v);
1357 TileIndex vt = TileVirtXYClampedToMap(v->x_pos, v->y_pos);
1358
1359 EncodedString headline;
1360 if (st == nullptr) {
1361 headline = GetEncodedString(STR_NEWS_PLANE_CRASH_OUT_OF_FUEL, victims);
1362 } else {
1363 headline = GetEncodedString(STR_NEWS_AIRCRAFT_CRASH, victims, st->index);
1364 }
1365
1366 AI::NewEvent(v->owner, new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims, v->owner));
1367 Game::NewEvent(new ScriptEventVehicleCrashed(v->index, vt, st == nullptr ? ScriptEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT : ScriptEventVehicleCrashed::CRASH_PLANE_LANDING, victims, v->owner));
1368
1369 NewsType newstype = NewsType::Accident;
1370 if (v->owner != _local_company) {
1371 newstype = NewsType::AccidentOther;
1372 }
1373
1374 AddTileNewsItem(std::move(headline), newstype, vt, st != nullptr ? st->index : StationID::Invalid());
1375
1376 ModifyStationRatingAround(vt, v->owner, -160, 30);
1377 if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v);
1378}
1379
1380/**
1381 * Decide whether aircraft \a v should crash.

Callers 2

MaybeCrashAirplaneFunction · 0.85

Calls 11

CreateEffectVehicleRelFunction · 0.85
GetTargetAirportIfValidFunction · 0.85
TileVirtXYClampedToMapFunction · 0.85
AddTileNewsItemFunction · 0.85
InvalidFunction · 0.85
SndPlayVehicleFxFunction · 0.85
TruncateMethod · 0.80
GetEncodedStringFunction · 0.70
CrashMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected