From eed722c7775b36624d764473b47b5e5bfc51fe61 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 27 Sep 2015 19:04:12 +0100 Subject: [PATCH] Improved breakdowns: Remove non-deterministic changes to breakdown_chance. These cause desyncs in multiplayer. --- src/settings.cpp | 8 ++++++++ src/train_cmd.cpp | 9 +++++++-- src/vehicle.cpp | 4 ---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index e6754bb905..41a7491067 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1016,6 +1016,14 @@ static bool RoadVehAccelerationModelChanged(int32 p1) } } } + if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL || !_settings_game.vehicle.improved_breakdowns) { + RoadVehicle *rv; + FOR_ALL_ROADVEHICLES(rv) { + if (rv->IsFrontEngine()) { + rv->breakdown_chance = 128; + } + } + } /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */ SetWindowClassesDirty(WC_ENGINE_PREVIEW); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index eba7c342da..d8873654a4 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -484,8 +484,13 @@ void Train::UpdateAcceleration() assert(weight != 0); this->acceleration = Clamp(power / weight * 4, 1, 255); - /* for non-realistic acceleration, breakdown chance is 128, corrected by the multiengine factor of 3/(n+2) */ - this->breakdown_chance = min(128 * 3 / (this->tcache.cached_num_engines + 2), 5); + if (_settings_game.vehicle.improved_breakdowns) { + if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) { + this->breakdown_chance = max(128 * 3 / (this->tcache.cached_num_engines + 2), 5); + } + } else { + this->breakdown_chance = 128; + } } /** diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 6b442b278e..a23ab740eb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -116,16 +116,12 @@ void VehicleServiceInDepot(Vehicle *v) v->reliability = e->reliability; v->breakdown_ctr = 0; v->vehstatus &= ~VS_AIRCRAFT_BROKEN; - /* Prevent vehicles from breaking down directly after exiting the depot. */ - v->breakdown_chance /= 4; SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated do { v->date_of_last_service = _date; v->breakdowns_since_last_service = 0; v->reliability = v->GetEngine()->reliability; - /* Prevent vehicles from breaking down directly after exiting the depot. */ - v->breakdown_chance /= 4; v = v->Next(); } while (v != NULL && v->HasEngineType()); }