Page 1 of 1

Road Pathfinder

Posted: 25 Dec 2010 15:01
by DeletedUser6
Could someone tell me how the Road Pathfinder works - as I'm attempting to make my own....

Thank you!

Matthew:out

Re: Road Pathfinder

Posted: 25 Dec 2010 15:13
by Alberth
Search for "games path finding" at the Internet.
A common algorithm is A* (pronounced A-star).

Re: Road Pathfinder

Posted: 25 Dec 2010 15:21
by DeletedUser6
I know how the A* graph works, (compare cost of two lines, choose the one with least cost, is the jist of it) but I want to know about the commands used for placing a node, getting that node, sectioning the route and building the road from that. Some sort of tutorial would be nice.

Matthew:out

Re: Road Pathfinder

Posted: 25 Dec 2010 17:04
by Lord Aro
A read of the code would surely give you the best idea of what's going on 'inside' the pathfinder...
Then ask if you don't get it entirely ;)

(I don't get it entirely myself to be honest :lol: )

Re: Road Pathfinder

Posted: 25 Dec 2010 17:28
by DeletedUser6
*cough* *cough* Already have, twice... I still see text - it's not my fault I'm rubbish at anything to do with code...

Matthew:out

EDIT: And I barely understand the Doxygen documents, so no use there.

Re: Road Pathfinder

Posted: 25 Dec 2010 17:32
by Alberth
The AI main page at the wiki has a link to documentation, which should have a link to road-related functions.
Those are your primtive operations in which you have to express road building.

Re: Road Pathfinder

Posted: 25 Dec 2010 18:03
by DeletedUser6
Evidently I am being misunderstood...

AroAI already has a route builder, I need to know how to get the result from the AyStar into a route usable by the bus route builder. Which is what the Road Pathfinder does.

MAtthew:out

Re: Road Pathfinder

Posted: 25 Dec 2010 20:51
by Arie-
I think you are misunderstanding as well, most of the AI's available, code examples on the wiki and the doxygen comments should help you a lot. If that is not enough, several questions which you preferably answer all as clearly as possibly:
- what is the problem?
- what solutions to your problem did you find and how did you find them?
- what parts of your solutions didn't work?
- what errors did those parts generate?
Reading the code of available AI's should help you a lot, they al already tackled your problem!

Re: Road Pathfinder

Posted: 26 Dec 2010 11:44
by DeletedUser6
The problem: I want to make a Road Pathfinder Library. The wiki says how to use the existing one, but not how to make one.
The solution: Ask the people who made it how it works, and copy the existing RPF.
How I got there: PM'd TrueBrain.
Problems encountered: The people haven't answered, and I have no idea how the existing Road PF works, plus the AI (AroAI)/ AI Debug isn't recognising the library I've made from the solution.
Error's generated: As above (Couldn't find library 'superpf')

The library.nut, and main.nut are attached.

Matthew:out

Re: Road Pathfinder

Posted: 26 Dec 2010 12:08
by Yexo
Getting a "library not found" error message usually indicates an error in your library.nut. In this case:

Code: Select all

function GetVersion()		{ return "1"; }
GetVersion should return an integer, so that line of code should read:

Code: Select all

function GetVersion()		{ return 1; }
Also, while TrueBrain has helped a lot with the A* library and the road pathfinder, I wrote them originally.

Re: Road Pathfinder

Posted: 26 Dec 2010 12:19
by Alberth
I still don't understand what your problem is (besides the thing yexo pointed out).

Perhaps you should simplify the problem, and learn to crawl before trying to walk.
I suggest you create a flat landscape of 64x64 tiles with a single town somewhere in the corner where it does not bother you.

Then make an AI for that scenario that builds a road from tile (10, 15) to (30, 15) or some other straight line.
(Yes, you can build stuff in the middle of nowhere, not useful in real games, but as a first step it may be useful.)

If that works, try making a road with a corner in it.

Re: Road Pathfinder

Posted: 26 Dec 2010 12:22
by DeletedUser6
@Yexo Ah, it was the fact it said:
truebrain
that threw me...

Thank you, for getting it detected, even if I still don't understand how to call nodes (I am simplifying it, to make it faster, that is assuming that each tile is a node.), or how to give AroAI a path.

It's better than nothing...

@Alberth I'll try that.
Matthew:out

Re: Road Pathfinder

Posted: 26 Dec 2010 12:36
by Alberth
OTTDmaster wrote:... how to call nodes (I am simplifying it, to make it faster, that is assuming that each tile is a node.), or how to give AroAI a path.
1. Don't bother about speed until you got it working. Optimizations only get in the way of understanding.
2. What is a node? OpenTTD has no nodes. If you mean PF algorithm nodes, then quite likely, tile == node.

Re: Road Pathfinder

Posted: 26 Dec 2010 13:04
by Yexo
A node can be everything you want. If I recall correctly in the default road pathfinder library it is indeed true that node==tile. In the rail pathfinder a node is a combination of a tile + a direction, because you cannot go in every direction when 90 degree turns are disabled.

Are you trying to use the A* library or not? If you want to use it, just copy the default road pathfinder and implement your own _Cost function. The return value of FindPath is an instance of AyStar.Path which is a linked list that contains the complete path.

Re: Road Pathfinder

Posted: 26 Dec 2010 17:14
by Lord Aro
In case anyone is wondering or cares about the excessive use of AroAI, OTTDmaster has become a sort of assistant developer with me
Just thought i'd let you know ;)