aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2020-01-12 17:40:22 +0100
committerywang <yw05@forksworld.de>2020-01-12 17:40:22 +0100
commit2dd280b93146fad9edca072a1ccdeb2b7b979691 (patch)
tree0ab117c495a4ec6f5780860c0572945b46c8d626
parent1b24fb775736799d9cdb05b2bc4e43e0f783f94d (diff)
downloadadvtrains-2dd280b93146fad9edca072a1ccdeb2b7b979691.tar.gz
advtrains-2dd280b93146fad9edca072a1ccdeb2b7b979691.tar.bz2
advtrains-2dd280b93146fad9edca072a1ccdeb2b7b979691.zip
Fix bug with Point Speed Restriction Rail
-rw-r--r--advtrains/lzb.lua23
-rw-r--r--advtrains/trainlogic.lua1
2 files changed, 17 insertions, 7 deletions
diff --git a/advtrains/lzb.lua b/advtrains/lzb.lua
index 2574c51..794ad42 100644
--- a/advtrains/lzb.lua
+++ b/advtrains/lzb.lua
@@ -87,20 +87,29 @@ end
s = v0 * t + ---
2
]]
+function advtrains.lzb_get_limit_zone(train, lzb, lever, vel)
+ local lvr = lever or train.lever
+ local v0 = vel or train.velocity
+ local v1 = lzb.spd
+ local s = (v1*v1-v0*v0)/2/advtrains.get_acceleration(train, 1)
+ if v0 > 3 then s = s + params.ADD_FAST
+ elseif v0 <= 0 then s = s + params.ADD_STAND
+ else s = s + params.ADD_SLOW
+ end
+ if lvr >= 2 then s = s + params.ZONE_HOLD end
+ if lvr >= 3 then s = s + params.ZONE_ROLL end
+ return advtrains.path_get_index_by_offset(train, lzb.idx, -s)
+end
+
function advtrains.lzb_get_limit_by_entry(train, lzb, dtime)
if not (type(lzb)=="table") then return nil end
local getacc = advtrains.get_acceleration
local v0 = train.velocity
local v1 = lzb.spd
- local s = (v1*v1-v0*v0)/2/getacc(train,1)
local t = dtime or 0.2
- local i = advtrains.path_get_index_by_offset(train, lzb.idx, -s)
- if v0 > 3 then i = advtrains.path_get_index_by_offset(train, i, -params.ADD_FAST)
- elseif v0 <= 0 then i = advtrains.path_get_index_by_offset(train, i, -params.ADD_STAND)
- else i = advtrains.path_get_index_by_offset(train, i, -params.ADD_SLOW) end
- i = advtrains.path_get_index_by_offset(train, i, -params.ZONE_ROLL)
- i = advtrains.path_get_index_by_offset(train, i, -params.ZONE_HOLD)
+ local i = advtrains.lzb_get_limit_zone(train, lzb, 4, v0 + getacc(train,4))
if train.index + v0*t + getacc(train,4)*t*t/2 <= i then return 4 end
+ i = advtrains.lzb_get_limit_zone(train, lzb, 3, v0)
if train.index + v0*t <= i then return 3 end
i = advtrains.path_get_index_by_offset(train, i, params.ZONE_HOLD)
if train.index + v0*t + getacc(train,2)*t*t/2 <= i then return 2 end
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 8e1ac93..886abe8 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -457,6 +457,7 @@ function advtrains.train_step_b(id, train, dtime)
if a == 0 then s = v1*dtime
else
s = (v1*v1 - v0*v0)/2/a
+ s = math.max(s, 0)
local acctime = (v1-v0)/a
if acctime < dtime then s = s + v1*(dtime - acctime) end
end