High speed train driving

Place to get help with not working mods / modding interface.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

High speed train driving

Post by DaveMcW »

I am using this function to "manually" drive a train.

Code: Select all

function on_tick_driver(driver, direction)
  driver.riding_state = {
    acceleration = defines.riding.acceleration.accelerating,
    direction = direction,
  }
end
It works great for vanilla train speeds. But for very fast trains, it is possible to drive past several branches in a single tick. Is there any way to queue up several riding commands in a single tick?

If not, what is the theoretical max train speed I can handle before this breaks down?
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: High speed train driving

Post by DaveMcW »

DaveMcW wrote: Fri May 31, 2019 8:40 amIf not, what is the theoretical max train speed I can handle before this breaks down?
I did some investigation into this, and found three limiting examples. Let me know if I missed any!

Example 1

In this example, driving north, the three possible paths are:
  • Left
  • Straight + Left
  • Straight + Straight + Left
If a manually controlled train wants to take the middle path, it must hold straight for exactly 2 tiles, then left. This becomes impossible at speeds over 2 tiles/tick.

3-left.jpg
3-left.jpg (273.72 KiB) Viewed 501 times

Example 2

In this example, driving northwest, the three possible paths are:
  • Left
  • Straight + Straight + Left
  • Straight + Straight + Straight + Straight + Left
Diagonal rails are only √2 tiles long, but there are two of them between each turn. If a manually controlled train wants to take the middle path, it must hold straight for exactly 2√2 tiles, then left. This becomes impossible at speeds over 2.8284 tiles/tick.

3-left-diagonal.jpg
3-left-diagonal.jpg (317.82 KiB) Viewed 501 times

Example 3

In this example, driving northwest, the three possible paths are:
  • Right
  • Straight + Left
  • Straight + Straight + Right
If a manually controlled train wants to turn left, it should hold straight for exactly √2 tiles, then left. Correct? Wrong! It can hold left the entire time, because left is not an option on the first straight track! This reduces the problem to the previous case, where it only becomes impossible at speeds over 2.8284 tiles/tick.

right-left-right.jpg
right-left-right.jpg (316.15 KiB) Viewed 501 times

Conclusion

The minimum limit is Example 1. Manual driving works perfectly at speeds up to 2 tiles/tick (432 km/h), and after that it starts to fail. On diagonal tracks, you need to start turning 1 track early at speeds over 1.41 tiles/tick (305 km/h).
Post Reply

Return to “Modding help”