Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Thu Feb 21, 2019 5:03 pm

All times are UTC




Post new topic  Reply to topic  [ 30 posts ]  Go to page Previous 1 2
Author Message
PostPosted: Tue Aug 30, 2011 4:32 am 
Offline
Engineer
Engineer
User avatar

Joined: Sun Mar 22, 2009 7:24 am
Posts: 81
Location: Haarlem, The Netherlands
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.
Code:
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 :))


Top
   
PostPosted: Tue Aug 30, 2011 4:15 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Zuu wrote:
Above in the same function this code makes sure that the plane_type is an expected type.


Miss it sorry, you are right :)
Keep up the good work


Top
   
PostPosted: Tue Aug 30, 2011 4:32 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4548
Location: /home/sweden
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)


Top
   
PostPosted: Wed Aug 31, 2011 6:21 am 
Offline
Engineer
Engineer
User avatar

Joined: Sun Mar 22, 2009 7:24 am
Posts: 81
Location: Haarlem, The Netherlands
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?


Top
   
PostPosted: Wed Sep 07, 2011 7:53 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4548
Location: /home/sweden
Update!

Screenshot
Attachment:
File comment: This Airport was built by my test AI
Hisköping Transport, 12th Oct 1950.png [71.37 KiB]
Downloaded 1 time


Patch queue:
- Extends the API to allow usage of views.

Click on the links to read each patch, or view all changes:
Attachment:
File comment: Patch with changes from r22893 to last patch in queue.
all.patch [44.3 KiB]
Downloaded 108 times


Test AI
Attachment:
File comment: 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.

AirportAPITestAI.tar [7.5 KiB]
Downloaded 64 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)


Top
   
PostPosted: Thu Sep 08, 2011 6:14 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4548
Location: /home/sweden
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.

AIAirport:
    bool AIAirport::IsHangarTile(TileIndex tile)
    bool AIAirport::IsAirportTile(TileIndex tile)
    bool AIAirport::BuildAirport(TileIndex tile, AirportType type, AirportView view, StationID station_id) // takes new argument
    bool AIAirport::RemoveAirport(TileIndex tile)
    int32 AIAirport::GetNumHangars(TileIndex tile)
    TileIndex AIAirport::GetHangarOfAirport(TileIndex tile)
    AirportType AIAirport::GetAirportType(TileIndex tile)
    AirportView AIAirport::GetAirportView(TileIndex tile) // new

AIAirportType:
    bool AIAirportType::IsBuildableAirportType(AirportType type) // replaces AIAirport::IsValidAirportType
    bool AIAirportType::IsAirportTypeInformationAvailable(AirportType type)
    bool AIAirportType::IsValidAirportView(AirportView airport_view, AirportType airport_type)
    bool AIAirportType::IsValidPlaneType(PlaneType plane_type)
    Money AIAirportType::GetPrice(AirportType type)
    int32 AIAirportType::GetAirportWidth(AirportType type, AirportView view) // takes new argument
    int32 AIAirportType::GetAirportHeight(AirportType type, AirportView view) // takes new argument
    int32 AIAirportType::GetNumHangars(AirportType type) // new function
    int32 AIAirportType::GetNumHelipads(AirportType type) // new function
    int32 AIAirportType::GetNumTerminals(AirportType type) // new function
    bool AIAirportType::CanPlaneTypeLand(AirportType type, AIAirportType::PlaneType plane_type) // new function
    bool AIAirportType::IsLandingExtraDangerous(AirportType type, AIAirportType::PlaneType plane_type) // new function
    int32 AIAirportType::GetAirportCoverageRadius(AirportType type)
    int AIAirportType::GetNoiseLevelIncrease(TileIndex tile, AirportType type)
    TownID AIAirportType::GetNearestTown(TileIndex tile, AirportType type)

AIAirportTypeList:
    AIAirportTypeList::AIAirportTypeList() // new - lists all airport types

AIAirportViewList:
    AIAirportViewList::AIAirportViewList(AIAirportType type) // new - lists all views of given airport type


For reference: Trunk AIAirport


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.


Win32 binary
Attachment:
File comment: Win32 release binary. Includes the test AI in the ai directory.
noai_airport_2011-09-07.zip [4.17 MiB]
Downloaded 64 times

_________________
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)


Top
   
PostPosted: Fri Sep 09, 2011 10:35 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Dec 29, 2010 7:36 pm
Posts: 336
Code:
bool AIAirport::BuildAirport(TileIndex tile, AirportType type, AirportView view, StationID station_id) // takes new argument


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


Top
   
PostPosted: Fri Sep 09, 2011 10:59 am 
Offline
Tycoon
Tycoon

Joined: Thu Dec 20, 2007 12:49 pm
Posts: 3653
krinn wrote:
Code:
bool AIAirport::BuildAirport(TileIndex tile, AirportType type, AirportView view, StationID station_id) // takes new argument


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.


Top
   
PostPosted: Thu Sep 15, 2011 8:17 am 
Offline
Engineer
Engineer
User avatar

Joined: Sun Mar 22, 2009 7:24 am
Posts: 81
Location: Haarlem, The Netherlands
Is there still work to be done on this branch? Since I've finished the Stop AI Cheat, I'm looking for something else to help with.


Top
   
PostPosted: Thu Sep 15, 2011 4:17 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4548
Location: /home/sweden
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)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 30 posts ]  Go to page Previous 1 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2019 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2019.
Hosted by Zernebok Hosting.