From 557cc4d14fb26a838d32ea101620b17df5d32e27 Mon Sep 17 00:00:00 2001 From: Tyler Trahan Date: Tue, 16 Apr 2024 22:34:27 -0400 Subject: [PATCH] Fix: Smooth outliers in unbunching round trip calculations --- src/vehicle.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c8fefff234..ce038d1ab7 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1666,7 +1666,14 @@ void VehicleEnterDepot(Vehicle *v) /* If we've entered our unbunching depot, record the round trip duration. */ if (v->current_order.GetDepotActionType() & ODATFB_UNBUNCH && v->depot_unbunching_last_departure > 0) { - v->round_trip_time = (TimerGameTick::counter - v->depot_unbunching_last_departure); + TimerGameTick::Ticks measured_round_trip = TimerGameTick::counter - v->depot_unbunching_last_departure; + if (v->round_trip_time == 0) { + /* This might be our first round trip. */ + v->round_trip_time = measured_round_trip; + } else { + /* If we have a previous trip, smooth the effects of outlier trip calculations caused by jams or other interference. */ + v->round_trip_time = Clamp(measured_round_trip, (v->round_trip_time / 2), ClampTo(v->round_trip_time * 2)); + } } v->current_order.MakeDummy();