FS#4704 - Fix: Allow AIs to query noise level of depricated airport types if they have such airports

Attached to Project: OpenTTD
Opened by Leif Linse (Zuu) - Saturday, 30 July 2011, 20:14 GMT
Last edited by frosch (frosch) - Monday, 01 August 2011, 20:15 GMT
Type Patch
Category Script → NoAI
Status Closed
Assigned To No-one
Operating System All
Severity Medium
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


I would classify this fix as something that would be very useful if it could be backported as it is critical when upgrading old airports to know how much noise the old airport contributed. It is much better to deny upgrading before the old airport has been removed than trying and take the risk to not be able to rebuild it again if upgrading fails.
This task depends upon

Closed by  frosch (frosch)
Monday, 01 August 2011, 20:15 GMT
Reason for closing:  Fixed
Additional comments about closing:  in r22710
Comment by Leif Linse (Zuu) - Monday, 01 August 2011, 19:03 GMT
In the NoAI API for airports, there are two levels of "validity" of airport types:
1) - IsValidAirportType: A more strict version which checks if the airport type is valid AND buildable
2) - IsAirportInformationAvailable: A less strict version which only require that the airport type is valid and is either buildable OR that the company have at least one airport of the given type.

The later case was added later to the API because it was found in practice that AIs need to access some of the AIAirport functions like the ones for getting the dimension of an airport type for airports that are no longer buildable. This is because that is the only way of getting the size of an airport other than requesting a list of all tiles and iterating through to figure out the size.

What this patch does is that it makes it possible to get noise information for an airport that is no longer buildable, but the AI have one or more built (and remaining).

I should note that I haven't yet compiled this patch in a release build in order to within feasible time verify that it works.
Comment by Leif Linse (Zuu) - Monday, 01 August 2011, 20:16 GMT
I have now playtested this patch with an AI that each game-day prints the noise level of the small airport.

On a build with the patch applied:
1. Start in 1950
2. Start AI (and open AI debug window)
3. Cheat to the AI company
4. Build small airport
5. AI now prints noise level = 3
6. Use year cheat to 1980 (a year when small airport is no longer available)
7. AI now prints noise level = 3
8. Remove airport
9. AI now prints noise level = 3

On a build without the patch applied: (I used 1.1.2-RC2)
1 - 6 as above
7. AI now prints noise level = -1

At step 7 the patch work as intended. That the AI still get information about the airport which is different from what how I understood from Yexo that it would work with IsAirportInformationAvailable. The behavior in step 9 can however also be observed for other AIAirport APIs that use IsAirportInformationAvailable to validate the airport type - so nothing unique for this patch.