Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: Rework automatic service for helicopters (#6493) #7111

Conversation

SamuXarick
Copy link
Contributor

@SamuXarick SamuXarick commented Jan 26, 2019

In order to verify if a helicopter with serviceathelipad has a pending replace, it's needed to call HasPendingReplace directly, as a seperate function, that can be used by AircraftEventHandler_AtTerminal and CheckIfAircraftNeedsService.

If a helicopter needs to be sent to a hangar during automatic service, and there are no airports with hangars in the orders (travelling between heliports), a nearby hangar outside the orders will be searched. If the distance to a found hangar is shorter than the distance to the helistation/airport the helicopter is headed to, the helicopter is sent to that hangar.

Also, when an aircraft (of any type) is at a terminal, it is checked whether it needs automatic servicing, and in the case of helicopter, due to the complexity of serviceathelipad, whether it has a pending replace, and then sent to the hangar of the airport, before being sent to takeoff.

These changes thus replace the two methods which were attempting to do the same.

  • For the case of airplanes, the check was being done upon landing, which could result in canceling the automatic servicing order, only to have it re-applied on the next daily check.
  • For the case of helicopters, the check was being done right after taking off, which is now handled via CheckIfAircraftNeedsService every day.

…dingReplace

In order to verify if a helicopter with service at helipad has a pending replace, it's needed to call HasPendingReplace directly, as a seperate function that can be used by some aircraft_cmd.cpp functions
…ft at a hangar outside the order list

If a helicopter needs to be sent to a hangar during automatic service, and there are no airports with hangars in the orders (travelling between heliports), a nearby hangar outside the orders will be searched. If the distance to a found hangar is shorter than the distance to the helistation/airport the helicopter is headed to, the helicopter is sent to that hangar.
@SamuXarick SamuXarick force-pushed the rework-automatic-service-for-helicopters branch from 1cd6f23 to 8dd4379 Compare January 26, 2019 18:35
bool needs_automatic_servicing = v->NeedsAutomaticServicing();
bool has_pending_replace = v->HasPendingReplace();
if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || (!needs_automatic_servicing &&
(!has_pending_replace || v->subtype != AIR_HELICOPTER || !_settings_game.order.serviceathelipad))) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serviceathelipad is a legacy setting only present for compatibility with TTDPatch savegames, and OTTD savegames from before the helistations with hangars were introduced. It should not be considered for this change, to reduce cyclomatic complexity (which is already being increased significantly).

Presumably, helicopters on a helipads-only route with the setting enabled would be serviced very often regardless, so the usual NeedsAutomaticServicing will likely not kick in before an autoreplace or autorenew triggers. That's an additional reason I think the checks for serviceathelipad are unnecessary.

const Station *ost = Station::Get(o->GetDestination());
if (ost->airport.HasHangar() ||
/* Helicopters can be serviced at helipads as long as there is no pending replace and serviceathelipad is enabled */
(v->subtype == AIR_HELICOPTER && !has_pending_replace && _settings_game.order.serviceathelipad && ost->airport.GetFTA()->num_helipads)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be simplified significantly by not considering serviceathelipad.

*/
bool Vehicle::NeedsServicing() const
bool Vehicle::HasPendingReplace() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a critique, but I think the diff will look nicer if you move HasPendingReplace to below ´NeedsServicing` :)

/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);

if (nearest_hangar != INVALID_STATION && ((has_pending_replace && v->subtype == AIR_HELICOPTER && _settings_game.order.serviceathelipad && !needs_automatic_servicing) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be simplified significantly by not considering serviceathelipad.

@@ -1529,6 +1565,14 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass *
/* 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 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be simplified significantly by not considering serviceathelipad.

@nielsmh
Copy link
Contributor

nielsmh commented Jan 27, 2019

This is not an actual problem that needs fixing. The serviceathelipad setting exists in OpenTTD because it was implemented in TTDPatch at the dawn of time, and its only purpose was to make helipad-only routes somewhat viable when helistations with hangars did not yet exist. Now helistations do exist, and thus the setting is pretty much pointless.

Closing as not a bug.

@nielsmh nielsmh closed this Jan 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants