diff options
author | ywang <yw05@forksworld.de> | 2019-12-18 16:04:51 +0100 |
---|---|---|
committer | ywang <yw05@forksworld.de> | 2020-04-12 16:07:56 +0200 |
commit | ba91ba810943fffc20b841ee9a751ec159f18cd8 (patch) | |
tree | d40b2c8ca9f4ea8e16b2b44311237a2769da9f76 | |
parent | 314ed9aa0b4367ed1fc0df5f4b334745b2469df5 (diff) | |
download | advtrains-ba91ba810943fffc20b841ee9a751ec159f18cd8.tar.gz advtrains-ba91ba810943fffc20b841ee9a751ec159f18cd8.tar.bz2 advtrains-ba91ba810943fffc20b841ee9a751ec159f18cd8.zip |
Fix failure to recognize braking
-rw-r--r-- | advtrains/atc.lua | 10 | ||||
-rw-r--r-- | advtrains/trainlogic.lua | 27 |
2 files changed, 29 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 7fb0c1b..5c52ad4 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -370,13 +370,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 @@ -391,8 +394,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 @@ -407,22 +412,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) @@ -434,6 +454,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 |