Loading

Paste #pb2hvgyfg

  1. static void CheckIfAircraftNeedsService(Aircraft *v)
  2. {
  3.     if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return;
  4.     if (v->IsChainInDepot()) {
  5.         VehicleServiceInDepot(v);
  6.         return;
  7.     }
  8.  
  9.     /* When we're parsing conditional orders and the like
  10.      * we don't want to consider going to a depot too. */
  11.     if (!v->current_order.IsType(OT_GOTO_DEPOT) && !v->current_order.IsType(OT_GOTO_STATION)) return;
  12.  
  13.     const Station *st = Station::Get(v->current_order.GetDestination());
  14.  
  15.     assert(st != NULL);
  16.  
  17.     /* only goto depot if the target airport has a depot */
  18.     if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) {
  19.         v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);
  20.         SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
  21.     } else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
  22.         v->current_order.MakeDummy();
  23.         SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
  24.     } else {
  25.         bool hangar = false;
  26.         const Order *o;
  27.  
  28.         /* Is there at least an airport with a hangar in the orders? */
  29.         FOR_VEHICLE_ORDERS(v, o) {
  30.             if (o->IsType(OT_GOTO_STATION)) {
  31.                 const Station *ost = Station::Get(o->GetDestination());
  32.                 if (CanVehicleUseStation(v, ost) && ost->airport.HasHangar()) {
  33.                     hangar = true;
  34.                     break;
  35.                 }
  36.             }
  37.         }
  38.         if (!hangar) {
  39.             /* there's no airport with a hangar in the orders,
  40.              * so look for a nearby hangar  */
  41.             const StationID station = FindNearestHangar(v);
  42.  
  43.             TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
  44.             if (station != INVALID_STATION &&
  45.                     /* is hangar closer than destination? */
  46.                     DistanceManhattan(vtile, Station::Get(station)->airport.tile) <= DistanceManhattan(vtile, st->airport.tile)) {
  47.                 /* defer destination, service aircraft at that hangar now */
  48.                 v->current_order.MakeGoToDepot(station, ODTFB_SERVICE);
  49.                 v->dest_tile = v->GetOrderStationLocation(station);
  50.                 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
  51.             }
  52.         }
  53.     }
  54. }

Comments