diff -r bb9639bf29af src/aircraft_cmd.cpp
--- a/src/aircraft_cmd.cpp Thu Jan 25 23:18:41 2018 +0000
+++ b/src/aircraft_cmd.cpp Thu Jan 25 23:39:33 2018 +0000
@@ -1513,6 +1513,14 @@
/* airport-road is free. We either have to go to another airport, or to the hangar
* ---> start moving */
+ if (Station::Get(v->targetairport)->airport.HasHangar()) {
+ if (v->NeedsAutomaticServicing() || v->subtype == AIR_HELICOPTER && v->HasPendingReplace() && _settings_game.order.serviceathelipad &&
+ (!v->HasDepotOrder() || !(v->current_order.IsType(OT_GOTO_DEPOT) && v->current_order.GetDepotOrderType() != ODTFB_SERVICE))) {
+ v->current_order.MakeGoToDepot(v->targetairport, ODTFB_SERVICE);
+ SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
+ }
+ }
+
bool go_to_hangar = false;
switch (v->current_order.GetType()) {
case OT_GOTO_STATION: // ready to fly to another airport
@@ -1571,11 +1579,17 @@
/* get the next position to go to, differs per airport */
AircraftNextAirportPos_and_Order(v);
- /* Send the helicopter to a hangar if needed for replacement */
- if (v->NeedsAutomaticServicing()) {
- Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
- DoCommand(v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
- cur_company.Restore();
+ /* Send the helicopter to a hangar if needed for replacement when NeedsAutomaticServicing fails */
+ if (!v->NeedsAutomaticServicing() && v->HasPendingReplace() && _settings_game.order.serviceathelipad) {
+ Order *o = &v->current_order;
+ if (!v->HasDepotOrder() || !(o->IsType(OT_GOTO_DEPOT) && o->GetDepotOrderType() != ODTFB_SERVICE)) {
+ DestinationID destination;
+ if (v->FindClosestDepot(NULL, &destination, NULL)) {
+ o->MakeGoToDepot(destination, ODTFB_SERVICE);
+ AircraftNextAirportPos_and_Order(v);
+ SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
+ }
+ }
}
}
@@ -1620,13 +1634,6 @@
{
v->state = ENDLANDING;
AircraftLandAirplane(v); // maybe crash airplane
-
- /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
- if (v->NeedsAutomaticServicing()) {
- Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE);
- DoCommand(v->tile, v->index | DEPOT_SERVICE, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT);
- cur_company.Restore();
- }
}
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)