From f786477c6d4a909b6e7bc975d51a915b613e621f Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Mon, 1 Jan 2024 18:10:22 +0000 Subject: [PATCH] Codechange: Iterate group vehicle lists for SettingsDisableElrail --- src/elrail.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/elrail.cpp b/src/elrail.cpp index 72021cb9ed..c39ca6a5f6 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -625,10 +625,13 @@ void SettingsDisableElrail(int32_t new_value) } } - /* Fix the total power and acceleration for trains */ - for (Train *t : Train::Iterate()) { - /* power and acceleration is cached only for front engines */ - if (t->IsFrontEngine()) { + for (const Company *c : Company::Iterate()) { + /* Fix the total power and acceleration for trains. + * These values are only cached for front engines which + * is what the collection enumerates. */ + const VehicleList &vehicle_list = c->group_all[VEH_TRAIN].vehicle_list; + for (const Vehicle *v : vehicle_list) { + Train *t = Train::From(Vehicle::Get(v->index)); t->ConsistChanged(CCF_TRACK); } }