Road pathfinder

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
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Road pathfinder

Post 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)
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Road pathfinder

Post 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.
Last edited by Zutty on 15 Feb 2010 17:55, edited 1 time in total.
PathZilla - A networking AI - Now with tram support.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Road pathfinder

Post by Kogut »

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
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Road pathfinder

Post 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)
PathZilla - A networking AI - Now with tram support.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Road pathfinder

Post by Kogut »

Thanks for fast reply!
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
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Road pathfinder

Post 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.
PathZilla - A networking AI - Now with tram support.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Road pathfinder

Post 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)
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
User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Road pathfinder

Post by Zutty »

Kogut wrote:...
class CustomPathfinder extends RoadPathFinder{
...
The class name will be whatever you specified in the import() command.
PathZilla - A networking AI - Now with tram support.
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Road pathfinder

Post 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.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Road pathfinder

Post 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
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Google [Bot] and 3 guests