Page 1 of 1

Road pathfinder

Posted: 15 Feb 2010 16:32
by Kogut
I started from scratch with new ai and I have problem - is it possible to prevent pathfinder from using certain tiles?
(Tiles reservered for truck stations)

Re: Road pathfinder

Posted: 15 Feb 2010 17:10
by Zutty
Yes...

Code: Select all

local ignoredTiles = [...] // The tiles you want to prevent the pathfinder from using
local pathfinder = Road();
pathfinder.InitializePath([fromTile], [toTile], 2, 20, ignoredTiles);
Edit: This is wrong! See my further post below.

Re: Road pathfinder

Posted: 15 Feb 2010 17:35
by Kogut
What means 2 and 20? What it is?

Re: Road pathfinder

Posted: 15 Feb 2010 17:54
by Zutty
Ooops! :oops: Sorry, thats a custom version of the pathfinder based on Yexo's version! I forgot that those changes never made it to version 4.

Try something like this...

Code: Select all

class CustomPathfinder extends Road {
	function InitializePath(sources, goals, ignored) {
		local nsources = [];

		foreach (node in sources) {
			nsources.push([node, 0xFF]);
		}

		this._pathfinder.InitializePath(nsources, goals, ignored);
	}
}

local ignoredTiles = [...] // The tiles you want to prevent the pathfinder from using
local pathfinder = CustomPathfinder()
pathfinder.InitializePath([fromTile], [toTile], ignoredTiles)

Re: Road pathfinder

Posted: 15 Feb 2010 18:29
by Kogut
Thanks for fast reply!
But how it works:

Code: Select all

nsources.push([node, 0xFF]);
?

Re: Road pathfinder

Posted: 15 Feb 2010 21:57
by Zutty
I just copied that from the pathfinder source code...

http://noai.openttd.org/repositories/en ... k/main.nut

Basically, the AyStar library expects a tile and a direction (which is the 0XFF). The code for that is here...

http://noai.openttd.org/repositories/en ... k/main.nut

Of course the direction for a source node is somewhat meaningless. Its just to keep the main loop happy. I wouldn't worry too much about it, unless you want to get into the internals of the A* algorithm.

Re: Road pathfinder

Posted: 17 Feb 2010 15:50
by Kogut
One more thing: //EDIT: To make it compatibile with wiki tutorial

class CustomPathfinder extends RoadPathFinder{
function InitializePath(sources, goals, ignored) {
local nsources = [];

foreach (node in sources) {
nsources.push([node, 0xFF]);
}

this._pathfinder.InitializePath(nsources, goals, ignored);
}
}

local ignoredTiles = [...] // The tiles you want to prevent the pathfinder from using
local pathfinder = CustomPathfinder()
pathfinder.InitializePath([fromTile], [toTile], ignoredTiles)

Re: Road pathfinder

Posted: 17 Feb 2010 17:07
by Zutty
Kogut wrote:...
class CustomPathfinder extends RoadPathFinder{
...
The class name will be whatever you specified in the import() command.

Re: Road pathfinder

Posted: 18 Feb 2010 02:17
by fanioz
Kogut wrote:Thanks for fast reply!
But how it works:

Code: Select all

nsources.push([node, 0xFF]);
?
it tell pathfinder to mark a tile node with 0xFF direction, this would tell the "Add Neighbour" part of AyStar to ignore that node.
Yes, the Neighbour call back inside (Road) PathFinder could add any tile "pushed" there, but later AyStar Neighbour would evaluate them, thus if a node had direction flag 0xFF it would never added (again) into path queue.

Less or more, a direction is a marker for a pair of tile, wether going from tile A to tile B was ever done before in a path finding.

Re: Road pathfinder

Posted: 18 Feb 2010 07:57
by Kogut
fanioz wrote:
Kogut wrote:Thanks for fast reply!
But how it works:

Code: Select all

nsources.push([node, 0xFF]);
?
it tell pathfinder to mark a tile node with 0xFF direction, this would tell the "Add Neighbour" part of AyStar to ignore that node.
Yes, the Neighbour call back inside (Road) PathFinder could add any tile "pushed" there, but later AyStar Neighbour would evaluate them, thus if a node had direction flag 0xFF it would never added (again) into path queue.

Less or more, a direction is a marker for a pair of tile, wether going from tile A to tile B was ever done before in a path finding.
Thanks for information