Basic Road Pathfinder always return null
Posted: 11 Apr 2009 18:07
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.
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
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");
}
Can anybody help me?

Thanks in advance