No Order Trains + Network logic

Got an idea for OpenTTD? Post it here!

Moderator: OpenTTD Developers

Post Reply
Mr X
Engineer
Engineer
Posts: 3
Joined: 04 Nov 2021 12:38

No Order Trains + Network logic

Post by Mr X »

Greetings all.

I made this account to just come ask this, if a dev has the time it would be much appreciated.

In the original TTD if you had a train with 'no orders' this is handled in a special way. It then skips over any path finding logic (since it has no destination) and just moves forward in any open path that is available to it and stops at every station it runs into, picking up and dropping off cargo that is accepted or available. Similar to how you can run buses with no orders, but this doesn't seem to work in OpenTTD.

This opens up a different way of playing the game where you can then focus on building the logic into the network itself, rather than issuing specific orders to trains. This results in a pretty cool dynamic system where if you add many trains to the network you see them all taking seemingly random paths to random stations and its pretty cool to watch. Kind of like a living system or something and you see some funny emergent and complex behaviour that you might not expect. This works fine in the original game, but no longer in OpenTTD.

It should be a very simple change in code, to just skip over any path finding or other logic / orders etc. if it has 'no orders' and just make it go forward instead of to any specific destination. Also remove the 'train is lost' message since it can't be lost if it isn't going anywhere in particular (or add an option to suppress that message in the settings)

Why would you want to do this? Well consider a passenger train network where you have many interconnected stations with bi-directional tracks and signaling. If a station or piece of track is occupied then other trains on the network will take any path that is open to them and skip that station, and you get things moving along without jamming up a huge network. You can build out a complex network and then dump a whole bunch of no order trains onto the network and then just watch them run around, kind of like playing with a train set. This makes the whole track signal thing a whole lot more dynamic and fun to play with imo. and diagnosing problem areas and optimizing things etc. Its just a different way to play the game.

I'll download the source and try to take a stab at it myself but I don't have much time or experience with that kind of thing.. Can it be done with a newgrf script or something? Is there maybe some trick to achieve this that I don't know about?

I can make a small example map to show what I have in mind.. maybe fire up the original game and play it in DosBox for the time being, but yeah 320x200 is a little too nostalgic for my taste D

Sorry for the long winded post.

Cheers
Taschi
Route Supervisor
Route Supervisor
Posts: 425
Joined: 11 Oct 2014 22:58

Re: No Order Trains + Network logic

Post by Taschi »

A train that just randomly wanders across the network could cause horrible deadlocks in complex networks. That is a risk that does not exist for road vehicles.
Eddi
Tycoon
Tycoon
Posts: 8278
Joined: 17 Jan 2007 00:14

Re: No Order Trains + Network logic

Post by Eddi »

i think what you're looking for is a Self-regulating Network
Mr X
Engineer
Engineer
Posts: 3
Joined: 04 Nov 2021 12:38

Re: No Order Trains + Network logic

Post by Mr X »

Taschi wrote: 04 Nov 2021 14:49 A train that just randomly wanders across the network could cause horrible deadlocks in complex networks. That is a risk that does not exist for road vehicles.
Hi Taschi. Well, if you do only one way tracks with junctions that converge or diverge in the same direction then you shouldn't get deadlocks. Designing the network so that things like that won't happen is part of the challenge I think... Trains should always be able to move forward on a one way track, similar to road vehicles that stick to their side of the road. The point of it is to make the network self-regulate, if one part of the network is congested the backed up trains will skip that part of the network and go somewhere else - anywhere else, to whatever random stations are ahead where there is open track ahead. Here is a screenshot to illustrate the problem:
1.jpg
1.jpg (455.25 KiB) Viewed 1973 times
The path to the right (from the trains point of view) is green, yet it won't ever go that way. It would rather sit there for eternity, and auto reversing just makes it stop in front of the red light again. The train has no orders yet it insists on only going on a specific route (still using path finding it seems and going to a specific station, like a series of 'implicit' orders despite having no orders). What I'm suggesting is pretty simple, to treat 'no orders' as a special case where you don't do any kind of path finding at all and have no destination. Instead just go wherever there is open track ahead.

As for the implementation, just check the very next tile of track if it is not blocked and then move forward in that direction, I think that is all it will take.

If its a junction then one way signals can be placed on either side of the junction, so again it just iterates over the very next track tile pieces in front of the train and picks the one that is not blocked.


I'll take a look at the self-regulating network stuff, thanks. I'm not sure if it can do what I want it to, to keep it dynamic and not go to any station or group of stations specifically.

If no-one feels up to it I'll take a look at the source code and tinker a bit, if I get time. If however someone wants to take a shot at it, I'd appreciate it.
User avatar
odisseus
Director
Director
Posts: 579
Joined: 01 Nov 2017 21:19

Re: No Order Trains + Network logic

Post by odisseus »

To achieve the behaviour you want, you need to enable 2-way end of line, which is linked in the SRNW article. No need to modify the source code.

As for the implicit "orders", the are just a record of stations that the train has visited and will presumably visit again. Of course, this is based on the assumption that the train runs in a loop through the same stations over and over. In your case, this assumption doesn't hold, so you may just ignore the implicit orders.
Mr X
Engineer
Engineer
Posts: 3
Joined: 04 Nov 2021 12:38

Re: No Order Trains + Network logic

Post by Mr X »

odisseus wrote: 05 Nov 2021 09:00 To achieve the behaviour you want, you need to enable 2-way end of line, which is linked in the SRNW article. No need to modify the source code.

As for the implicit "orders", the are just a record of stations that the train has visited and will presumably visit again. Of course, this is based on the assumption that the train runs in a loop through the same stations over and over. In your case, this assumption doesn't hold, so you may just ignore the implicit orders.
Thanks odisseus, that worked great.

Ok so for anyone else that might be interested, you edit the openttd.cfg file (in OpenTTD folder under Documents in Windows) and change:
yapf.rail_firstred_twoway_eol = false to yapf.rail_firstred_twoway_eol = true

To suppress the 'train is lost' messages add "lost_train_warn = false" under the [GUI] section

I put the two way signal on the straight piece of track and it will then take the alt route if that section of track is blocked.

Thanks again.
Post Reply

Return to “OpenTTD Suggestions”

Who is online

Users browsing this forum: No registered users and 2 guests