Basic Road Pathfinder always return null

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
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

Basic Road Pathfinder always return null

Post by deepblue2k8 »

Hi,

I tried to play around with NoAI in my spare time this weekend but couldn't get very far.

I copied the example source code from the wiki for my new AI to see how that works.

Code: Select all

import("pathfinder.road", "RoadPathFinder", 3);

//.......

local townid_a = townlist.Begin();
		local townid_b = townlist.Next();

		AILog.Info("Town " + AITown.GetName(townid_a) + " Pop " + AITown.GetPopulation(townid_a));
		AILog.Info("Town " + AITown.GetName(townid_b) + " Pop " + AITown.GetPopulation(townid_b));

		local pathfinder = RoadPathFinder();
		AILog.Info("Pos A: " + AITown.GetLocation(townid_a));
		AILog.Info("Pos B: " + AITown.GetLocation(townid_b));
		AILog.Info("IsRoad A: " + AIRoad.IsRoadTile(AITown.GetLocation(townid_a)));
		AILog.Info("IsRoad B: " + AIRoad.IsRoadTile(AITown.GetLocation(townid_b)));

		/* Try to find a path. */
		local path = false;
		pathfinder.InitializePath([AITown.GetLocation(townid_a)], [AITown.GetLocation(townid_b)]);
		while (path == false) {
			path = pathfinder.FindPath(100);
			AIController.Sleep(1);
		}

		if (path == null) {
			/* No path was found. */
			AILog.Error("pathfinder.FindPath return null");
		}
But the problem was that path was alway null. It never finds any path between the two towns. Even if there are only two towns on a flat map.

Can anybody help me? :-)

Thanks in advance
Attachments
BlueAI.tar
(6 KiB) Downloaded 76 times
User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: Basic Road Pathfinder always return null

Post by GeekToo »

Town.Getlocation does not neccesarily return a road buildable tile, you will have to check that, not only log it.
deepblue2k8
Engineer
Engineer
Posts: 44
Joined: 06 Sep 2008 12:41
Location: Hamburg, Germany

Re: Basic Road Pathfinder always return null

Post by deepblue2k8 »

Yeah of cause, but in my test cases IsRoadTile returns true for both start and destination tile. In that case the road path finder should find a valid path but for a reason it doesn't :(

Update:

I traced my problem to the line

Code: Select all

AIRoad.BuildRoad(cur_node, next_tile)) 
of the function Road::_Neighbours(path, cur_node, self) in the road pathfinder 3.

BuildRoad seems to return always false, even if both cur_node and next_tile are both empty or one of them is a road in the right direction.
I tested this in OpenTTD 0.7.0, but I still cant make any sense of it, because the downloaded AIs are working fine....


Update 2:

Nevermind that I am an idiot...

It will work if you set: AIRoad.SetCurrentRoadType(AIRoad.ROADTYPE_ROAD);

...
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 7 guests