[2.0.66] Train Manager does not calculate path from departure station

Bugs that are actually features.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 141
Joined: Tue Feb 06, 2024 5:18 am
Contact:

[2.0.66] Train Manager does not calculate path from departure station

Post by hgschmie »

So I have a train. The train is departing a station (wait_station -> on_the_track) and has a path (and a path_end_rail, but not a path_end_station):
Screenshot 2025-09-14 at 08.52.06.png
Screenshot 2025-09-14 at 08.52.06.png (57.48 KiB) Viewed 358 times
If I ask the train manager to calculate the path for the train itself, it works fine:

Code: Select all

game.train_manager.request_train_path {
    train = train,
    goals = { { rail = train.path_end_rail, direction = 0 } },
}
results in { found_path=true, goal_index=1, start_index=1, penalty=4898.2439923066, is_front=true, total_length=4898.2439923066, steps_count=1209, } which is the same that the train has.

But if I ask the same question from the very station that the train has just departed from (this is the station from the previous path that is 'path_end_station':

Code: Select all

game.train_manager.request_train_path {
    starts = {
        {
            rail = train_info.current_station.connected_rail,
            direction = defines.rail_direction.front,
        },
        {
            rail = train_info.current_station.connected_rail,
            direction = defines.rail_direction.back,
        },
    },
    goals = { { rail = train.path_end_rail, direction = 0 } },
}
it fails: { found_path=false, steps_count=3, }

No matter what combination (rail or station) for the starts and goals I use, the train manager does not find a path between the two stations when called from a mod. steps_limit or shortest_path makes no difference. It works fine when the source is a train but not when given starts.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 141
Joined: Tue Feb 06, 2024 5:18 am
Contact:

Re: [2.0.66] Train Manager does not calculate path from departure station

Post by hgschmie »

So it seems there is an explanation to the behavior but I still think it is kind of a bug. The station in question looks like this:
Screenshot 2025-09-14 at 16.43.36.png
Screenshot 2025-09-14 at 16.43.36.png (806.88 KiB) Viewed 325 times
There are two rails. One straight rail that the station is connected to and a curved rail that connects (on the left side) to the same rail on the left as the station rail.

So while the station is connected to a (legacy) straight rail which leads nowhere, there is also a second rail that curves off.

When the train departs the station, it departs on the curved rail! But it will stop at the station even though the actually connected rail has no front connection. It departs the station on a rail different than the connected one.

This seems to be a weird corner case (I would still call it a bug) but I understand that changing it would break station setups (such as mine).

So what is the best way to determine, based on station names, what the path between two stations is? The surprise here (for me) was that the train manager can not find a path between two stations by looking at their connected rails (because the rail connected to the station actually does not have any rail connected to the front), but a train *can* find a path (by "jumping" on the curved rail that is adjacent to the station connected rail and using that as the start of the path).
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4203
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [2.0.66] Train Manager does not calculate path from departure station

Post by boskid »

In that case its not a bug. Train never reaches rail where train stop is connected due to "arrive distance = 2" and as such train can path to places that are not possible from a rail next to a train stop.

-- edit:

Take a look at this setup:


Pathing from train stop A will give you a path to stop B on the right, however short train always goes to middle train stop and long train always goes to the left train stop. There may be more setups like this where trying to path from a train stop's point of view is simply impossible because a train may reach a train stop while having its far end at a position where some train stops are possible that were not possible from starting stop, or may be at a position where some train stops are not possible even when they were possible from starting stop.
Post Reply

Return to “Not a bug”