SuperLib: Helper, Direction, Tile, ... libraries

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

User avatar
yorg
Engineer
Engineer
Posts: 18
Joined: 19 May 2008 21:48
Location: Peterborough, Ontario

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by yorg »

Hi,

I don't have a rock-steady case for reproducing the issue, but the AI I'm working on seems to run into it eventually on big enough maps. Where can I download your patch for testing?

Thanks for the guidance regarding making patches - I have a bit of knowledge of git but am still learning all the ins and outs, so I appreciate the information.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Hey,

I forgot to attach the patch file. I've edited my post and added it now. :-)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
yorg
Engineer
Engineer
Posts: 18
Joined: 19 May 2008 21:48
Location: Peterborough, Ontario

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by yorg »

Perfect, thanks, I've got it now.

At a glance, it seems to match my changes. I'll spend some time testing your patch and report back.

EDIT:

Running your patch throws an error - the iterator falls out of scope after the end of the for... loop in DoPathfinding. The attached patch just moves the declaration if it a line earlier. With that applied, it looks like everything works well and the issues in my last post are all resolved.

I'm going to keep poking around and see if anything else comes up, but for now it looks good to me.
Attachments
error.patch
Apply after zuu's patch
(430 Bytes) Downloaded 206 times
kraken
Engineer
Engineer
Posts: 13
Joined: 16 Dec 2016 14:11

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by kraken »

Is somewhere documentation please?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

The documentation is included in the tar file. There is a readme file with introduction and pointers for where to find further documentation.
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: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

Version 40
I have made an update to SuperLib that fixes that RoadBuilder would not timeout.

If you use SuperLib.RoadPathFinder directly in your AI or library, you need to update your code, as I have fixed it to now behave as documented. If you only use RoadBuilder, then the interface has not changed.

Changelog:

Code: Select all

Fix:
- RoadPathFinder::FindPath and ::GetFindPathError was not responding as documented
- RoadBuilder timeout was not working
- Road::GrowStation was connecting added stop in a suboptimal way
- Town::GetTownProducedCargoList and Town::GetTownAcceptedCargoList now neturn a new 
  list instance each time, so that if you modify the returned list, it will not affect the next
  call to the method.
- A few debug messages printed using AILog was fixed to use the Log system 

Thanks to yorg for debugging and posting patches that contributed towards
solving the timeout problem.

The update is available on bananas

Edit: Forgot to include Town::GetTownProducedCargoList and Town::GetTownAcceptedCargoList in changelog.
Attachments
NoGoSuperLib-v40.tar
GS version
(346 KiB) Downloaded 234 times
SuperLib-v40.tar
AI version
(350 KiB) Downloaded 233 times
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: SuperLib: Helper, Direction, Tile, ... libraries

Post by Zuu »

A word of advice.

If your AI is using RoadBuilder and was using SuperLib pre 40 and then changed to 40, review your max_loops parameter if you set it explicitly when you call RoadBuilder.Init. If you used a too low limit in past versions of your AI it was not a problem in SuperLib 39 because it had a bug that it would not abort at max_loops, so you didn't notice that you used a too low limit. Now with SuperLib 40, you need to take care to not use a too low limit in relation to how long distance your routes are. The SuperLib default value is 4000, but please play around and find a value that suits your AI.

Parameters of the Init method:

Code: Select all

function Init(tile1, tile2, repair_existing = false, max_loops = 4000, forbidden_tiles = []);
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Wormnest
Engineer
Engineer
Posts: 117
Joined: 14 Jul 2013 12:33
Location: Netherlands

Re: SuperLib: Helper, Direction, Tile, ... libraries

Post by Wormnest »

_SuperLib_Money::GetInflationRate can cause a division by zero if "difficulty.max_loan" is zero. See e.g. viewtopic.php?p=1267811&sid=920eabb163d ... c#p1267811
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests