{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreid3gdiwj73tznqpxnxtungnoakf5sz647u5ggvzukifgjyalk53yy",
"uri": "at://did:plc:i7budt2wflrcfy6jtvfocbix/app.bsky.feed.post/3mewxi3s42j42"
},
"path": "/viewtopic.php?p=1278083#p1278083",
"publishedAt": "2026-02-15T12:34:49.000Z",
"site": "https://www.tt-forums.net",
"tags": [
"HGus"
],
"textContent": "> I see, what this function does is returns a factor that produces 16 possible directions, this is done by left shift to produce 16 unique numbers, out of which only 12 are needed for rail directions.\n\nNo. Tha function creates a 4-bit flags field with 4 possible directions. But it doesn't matter now, let's focus in the original problem. I figured out the \"undocumented reason\".\n\nThe formula you quoted is:\n\n\nCode:\n\n\n 1067: local dir = (cur_node - par_tile) / parDistance;\n\ncur_node is the tile being evaluated for build, par_tile is its parent in the path. parDistance is the Manhattan distance between. Note that these tiles are always in the same row/column.\n\nparDistance values can be:\n\n\n * 0 (cur_node is the first tile in the path so it doesn't have a parent)\n * 1 (adjacent tiles)\n * MapSizeX (crossing the NW or SE borders)\n * other (bridge heads, tunnel entrances or straight buildable terrain)\n\nAccording to line 1066, dir is only calculated if parDistance is grater than one, as this is integer math a value of MapSizeX gives zero, so the function is aborted in line 1068 (it is in the Japanese comment)\nIf 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\nAnyway, in the next line:\n\n\nCode:\n\n\n 1069: local next_tile = cur_node + dir;\n\nThe adjacent tile in the right direction is obtained. That was the purpose of the math and the answer to your original question.\n\nStatistics: Posted by HGus — 15 Feb 2026 12:34\n\n* * *",
"title": "OpenTTD AIs and Game Scripts • Re: Can somebody teach me tile arithmetic?",
"updatedAt": "2026-02-15T12:34:49.000Z"
}