static void CheckIfAircraftNeedsService(Aircraft *v) { if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return; if (v->IsChainInDepot()) { VehicleServiceInDepot(v); return; } /* When we're parsing conditional orders and the like * we don't want to consider going to a depot too. */ if (!v->current_order.IsType(OT_GOTO_DEPOT) && !v->current_order.IsType(OT_GOTO_STATION)) return; const Station *st = Station::Get(v->current_order.GetDestination()); assert(st != NULL); /* only goto depot if the target airport has a depot */ if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) { v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); } else if (v->current_order.IsType(OT_GOTO_DEPOT)) { v->current_order.MakeDummy(); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); } else { bool hangar = false; const Order *o; /* Is there at least an airport with a hangar in the orders? */ FOR_VEHICLE_ORDERS(v, o) { if (o->IsType(OT_GOTO_STATION)) { const Station *ost = Station::Get(o->GetDestination()); if (CanVehicleUseStation(v, ost) && ost->airport.HasHangar()) { hangar = true; break; } } } if (!hangar) { /* there's no airport with a hangar in the orders, * so look for a nearby hangar */ const StationID station = FindNearestHangar(v); TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos); if (station != INVALID_STATION && /* is hangar closer than destination? */ DistanceManhattan(vtile, Station::Get(station)->airport.tile) <= DistanceManhattan(vtile, st->airport.tile)) { /* defer destination, service aircraft at that hangar now */ v->current_order.MakeGoToDepot(station, ODTFB_SERVICE); v->dest_tile = v->GetOrderStationLocation(station); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP); } } } }