diff options
author | ywang <yw05@forksworld.de> | 2019-12-18 16:04:51 +0100 |
---|---|---|
committer | ywang <yw05@forksworld.de> | 2019-12-18 16:04:51 +0100 |
commit | b83dc400f0fffb291c66cb2dd74b8f9810aafd28 (patch) | |
tree | f8496f363b17f6b37352ea9aeb31975afa5dbb7c | |
parent | dae5a07eec6588e44d84c2126f9e483460c25571 (diff) | |
download | advtrains-b83dc400f0fffb291c66cb2dd74b8f9810aafd28.tar.gz advtrains-b83dc400f0fffb291c66cb2dd74b8f9810aafd28.tar.bz2 advtrains-b83dc400f0fffb291c66cb2dd74b8f9810aafd28.zip |
Fix failure to recognize braking
-rw-r--r-- | advtrains/atc.lua | 10 | ||||
-rw-r--r-- | advtrains/trainlogic.lua | 26 |
2 files changed, 28 insertions, 8 deletions
diff --git a/advtrains/atc.lua b/advtrains/atc.lua index fa9f097..c08acb3 100644 --- a/advtrains/atc.lua +++ b/advtrains/atc.lua @@ -186,18 +186,18 @@ end local matchptn={ ["SM"]=function(id, train) train.tarvelocity=train.max_speed + train.atc_brake_target=nil return 2 end, ["S([0-9]+)"]=function(id, train, match) train.tarvelocity=tonumber(match) + train.atc_brake_target=nil return #match+1 end, ["B([0-9]+)"]=function(id, train, match) - if train.velocity>tonumber(match) then - train.atc_brake_target=tonumber(match) - if not train.tarvelocity or train.tarvelocity>train.atc_brake_target then - train.tarvelocity=train.atc_brake_target - end + train.atc_brake_target=tonumber(match) + if not train.tarvelocity or train.tarvelocity>train.atc_brake_target then + train.tarvelocity=train.atc_brake_target end return #match+1 end, diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index a28fadc..8e1ac93 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -368,13 +368,16 @@ function advtrains.train_step_b(id, train, dtime) braketar = 0 emerg = true end + --[[ if braketar and braketar>=trainvelocity then train.atc_brake_target=nil braketar = nil end + ]] --if train.tarvelocity and train.velocity==train.tarvelocity then -- train.tarvelocity = nil --end + --[[ if train.atc_wait_finish then if not train.atc_brake_target and (not train.tarvelocity or train.velocity==train.tarvelocity) then train.atc_wait_finish=nil @@ -389,8 +392,10 @@ function advtrains.train_step_b(id, train, dtime) elseif train.atc_delay then train.atc_delay = nil end + ]] train.ctrl.atc = nil + if train.tarvelocity then train.ctrl.atc = 3 end if train.tarvelocity and train.tarvelocity>trainvelocity then train.ctrl.atc=4 end @@ -405,23 +410,37 @@ function advtrains.train_step_b(id, train, dtime) train.ctrl.atc=2 end end + if train.atc_wait_finish then + if (not train.ctrl.atc) or (train.ctrl.atc<3 and train.tarvelocity>=train.velocity) or (train.ctrl.atc==3) or (train.ctrl.atc>3 and train.velocity>=train.tarvelocity) then + train.atc_wait_finish=nil + end + end + if train.atc_command then + if (not train.atc_delay or train.atc_delay<=0) and not train.atc_wait_finish then + advtrains.atc.execute_atc_command(id, train) + else + train.atc_delay=train.atc_delay-dtime + end + elseif train.atc_delay then + train.atc_delay = nil + end end --if tarvel_cap and train.tarvelocity and tarvel_cap<train.tarvelocity then -- train.tarvelocity=tarvel_cap --end - local tmp_lever = (train.ctrl.user or train.ctrl.atc) or 3 + local tmp_lever = (train.ctrl.atc or train.ctrl.user) or 3 if tarvel_cap then if trainvelocity > tarvel_cap then tmp_lever = 0 elseif trainvelocity == tarvel_cap then - tmp_lever = 3 + tmp_lever = math.min(3, tmp_lever) end end - train.lever = tmp_lever + --train.lever = tmp_lever --- 4a. Calculate movement --- local lzbnxt,lzblever = advtrains.lzb_get_next(train,dtime) @@ -433,6 +452,7 @@ function advtrains.train_step_b(id, train, dtime) 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 + if tmp_lever == 4 and train.tarvelocity then v1=math.min(train.tarvelocity,v1) end local s if a == 0 then s = v1*dtime else |