[GUIDE] Routing Restrictions: building an overtake lane

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
Gliptal
Engineer
Engineer
Posts: 82
Joined: 01 Dec 2013 01:11

[GUIDE] Routing Restrictions: building an overtake lane

Post by Gliptal »

This is for everyone that would like to leverage the Routing Restrictions patch (you can find it in JGR's Patch Pack), but isn't doing so due to lack of documentation or examples.

We will build an overtake lane, i.e. a simple track layout that allows faster trains to overtake slower trains. The idea of this guide is to present an easy solution to a common problem (trains overtaking), and at the same time get players started with Routing Restrictions. As such, there may be better ways to do this, with or without the patch.

Let's start with the overall situation.

Image

And the basic layout. 6 tiles signal spacing is used here, but any value should work.

Image

Red tracks will be the overtake lanes, blue tracks will be the lanes used by the slower trains. This is slightly counterintuive (overtaking on the inside rather than the outside), but it keeps fast trains on the main line and makes the signal programming more understandable.

Image

We first implement the overtaking aspect of the system. This means forcing trains slower than a threshold (112 km/h in our case) to the outer lanes. We do this by restricting the inner lane route: the two signals marked in red Deny the overtaking lane to all trains whose max speed < 112 km/h (ignore the Long reserve for now); this forces slower trains to take the only other available lane. Note the inversion of control: the inner lane signals control what trains go the the outer lane, and vice-versa.

Image

What happens though if the slower train is only slightly slower than the faster one, or if the latter is too much behind than the former when they both reach the overtaking area? For example, the slow train (in red) will reenter the main line before the faster train (in blue) had any chance to overtake it.

Image

We solve this by reserving a path through the whole overtaking lane for the faster train to use. Reserving the track up until the first signal not in the layout (reserving in grey) means that any train in the outer lane (in red) will have to stop at the last signal and wait for any trains within the overtaking lane to pass.

Image

We do this with the Long reserve command: this tells YAPF that the path should be reserved up to the following signal, instead of stopping at the current one. Chaining the signals within the overtake lane implements exactly the behaviour we wanted.

Image

Now another problem arises: if two fast trains are closely following each other, the one behind will take the slow lane because YAPF sees that lane as free.

Image

We avoid this by denying entry to the overtake lane to all trains faster than the threshold speed.

Image

This layout scales well, and works wonderfully with most other features (like the improved breakdowns patch). You can also have overtaking lanes on your overtaking lanes, with different speed tiers. Also keep in mind this example was done with a speed acting as the deciding threshold, but you can use any property provided by the patch: e.g. give priority to full trains over half empty ones, passengers over freight, express over local, and so on.
Kruemelchen
Transport Coordinator
Transport Coordinator
Posts: 287
Joined: 18 Feb 2017 17:47

Re: [GUIDE] Routing Restrictions: building an overtake lane

Post by Kruemelchen »

Thank you for the great explanation on how to use Routing Restriction on an example :)
Maybe it will help introduce this awesome feature to whom by now was clueless how to use it effectively.

Myself I haven't thought of laying out the overtake track in the middle, but on the contrary it's a great and realistic idea to do so. Thank you for sharing this, I think I'll introduce this to my track layouts as well :mrgreen:

Maybe some additions on my behalf, I rarely use 'allow' and 'forbid' in my layouts, but use a 'pathfinding penalty' to dynamically force trains to their tracks. The advantage of that is, that a medium fast train can overtake a slow train, but a fast one can overtake both. Your track layout is nevertheless totally efficient for use of two train classes, slow and fast.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: peter1138 and 10 guests