diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 7048c0b818..e44903ea14 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -32,7 +32,9 @@ void CcBuildWagon(Commands, const CommandCost &result, VehicleID new_veh_id, uin /* find a locomotive in the depot. */ const Vehicle *found = nullptr; - for (const Train *t : Train::Iterate()) { + const VehicleList &vehicle_list = Company::Get(GetTileOwner(tile))->group_all[VEH_TRAIN].vehicle_list; + for (const Vehicle *v : vehicle_list) { + const Train *t = Train::From(v); if (t->IsFrontEngine() && t->tile == tile && t->IsStoppedInDepot()) { if (found != nullptr) return; // must be exactly one. found = t;