External Publication
Visit Post

OpenTTD AIs and Game Scripts • Re: Can somebody teach me tile arithmetic?

Transport Tycoon Forums - Index page [Unofficial] February 15, 2026
Source

If the tiles are in the X direction, then dir equals to 1 * sign(cur_node - par_tile), if they are in the Y direction, multiply that by MapSizeX

I definitely understand now, when current tile index is substracted from parent tile index we get either +1 or -1 for X axis or mapsizeX for Y axis, divided by distance it gives tile index next to current tile. So the result can be called either direction or index.

This formula seems to be enough for tile arithmetic since diagonal neighbors are not used for path finding, although it's possible to derive one.

I just tried with calculator and this is impressive, thanks for help.

Statistics: Posted by GoldMine — 15 Feb 2026 15:45


Discussion in the ATmosphere

Loading comments...