diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index a48eec3ca0..7fe8497d3a 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -156,7 +156,8 @@ GroundVehicleAcceleration GroundVehicle::GetAcceleration() */ int64 resistance = 0; - bool maglev = v->GetAccelerationType() == 2; + int accleration_type = v->GetAccelerationType(); + bool maglev = (accleration_type == 2); const int area = v->GetAirDragArea(); if (!maglev) { @@ -250,7 +251,7 @@ GroundVehicleAcceleration GroundVehicle::GetAcceleration() /* Defensive driving: prevent ridiculously fast deceleration. * -130 corresponds to a braking distance of about 6.2 tiles from 160 km/h. */ - braking_accel = std::max(braking_accel, -130); + braking_accel = std::max(braking_accel, -(GetTrainRealisticBrakingTargetDecelerationLimit(accleration_type) + 10)); } else { braking_accel = ClampToI32(std::min(-braking_force - resistance, -10000) / mass); } diff --git a/src/train.h b/src/train.h index 082b14291d..3d09866e31 100644 --- a/src/train.h +++ b/src/train.h @@ -83,6 +83,11 @@ void DeleteVisibleTrain(Train *v); void CheckBreakdownFlags(Train *v); void GetTrainSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); +inline int GetTrainRealisticBrakingTargetDecelerationLimit(int acceleration_type) +{ + return 120 + (acceleration_type * 48); +} + /** Variables that are cached to improve performance and such */ struct TrainCache { /* Cached wagon override spritegroup */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 53ed256c04..59204d3be4 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1030,7 +1030,8 @@ void Train::UpdateAcceleration() break; case AM_REALISTIC: { - bool maglev = this->GetAccelerationType() == 2; + int accleration_type = this->GetAccelerationType(); + bool maglev = (accleration_type == 2); int64 power_w = power * 746ll; int64 min_braking_force = this->gcache.cached_total_length * 300; if (!maglev) { @@ -1072,7 +1073,7 @@ void Train::UpdateAcceleration() } min_braking_force -= (min_braking_force >> 3); // Slightly underestimate braking for defensive driving purposes this->tcache.cached_uncapped_decel = Clamp(min_braking_force / weight, 1, UINT16_MAX); - this->tcache.cached_deceleration = Clamp(this->tcache.cached_uncapped_decel, 1, 120); + this->tcache.cached_deceleration = Clamp(this->tcache.cached_uncapped_decel, 1, GetTrainRealisticBrakingTargetDecelerationLimit(accleration_type)); break; } }