* Bring the aircraft in a crashed state, create the explosion animation, and create a news item about the crash. * @param v Aircraft that crashed. */
| 1346 | * @param v Aircraft that crashed. |
| 1347 | */ |
| 1348 | static 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. |
no test coverage detected