diff options
author | Singularis <singularis@volny.cz> | 2025-04-21 07:21:53 +0200 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-05-27 20:22:01 +0200 |
commit | 95a5586e0fe196e2291acaf128b8d1b4f8a32510 (patch) | |
tree | 6cc5ff9a64e533c8d9262f965e2246dfa2b3da24 /advtrains_interlocking/ars.lua | |
parent | 1d6913cec797b3848c93e8c6b16c3b6b2711d38c (diff) | |
download | advtrains-95a5586e0fe196e2291acaf128b8d1b4f8a32510.tar.gz advtrains-95a5586e0fe196e2291acaf128b8d1b4f8a32510.tar.bz2 advtrains-95a5586e0fe196e2291acaf128b8d1b4f8a32510.zip |
[advtrains] přechod na Advtrains 2.5.0 (první pokus)
- [ch_core/lib] drobná oprava
- [advtrains_attachment_offset_patch] použití initial_properties
Diffstat (limited to 'advtrains_interlocking/ars.lua')
-rw-r--r-- | advtrains_interlocking/ars.lua | 68 |
1 files changed, 44 insertions, 24 deletions
diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua index 4f50df9..eb10497 100644 --- a/advtrains_interlocking/ars.lua +++ b/advtrains_interlocking/ars.lua @@ -52,7 +52,7 @@ function il.ars_to_text(arstab) end function il.text_to_ars(t) - if t=="" then + if not string.match(t, "%S+") then return nil elseif t=="*" then return {default=true} @@ -129,29 +129,49 @@ function il.ars_check_rule_match(ars, train) return nil end -function advtrains.interlocking.ars_check(sigd, train) - local tcbs = il.db.get_tcbs(sigd) - if not tcbs or not tcbs.routes then return end - - if tcbs.ars_disabled or tcbs.ars_ignore_next then - -- No-ARS mode of signal. - -- ignore... - -- Note: ars_ignore_next is set by signalling formspec when route is cancelled - tcbs.ars_ignore_next = nil - return - end - - if tcbs.routeset then - -- ARS is not in effect when a route is already set - -- just "punch" routesetting, just in case callback got lost. - minetest.after(0, il.route.update_route, sigd, tcbs, nil, nil) - return +function advtrains.interlocking.ars_check(signalpos, train, trig_from_dst) + -- check for distant signal + -- this whole check must be delayed until after the route setting has taken place, + -- because before that the distant signal is yet unknown + if not trig_from_dst then + minetest.after(0.5, function() + -- does signal have dst? + local _, remote = il.signal.get_aspect(signalpos) + if remote then + advtrains.interlocking.ars_check(remote, train, true) + end + end) end - - local rteid = find_rtematch(tcbs.routes, train) - if rteid then - --delay routesetting, it should not occur inside train step - -- using after here is OK because that gets called on every path recalculation - minetest.after(0, il.route.update_route, sigd, tcbs, rteid, nil) + + local sigd = il.db.get_sigd_for_signal(signalpos) + local tcbs = sigd and il.db.get_tcbs(sigd) + -- trigger ARS on this signal + if tcbs and tcbs.routes then + + if tcbs.ars_disabled or tcbs.ars_ignore_next then + -- No-ARS mode of signal. + -- ignore... + -- Note: ars_ignore_next is set by signalling formspec when route is cancelled + tcbs.ars_ignore_next = nil + return + end + if trig_from_dst and tcbs.no_dst_ars_trig then + -- signal not to be triggered from distant + return + end + + if tcbs.routeset then + -- ARS is not in effect when a route is already set + -- just "punch" routesetting, just in case callback got lost. + minetest.after(0, il.route.update_route, sigd, tcbs, nil, nil) + return + end + + local rteid = find_rtematch(tcbs.routes, train) + if rteid then + --delay routesetting, it should not occur inside train step + -- using after here is OK because that gets called on every path recalculation + minetest.after(0, il.route.update_route, sigd, tcbs, rteid, nil) + end end end |