Help Path Finding with SuperLib

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
crof
Engineer
Engineer
Posts: 1
Joined: 07 Sep 2015 21:28

Help Path Finding with SuperLib

Post by crof »

So I'm fairly new to building AI's for openTTD. I recently managed to make an AI that uses airplanes :D However, now I'm trying to learn how to get my AI to create roads between two stations.

I've decided to try this using SuperLib and the pathfinder it uses. However, I can't seem to get it to successfully find a path between two points and build the road. I'm assuming that's because I don't know how to use it properly.

Here is the current test code I'm trying:

Code: Select all

  ///////////Temp Test of Roadbuilder//////////////////
  local testRoadBuilder = SuperLib.RoadBuilder();
  testRoadBuilder.Init(AIMap.GetTileIndex(43,23), AIMap.GetTileIndex(38,36), false, 4000, null);
  while(!testRoadBuilder.DoPathfinding()){AILog.Info("trying to find path...");this.Sleep(10);}
  testRoadBuilder.ConnectTiles();
 
Note: The hard coded numbers in the "GetTileInex(##,##)" segments were just for testing on a generated map. They were coordinates of two close towns outside road tiles I was trying to get it to connect. I've tried to use coordinates for two grass tiles with no obstacles between them and about 10 tiles apart with the same results.

In the code above, "DoPathfinding()" never returns true.

I also tried:

Code: Select all

  ///////////Temp Test of Roadbuilder//////////////////
  local testRoadBuilder = SuperLib.RoadBuilder();
  testRoadBuilder.Init(AIMap.GetTileIndex(43,23), AIMap.GetTileIndex(38,36), false, 4000, null);
  testRoadBuilder.ConnectTiles();
 
This code just creates a log entry that says the path building failed.

So obviously I am not understanding how to use this and I'm hoping someone can nudge me in the right direction. Maybe there are some code examples around that I haven't found yet?

Or maybe using SuperLib isn't the correct way to go either?

Thanks in advance for any help :)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Help Path Finding with SuperLib

Post by Zuu »

Have you set the current road type by calling the API method for that? You need to set this to road or tram before any road operations in OpenTTD as AI. The his could be the cause.
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 4 guests