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

This reduces the search time as shared orders are only searched once and non-front vehicles are skipped.
pull/693/head
Peter Nelson 3 months ago committed by GitHub
parent 6c5a8f55df
commit ab94c8b511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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;
}
}
}

Loading…
Cancel
Save