Skip to content

Commit

Permalink
unfinished
Browse files Browse the repository at this point in the history
  • Loading branch information
J0anJosep committed Feb 19, 2024
1 parent 83396ff commit ef84da1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/aircraft_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,19 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
return CommandCost();
}

static bool CheckDesiredDestination(const Aircraft *v);

/** Check whether the aircrafts needs to visit a hangar.
* @param v Aircraft
*/
static void CheckIfAircraftNeedsService(Aircraft *v)
{
if (v->state < AS_MOVE) {
if (!CheckDesiredDestination(v)) return;
} else if (v->state != AS_FLYING) {
return;
}

if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return;
if (v->IsChainInDepot()) {
VehicleServiceInDepot(v);
Expand All @@ -418,9 +429,12 @@ static void CheckIfAircraftNeedsService(Aircraft *v)

/* only goto depot if the target airport has a depot */
if (st->airport.HasHangar() && CanVehicleUseStation(v, st)) {
Debug(misc, 0, "Setting a hangar for aircraft {}, within airport {}", v->index, v->state <= AS_MOVE);
v->current_order.MakeGoToDepot(st->airport.hangar->index, ODTFB_SERVICE);
v->SetDestTile(v->GetOrderHangarLocation(st->airport.hangar->index));
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
} else if (v->current_order.IsType(OT_GOTO_DEPOT)) {
Debug(misc, 0, "Setting dummy goto hangar for aircraft {}, within airport {}", v->index, v->state <= AS_MOVE);
v->current_order.MakeDummy();
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
}
Expand Down Expand Up @@ -1272,7 +1286,7 @@ static void AircraftEntersTerminal(Aircraft *v)
assert(IsDiagonalTrackdir(v->trackdir));
if (v->IsHelicopter()) SetBit(v->flags, VAF_ON_LAND);

if (v->current_order.IsType(OT_GOTO_DEPOT)) return;
if (v->current_order.IsType(OT_GOTO_DEPOT)) NOT_REACHED();

Station *st = v->GetTargetAirport();
assert(st != nullptr);
Expand Down Expand Up @@ -2938,7 +2952,8 @@ static bool AircraftController(Aircraft *v, bool mode)
v->UpdateNextTile(INVALID_TILE);
UpdateNextAircraftState(v);
return true;
} else if (v->next_state == AS_APRON) {
} else if (v->state < AS_MOVE) {
Debug(misc, 0 ,"setting go to hangar");
v->next_state = AS_HANGAR;
v->state = AS_IDLE;
UpdateNextAircraftState(v);
Expand Down

0 comments on commit ef84da1

Please sign in to comment.