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

Function HandleCrashedAircraft

src/aircraft_cmd.cpp:1188–1241  ·  view source on GitHub ↗

* Handle crashed aircraft \a v. * @param v Crashed aircraft. */

Source from the content-addressed store, hash-verified

1186 * @param v Crashed aircraft.
1187 */
1188static bool HandleCrashedAircraft(Aircraft *v)
1189{
1190 v->crashed_counter += 3;
1191
1192 Station *st = GetTargetAirportIfValid(v);
1193
1194 /* make aircraft crash down to the ground */
1195 if (v->crashed_counter < 500 && st == nullptr && ((v->crashed_counter % 3) == 0)) {
1196 int z = GetSlopePixelZ(Clamp(v->x_pos, 0, Map::MaxX() * TILE_SIZE), Clamp(v->y_pos, 0, Map::MaxY() * TILE_SIZE));
1197 v->z_pos -= 1;
1198 if (v->z_pos <= z) {
1199 v->crashed_counter = 500;
1200 v->z_pos = z + 1;
1201 } else {
1202 v->crashed_counter = 0;
1203 }
1204 SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
1205 }
1206
1207 if (v->crashed_counter < 650) {
1208 uint32_t r;
1209 if (Chance16R(1, 32, r)) {
1210 static const DirDiff delta[] = {
1211 DIRDIFF_45LEFT, DIRDIFF_SAME, DIRDIFF_SAME, DIRDIFF_45RIGHT
1212 };
1213
1214 v->direction = ChangeDir(v->direction, delta[GB(r, 16, 2)]);
1215 SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos);
1216 r = Random();
1217 CreateEffectVehicleRel(v,
1218 GB(r, 0, 4) - 4,
1219 GB(r, 4, 4) - 4,
1220 GB(r, 8, 4),
1221 EV_EXPLOSION_SMALL);
1222 }
1223 } else if (v->crashed_counter >= 10000) {
1224 /* remove rubble of crashed airplane */
1225
1226 /* clear runway-in on all airports, set by crashing plane
1227 * small airports use AIRPORT_BUSY, city airports use AirportBlock::RunwayInOut, etc.
1228 * but they all share the same number */
1229 if (st != nullptr) {
1230 st->airport.blocks.Reset(AirportBlock::RunwayIn);
1231 st->airport.blocks.Reset(AirportBlock::RunwayInOut); // commuter airport
1232 st->airport.blocks.Reset(AirportBlock::RunwayIn2); // intercontinental
1233 }
1234
1235 delete v;
1236
1237 return false;
1238 }
1239
1240 return true;
1241}
1242
1243
1244/**

Callers 1

AircraftEventHandlerFunction · 0.85

Calls 10

GetTargetAirportIfValidFunction · 0.85
GetSlopePixelZFunction · 0.85
ClampFunction · 0.85
SetAircraftPositionFunction · 0.85
Chance16RFunction · 0.85
ChangeDirFunction · 0.85
GBFunction · 0.85
CreateEffectVehicleRelFunction · 0.85
RandomFunction · 0.50
ResetMethod · 0.45

Tested by

no test coverage detected