Road pathfinder
Moderator: OpenTTD Developers
Road pathfinder
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)
(Tiles reservered for truck stations)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Road pathfinder
Yes...
Edit: This is wrong! See my further post below.
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);
Last edited by Zutty on 15 Feb 2010 17:55, edited 1 time in total.
PathZilla - A networking AI - Now with tram support.
Re: Road pathfinder
What means 2 and 20? What it is?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Road pathfinder
Ooops!
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...

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)
PathZilla - A networking AI - Now with tram support.
Re: Road pathfinder
Thanks for fast reply!
But how it works:
?
But how it works:
Code: Select all
nsources.push([node, 0xFF]);
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Road pathfinder
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.
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.
PathZilla - A networking AI - Now with tram support.
Re: Road pathfinder
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)
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)
Last edited by Kogut on 17 Feb 2010 17:32, edited 1 time in total.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Re: Road pathfinder
The class name will be whatever you specified in the import() command.Kogut wrote:...
class CustomPathfinder extends RoadPathFinder{
...
PathZilla - A networking AI - Now with tram support.
Re: Road pathfinder
it tell pathfinder to mark a tile node with 0xFF direction, this would tell the "Add Neighbour" part of AyStar to ignore that node.Kogut wrote:Thanks for fast reply!
But how it works:?Code: Select all
nsources.push([node, 0xFF]);
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
Thanks for informationfanioz wrote:it tell pathfinder to mark a tile node with 0xFF direction, this would tell the "Add Neighbour" part of AyStar to ignore that node.Kogut wrote:Thanks for fast reply!
But how it works:?Code: Select all
nsources.push([node, 0xFF]);
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.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
AIAI - AI for OpenTTD
Who is online
Users browsing this forum: Google [Bot] and 3 guests