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.

(cherry picked from commit 6deee5e5e2)
This commit is contained in:
Peter Nelson 2024-09-12 06:47:54 +01:00 committed by Jonathan G Rennison
parent b5c64354fb
commit d91853bb6d

View File

@ -635,7 +635,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;
@ -648,7 +648,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<int>(VEHICLE_LENGTH) && max_speed > 88) {
max_speed = 88;
}
}
@ -665,6 +665,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));
}