i_like_trains wrote: Sat Apr 11, 2026 2:06 pm
Line 314 suggests that there's a difference between segments and blocks. Seems like a segment is in a block, but there can be multiple segments in a block.
if (neighborSegment->getBlock() != currentSegment->getBlock())
don't trust my wording on this, i linked the code because it's the correct answer, i only have "some" understanding of the principles, when i say "list all the rail" that may very well be what is actually a segment in the game, and thus a block would indeed be composed of several segment (rails).
To me when the path finding algo runs, i imagine the "logic" starts where the locomotive is and look forward as if the locomotives is about to drive in a maze and keep track of the distances of each branch, wether they turn left or right or go straight when given a choice.
If it has 2 loco it does twice the work , it starts 2 of those trees, from the point of view of each loco.
But when mapping such trees, the train isn't allowed to reverse direction, it consider driving "always forward".
The "segment" part i associate as rail adjacency rules, which one ares "neighbours" to each other in the sense of allowing a train to pass from one to another. I think it is at this level that a train isn't able to see a path in the rail that it isn't able to drive through because that would mean reversing direction or turning an impossible angle. ( because when "exploring" it embed train driving rules).
The sum of the segments, makes a block, with "entries" and "exits", which are "linked", not all entries lead to all exits , depending on which direction you enter the block.
I think it is something like A* the pathfinding algo, applied at the "block" level whereas the segment logic is done "before" as a necessary step to create the graph on which the A* (or equivalent) is run.
You probably can tell i'm no expert, i am also curious how things works, and sharing what i think i understand from bits gathered here and there over the years, i think it's not as complicated as graph with states, i think i understand intuitively why this : ""So just because aRb and bRc doesn't mean aRc. "" isn't the way the game logic handle pathinding because i implemented for fun a A* algo in javascript once, with the idea that it was similar to how factorio trains works, to understand better, and when i read the question you ask yourself, i feel it's too complicated but it may be because i'm missing the little details.
Edit : Thanks boskid for the clarifications