From a404f83ebb6aa26b16e56debc2d6d86f52df680e Mon Sep 17 00:00:00 2001 From: ywang Date: Sat, 7 Dec 2019 16:48:19 +0100 Subject: Improved quadratic function solver; added wrapper for math.sqrt() --- advtrains/trainlogic.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'advtrains/trainlogic.lua') diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 5f340ac..441a11a 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -433,7 +433,7 @@ function advtrains.train_step_b(id, train, dtime) else s = (v1*v1 - v0*v0)/2/a end train.ctrl.lzb = nil - if lzblimit.velocity and lzblimit.velocity < train.velocity then + if lzblimit.velocity and lzblimit.lever < train.lever then tmp_lever = lzblimit.lever while (lzbmap[tmp_lever].t > dtime) do tmp_lever = tmp_lever - 1 @@ -456,7 +456,7 @@ function advtrains.train_step_b(id, train, dtime) 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 + local distance = pdist == 0 and s or s / pdist train.lever = tmp_lever train.velocity = v1 train.acceleration = a -- cgit v1.2.3