diff options
author | ywang <yw05@forksworld.de> | 2019-12-17 20:11:45 +0100 |
---|---|---|
committer | ywang <yw05@forksworld.de> | 2019-12-17 20:11:45 +0100 |
commit | 6bc8fa44df56d55baa0fa4e244f1f5660559cad7 (patch) | |
tree | d697086feb75dfb6857127f07558aeb038f33cbf | |
parent | f4e3592b5bb6a1a7ad7ccc4fcceec9185fa9ea8a (diff) | |
download | advtrains-6bc8fa44df56d55baa0fa4e244f1f5660559cad7.tar.gz advtrains-6bc8fa44df56d55baa0fa4e244f1f5660559cad7.tar.bz2 advtrains-6bc8fa44df56d55baa0fa4e244f1f5660559cad7.zip |
Consider speed limit; minor improvments
-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 |