From 6deee5e5e2117dcca683f134d22268c4a56da2a1 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 12 Sep 2024 06:47:54 +0100 Subject: [PATCH] Fix: Train curve detection did not take shortened parts into account. (#12910) Only the number of parts between curves was counted, which with shortened parts would be higher than full length parts and fail to limit as expected. --- src/train_cmd.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 326c7c81cd..c60c66d80d 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -320,7 +320,7 @@ uint16_t Train::GetCurveSpeedLimit() const int sum = 0; int pos = 0; int lastpos = -1; - for (const Vehicle *u = this; u->Next() != nullptr; u = u->Next(), pos++) { + for (const Train *u = this; u->Next() != nullptr; u = u->Next(), pos += u->gcache.cached_veh_length) { Direction this_dir = u->direction; Direction next_dir = u->Next()->direction; @@ -333,7 +333,7 @@ uint16_t Train::GetCurveSpeedLimit() const if (lastpos != -1) { numcurve++; sum += pos - lastpos; - if (pos - lastpos == 1 && max_speed > 88) { + if (pos - lastpos <= static_cast(VEHICLE_LENGTH) && max_speed > 88) { max_speed = 88; } } @@ -350,6 +350,7 @@ uint16_t Train::GetCurveSpeedLimit() const if (curvecount[0] == 1 && curvecount[1] == 1) { max_speed = absolute_max_speed; } else { + sum = CeilDiv(sum, VEHICLE_LENGTH); sum /= numcurve; max_speed = 232 - (13 - Clamp(sum, 1, 12)) * (13 - Clamp(sum, 1, 12)); }