From e043a78c9da9200912d08e5b8de94546b48001fa Mon Sep 17 00:00:00 2001 From: ywang Date: Tue, 17 Dec 2019 20:11:45 +0100 Subject: Consider speed limit; minor improvments --- advtrains/trainlogic.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index c46d2d2..7fb0c1b 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -414,8 +414,12 @@ function advtrains.train_step_b(id, train, dtime) --end 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 @@ -429,9 +433,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 -- cgit v1.2.3