1
0
Fork 0

(svn r19463) -Codechange: add helper function to determine if an airport has at least one hangar

release/1.1
yexo 2010-03-19 09:48:44 +00:00
parent 81ca0e28c4
commit 414071d07f
4 changed files with 12 additions and 9 deletions

View File

@ -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; if (v->type != VEH_AIRCRAFT) return ::Depot::Get(order->GetDestination())->xy;
/* Aircraft's hangars are referenced by StationID, not DepotID */ /* Aircraft's hangars are referenced by StationID, not DepotID */
const Station *st = ::Station::Get(order->GetDestination()); 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); return st->GetHangarTile(0);
} }

View File

@ -117,8 +117,7 @@ static StationID FindNearestHangar(const Aircraft *v)
if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue; if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue;
const AirportFTAClass *afc = st->airport.GetFTA(); const AirportFTAClass *afc = st->airport.GetFTA();
const AirportSpec *as = st->airport.GetSpec(); if (!st->airport.HasHangar() || (
if (as->nof_depots == 0 || (
/* don't crash the plane if we know it can't land at the airport */ /* don't crash the plane if we know it can't land at the airport */
(afc->flags & AirportFTAClass::SHORT_STRIP) && (afc->flags & AirportFTAClass::SHORT_STRIP) &&
(avi->subtype & AIR_FAST) && (avi->subtype & AIR_FAST) &&
@ -415,7 +414,7 @@ bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination,
{ {
const Station *st = GetTargetAirportIfValid(this); const Station *st = GetTargetAirportIfValid(this);
/* If the station is not a valid airport or if it has no hangars */ /* 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 */ /* the aircraft has to search for a hangar on its own */
StationID station = FindNearestHangar(this); StationID station = FindNearestHangar(this);
@ -515,7 +514,7 @@ static void CheckIfAircraftNeedsService(Aircraft *v)
assert(st != NULL); assert(st != NULL);
/* only goto depot if the target airport has a depot */ /* 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); v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
} else if (v->current_order.IsType(OT_GOTO_DEPOT)) { } else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
@ -1468,7 +1467,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
return; return;
default: // orders have been deleted (no orders), goto depot and don't bother us default: // orders have been deleted (no orders), goto depot and don't bother us
v->current_order.Free(); 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) { 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 (v->current_order.IsType(OT_GOTO_STATION)) {
if (AirportFindFreeHelipad(v, apc)) return; if (AirportFindFreeHelipad(v, apc)) return;
} }
const AirportSpec *as = Station::Get(v->targetairport)->airport.GetSpec(); v->state = Station::Get(v->targetairport)->airport.HasHangar() ? HANGAR : HELITAKEOFF;
v->state = (as->nof_depots != 0) ? HANGAR : HELITAKEOFF;
} }
typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc); typedef void AircraftStateHandler(Aircraft *v, const AirportFTAClass *apc);

View File

@ -535,7 +535,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
ret.SetGlobalErrorMessage(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret; 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; return CMD_ERROR;
} }
} else { } else {

View File

@ -62,6 +62,11 @@ struct Airport : public TileArea {
{ {
return this->GetSpec()->fsm; return this->GetSpec()->fsm;
} }
FORCEINLINE bool HasHangar() const
{
return this->GetSpec()->nof_depots > 0;
}
}; };
typedef SmallVector<Industry *, 2> IndustryVector; typedef SmallVector<Industry *, 2> IndustryVector;