aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2019-12-05 22:38:18 +0100
committerywang <yw05@forksworld.de>2020-04-12 16:07:16 +0200
commita86677b42fc37c59c9297baa567a7e1d68660d4f (patch)
treefd5cd25082a72f57489d127069f9a45a79175b7d
parentbe22775cdbefa54fa4047d32428ce7d80c15bc5b (diff)
downloadadvtrains-a86677b42fc37c59c9297baa567a7e1d68660d4f.tar.gz
advtrains-a86677b42fc37c59c9297baa567a7e1d68660d4f.tar.bz2
advtrains-a86677b42fc37c59c9297baa567a7e1d68660d4f.zip
Fix minor bugs
-rw-r--r--advtrains/trainlogic.lua8
1 files changed, 8 insertions, 0 deletions
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