Option to allow long trains to work reliably with roundabouts

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

smcpeak
Burner Inserter
Burner Inserter
Posts: 17
Joined: Tue Dec 05, 2017 7:50 am
Contact:

Option to allow long trains to work reliably with roundabouts

Post by smcpeak »

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.
example of a train colliding in a roundabout
example of a train colliding in a roundabout
loop-crash.jpg (432.69 KiB) Viewed 229 times
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:
There are no easy solutions to make trains pathfinder not find paths that would cross themselves given certain train length
I think this refers to the potential problem of a self-intersecting path that is passable only by short trains:
self intersection, safety depends on train length
self intersection, safety depends on train length
self-intersect.jpg (310.3 KiB) Viewed 229 times
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:
loop with two stations, block reuse required
loop with two stations, block reuse required
two-station-loop.jpg (123.29 KiB) Viewed 229 times
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;
The "continue" here means there is currently no additional penalty for a train that wants to drive onto a segment it currently occupies (whereas the code afterward adds a penalty for using a segment that has some other train currently on it). The option I'm asking for could be implemented as a user-controllable boolean that chooses between a penalty value of zero (the current behavior) and a large one. For maximum reliability, the penalty should be large enough to be disuasive even if multiple other trains are blocking the non-self-intersecting path.
Attachments
train_self_collision.zip
reproducer of repath collision
(4.75 MiB) Downloaded 5 times
computeraddict
Filter Inserter
Filter Inserter
Posts: 430
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Option to allow long trains to work reliably with roundabouts

Post by computeraddict »

A minimal example of a self-deadlocking setup if the "never pass red signal" rule is applied, that is avoided with current logic. The train in this example is short enough that it will not self-collide, but the proposed pathing logic would deadlock it anyway.
04-10-2026, 22-39-04.png
04-10-2026, 22-39-04.png (2.72 MiB) Viewed 191 times
Kyralessa
Filter Inserter
Filter Inserter
Posts: 849
Joined: Thu Sep 29, 2016 5:58 pm
Contact:

Re: Option to allow long trains to work reliably with roundabouts

Post by Kyralessa »

This seems like kind of a "Doctor, it hurts if I do this" issue.

You're creating track that crosses itself, and then creating a train long enough to hit itself, and then asking how this can be prevented.

Maybe by creating longer track or a shorter train?
Rseding91
Factorio Staff
Factorio Staff
Posts: 16704
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Option to allow long trains to work reliably with roundabouts

Post by Rseding91 »

I think there has been a misunderstanding with this; if there was a way for us to make this work (that didn’t have terrible performance) we already would have done it. So, asking for an option to something that as far as we know isn’t possible … isn’t possible.
If you want to get ahold of me I'm almost always on Discord.
smcpeak
Burner Inserter
Burner Inserter
Posts: 17
Joined: Tue Dec 05, 2017 7:50 am
Contact:

Re: Option to allow long trains to work reliably with roundabouts

Post by smcpeak »

Could you explain why the cost adjustment I suggested won't work?
Post Reply

Return to “Ideas and Suggestions”