aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/trainlogic.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 30d2d6a..5f340ac 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -427,25 +427,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