mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
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.
This commit is contained in:
parent
6c5a8f55df
commit
ab94c8b511
@ -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…
Reference in New Issue
Block a user