AIAirport API improvements - towards better NewGRF support
Posted: 01 Aug 2011 21:48
Hi,
For some time OpenTTD have supported for NewGRFs that define new airports. As of now, they can't define new state machines (movement patterns). What they can do is to create more views/rotations of airports. In the OpenGFX+ Airports set there exist a 180 degree rotation of the small airport.
In order to support the NewGRF movements in airports, some work need to be done on the NoAI API. I start this thread in order to open up for thoughts about how this API expansion should be done to keep backward compatibility as good as possible while still providing a good API for the future.
My initial proposal:
These exiting functions would gain an extra argument at the end "airport_view". If possible the argument will default to 0. If not, it will have to become mandatory and the compatibility layer for API 1.1 and lower will provide the old functions with fewer arguments. (given that overloading is supported by Squirrel - if not, these functions have to be renamed)
Since views are just rotations and can not have different introduction dates there is no need to include the concept of views in functions like IsValidAirport and IsAirportInformationAvailable.
To clean up a bit I would propose a rename as follows. I personally think that AIAirport.IsAirportInformationAvailable better fit under the name "IsValid" and the IsValid.. function could go under the name "IsBuildable". However such a rename could potentially cause unnecessary confusion.
As for getting more information about airports via the API, now that you soon can't trust hard coded values anymore, I here just give an idea of what I have in my wish-list: (that I also think could be possible to implement) Some of these might not be possible with the current NewGRF Spec. In that case we AI authors will have to work with the NewGRF people to find a solution.
Note that a function such as AIAirport.GetAirportCapacity() will most likely never be possible unless NewGRF authors themselves judge the performance of their airports and hard code some value. Something which might lead to anarchy. For it to work OpenTTD would need to support a way to build airports in memory (but not on the game map) and stress test it, something which is far from easy to do (but not impossible, just a lot of work).
As for actually implementing this it is something that will take some time and I will probably see what I can do, but before getting started with actual code, it is useful to get reflections on this proposal which is just based on my initial thoughts.
For some time OpenTTD have supported for NewGRFs that define new airports. As of now, they can't define new state machines (movement patterns). What they can do is to create more views/rotations of airports. In the OpenGFX+ Airports set there exist a 180 degree rotation of the small airport.
In order to support the NewGRF movements in airports, some work need to be done on the NoAI API. I start this thread in order to open up for thoughts about how this API expansion should be done to keep backward compatibility as good as possible while still providing a good API for the future.
My initial proposal:
- We need APIs to interact with views/rotations
- Acquire information about airports that previously could be hard coded in the AIs
Code: Select all
AIAirportTypeList() // List of airport types
AIAirportViewList(airport_type) // List of available views for a given airport type
AIAirport.IsValidAirportView(airport_view)
Code: Select all
AIAirport.GetAirportWidth
AIAirport.GetAirportHeight
AIAirport.BuildAirport
AIAirport.GetNoiseLevelIncrease
AIAirport.GetNearestTown
To clean up a bit I would propose a rename as follows. I personally think that AIAirport.IsAirportInformationAvailable better fit under the name "IsValid" and the IsValid.. function could go under the name "IsBuildable". However such a rename could potentially cause unnecessary confusion.
Code: Select all
AIAirport.IsValidAirport => AIAirport.IsValidAirportType
AIAirport.IsAirportInformationAvailable => AIAirport.IsAirportTypeInformationAvailable
As for getting more information about airports via the API, now that you soon can't trust hard coded values anymore, I here just give an idea of what I have in my wish-list: (that I also think could be possible to implement) Some of these might not be possible with the current NewGRF Spec. In that case we AI authors will have to work with the NewGRF people to find a solution.
Code: Select all
AIAirport.GetHoldingQueueLength(airport_tile) // Get the number of aircrafts that are waiting to land on the airport
AIAirport.GetNumberOfRunways(airport_type) // Gets the number of runways that a given airport type have
AIAirport.GetNumberOfHelicopterLandingPlaces(airport_type) // Gets the number of places where helicopters can start and land
AIAirport.GetNumberOfLoadingBays(airport_type) // Gets the number of loading bays for aircrafts of a given airport type.
As for actually implementing this it is something that will take some time and I will probably see what I can do, but before getting started with actual code, it is useful to get reflections on this proposal which is just based on my initial thoughts.