summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-28 14:14:37 +0000
committerrubidium <rubidium@openttd.org>2010-08-28 14:14:37 +0000
commit2fb18e975c0d9bcd75e3536bf41192c5fedda8b6 (patch)
tree1679e9e6786d2599682c0bcc697071426b5d7e22
parent702cc96943a5ffb52fd59718075667044a86775e (diff)
downloadopenttd-2fb18e975c0d9bcd75e3536bf41192c5fedda8b6.tar.xz
(svn r20645) -Codechange [FS#4086]: unify the code for checking for breakdown handling as well (Hirundo)
-rw-r--r--src/aircraft_cmd.cpp9
-rw-r--r--src/roadveh_cmd.cpp9
-rw-r--r--src/ship_cmd.cpp8
-rw-r--r--src/train_cmd.cpp8
-rw-r--r--src/vehicle.cpp10
-rw-r--r--src/vehicle_base.h7
6 files changed, 17 insertions, 34 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 3b7b9044a..1a7710f53 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1775,14 +1775,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
if (v->vehstatus & VS_STOPPED) return true;
- /* aircraft is broken down? */
- if (v->breakdown_ctr != 0) {
- if (v->breakdown_ctr <= 2) {
- v->HandleBreakdown();
- } else {
- if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
- }
- }
+ v->HandleBreakdown();
HandleAircraftSmoke(v);
ProcessOrders(v);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 2e9626ae8..d2529185f 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1485,14 +1485,7 @@ static bool RoadVehController(RoadVehicle *v)
}
/* road vehicle has broken down? */
- if (v->breakdown_ctr != 0) {
- if (v->breakdown_ctr <= 2) {
- v->HandleBreakdown();
- return true;
- }
- if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
- }
-
+ if (v->HandleBreakdown()) return true;
if (v->vehstatus & VS_STOPPED) return true;
ProcessOrders(v);
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index a58fe7b29..ef2b49fcc 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -424,13 +424,7 @@ static void ShipController(Ship *v)
v->tick_counter++;
v->current_order_time++;
- if (v->breakdown_ctr != 0) {
- if (v->breakdown_ctr <= 2) {
- v->HandleBreakdown();
- return;
- }
- if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
- }
+ if (v->HandleBreakdown()) return;
if (v->vehstatus & VS_STOPPED) return;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 3fab4a3bc..28b1d997f 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3716,13 +3716,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
}
/* train is broken down? */
- if (v->breakdown_ctr != 0) {
- if (v->breakdown_ctr <= 2) {
- v->HandleBreakdown();
- return true;
- }
- if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
- }
+ if (v->HandleBreakdown()) return true;
if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
ReverseTrainDirection(v);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 864b971cc..575f5a3a3 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -986,13 +986,18 @@ void CheckVehicleBreakdown(Vehicle *v)
}
}
-void Vehicle::HandleBreakdown()
+bool Vehicle::HandleBreakdown()
{
/* Possible states for Vehicle::breakdown_ctr
* 0 - vehicle is running normally
* 1 - vehicle is currently broken down
* 2 - vehicle is going to break down now
* >2 - vehicle is counting down to the actual breakdown event */
+ if (this->breakdown_ctr == 0) return false;
+ if (this->breakdown_ctr > 2) {
+ if (!this->current_order.IsType(OT_LOADING)) this->breakdown_ctr--;
+ return false;
+ }
if (this->breakdown_ctr != 1) {
this->breakdown_ctr = 1;
@@ -1024,7 +1029,7 @@ void Vehicle::HandleBreakdown()
}
/* Aircraft breakdowns end only when arriving at the airport */
- if (this->type == VEH_AIRCRAFT) return;
+ if (this->type == VEH_AIRCRAFT) return false;
/* For trains this function is called twice per tick, so decrease v->breakdown_delay at half the rate */
if ((this->tick_counter & (this->type == VEH_TRAIN ? 3 : 1)) == 0) {
@@ -1034,6 +1039,7 @@ void Vehicle::HandleBreakdown()
SetWindowDirty(WC_VEHICLE_VIEW, this->index);
}
}
+ return true;
}
void AgeVehicle(Vehicle *v)
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index e6fe20e17..b2b38791d 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -523,11 +523,14 @@ public:
this->service_interval = src->service_interval;
}
+
/**
- * Handle all of the aspects of a vehicle breakdown.
+ * Handle all of the aspects of a vehicle breakdown
* This includes adding smoke and sounds, and ending the breakdown when appropriate.
+ * @return true iff the vehicle is stopped because of a breakdown
+ * @note This function always returns false for aircraft, since these never stop for breakdowns
*/
- void HandleBreakdown();
+ bool HandleBreakdown();
bool NeedsAutorenewing(const Company *c) const;