| 289 | } |
| 290 | |
| 291 | uint 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 | /** |
no test coverage detected