From 47d72737db158b5ef459485ef95cd4d1a10736d5 Mon Sep 17 00:00:00 2001 From: Mateusz Marszalek Date: Sun, 10 Sep 2023 13:51:03 +0200 Subject: [PATCH] Fix #11161: Apply cargo filter to shared groups --- src/vehicle_gui.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 9810c9c17f..4eab4746d7 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -204,22 +204,33 @@ void BaseVehicleListWindow::BuildVehicleList() } else { /* Sort by the primary vehicle; we just want all vehicles that share the same orders to form a contiguous range. */ std::stable_sort(this->vehicles.begin(), this->vehicles.end(), [](const Vehicle * const &u, const Vehicle * const &v) { + if (u->FirstShared() == v->FirstShared()) { + return u->cargo_type < v->cargo_type; + } return u->FirstShared() < v->FirstShared(); }); + for (auto it = this->vehicles.begin(); it != this->vehicles.end(); ++it) { + this->vehgroups.emplace_back(it, it + 1); + } + + this->FilterVehicleList(); + uint max_num_vehicles = 0; - VehicleList::const_iterator begin = this->vehicles.begin(); - while (begin != this->vehicles.end()) { - VehicleList::const_iterator end = std::find_if_not(begin, this->vehicles.cend(), [first_shared = (*begin)->FirstShared()](const Vehicle * const &v) { - return v->FirstShared() == first_shared; - }); - - this->vehgroups.emplace_back(begin, end); + GUIVehicleGroupList::iterator begin = this->vehgroups.begin(); + GUIVehicleGroupList::iterator end = begin; + std::advance(end, 1); + while (begin != this->vehgroups.end()) { + while (end != this->vehgroups.end() && begin->vehicles_begin[0]->FirstShared() == end->vehicles_begin[0]->FirstShared()) { + begin->vehicles_end = end->vehicles_end; + end = this->vehgroups.erase(end); + } max_num_vehicles = std::max(max_num_vehicles, static_cast(end - begin)); begin = end; + std::advance(end, 1); } this->unitnumber_digits = CountDigitsForAllocatingSpace(max_num_vehicles);