aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2019-12-17 20:11:45 +0100
committerywang <yw05@forksworld.de>2020-04-12 16:07:16 +0200
commite043a78c9da9200912d08e5b8de94546b48001fa (patch)
tree6c5cf22cac4e2436fc7e078d5b8a469351111fe5 /advtrains
parentcaf53fbafb751eb25983ac9a31882bfbb7f47e58 (diff)
downloadadvtrains-e043a78c9da9200912d08e5b8de94546b48001fa.tar.gz
advtrains-e043a78c9da9200912d08e5b8de94546b48001fa.tar.bz2
advtrains-e043a78c9da9200912d08e5b8de94546b48001fa.zip
Consider speed limit; minor improvments
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/trainlogic.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index c46d2d2..7fb0c1b 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -414,8 +414,12 @@ function advtrains.train_step_b(id, train, dtime)
--end
local tmp_lever = (train.ctrl.user or train.ctrl.atc) or 3
- if tarvel_cap and trainvelocity>tarvel_cap then
- tmp_lever = 0
+ if tarvel_cap then
+ if trainvelocity > tarvel_cap then
+ tmp_lever = 0
+ elseif trainvelocity == tarvel_cap then
+ tmp_lever = 3
+ end
end
train.lever = tmp_lever
@@ -429,9 +433,13 @@ function advtrains.train_step_b(id, train, dtime)
local v1 = a*dtime+v0
v1 = math.min(v1, (train.max_speed or 10))
v1 = math.max(v1, 0)
+ if tarvel_cap then v1 = math.min(v1, tarvel_cap) end
local s
if a == 0 then s = v1*dtime
- else s = (v1*v1 - v0*v0)/2/a
+ else
+ s = (v1*v1 - v0*v0)/2/a
+ local acctime = (v1-v0)/a
+ if acctime < dtime then s = s + v1*(dtime - acctime) end
end
-- FIX: calculate the average acceleration, as if it is static, to avoid
-- weird wagon positions