Rivens Realistic Train Acceleration (based on cargo)


This mod makes train acceleration more realistic and depend on the amount of Cargo. (youtube demo included)

Tweaks
11 months ago
1.1
3.29K
Trains

g [solved] Support for Multiple Unit Train Control

1 year, 8 months ago

I was wondering if you might consider adding support?
https://mods.factorio.com/mod/MultipleUnitTrainControl

With my testing, I think when the locomotives are coupled, the locomotives are replaced with MUTC locomotives.

1 year, 8 months ago
(updated 1 year, 8 months ago)

Hmm, I think it does work with the MUTC mod, by adding it as an optional dependency... at least it seems to be working in my limited testing.

Edit: Upon further testing, while the weight effects work... the MUTC locomotive's power is not doubled, so it runs as a single unit.
The MUTC locomotives get a '-mu' added to their name, I hope you might be able to adjust for that?

Edit 2:
There may be other considerations that I am not aware of, but adding two lines to control.lua seems to resolve the power issue.

function getLocomotiveEngineForceMultiplier(locomotive)
    local protoname = locomotive.name
    if protoname == 'locomotive' then
        return 1.00
    elseif protoname == 'locomotive-mu' then
        return 2.00 -- MUTC
    elseif protoname == 'bob-locomotive-2' then
        return 1.50 -- mk2
1 year, 8 months ago
(updated 1 year, 8 months ago)

Since MUTC supports other modded locomotives (like the new Mini Trains mod), I needed to change it up some. I now check if the last 3 chars are '-mu'. If true, multiply the getLocomotiveEngineForceMultiplier return values by 2.

function getLocomotiveEngineForceMultiplier(locomotive)
    local protoname = locomotive.name
    local multiplier = 1

    if string.find(protoname, '-mu', string.len(protoname) - 3) then
        multiplier = 2
    end

    if protoname == 'locomotive' then
        return 1.00 * multiplier
    elseif protoname == 'bob-locomotive-2' then
        return 1.50 * multiplier -- mk2
1 year, 8 months ago
(updated 1 year, 8 months ago)

And pertaining to the new Mini Trains mod, seems the lighter weight of locomotives makes them a little faster accelerating.

Edit: By making the train weight the same, the Mini Trains do run slower, so maybe all is well.

1 year, 8 months ago
(updated 1 year, 8 months ago)

My mod actually ignores the direction of the locomotive. Some call it a glaring oversight, some call it a feature, others have no strong opinion.

So when your train configuration is like this:
[<<][>>][CARGO][CARGO][CARGO]
then from the perspective of the mod, you already get the acceleration of both locomotives, eventhough the game-engine is only powering 1 locomotive. This is all under the assumption that 2 locomotives with my mod (regardless of their direction), would always be slower than 1 acceleration in vanilla -- which you can pretty much rely on.

So currently my mod behaves the same as the MultipleUnitTrainControl mod, and that mod should (ideally) be disabled, but feel free to 'cheat' :)

1 year, 8 months ago

In v0.1.19 I added this line to function getLocomotiveEngineForceMultiplier(locomotive)

elseif protoname == 'mini-locomotive' then
    return 0.50

to make the mini-locomotive significantly less powerful than a regular locomotive.

1 year, 8 months ago

Yes, the setting the mini trains to half is just about right to me, that was the value I have been testing with.

In my testing with TrainSpeeds 0.1.19 active, I find that:
[<<][<<][CARGO][CARGO][CARGO][CARGO] is faster than [<<][>>][CARGO][CARGO][CARGO][CARGO]

Is that the expected effect?

If I then also enable MUTC and double the multiplier for the '-mu' locomotive, then they will run at exactly the same speed. It was this result that made me think that doubling the multiplier was correct.

I am far removed from being an expert on factorio trains, I am asking out of my ignorance on the subject.

1 year, 8 months ago

Thx! Should be equal. Will look into it tomorrow!

1 year, 8 months ago
(updated 1 year, 8 months ago)

With just TrainSpeeds active:
[<<][>>][CARGO][CARGO][CARGO][CARGO] is equal to [<<][CARGO][CARGO][CARGO][CARGO][CARGO][CARGO]

With this configuration the trains are of equal weight, so I think the second (reversed) locomotive is adding weight but not adding power.

1 year, 8 months ago
(updated 1 year, 8 months ago)
    if global.settings.fuelTypeBasedAcceleration then
        pullingForce = pullingForce * getTrainForceMultiplier(train);
    else
        pullingForce = pullingForce * getLocomotiveCount(train);
    end

I have been testing with fuelTypeBasedAcceleration = true.

Edit: Now with some testing with fuelTypeBasedAcceleration = false (and MUTC disabled), it seems to work pretty close to expected.
[<<][<<][CARGO][CARGO][CARGO][CARGO] is now only a little faster than [<<][>>][CARGO][CARGO][CARGO][CARGO]
And the difference appears to be due to a difference in top speed, the acceleration seems to be equal. I am pleased with the result.

And if I then enable MUTC, they run exactly the same.

1 year, 8 months ago
(updated 1 year, 8 months ago)

I also run with fuelTypeBasedAcceleration=true (which is preferable, IMHO)

But I found the culprit. I calculate the locomotive force based on the fuel that is currently being burnt. (!)

When I create these trains, put fuel in them, and send them on their way:
A: [<<][<<][CARGO][CARGO][CARGO][CARGO]
B: [<<][>>][CARGO][CARGO][CARGO][CARGO]
then A is significantly faster than B, because... the 2nd locomotive of train B has never had a reason to burn anything yet, so the burn-slot is empty, it only has filled fuel-stacks.
So if I move train B back and forth a bit, colloquially known as "the wiggle", it triggers both locomotives to shortly burn fuel, after which train A and B are equally fast (well, >99%).

This is all measured with MUTC disabled. This was the reason of our different observations. I'm not yet sure how to fix it (or if it should be fixed). The workaround is to have the train reverse direction at least once, and after that there will always be something in the burn-slot.

1 year, 8 months ago

With 0.1.20, it seems [<<][<<] is equal to [<<][>>], even without moving in reverse to load the burn-slot of the reversed locomotive. In fact, the reversed locomotive does not need fuel to contribute power. Without fuel, the train runs at an equal speed in the forward direction of the train. Of course, the train can not move in the reverse direction without adding fuel to the reversed locomotive. Also as a note, the fuel consumption remains the same as a single unit... so only half of the amount of fuel is consumed with [<<][>>] verses [<<][<<].

1 year, 8 months ago
(updated 1 year, 8 months ago)

And the above are just my observations. I am not suggesting that a change should be made, in fact, it might cause grief for some folks. MUTC seems compatible, this way folks have a choice how the fuel is handled.

1 year, 8 months ago

I create 3 trains:
- A [<<][<<]CCCC
- B [<<][>>]CCCC (one burn-slot filled)
- C [<<][>>]CCCC (two burn-slots filled, after a wiggle)
I send them off at exactly the same moment, they are waiting on a rail-signal that is forced to be red, by circuit-conditon.

A and C have the same acceleration, B has approximately half of it. This behavior is in line with the code I wrote.

Maybe it's due to you still having:
- fuelTypeBasedAcceleration=false
which disables all the fuel-logic and only looks at the locomotive count.

1 year, 8 months ago

Yes, that was it exactly. I confirm your results.

1 year, 8 months ago

Thx!

New response