Loading

Revision differences

Old revision #pb2hvgyfgNew revision #plmhkfy3k
15    assert(st != NULL);  15    assert(st != NULL);  
16  16  
17    /* only goto depot if the target airport has a depot */  17    /* only goto depot if the target airport has a depot */  
18    if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) {  18    if (st->airport.HasHangar() && (CanVehicleUseStation(v, st) || !(v->state >= TAKEOFF && v->state <= FLYING))) {
19        v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);  19        v->current_order.MakeGoToDepot(st->index, ODTFB_SERVICE);  
20        SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  20        SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  
21    } else if (v->current_order.IsType(OT_GOTO_DEPOT)) {  21    } else if (v->current_order.IsType(OT_GOTO_DEPOT)) {  
22        v->current_order.MakeDummy();  22        v->current_order.MakeDummy();  
23        SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  23        SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  
24    } else {  24    } else {  
25        bool hangar = false;  25        bool hangar_in_o = false;
26        const Order *o;  26        const Order *o;  
27  27  
28        /* Is there at least an airport with a hangar in the orders? */  28        /* Is there at least an airport with a hangar in the orders? */  
  
30            if (o->IsType(OT_GOTO_STATION)) {  30            if (o->IsType(OT_GOTO_STATION)) {  
31                const Station *ost = Station::Get(o->GetDestination());  31                const Station *ost = Station::Get(o->GetDestination());  
32                if (CanVehicleUseStation(v, ost) && ost->airport.HasHangar()) {  32                if (CanVehicleUseStation(v, ost) && ost->airport.HasHangar()) {  
33                    hangar = true;  33                    hangar_in_o = true;
34                    break;  34                    break;  
35                }  35                }  
36            }  36            }  
37        }  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  38  
  39        if (!hangar_in_o || !CanVehicleUseStation(v, st) && v->state >= TAKEOFF && v->state <= FLYING) {  
  40            /* there's no airport with a hangar in the orders, or the aircraft  
  41             * can't use the airport, so look for a nearby hangar */  
  42            const StationID nearest_hangar = FindNearestHangar(v);  
  43  
  44            /* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */  
43            TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);  45            TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);  
44            if (station != INVALID_STATION &&  46
45                    /* is hangar closer than destination? */  47            if (nearest_hangar != INVALID_STATION && (!CanVehicleUseStation(v, st) && v->state >= TAKEOFF && v->state <= FLYING || !st->airport.HasHangar() &&
46                    DistanceManhattan(vtile, Station::Get(station)->airport.tile) <= DistanceManhattan(vtile, st->airport.tile)) {  48                    /* is nearest hangar closer than destination? */
   49                    DistanceSquare(vtile, Station::Get(nearest_hangar)->airport.tile) <= DistanceSquare(vtile, st->airport.tile))) {
47                /* defer destination, service aircraft at that hangar now */  50                /* defer destination, service aircraft at that hangar now */  
48                v->current_order.MakeGoToDepot(station, ODTFB_SERVICE);  48                v->current_order.MakeGoToDepot(nearest_hangar, ODTFB_SERVICE);
49                v->dest_tile = v->GetOrderStationLocation(station);  49                v->dest_tile = v->GetOrderStationLocation(nearest_hangar);
50                SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  53                SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);  
51            }  54            }  
52        }  55        }