RPF (Road path finder) Updates - Version 4

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.

Moderator: OpenTTD Developers

Post Reply
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

RPF (Road path finder) Updates - Version 4

Post by Zuu » 19 Aug 2012 10:43

Problem/solutions
In order to get out a RPF library for NoGo that is compatible with the AI version there are two options:
  • Release a new updated AI RPF that use AyStar 6 (instead of 4 as of now) as well as a NoGo version of this RPF that use the already ported AyStar 6 for NoGo.
  • Release a NoGo port of AyStar 4 as eg. "AyStar Classic" and use that as basis for a RPF port of RPF 3 for AIs.
What is worth to mention is that the order which the arguments to the callback-functions (cost, neighbours, etc.) are different in AyStar 4 and 6. Thus if you derive a RPF based on the stock RPF for AIs, it will not just simply work with a RPF based on AyStar 6, making it troublesome for projects like SuperLib that use the same code base to support both AIs and NoGo.

The first option (in the list above) give us a RPF based on AyStar 6 while the later will use AyStar 4 as the basis for both RPFs.

Selected solution - Make RPF 4 that depend on AyStar 6
After a discussion on IRC a few days ago the conclusion was that while AI authors that use RPF 3 will need to change about 4-5 lines of code when switching to RPF 4 (based on AyStar 6), that is still better as this is a good moment to introduce the API change and switch to AyStar 6.

The changes needed are eg:

Code: Select all

// from:
function _SuperLib_RoadPathFinder_private_CustomRPF::_Cost(path, new_tile, new_direction, self)
// to:
function _SuperLib_RoadPathFinder_private_CustomRPF::_Cost(self, path, new_tile, new_direction)

I've attached the new RPF 4 for AI and NoGo. These have not yet been committed at devZone or uploaded to bananas. I plan to also upload a new SuperLib at the same moment as RPF 4 is uploaded that support the new RPF version 4.

Edit: Removed attachments. Final tar files of RPF 4 have been uploaded to bananas.
Last edited by Zuu on 19 Aug 2012 22:08, edited 2 times in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2366
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: RPF (Road path finder) Updates

Post by Lord Aro » 19 Aug 2012 13:30

Note: if you want AI devs to use this, you'll need to get it uploaded to BaNaNaS asap

Just sayin' :)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RPF (Road path finder) Updates

Post by Zuu » 19 Aug 2012 14:57

It will get uploaded to bananas within a few days or so. I was just telling ahead about the change.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RPF (Road path finder) Updates - Version 4

Post by Zuu » 19 Aug 2012 22:13

Version 4 of Pathfinder.Road have been uploaded to BaNaNaS - both for AIs and Game Scripts.

If you have derived your own RPF class and overridden _Neighbours, _Estimate, etc. you will need to move the self parameter from the back of the argument list to the front for those functions. Otherwise you will run into errors and crashes. (see the code example in first post)

Also remember when uploading your next AI version to select the RPF as dependency again as it have now been deselected as you previously had version 3 selected and that one is not available anymore for new content to use. (unless TrueBrain or someone else get around to change it so that we can set old libraries as dependencies in bananas)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: RPF (Road path finder) Updates - Version 4

Post by Kogut » 01 Oct 2012 20:45

So it is only necessary to change code in places where _Cost function is somehow used?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: RPF (Road path finder) Updates - Version 4

Post by Zuu » 01 Oct 2012 20:50

_Cost, or any of the other callback functions (IIRC 5 in total). There is for example one that determines which neighbours there are, which is useful to customize in order to find solutions to bridge canals or rail tracks.

But if your only inherited RPF class is the one in KRAIpathfinder.nut, then you only have a customized _Cost callback.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest