Rivens Train Speed Signs


This mod makes trains respect speed sign values through the circuit network. (youtube demo included)

Content
3 years ago
1.1
3.02K
Trains

g 2.1 Update

4 days ago

Hi again!

Any chance you might consider reviving this mod, or do you know of a good alternative?

I recently came across this one: https://mods.factorio.com/mod/train-speed-limits

I really like the simplicity of its UI, using the existing signal GUI to configure speed limits. After looking through its implementation, though, I got the impression that it's still an early implementation of the idea.

Since I'm already using your other mod, I figured you'd probably be the best person to handle speed limits together with realistic train acceleration.

A bit of a bold request... If you ever decide to update it for Factorio 2.1, would you consider using a similar UI to the mod above? I think combining your implementation with that simple interface would make for a really nice solution.

I know updating an old mod is a lot of work, but since Wube has said that Factorio 2.1 is intended to be the final major version, I thought now might be a good time to ask.

4 days ago

There is an issue with the Factorio mod API regarding rail-signals. You simply cannot reliably detect whether there is a rail-signal attached to a rail. This is rather surprising, but my workaround is to trace the middle of a pair of rails, find the entities along that path, using a small radius area-scan. Then I hopefully catch the signals, which may belong to another rail altogether. Then I check the rail connected to the signal (this works well, it's just that the other way around is broken), and check whether the detected rail is on the track that I was tracing (if not, it may have been a crossing rail). Then you have the issue of which side the signal is on, which is not too trivial, because individual rails have no obvious side (as they don't have a direction), and two-way tracks are ofcourse much harder. You basically have to determine left/right, relatively, based on the orientation of the locomotive which is passing by (which may or may not be driving backwards, flipping the orientation). Anyway, that can all be solved, with a huge UPS cost, so in the end you can almost... reliably detect whether a train passes a signal, which my own mod, and your referenced mod use to permanently set the max speed of the train.

However, this is not how speed limits work. Let's say you have station A and B, after each station, a speed limit is set, say, A' and B'. Now each train will forever have their custom speed limit (saved per train), while in reality, a road-segment has a speed limit, it's not that each car has its own speed limit based on the last speed sign it passed. With this naive approach used in the mods, we can have a train still capped at 10km/h, on the same rails whether other trains can go 200km/h.

Hence the design of both my mod and their mod is all wrong. If you'd want a realistic approach, you'd ideally have to trace logical rail-segments (between signals with defined speed limits), and end speed limits where tracks merge. It would become a logical nightmare, even if the UI would show it. You can look at real-life, where you see a billion speed signs in your daily commute, to define the limit on every segment of the road.

So the current approach is logically deeply flawed, and the proper approach is impossible to manage by the player.

All this even ignores the point that vehicles should not start braking after the speed sign, but ahead of it, and pass it at (at most) the displayed value.

Additionally, multiple mods messing with train-speeds truly leads to instability, as it interferes. Even with one mod, if you set the train speed to 50km/h, the engine will accelerate it each frame, and you have to account for that. So you measure the error, and say, cap it at 49km/h, to end up at 50. This is messy, when you're the only mod. This gets nasty when other mods are changing the acceleration too. So it's best all handled in 1 mod. Hence if I were to consider this, it would be an addition to RRTA, as opposed to this separate mod.

I will have to think how to design this properly though, because everything I considered so far, seems rather bad :)

4 days ago

Oh wow, that is surprising. I would have assumed the API allowed you to hook into the signal-check for a train somehow, or at least determine which signal the train is approaching. It feels like that should be something the game itself has to know in order to handle signals correctly.

It would already be good enough if the train simply started decelerating when it reaches the signal and slowed down to the configured speed. I know that's not particularly realistic, but it's a game, and I think that would be a perfectly reasonable and much simpler implementation. But yeah the detection problem and direction problem feels crazy to me.

I can definitely see how the workaround could become quite expensive in terms of UPS on a huge rail network, especially if you have to constantly scan the track and determine which signal belongs to which rail.

So yeah, maybe it makes sense to let this mod rest for now until you have an answer for the curve braking you're planning for RRTA. If that gives you some useful way to look ahead along the track, maybe it will also make a speed limit implementation more feasible.

And if it turns out that it's simply not practical with the current API, then that's just how it is and I would agree that RRTA has more potential. ;)

New response