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

Method Crash

src/vehicle.cpp:291–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289}
290
291uint Vehicle::Crash(bool)
292{
293 assert(!this->vehstatus.Test(VehState::Crashed));
294 assert(this->Previous() == nullptr); // IsPrimaryVehicle fails for free-wagon-chains
295
296 uint pass = 0;
297 /* Stop the vehicle. */
298 if (this->IsPrimaryVehicle()) this->vehstatus.Set(VehState::Stopped);
299 /* crash all wagons, and count passengers */
300 for (Vehicle *v = this; v != nullptr; v = v->Next()) {
301 /* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */
302 if (IsCargoInClass(v->cargo_type, CargoClass::Passengers)) pass += v->cargo.TotalCount();
303 v->vehstatus.Set(VehState::Crashed);
304 v->MarkAllViewportsDirty();
305 }
306
307 /* Dirty some windows */
308 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0);
309 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP);
310 SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
311 SetWindowDirty(WC_VEHICLE_DEPOT, this->tile);
312
313 delete this->cargo_payment;
314 assert(this->cargo_payment == nullptr); // cleared by ~CargoPayment
315
316 return RandomRange(pass + 1); // Randomise deceased passengers.
317}
318
319
320/**

Callers 2

FloodVehicleFunction · 0.45
DisasterTick_UfoFunction · 0.45

Calls 13

PreviousMethod · 0.95
IsPrimaryVehicleMethod · 0.95
IsCargoInClassFunction · 0.85
SetWindowWidgetDirtyFunction · 0.85
SetWindowDirtyFunction · 0.85
RandomRangeFunction · 0.85
TestMethod · 0.80
MarkAllViewportsDirtyMethod · 0.80
SetMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected