diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -10,6 +10,7 @@ #include "stdafx.h" #include "train.h" #include "vehiclelist.h" +#include "vehiclelist_func.h" #include "group.h" #include "safeguards.h" @@ -116,17 +117,11 @@ bool GenerateVehicleSortList(VehicleList switch (vli.type) { case VL_STATION_LIST: - for (const Vehicle *v : Vehicle::Iterate()) { - if (v->type == vli.vtype && v->IsPrimaryVehicle()) { - for (const Order *order : v->Orders()) { - if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) - && order->GetDestination() == vli.index) { - list->push_back(v); - break; - } - } - } - } + FindVehiclesWithOrder( + [&vli](const Vehicle *v) { return v->type == vli.vtype; }, + [&vli](const Order *order) { return (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT) || order->IsType(OT_IMPLICIT)) && order->GetDestination() == vli.index; }, + [&list](const Vehicle *v) { list->push_back(v); } + ); break; case VL_SHARED_ORDERS: { @@ -161,16 +156,11 @@ bool GenerateVehicleSortList(VehicleList break; case VL_DEPOT_LIST: - for (const Vehicle *v : Vehicle::Iterate()) { - if (v->type == vli.vtype && v->IsPrimaryVehicle()) { - for (const Order *order : v->Orders()) { - if (order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index) { - list->push_back(v); - break; - } - } - } - } + FindVehiclesWithOrder( + [&vli](const Vehicle *v) { return v->type == vli.vtype; }, + [&vli](const Order *order) { return order->IsType(OT_GOTO_DEPOT) && !(order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && order->GetDestination() == vli.index; }, + [&list](const Vehicle *v) { list->push_back(v); } + ); break; default: return false;