AIEngine::GetMaximumOrderDistance

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
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

AIEngine::GetMaximumOrderDistance

Post by Brumi »

I've been trying to implement aircraft range support for SimpleAI, and I encountered this strange thing:
aircraft range.png
aircraft range.png (15.64 KiB) Viewed 1368 times
The range of that airplane seems to be way too large.
The code printing these lines:

Code: Select all

AILog.Info("Selected aircraft: " + AIEngine.GetName(planetype));
AILog.Info("Distance: " + AIMap.DistanceManhattan(srcplace, dstplace) + "   Range: " + AIEngine.GetMaximumOrderDistance(planetype));
Am I overlooking something? It may be the case that I'm simply tired :?
krinn
Transport Coordinator
Transport Coordinator
Posts: 342
Joined: 29 Dec 2010 19:36

Re: AIEngine::GetMaximumOrderDistance

Post by krinn »

The unit of the order distances is unspecified and should not be compared with map distances
It mean you cannot compare it with AIMap.DistanceManhattan(srcplace, dstplace) as this is a map reference function
And only use AIOrder.GetOrderDistance to compare it.

I suppose it cames from NEWGRF specs, but now we are playing with what ? potatoes distance ? ant foot steps ? Little rock spacing ?
So you will try to compare on openttd map the distance between two points, in ant foot, while you don't even know how many tile an ant foot could be.

It may work blindly for a vehicle, but as soon as you are trying to put two airports within range of an aircraft, you get the crazy situtation where you don't have any clue what could be that distance in openttd map.
Brumi
President
President
Posts: 921
Joined: 18 Jul 2009 17:54

Re: AIEngine::GetMaximumOrderDistance

Post by Brumi »

Thank you, now I understand :)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: AIEngine::GetMaximumOrderDistance

Post by Yexo »

krinn wrote:I suppose it cames from NEWGRF specs, but now we are playing with what ? potatoes distance ? ant foot steps ? Little rock spacing ?
It doesn't come from the NewGRF specs, and yes, this is somewhat problematic for AIs.

Currently the order distance is ManhattanDistance for trains, road vehicles and ships but Squared distance for aircraft. The reason that's not documented in the NoAI documentation is because this might change in the future. Say we want to change how the order distance for ships is computed by doing sqrt(dx^2 + dy^2) instead of dx+dy. If we'd documented how we compute the order distance than as soon as we change the computation we break the specs. By not documenting the exact behavior but instead providing you with functions that call our internal calculation code we can make changes to the calculation later if that's found to improve gameplay.

Of course this can be hard to deal with for AIs, as you've found with your example when trying to place two airports. However AIOrder.GetOrderDistance is a very fast function, so there shouldn't be much problem calling this function repeatedly to find a nice estimate for where you can build your airports.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: AIEngine::GetMaximumOrderDistance

Post by planetmaker »

And just te emphasise: You can get the order distance also between two tiles, if you need to check distances for airport placement.
http://noai.openttd.org/api/trunk/class ... 2aec378dc7
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Bing [Bot] and 13 guests