summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-28 14:18:56 +0000
committerrubidium <rubidium@openttd.org>2010-08-28 14:18:56 +0000
commitf1f1c71a415354b00c744573eec7e7b2ce3cf7a4 (patch)
tree8cb0d8779d8df62b0bd1754afb2e116e32333c32 /src/vehicle.cpp
parent2fb18e975c0d9bcd75e3536bf41192c5fedda8b6 (diff)
downloadopenttd-f1f1c71a415354b00c744573eec7e7b2ce3cf7a4.tar.xz
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp82
1 files changed, 43 insertions, 39 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 575f5a3a3..915e1f714 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -993,53 +993,57 @@ bool Vehicle::HandleBreakdown()
* 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;
+ switch (this->breakdown_ctr) {
+ case 0:
+ return false;
- if (this->breakdowns_since_last_service != 255) {
- this->breakdowns_since_last_service++;
- }
+ case 2:
+ this->breakdown_ctr = 1;
- this->MarkDirty();
- SetWindowDirty(WC_VEHICLE_VIEW, this->index);
- SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
+ if (this->breakdowns_since_last_service != 255) {
+ this->breakdowns_since_last_service++;
+ }
- if (this->type == VEH_AIRCRAFT) {
- /* Aircraft just need this flag, the rest is handled elsewhere */
- this->vehstatus |= VS_AIRCRAFT_BROKEN;
- } else {
- this->cur_speed = 0;
+ this->MarkDirty();
+ SetWindowDirty(WC_VEHICLE_VIEW, this->index);
+ SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
+
+ if (this->type == VEH_AIRCRAFT) {
+ /* Aircraft just need this flag, the rest is handled elsewhere */
+ this->vehstatus |= VS_AIRCRAFT_BROKEN;
+ } else {
+ this->cur_speed = 0;
+
+ if (!PlayVehicleSound(this, VSE_BREAKDOWN)) {
+ SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ?
+ (this->type == VEH_TRAIN ? SND_10_TRAIN_BREAKDOWN : SND_0F_VEHICLE_BREAKDOWN) :
+ (this->type == VEH_TRAIN ? SND_3A_COMEDY_BREAKDOWN_2 : SND_35_COMEDY_BREAKDOWN), this);
+ }
- if (!PlayVehicleSound(this, VSE_BREAKDOWN)) {
- SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ?
- (this->type == VEH_TRAIN ? SND_10_TRAIN_BREAKDOWN : SND_0F_VEHICLE_BREAKDOWN) :
- (this->type == VEH_TRAIN ? SND_3A_COMEDY_BREAKDOWN_2 : SND_35_COMEDY_BREAKDOWN), this);
+ if (!(this->vehstatus & VS_HIDDEN)) {
+ EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE);
+ if (u != NULL) u->animation_state = this->breakdown_delay * 2;
+ }
}
-
- if (!(this->vehstatus & VS_HIDDEN)) {
- EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE);
- if (u != NULL) u->animation_state = this->breakdown_delay * 2;
+ /* FALL THROUGH */
+ case 1:
+ /* Aircraft breakdowns end only when arriving at the airport */
+ 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) {
+ if (--this->breakdown_delay == 0) {
+ this->breakdown_ctr = 0;
+ this->MarkDirty();
+ SetWindowDirty(WC_VEHICLE_VIEW, this->index);
+ }
}
- }
- }
-
- /* Aircraft breakdowns end only when arriving at the airport */
- if (this->type == VEH_AIRCRAFT) return false;
+ return true;
- /* 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) {
- if (--this->breakdown_delay == 0) {
- this->breakdown_ctr = 0;
- this->MarkDirty();
- SetWindowDirty(WC_VEHICLE_VIEW, this->index);
- }
+ default:
+ if (!this->current_order.IsType(OT_LOADING)) this->breakdown_ctr--;
+ return false;
}
- return true;
}
void AgeVehicle(Vehicle *v)