Train Speed Limit deprecated


Introduces configurable speed limit signs for trains. Updated for 0.18 compatibility.

Content
4 years ago
0.18 - 1.1
2.35K
Trains

g Braking distance too long

2 years ago
(updated 2 years ago)

When I place these signs inside my base the trains take much too long to get to the allowed distance. The braking should be BEFORE and not AFTER the sign. If this is technically to difficult then a "immediately set train speed to speed limit" option would be cool. Of course only for trains which are faster then the speed limit.

2 years ago

Yes, that would be nice.
Unfortunately I have no idea how to do that (For me it is even a challenge to add a new item). I have only updated this mod, because the original mod author has not done it anymore.
sorry

2 years ago

I double checked the code. In the control.lua you find the decelleration factors. If you simply multiply them by 10 via "*10" in all 3 lines then the trains should decellerate 10 times faster instead of SLOOOOWLY braking until speed limit reached.

2 years ago

I tried modifying the code that way. But this leads to errors because the math turns around the train during driving which is not allowed (and not wished...) Thus its a bit more complicated to code.

2 years ago

Now got it to work.

I had to change the code to this:

-- decelerate the train if needed
if twrap.limit and twrap.train.speed ~= 0 and shouldBrakeTrain(twrap.train, twrap.limit) then
local decel = calcDeceleration(twrap.train)

            if twrap.train.speed > 0 then
                if (twrap.train.speed - decel) > 0 then
                    twrap.train.speed = math.max(twrap.train.speed - decel, twrap.limit)
                else
                    twrap.train.speed = twrap.limit
                end
            else
                if (twrap.train.speed + decel) < 0 then
                    twrap.train.speed = math.min(twrap.train.speed + decel, -twrap.limit)
                else
                    twrap.train.speed = -twrap.limit
                end
            end
        end

And to this:

function calcDeceleration(train)
local abs_speed = math.abs(train.speed)
local factor = 1

if isTrainArriving(train) then
    factor = 0.75
end

factor = factor * 10.0 -- line added to decellerate much quicker

if abs_speed > 0.6 then
    factor = 0.005*factor
elseif abs_speed > 0.3 then
    factor =  0.0075*factor
else
    factor = 0.01*factor
end

return math.min(1, factor)

end

I will fork your mod and enter those changes there since not everybody will like this change. This leads to unrealistically hard braking trains.

2 years ago

I uploaded the fork with the above mentioned changed code here: https://mods.factorio.com/mod/SpeedLimitSignsForTrains

New response