Hi,
I was trying to solve a train balancing issue, but sadly my solution didn't work and it's got me curious about a confusing train mechanic.
Suppose two trains both have the same destination station, and are waiting for it to have space. When the destination finally gets space, which one should win the race? I think I would expect it to either be the closest as defined at https://wiki.factorio.com/Railway/Train_path_finding, or the one that started waiting first, but I'm seeing counterexamples to both theories. Happy to share more details on my experiments but thought I'd check if people know what should happen first...
An example, with a signal set to red by control signal meaning the right train should be "closer" but the left train seems to win.
Train order when waiting for destination space
Re: Train order when waiting for destination space
Trains search for the closest available stops. They don't look at any other trains when they do this, and stops do not "look" for trains in any way. The trains are processed in arbitrary determistic order (probably sorted by Train ID, so the one that was built is processed goes first).
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Re: Train order when waiting for destination space
As far as I understand the wiki information as well as observation of the game, trains are choosing their destination, not stations are choosing their trains.
It is documented, that whenever a train is choosing a destination, all destinations with the same station name are eligible, and the nearest one is chosen.
It is nowhere mentioned something special will happen if a station gets an unused reservation slot. It just becomes available, and that's that.
Instead, as one step in tick processing, the game iterates over the list of all trains with no destination. The pathfinding for each train is started, and if found a destination, the train is assigned this destination. It may happen the slot just freed is then occupied again, if there was a train whose pathfinding found that station. Which train it was depends on the position in the list of trains - essentially, random.
Trains choose the nearest destination.
Stations don't choose the nearest train - they don't choose at all.
It is documented, that whenever a train is choosing a destination, all destinations with the same station name are eligible, and the nearest one is chosen.
It is nowhere mentioned something special will happen if a station gets an unused reservation slot. It just becomes available, and that's that.
Instead, as one step in tick processing, the game iterates over the list of all trains with no destination. The pathfinding for each train is started, and if found a destination, the train is assigned this destination. It may happen the slot just freed is then occupied again, if there was a train whose pathfinding found that station. Which train it was depends on the position in the list of trains - essentially, random.
Trains choose the nearest destination.
Stations don't choose the nearest train - they don't choose at all.
Re: Train order when waiting for destination space
Hmm, interesting. That's a little surprising, but I guess I can work around it. Thank you for the quick responses!
Re: Train order when waiting for destination space
"Closest" here means as the crow flies, not train pathfinding
Or at least it did the last time I saw someone run this experiment, which was years ago.
Or at least it did the last time I saw someone run this experiment, which was years ago.