diff options
author | yexo <yexo@openttd.org> | 2010-03-19 09:48:44 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2010-03-19 09:48:44 +0000 |
commit | 414071d07f787042364fec573030720ba664154e (patch) | |
tree | 57593a3df5182caf905c03c7f99b0ac8802048ce | |
parent | 81ca0e28c4504bbc7828df50b2086bbdb8776dd1 (diff) | |
download | openttd-414071d07f787042364fec573030720ba664154e.tar.xz |
(svn r19463) -Codechange: add helper function to determine if an airport has at least one hangar
-rw-r--r-- | src/ai/api/ai_order.cpp | 2 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 12 | ||||
-rw-r--r-- | src/order_cmd.cpp | 2 | ||||
-rw-r--r-- | src/station_base.h | 5 |
4 files changed, 12 insertions, 9 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index 6290525d5..500841415 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -181,7 +181,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination())->xy; /* Aircraft's hangars are referenced by StationID, not DepotID */ const Station *st = ::Station::Get(order->GetDestination()); - if (st->airport.GetSpec()->nof_depots == 0) return INVALID_TILE; + if (!st->airport.HasHangar()) return INVALID_TILE; return st->GetHangarTile(0); } diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index df7690a2c..3ff480c55 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -117,8 +117,7 @@ static StationID FindNearestHangar(const Aircraft *v) if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue; const AirportFTAClass *afc = st->airport.GetFTA(); - const AirportSpec *as = st->airport.GetSpec(); - if (as->nof_depots == 0 || ( + if (!st->airport.HasHangar() || ( /* don't crash the plane if we know it can't land at the airport */ (afc->flags & AirportFTAClass::SHORT_STRIP) && (avi->subtype & AIR_FAST) && @@ -415,7 +414,7 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, { const Station *st = GetTargetAirportIfValid(this); /* If the station is not a valid airport or if it has no hangars */ - if (st == NULL || st->airport.GetSpec()->nof_depots == 0) { + if (st == NULL || !st->airport.HasHangar()) { /* the aircraft has to search for a hangar on its own */ StationID station = FindNearestHangar(this); @@ -515,7 +514,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v) assert(st != NULL); /* only goto depot if the target airport has a depot */ - if (st->airport.GetSpec()->nof_depots > 0 && CanVehicleUseStation(v, st)) { + if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) { v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } else if (v->current_order.IsType(OT_GOTO_DEPOT)) { @@ -1468,7 +1467,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass * return; default: // orders have been deleted (no orders), goto depot and don't bother us v->current_order.Free(); - go_to_hangar = Station::Get(v->targetairport)->airport.GetSpec()->nof_depots != 0; + go_to_hangar = Station::Get(v->targetairport)->airport.HasHangar(); } if (go_to_hangar) { @@ -1609,8 +1608,7 @@ static void AircraftEventHandler_HeliEndLanding(Aircraft *v, const AirportFTACla if (v->current_order.IsType(OT_GOTO_STATION)) { if (AirportFindFreeHelipad(v, apc)) return; } - const AirportSpec *as = Station::Get(v->targetairport)->airport.GetSpec(); - v->state = (as->nof_depots != 0) ? HANGAR : HELITAKEOFF; + v->state = Station::Get(v->targetairport)->airport.HasHangar() ? HANGAR : HELITAKEOFF; } typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 953a9d980..4d7487185 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -535,7 +535,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 ret.SetGlobalErrorMessage(); if (ret.Failed()) return ret; - if (!CanVehicleUseStation(v, st) || st->airport.GetSpec()->nof_depots == 0) { + if (!CanVehicleUseStation(v, st) || !st->airport.HasHangar()) { return CMD_ERROR; } } else { diff --git a/src/station_base.h b/src/station_base.h index adb58cc89..f15a5dabd 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -62,6 +62,11 @@ struct Airport : public TileArea { { return this->GetSpec()->fsm; } + + FORCEINLINE bool HasHangar() const + { + return this->GetSpec()->nof_depots > 0; + } }; typedef SmallVector<Industry *, 2> IndustryVector; |