From d484c32d44045732454fdc7cb2926a80ea84dc45 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 11 Apr 2021 22:53:02 +0100 Subject: [PATCH] Reduce sensitivity of train overheated breakdown --- src/settings.cpp | 3 +++ src/table/newgrf_debug_data.h | 7 +++++++ src/train.h | 2 +- src/train_cmd.cpp | 9 ++++++++- src/vehicle.cpp | 3 +++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 0fc6beef43..3a43605945 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1084,6 +1084,9 @@ static bool TrainAccelerationModelChanged(int32 p1) static bool TrainBrakingModelChanged(int32 p1) { for (Train *t : Train::Iterate()) { + if (!(t->vehstatus & VS_CRASHED)) { + t->crash_anim_pos = 0; + } if (t->IsFrontEngine()) { t->UpdateAcceleration(); } diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 0ea83db588..831f324e68 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -163,6 +163,13 @@ class NIHVehicle : public NIHelper { seprintf(buffer, lastof(buffer), " Railtype: %u, compatible_railtypes: 0x" OTTD_PRINTFHEX64, t->railtype, t->compatible_railtypes); print(buffer); + if (t->vehstatus & VS_CRASHED) { + seprintf(buffer, lastof(buffer), " CRASHED: anim pos: %u", t->crash_anim_pos); + print(buffer); + } else if (t->crash_anim_pos > 0) { + seprintf(buffer, lastof(buffer), " Brake heating: %u", t->crash_anim_pos); + print(buffer); + } if (t->lookahead != nullptr) { print (" Look ahead:"); const TrainReservationLookAhead &l = *t->lookahead; diff --git a/src/train.h b/src/train.h index 5eeed76d58..f18c73a250 100644 --- a/src/train.h +++ b/src/train.h @@ -120,7 +120,7 @@ struct Train FINAL : public GroundVehicle { uint32 flags; - uint16 crash_anim_pos; ///< Crash animation counter. + uint16 crash_anim_pos; ///< Crash animation counter, also used for realistic braking train brake overheating TrackBits track; TrainForceProceeding force_proceed; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 187661190b..275687d3d2 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -5959,6 +5959,9 @@ static bool TrainLocoHandler(Train *v, bool mode) /* train has crashed? */ if (v->vehstatus & VS_CRASHED) { return mode ? true : HandleCrashedTrain(v); // 'this' can be deleted here + } else if (v->crash_anim_pos > 0) { + /* Reduce realistic braking brake overheating */ + v->crash_anim_pos--; } if (v->force_proceed != TFP_NONE) { @@ -6794,7 +6797,11 @@ void TrainRoadVehicleCrashBreakdown(Vehicle *v) void TrainBrakesOverheatedBreakdown(Vehicle *v) { Train *t = Train::From(v)->First(); - if (t->breakdown_ctr != 0) return; + if (t->breakdown_ctr != 0 || (t->vehstatus & VS_CRASHED)) return; + + t->crash_anim_pos = std::min(1500, t->crash_anim_pos + 200); + if (t->crash_anim_pos < 1500) return; + t->breakdown_ctr = 2; SetBit(t->flags, VRF_CONSIST_BREAKDOWN); t->breakdown_delay = 255; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2ebccf8c00..736ac3b26f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2334,6 +2334,9 @@ void VehicleEnterDepot(Vehicle *v) t->ConsistChanged(CCF_ARRANGE); t->reverse_distance = 0; t->lookahead.reset(); + if (!(t->vehstatus & VS_CRASHED)) { + t->crash_anim_pos = 0; + } break; }