aboutsummaryrefslogtreecommitdiff
path: root/advtrains/lzb.lua
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2019-12-04 10:19:30 +0100
committerywang <yw05@forksworld.de>2020-04-12 16:07:16 +0200
commite22262a450b58f28d208dbc40d5716d80bf811a6 (patch)
tree3ffe7a8a6fe23832ce2a994ed093fd4b25834854 /advtrains/lzb.lua
parent2db7eab62e4339688a6d6e6613fefbc2d5074170 (diff)
downloadadvtrains-e22262a450b58f28d208dbc40d5716d80bf811a6.tar.gz
advtrains-e22262a450b58f28d208dbc40d5716d80bf811a6.tar.bz2
advtrains-e22262a450b58f28d208dbc40d5716d80bf811a6.zip
Fix problems related to zero
Note: this fix only makes sure that the mod does not throw errors, but there are currently weird behaviors related to trainlogic.
Diffstat (limited to 'advtrains/lzb.lua')
-rw-r--r--advtrains/lzb.lua10
1 files changed, 5 insertions, 5 deletions
diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua
index 461e863..a34c2de 100644
--- a/advtrains/lzb.lua
+++ b/advtrains/lzb.lua
@@ -152,10 +152,12 @@ end
-- Get the distance between the train and the LZB control point
-- If not sure, use 3 as the parameter for lever level.
function advtrains.lzb_get_distance_until_override(id, train, lever)
- if lever == 4 then return nil end -- acceleration can not be forced by LZB
+ if lever == 4 then return nil end
local lzb = train.lzb
local i = 1
local ret = nil -- the value to return
+ local a = advtrains.get_acceleration(train, lever) -- Acceleration
+ local v0 = train.velocity
-- Remove LZB entries that are no longer valid
while i <= #lzb.oncoming do
if lzb.oncoming[i].idx < train.index then
@@ -170,12 +172,10 @@ function advtrains.lzb_get_distance_until_override(id, train, lever)
end
-- Now run through all the LZB entries and find the one that is nearest to the train
for _, it in ipairs(lzb.oncoming) do
- local a = advtrains.get_acceleration(train, lever)
- local v0 = train.velocity
local v1 = it.spd
if v1 and v1 <= v0 then
- if a !~ 0 then local s = (v1*v1-v0*)/2/a else s = 0 end
- local st
+ local s, st
+ if a ~= 0 then s = (v1*v1-v0*v0)/2/a else s = 0 end
if v0 > 3 then st = s + params.ADD_FAST
elseif v0 <= 0 then st = s + params.ADD_STAND
else st = s + params.ADD_SLOW