Use vehicle order destination map for HasStationInUse()

This commit is contained in:
Jonathan G Rennison
2019-05-12 04:24:36 +01:00
parent 8196789eeb
commit 512bb5ca4d

View File

@@ -2638,19 +2638,18 @@ CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1,
*/ */
bool HasStationInUse(StationID station, bool include_company, CompanyID company) bool HasStationInUse(StationID station, bool include_company, CompanyID company)
{ {
const Vehicle *v; bool found = false;
FOR_ALL_VEHICLES(v) { IterateOrderRefcountMapForDestinationID(station, [&](CompanyID cid, OrderType order_type, VehicleType veh_type, uint32 refcount) {
if ((v->owner == company) == include_company) { if ((cid == company) == include_company) {
const Order *order; if (order_type == OT_GOTO_STATION || order_type == OT_GOTO_WAYPOINT) {
FOR_VEHICLE_ORDERS(v, order) { found = true;
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station) {
return true;
}
}
}
}
return false; return false;
} }
}
return true;
});
return found;
}
static const TileIndexDiffC _dock_tileoffs_chkaround[] = { static const TileIndexDiffC _dock_tileoffs_chkaround[] = {
{-1, 0}, {-1, 0},