diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 0dfee76c83..f2064f54b9 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2620,12 +2620,14 @@ CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id) */ bool HasStationInUse(StationID station, bool include_company, CompanyID company) { - for (const Vehicle *v : Vehicle::Iterate()) { - if ((v->owner == company) == include_company) { - for (const Order *order : v->Orders()) { - if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station) { - return true; - } + for (const OrderList *orderlist : OrderList::Iterate()) { + const Vehicle *v = orderlist->GetFirstSharedVehicle(); + assert(v != nullptr); + if ((v->owner == company) != include_company) continue; + + for (const Order *order = orderlist->GetFirstOrder(); order != nullptr; order = order->next) { + if (order->GetDestination() == station && (order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT))) { + return true; } } }