Option to allow long trains to work reliably with roundabouts
Posted: Sat Apr 11, 2026 4:28 am
TL;DR
Currently, a train longer than the circumference of a roundabout can collide with itself. Provide an option to prevent that.What?
Currently, if a long train repaths at just the right moment while in a roundabout, it can choose a new path that will collide with itself. I would like an option to change train pathfinding to not do that, so they can reliably use such intersections.See the attached save game file for a reproducer (from which the screenshot is taken). Load the save, instruct the train near the "Before Trigger" station to advance to that station, and around 20 seconds later a train will collide with itself in the roundabout.
With the requested option enabled, the train would (in this case) instead continue on the path it originally selected, and hence wait for the other blocking train to move.
Why?
In a large factory, long trains are very useful for scale and efficiency since the throughput scales almost linearly with the average train length. Roundabouts are very simple and economical to build, and offer the flexibility of allowing trains to turn around. Whether or not you agree with the factory design tradeoffs, both represent sensible options the player should be allowed to play with, but the current behavior makes them unreliable to use together.Furthermore, this isn't just a problem with roundabouts, although they are the most common cause. With sufficiently long trains (50+ loco/wagons), there will virtually always be a self-intersecting path somewhere in the network that could lead to a collision, and no good way to find and eliminate them all pre-emptively.
This problem has been reported many times, including recently by me (133314), with 77759 being the canonical dupe target, but the developers say the game is working as intended. Thus I'm asking for an option to change that.
How?
In 77759, boskid explains the reason for the current behavior:I think this refers to the potential problem of a self-intersecting path that is passable only by short trains:There are no easy solutions to make trains pathfinder not find paths that would cross themselves given certain train length
Indeed, I can see how pathfinding could be expensive and complicated if it is supposed to distinguish between safe and unsafe self-intersecting paths.
Additionally, while it is tempting to simply say that pathfinding should just refuse to make a path that uses any block more than once (effectively treating every train as if it had infinite length), there is then a potential problem with networks like this loop:
Here, the train has plotted a path that takes it back to the segment it is already on (its starting and ending segments are the same, albeit with a waypoint between), and this sort of rail network design should be supported, rather than causing a "no path" alert.
Consequently, I suggest adding a large but finite penalty for a train to enter a segment it already occupies. The train pathfinding code is posted at https://gist.github.com/Rseding91/c0d4d ... 3f6c6a8fe6 and has this check:
Code: Select all
// Add some cost to the path depending on what are the trains doing in the block
if (neighborSegment->getBlock() != currentSegment->getBlock())
{
for (auto& item : neighborSegment->getBlock()->getTrainsInBlock())
{
const Train* neighbourTrain = item.first;
if (neighbourTrain == request.train) // <----- HERE
continue;