1
0
Fork 0

Codechange: Iterate order lists instead of vehicles to find if any vehicle visits a station.

This reduces the search time as shared orders are only searched once and non-front vehicles are skipped.
pull/12315/head
Peter Nelson 2024-03-15 19:12:35 +00:00
parent d7c5e9e8ab
commit 9ae52ad8f3
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
1 changed files with 8 additions and 6 deletions

View File

@ -2620,12 +2620,14 @@ CommandCost CmdOpenCloseAirport(DoCommandFlag flags, StationID station_id)
*/ */
bool HasStationInUse(StationID station, bool include_company, CompanyID company) bool HasStationInUse(StationID station, bool include_company, CompanyID company)
{ {
for (const Vehicle *v : Vehicle::Iterate()) { for (const OrderList *orderlist : OrderList::Iterate()) {
if ((v->owner == company) == include_company) { const Vehicle *v = orderlist->GetFirstSharedVehicle();
for (const Order *order : v->Orders()) { assert(v != nullptr);
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station) { if ((v->owner == company) != include_company) continue;
return true;
} 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;
} }
} }
} }