diff options
author | rubidium <rubidium@openttd.org> | 2009-12-04 20:29:46 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-12-04 20:29:46 +0000 |
commit | 19fa38601d8df49c309052e8bccb8c2e4302b51e (patch) | |
tree | 52d8dac77300440aef8f3b55a6caad487d242816 /src/vehicle.cpp | |
parent | c22f9679b5c9e5a637ccc006d0b69680b8894ea3 (diff) | |
download | openttd-19fa38601d8df49c309052e8bccb8c2e4302b51e.tar.xz |
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r-- | src/vehicle.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp index ab4af88bb..1a94c9f82 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -112,6 +112,29 @@ bool Vehicle::NeedsAutomaticServicing() const return NeedsServicing(); } +uint Vehicle::Crash(bool flooded) +{ + assert((this->vehstatus & VS_CRASHED) == 0); + assert(this->Previous() == NULL); // IsPrimaryVehicle fails for free-wagon-chains + + uint pass = 0; + /* crash all wagons, and count passengers */ + for (Vehicle *v = this; v != NULL; v = v->Next()) { + if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count(); + v->vehstatus |= VS_CRASHED; + MarkSingleVehicleDirty(v); + } + + /* Dirty some windows */ + InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); + SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); + SetWindowDirty(WC_VEHICLE_DETAILS, this->index); + SetWindowDirty(WC_VEHICLE_DEPOT, this->tile); + + return pass; +} + + /** * Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking. * @param engine The engine that caused the problem |