Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.
krinn suggested me to help on this project, I've been reading through it.
Zuu wrote: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.
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.
Isn't it possible to rewrite AIAirport.GetNumberOfRunways(airport_type) to AIAirport.GetNumberOfRunways(airport_type, airplane_type), to take care for small, large and helis? I read about the problems with NewGRF airplanes unknown to the airport, but can't NewGRF airport programmers write AirplaneType_UNKNOWN (or whatever it is) to allow (or deny) 'other' aircrafts to land?
(You'll notice that I'm trying to get my head around the abstractions... so I might ask silly questions
1009: you want to combine GetNumberOfRunways(airport_type) with GetNumberOfHelicopterLandingPlaces(airport_type) and use a second parameter (plane_type) to decide if the number of runways or helicopter landing places should be returned?
A problem with this abstraction is that you then can't know if the X runways for small airplanes and Y runways for large aircrafts are the same or different runways. In the current OpenTTD you know for sure that large and small aircrafts use the same runways, but this abstraction implicitly suggests that that might not be the case in future.
Edit: However, we would need an API to tell if a plane-type is a helicopter or not in order to work with helicopters vs airplanes when the PlaneType enum get replaced with AIPlaneTypeList.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites) Junctioneer (a traffic intersection simulator)
Zuu: that's right. I think the problem you see (not knowing for sure whether it's the same runway for small or large airplanes) is not a problem but rather a good thing: if NewGRF aiport coders decide to make an airport with 4 runways for both small and large aircraft and 2 express ones for smaller, then that would make it possible.
Same if they make something for a new kind of airplane (a spaceship, a UFO, a zeppelin) - although I'm not sure whether airplanes that aren't helis, large or small ones are supported by that library. Is that the PlaneType enum / AIPlaneTypeList?
My test AI for this API extension. (Note: reports same version number as the previously uploaded one - but differs in implementation)
Obviously, you need to apply all patches to use this AI.
(7.5 KiB) Downloaded 190 times
Known issues:
airport-api-split.patch introduces AIAirportType::IsValidPlaneType without using it. Only the patch after it will actually use the function. So perhaps introduction of the function should come in the patch after it.
AIAirportType::GetNearestTown and AIAirportType::GetNoiseLevelIncrease should be changed in airport-view-usage.patch to take views into account. However, there are issues that need to be solved in OpentTTD before that can happen.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites) Junctioneer (a traffic intersection simulator)
I realize that I've missed out an important part in my last update, to explain what I've done. Something I will try to address here. I have also uploaded a win32 binary in case anyone want to try it out and find a windows binary useful.
Below follows a list of all airport related APIs as they exist when all patches in the patch queue has been applied. I have marked changes/additions as underlined text. The data types are the C++ data types where all types that are not a bool is a numeric value/index.
Comment
I realize that the new AIAirport::BuildAirport function possible should be renamed as AIAirports::BuildAirportView while the old one is kept as it will still work, just that it will always build the view with index 0. One could argue if the old function should be deprecated and moved to the compatibility layers or kept as an ordinary API function.
Would have been better with moving AirportView as 3rd arguement and default it if none pass to 0
Compatibility kept
And i would drop BuildAirportView as it mean nothing as building an airport would imply building it with a view now (even if the airport have only 1 view usable)
Note that just default AirportView everywhere in the new functions to 0 will kept old AI compatibility without need of a layer addition as long as the argument is the last one.
Nice work Zuu, will take a look at patch and if i have time build openttd with it to test
Would have been better with moving AirportView as 3rd arguement and default it if none pass to 0
Compatibility kept
And i would drop BuildAirportView as it mean nothing as building an airport would imply building it with a view now (even if the airport have only 1 view usable)
Note that just default AirportView everywhere in the new functions to 0 will kept old AI compatibility without need of a layer addition as long as the argument is the last one.
Only squirrel doesn't support default argument values (or at least or C++/squirrel layer doesn't). Therefor we need to change the name of the function when adding/removing a parameter.
The work is currently a bit on hold since the project is waiting for some decisions to be made by the development team. Thus, the last 4-6 days I've focused on other projects (mostly a non-OpenTTD program called Junctioneer)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites) Junctioneer (a traffic intersection simulator)