diff options
Diffstat (limited to 'advtrains')
-rw-r--r-- | advtrains/trainlogic.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 7999984..a28fadc 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -413,8 +413,12 @@ function advtrains.train_step_b(id, train, dtime) local tmp_lever = (train.ctrl.user or train.ctrl.atc) or 3 - if tarvel_cap and trainvelocity>tarvel_cap then - tmp_lever = 0 + if tarvel_cap then + if trainvelocity > tarvel_cap then + tmp_lever = 0 + elseif trainvelocity == tarvel_cap then + tmp_lever = 3 + end end train.lever = tmp_lever @@ -428,9 +432,13 @@ function advtrains.train_step_b(id, train, dtime) local v1 = a*dtime+v0 v1 = math.min(v1, (train.max_speed or 10)) v1 = math.max(v1, 0) + if tarvel_cap then v1 = math.min(v1, tarvel_cap) end local s if a == 0 then s = v1*dtime - else s = (v1*v1 - v0*v0)/2/a + else + s = (v1*v1 - v0*v0)/2/a + local acctime = (v1-v0)/a + if acctime < dtime then s = s + v1*(dtime - acctime) end end -- FIX: calculate the average acceleration, as if it is static, to avoid -- weird wagon positions |