Page 1 of 1

Add friction to rails?

Posted: Thu Jan 30, 2020 6:44 pm
by Pi-C
There are raíls and there are rails. The Junk Train mod offers very cheap, but also vulnerable rails, Bio Industries has wooden rails that can be upgraded to the vanilla type, and I guess many more mods have introduced some other rails as well.

Unfortunately, the type of rail doesn't limit what trains can use it. So, you could use a train with super-heavy rolling stock on junk rails and it wouldn't care about the low quality of the rails and go just as fast as on any other. I think I've already asked modders (or even posted here?) about a way to check what kind of track a train is running on and prevent it from using certain rail types. This isn't possible, I've been told, and I agree now that it would put a big toll on any rails-related operation.

However: What if it's not the trains that have to check where they can go, but if the rails could give them some movement penalty? The vehicle prototype has a friction property, and it affects how fast a vehicle can go. Why not apply that to rails as well? Let them have "friction = 0" by default, then mods can set it to, say, "friction = 2000" for really shitty rails, or to "friction = -500" for rails suitable for heavy express trains. Friction values of rails and rolling stock would be added. Any train would still be able to use all rails, but advanced (heavy/extremely fast) trains would profit from using advanced rails (and give you an incentive to update your rails), while junk trains would be able to use the express lanes but would give you an incentive to upgrade your trains because the junk trains are extremely slow by nature (and don't carry much, and are easily destroyed ) and would hold up your other trains.

Would that be a solution, or is there something I haven't considered yet?

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:13 pm
by Olacken
It would be way too calculation heavy to need to get every rail that is under each train to be able to calculate your speed at the next tick.

A track that wouldn't allow certain train to pass on it would be way less calculation heavy since you could just keep track on each block if a train can go there it would probably need a lot of work though so I don't think the dev would implment a way to do it unless they want themself to be able to limit what train can go on what track.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:23 pm
by coppercoil
Olacken wrote:
Thu Jan 30, 2020 8:13 pm
It would be way too calculation heavy to need to get every rail that is under each train to be able to calculate your speed at the next tick.
Mostly, where will be single type rail for entire train, so that's a singe min(,) function. It shouldn't be heavy. Mixed rails may be approximated, say, to the first locomotive experience.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:27 pm
by Pi-C
Last time, the argument was the pathfinder would have trouble determining what rails are accessible to a train. My suggestion wouldn't get in the pathfinder's way, but you're right: checking on each tick what kind of rail a train is driving on may be problematic as well. :-)

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:30 pm
by coppercoil
Pi-C wrote:
Thu Jan 30, 2020 8:27 pm
Last time, the argument was the pathfinder would have trouble determining what rails are accessible to a train.
That's a single multiplier for a segment weight, easy-peasy. It's calculated once, and it doesn't change until railway is modified.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:36 pm
by Olacken
coppercoil wrote:
Thu Jan 30, 2020 8:23 pm
Olacken wrote:
Thu Jan 30, 2020 8:13 pm
It would be way too calculation heavy to need to get every rail that is under each train to be able to calculate your speed at the next tick.
Mostly, where will be single type rail for entire train, so that's a singe min(,) function. It shouldn't be heavy. Mixed rails may be approximated, say, to the first locomotive experience.
Admitting that you still need to get the rail currently under every first locomotive every tick with no caching option whatsoever maybe it's fine but I'm not too sure.
I will admit that if you average it to the block it would probably be fine.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 8:45 pm
by coppercoil
Olacken wrote:
Thu Jan 30, 2020 8:36 pm
Admitting that you still need to get the rail currently under every first locomotive every tick with no caching option whatsoever
Is it a real problem for the locomotive? Do we know that? Actually, we don’t. We may guess, we may suggest, but that’s only exercise for us. We don’t know the internals well. But devs does, and they earn their salary by solving similar questions every day. But yes, we like to solve it too :mrgreen:

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 9:06 pm
by netmand
Pi-C wrote:
Thu Jan 30, 2020 6:44 pm
Would that be a solution, or is there something I haven't considered yet?
You haven't stated a problem this solution addresses. I may have missed it in your descriptions, can you restate it please?

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 9:19 pm
by planetmaker
Neither a problem with the pathfinder is really an argument against allowing some locomotives on certain track types and others not, nor is that an argument against limiting their speed or changing their friction:

Limits of locomotives for certain track types makes some tiles impassible, thus does exclude them from path finding (thus would work similar as a backward signal except in both directions).

Changes to the engine properties like friction or maximum speed, could be considered in the path finder penalty attributed to a tile or segment

What it *would* do is
* increase the number of rail segments, as a change of track type likely best is treated as separate rail segment
* slightly increase the time needed for actually moving an engine as it would need to query the track types ahead in order to adjust its properties (speed, friction, whatever).

Yet... if you want that: play OpenTTD... it uses to my knowledge conceptually an identical path finder ;) Yet this is Factorio and not a train sim... the gain in or use of different track types really is limited. Bridges and tunnels make much more of a difference.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 9:27 pm
by Pi-C
netmand wrote:
Thu Jan 30, 2020 9:06 pm
Pi-C wrote:
Thu Jan 30, 2020 6:44 pm
Would that be a solution, or is there something I haven't considered yet?
You haven't stated a problem this solution addresses. I may have missed it in your descriptions, can you restate it please?
The problem is that, currently, every train can travel over every kind of rail. That keeps the train system "simple" from a developer's perspective, but having too much freedom isn't good for every playstyle. In my opinion, it would make the game even more interesting if there were limitations: e.g. if you could have light railways that can only be served reasonably by small, trains with limited speed and storage place and heavy-duty rails for mass or express transports. Here's a request for just that behavior. My suggestion is aimed at finding a way to make it possible for mods to add such behavior.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 11:19 pm
by netmand
Pi-C wrote:
Thu Jan 30, 2020 9:27 pm
The problem is that, currently, every train can travel over every kind of rail. That keeps the train system "simple" from a developer's perspective, but having too much freedom isn't good for every playstyle. In my opinion, it would make the game even more interesting if there were limitations: e.g. if you could have light railways that can only be served reasonably by small, trains with limited speed and storage place and heavy-duty rails for mass or express transports. Here's a request for just that behavior. My suggestion is aimed at finding a way to make it possible for mods to add such behavior.
Thanks for this. I believe the locomotive and wagons have all of the properties to support a mod of this nature. And you can create your own junky rails.

Re: Add friction to rails?

Posted: Thu Jan 30, 2020 11:31 pm
by Pi-C
netmand wrote:
Thu Jan 30, 2020 11:19 pm
Thanks for this. I believe the locomotive and wagons have all of the properties to support a mod of this nature. And you can create your own junky rails.
Locomotives and wagons have friction already, that's right. But any prototype of rolling stock will always have the same friction. My idea is to add friction of the rails to that of the rolling stock. Vanilla rails would add 0, so nothing would change if you play without mods. But mods could change this to a positive value (i.e. punishing the player for using junk rails because trains would be slowed down) or to a negative value (giving players a reason to upgrade their rails because trains could go faster). For this to work, friction would have to be added to the rail prototypes, though.

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 9:54 am
by BlueTemplar
Negative friction might have weird results like trains forever coasting or spontaneously accelerating without any energy input, etc. Better set vanilla rails to something > 0 ?

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 10:10 am
by planetmaker
BlueTemplar wrote:
Fri Jan 31, 2020 9:54 am
Negative friction might have weird results like trains forever coasting or spontaneously accelerating without any energy input, etc. Better set vanilla rails to something > 0 ?
In some sense you just invented maglev technology :)

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 10:14 am
by Pi-C
BlueTemplar wrote:
Fri Jan 31, 2020 9:54 am
Negative friction might have weird results like trains forever coasting or spontaneously accelerating without any energy input, etc. Better set vanilla rails to something > 0 ?
If vanilla rails were set to friction = x (with x>0), that would add this penalty to all trains, making them slower than intended. Of course, this could be reverted in the vanilla equivalent of data-final-fixes.lua (reduce the friction value of every rolling stock prototype by x; set to 0 if the difference is negative). Likewise, if the sum of rails' and rolling stocks' friction values is negative (by using rails with a huge bonus), it should be set to 0.The question is, what would be an appropriate value for x? It's setting the scale for penalties and bonuses, so that's kind of important. :-)

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 11:51 am
by BlueTemplar
Yeah, Maglev would literally be ~0 friction.
(There's also air friction, which IIRC Factorio models too ?)

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 12:15 pm
by Olacken
Yes but this as nothing to do with rails or at least very little and maglev wouldn't help for that.
What you need for this kind of behavior is a closed tunel where the pressure at the back of the train is higher than at the front or no air at all/very little in front.

And you may already know that but a maglev introduce other forces that could be assimilated to friction in a classic train( though way smaller than friction or air resistance)

Ps: Yes I like to look knowledgeable

Re: Add friction to rails?

Posted: Fri Jan 31, 2020 3:58 pm
by BlueTemplar
Hence the "~" in front of the 0! :P

Ps: Nothing wrong with that ! ;)