OpenTTD / OpenTTD/OpenTTD

[Bug]: Train waits for free path when it doesn't have to

Open
#11,340 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: pathfinder
Dominant language
C++
Stars
8.3k
Forks
1.3k
Avg merge
1d 20h
Merged PRs (30d)
37

Description

Version of OpenTTD

13.4, Windows 11

Expected result

If there are two ways a train can go that are equally long but one is occupied by another train, the train should choose the one that's free. For example, in the following screenshot, the train should go along the red arrow:

Skärmbild 2023-09-28 213004
Actual result

The train waits for the occupied path to be free. For example, in the following screenshot, it wants to go along the red arrow, but that path is occupied so it's waiting for a free path instead of using the path that's already free:

Skärmbild 2023-09-28 213004

Note that there is a signal under the bridge in the middle track for trains going the other way, but that allows trains to go through it both ways (if it's not clear what I mean, you can download the saved game below and see for yourself). Removing the signal solves the issue. But normally occupied tracks have a higher penalty than tracks with a signal going the other way, so I don't see why that shouldn't be the case here.

Steps to reproduce
  1. Download and open this saved game: Stora Miggsvall Transport (no newgrf).zip (sorry it's in a zip file but GitHub refuses to let me upload .sav files)
  2. Look at train 9. It's on its way to Fomberg (which is in the direction the red arrows are pointing in the screenshot above), so obviously the best way to go is to use the middle track. The problem is that it's trying to use the track that train 17 is on, so it has to wait for train 17 to move, which itself has to wait for train 15 to move, which will take a while. I
    In this case I stopped train 15 to make it easier to see the problem before it goes away, but earlier train 15, which is on a schedule, was stopped at Kröndlöv Kalkbruk for a while to wait for its schedule, so train 9 has been sitting there for a while for no reason. The entire reason I built the middle track was to avoid situations like this, so it's annoying it didn't work.
  3. You can try removing the signal under the bridge on the middle track and then train 9 will use it, which shows that the signal is the problem.
  4. You can also try un-electrifying the track that train 17 is on and then train 9 will also use the middle track, which proves that it can, it's just not willing to pass through the signal if it doesn't have to (even if this means waiting for a long time for the other track to be free).
  5. If you try to un-stop train 15 so that train 17 can pass, train 9 will use the middle track as expected as soon as train 17 moves. So it seems like it's not entirely unwilling to use the middle track, it just waited for train 17 to move for some reason.

What's even more weird is that if I wait a while for train 75 to arrive in this area (train 75 is headed in the same direction as train 9), train 75 uses the middle track through Kröndlöv station and then continues on the middle track to pass train 17 just as it should, which train 9 isn't doing for some reason.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Load the supplied saved game and reproduce the routing decision with trains 9, 17, 15, and 75, focusing on the signal under the bridge. Trace the pathfinding choice when an equally long route is occupied; done means train 9 selects the free middle track without requiring the other train to move.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.