From a86677b42fc37c59c9297baa567a7e1d68660d4f Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 5 Dec 2019 22:38:18 +0100 Subject: Fix minor bugs --- advtrains/trainlogic.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 4b76deb..7e9a613 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -428,25 +428,33 @@ function advtrains.train_step_b(id, train, dtime) local v0 = train.velocity local v1 = a*dtime+v0 v1 = math.min(v1, (train.max_speed or 10)) + v1 = math.max(v1, 0) local s if a == 0 then s = v1*dtime else s = (v1*v1 - v0*v0)/2/a end + train.ctrl.lzb = nil if lzblimit.velocity and lzblimit.velocity < train.velocity then tmp_lever = lzblimit.lever while (lzbmap[tmp_lever].t > dtime) do tmp_lever = tmp_lever - 1 end + train.ctrl.lzb = tmp_lever a = advtrains.get_acceleration(train, tmp_lever) v0 = lzbmap[tmp_lever].v t = dtime - lzbmap[tmp_lever].t v1 = a*t+v0 v1 = math.min(v1, (train.max_speed or 10)) + v1 = math.max(v1, 0) s = lzbmap[tmp_lever].i - train.index if a == 0 then s = s + v1*t else s = s + (v1*v1-v0*v0)/2/a end end + -- FIX: calculate the average acceleration, as if it is static, to avoid + -- weird wagon positions + -- Since v0 might have been changed, we should use train.velocity instead. + a = (v1 - train.velocity)/dtime --- 4b. Move train and update train properties --- local pdist = train.path_dist[math.floor(train.index)] or 1 local distance = s / pdist -- cgit v1.2.3