Page 1 of 1

AIEngine::GetMaximumOrderDistance

Posted: 01 Nov 2012 01:22
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 1367 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 :?

Re: AIEngine::GetMaximumOrderDistance

Posted: 01 Nov 2012 02:23
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.

Re: AIEngine::GetMaximumOrderDistance

Posted: 01 Nov 2012 10:52
by Brumi
Thank you, now I understand :)

Re: AIEngine::GetMaximumOrderDistance

Posted: 01 Nov 2012 11:19
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.

Re: AIEngine::GetMaximumOrderDistance

Posted: 01 Nov 2012 11:31
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