494 } |
494 } |
495 |
495 |
496 return ret; |
496 return ret; |
497 } |
497 } |
498 |
498 |
499 /** Start/Stop an aircraft. |
|
500 * @param tile unused |
|
501 * @param flags for command type |
|
502 * @param p1 aircraft ID to start/stop |
|
503 * @param p2 unused |
|
504 * @return result of operation. Nothing if everything went well |
|
505 */ |
|
506 CommandCost CmdStartStopAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
|
507 { |
|
508 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
|
509 |
|
510 Vehicle *v = GetVehicle(p1); |
|
511 |
|
512 if (v->type != VEH_AIRCRAFT || !CheckOwnership(v->owner)) return CMD_ERROR; |
|
513 |
|
514 /* cannot stop airplane when in flight, or when taking off / landing */ |
|
515 if (v->u.air.state >= STARTTAKEOFF && v->u.air.state < TERM7) |
|
516 return_cmd_error(STR_A017_AIRCRAFT_IS_IN_FLIGHT); |
|
517 |
|
518 /* Check if this aircraft can be started/stopped. The callback will fail or |
|
519 * return 0xFF if it can. */ |
|
520 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
|
521 if (callback != CALLBACK_FAILED && GB(callback, 0, 8) != 0xFF) { |
|
522 StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
|
523 return_cmd_error(error); |
|
524 } |
|
525 |
|
526 if (flags & DC_EXEC) { |
|
527 if (v->IsStoppedInDepot()) { |
|
528 DeleteVehicleNews(p1, STR_A014_AIRCRAFT_IS_WAITING_IN); |
|
529 } |
|
530 |
|
531 v->vehstatus ^= VS_STOPPED; |
|
532 v->cur_speed = 0; |
|
533 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
|
534 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
|
535 InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
|
536 } |
|
537 |
|
538 return CommandCost(); |
|
539 } |
|
540 |
|
541 bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) |
499 bool Aircraft::FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse) |
542 { |
500 { |
543 const Station *st = GetStation(this->u.air.targetairport); |
501 const Station *st = GetStation(this->u.air.targetairport); |
544 /* If the station is not a valid airport or if it has no hangars */ |
502 /* If the station is not a valid airport or if it has no hangars */ |
545 if (!st->IsValid() || st->airport_tile == 0 || st->Airport()->nof_depots == 0) { |
503 if (!st->IsValid() || st->airport_tile == 0 || st->Airport()->nof_depots == 0) { |