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

Bugfix for errors in FindNearestHangar function in aircraft_cmd.c #235

Closed
DorpsGek opened this issue Jul 4, 2006 · 5 comments
Closed

Bugfix for errors in FindNearestHangar function in aircraft_cmd.c #235

DorpsGek opened this issue Jul 4, 2006 · 5 comments
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay

Comments

@DorpsGek
Copy link
Member

DorpsGek commented Jul 4, 2006

mart3p opened the ticket and wrote:

If the “send to depot” button is pressed for an aircraft in flight, it will go to the hangar at the next airport in its orders. If the next airport has no hanger (i.e. a heliport) the function FindNearestHangar is called which should send the aircraft to the nearest airport with a hangar.

There are a couple of bugs in this function. Most serious is use of v->tile to determine the aircraft’s position when checking the distance to airports. While an aircraft is in flight v->tile is set to zero. This causes the function to always find the most northerly airport (airport_tile nearest zero) and the aircraft is sent there!

There are also some problems in the test that large aircraft shouldn't be sent to a small airport (with high risk of crash). The test for a large aircraft is incorrect. Also only the Small airport type is checked, it should also check for Commuter airports. The code here should be the same as that used for the same test in MaybeCrashAirplane.

In fact, it is only under unusual circumstances that FindNearestHangar will be called for aeroplanes (it is mainly used for helicopters). It can occur if there is a heliport in the plane’s orders. If the “send to depot” button is pressed while the plane is circulating the heliport (unable to land), then the FindNearestHangar function is called and the plane will go to the most northerly airport.

This patch corrects these problems.

Attachments

Reported version: 0.4.7
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/235
@DorpsGek
Copy link
Member Author

Darkvater wrote:

Why this change:

- if (HASBIT(v->subtype, 1) && st->airport_type == AT_SMALL &&
+ if ((AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&

Why not v->subtype & AIR_FAST?


This comment was imported from FlySpray: https://bugs.openttd.org/task/235#comment387

@DorpsGek
Copy link
Member Author

mart3p wrote:

v->subtype for aircraft uses the following values:
0 - Helicopter
2 - Aeroplane (small or large)
4 - Shadow
6 - Helicopter rotor

To determine weather a plane can land at a small airport it is necessary to use AircraftVelInfo->subtype which uses the values:
0 - Helicopter
1 - AIR_CTOL (conventional take-off and landing)
2 - AIR_FAST (fast/large aircraft - can only use large airport)

This test needs to be the same as the test in the function MaybeCrashAirplane, I have used the same code as used there.


This comment was imported from FlySpray: https://bugs.openttd.org/task/235#comment388

@DorpsGek
Copy link
Member Author

Darkvater wrote:

The question was is there any reason to use AircraftVehInfo(engine)->subtype instead of v->subtype. Are there any circumstances where these two might differ, as logically they should be the same.

Eg, when you build an aircraft, its subtype is set:
v->subtype = (avi->subtype & AIR_CTOL ? 2 : 0);


This comment was imported from FlySpray: https://bugs.openttd.org/task/235#comment389

@DorpsGek
Copy link
Member Author

mart3p wrote:

Maybe logically they should be the same but in fact their use differs, as shown by the values that are used in each case (in comment above). As you see from the code used when an aircraft is built:
v->subtype = (avi->subtype & AIR_CTOL ? 2 : 0);
the vehicle subtype is set to either 2 or 0, regardless of whether avi->subtype has the AIR_FAST bit set.


This comment was imported from FlySpray: https://bugs.openttd.org/task/235#comment390

@DorpsGek
Copy link
Member Author

Darkvater closed the ticket.

Reason for closing: Fixed

Point taken, subtype only registers if the plane is a plane or a chopper, nothing about its speed or other flying capabilites, which you would want to know to decide if a plane should land there or not. Patch applied, bug closed.


This comment was imported from FlySpray: https://bugs.openttd.org/task/235

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Vehicles patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay labels Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) patch from FlySpray This issue is in fact a Patch, but imported from FlySrpay
Projects
None yet
Development

No branches or pull requests

1 participant