summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-12-04 20:29:46 +0000
committerrubidium <rubidium@openttd.org>2009-12-04 20:29:46 +0000
commit19fa38601d8df49c309052e8bccb8c2e4302b51e (patch)
tree52d8dac77300440aef8f3b55a6caad487d242816 /src/roadveh_cmd.cpp
parentc22f9679b5c9e5a637ccc006d0b69680b8894ea3 (diff)
downloadopenttd-19fa38601d8df49c309052e8bccb8c2e4302b51e.tar.xz
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index ab9982b87..d6c44da4a 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -537,21 +537,17 @@ static Vehicle *EnumCheckRoadVehCrashTrain(Vehicle *v, void *data)
v : NULL;
}
-static void RoadVehCrash(RoadVehicle *v)
+uint RoadVehicle::Crash(bool flooded)
{
- uint16 pass = 1;
-
- v->crashed_ctr++;
-
- for (Vehicle *u = v; u != NULL; u = u->Next()) {
- if (IsCargoInClass(u->cargo_type, CC_PASSENGERS)) pass += u->cargo.Count();
-
- u->vehstatus |= VS_CRASHED;
-
- MarkSingleVehicleDirty(u);
- }
+ uint pass = Vehicle::Crash(flooded);
+ if (this->IsRoadVehFront()) pass += 1; // driver
+ this->crashed_ctr = flooded ? 2000 : 1; // max 2220, disappear pretty fast when flooded
+ return pass;
+}
- SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
+static void RoadVehCrash(RoadVehicle *v)
+{
+ uint pass = v->Crash();
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, AIEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING));