diff options
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r-- | advtrains_interlocking/approach.lua | 5 | ||||
-rw-r--r-- | advtrains_interlocking/ars.lua | 66 | ||||
-rw-r--r-- | advtrains_interlocking/route_prog.lua | 4 | ||||
-rw-r--r-- | advtrains_interlocking/routesetting.lua | 4 | ||||
-rw-r--r-- | advtrains_interlocking/signal_api.lua | 2 | ||||
-rwxr-xr-x | advtrains_interlocking/tcb_ts_ui.lua | 7 | ||||
-rw-r--r-- | advtrains_interlocking/train_sections.lua | 7 |
7 files changed, 60 insertions, 35 deletions
diff --git a/advtrains_interlocking/approach.lua b/advtrains_interlocking/approach.lua index eecf09a..eaf0248 100644 --- a/advtrains_interlocking/approach.lua +++ b/advtrains_interlocking/approach.lua @@ -64,10 +64,7 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, has_entered, -- resetting the path does not matter to the set route and ARS doesn't need to be called again. if spos and ars_enabled then --atdebug(id,"IL Spos (ARS)",spos,asp) - local sigd = il.db.get_sigd_for_signal(spos) - if sigd then - il.ars_check(sigd, train) - end + il.ars_check(spos, train) end --atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht) local lspd diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua index 4f50df9..b3065ee 100644 --- a/advtrains_interlocking/ars.lua +++ b/advtrains_interlocking/ars.lua @@ -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 diff --git a/advtrains_interlocking/route_prog.lua b/advtrains_interlocking/route_prog.lua index 34807cd..37f751a 100644 --- a/advtrains_interlocking/route_prog.lua +++ b/advtrains_interlocking/route_prog.lua @@ -209,7 +209,7 @@ function advtrains.interlocking.visualize_route(origin, route, context, tmp_lcks end -- display locks set by player for pts, state in pairs(tmp_lcks) do - local pos = minetest.string_to_pos(pts) + local pos = advtrains.decode_pos(pts) routesprite(context, pos, "fixp"..pts, "at_il_route_lock_edit.png", "Fixed in state '"..state.."' by route "..route.name.." (punch to unfix)", function() clear_lock(tmp_lcks, pname, pts) end) end @@ -536,7 +536,7 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing) return end if advtrains.is_passive(pos) then - local pts = advtrains.roundfloorpts(pos) + local pts = advtrains.encode_pos(pos) if rp.tmp_lcks[pts] then clear_lock(rp.tmp_lcks, pname, pts) else diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index d619aac..34a273a 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -92,8 +92,8 @@ function ilrs.set_route(signal, route, try) end -- add all from locks, these override the rscache for lpts,lst in pairs(c_rseg.locks) do - atdebug("Add lock from Routedef:",lp,"->",lst,"overrides",c_locks[lp] or "none") - c_locks[lp] = lst + atdebug("Add lock from Routedef:",lpts,"->",lst,"overrides",c_locks[lpts] or "none") + c_locks[lpts] = lst end for lp, state in pairs(c_locks) do diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua index eddf9da..cede405 100644 --- a/advtrains_interlocking/signal_api.lua +++ b/advtrains_interlocking/signal_api.lua @@ -279,7 +279,7 @@ end function signal.get_aspect(pos) local aspt = signal.aspects[advtrains.encode_pos(pos)] local ma,dp = signal.get_aspect_internal(pos, aspt) - return ma, advtrains.decode_pos(dp) + return ma, dp and advtrains.decode_pos(dp) end local function cache_mainaspects(ndefat) diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 7f75bb9..82a57cf 100755 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -645,6 +645,7 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle form = form.."button[0.5,8;2.5,1;smartroute;Smart Route]" form = form.."button[ 3,8;2.5,1;newroute;New (Manual)]" form = form..string.format("checkbox[0.5,8.75;ars;Automatic routesetting;%s]", not tcbs.ars_disabled) + form = form..string.format("checkbox[0.5,9.25;dstarstrig;Distant signal triggers ARS;%s]", not tcbs.no_dst_ars_trig) end elseif sigd_equal(tcbs.route_origin, sigd) then -- something has gone wrong: tcbs.routeset should have been set... @@ -669,7 +670,7 @@ end function advtrains.interlocking.update_player_forms(sigd) for pname, tsigd in pairs(p_open_sig_form) do if advtrains.interlocking.sigd_equal(sigd, tsigd) then - advtrains.interlocking.show_signalling_form(sigd, pname, nil) + advtrains.interlocking.show_signalling_form(sigd, pname, nil, true) end end end @@ -761,6 +762,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) tcbs.ars_disabled = not minetest.is_yes(fields.ars) end + if fields.dstarstrig then + tcbs.no_dst_ars_trig = not minetest.is_yes(fields.dstarstrig) + end + if fields.auto then tcbs.route_auto = true end diff --git a/advtrains_interlocking/train_sections.lua b/advtrains_interlocking/train_sections.lua index 41da747..083676b 100644 --- a/advtrains_interlocking/train_sections.lua +++ b/advtrains_interlocking/train_sections.lua @@ -75,7 +75,10 @@ local function setsection(tid, train, ts_id, ts, sigd) end -- routes - local tcbs = advtrains.interlocking.db.get_tcbs(sigd) + local tcbs + if sigd then + tcbs = advtrains.interlocking.db.get_tcbs(sigd) + end -- route setting - clear route state if ts.route then @@ -90,7 +93,7 @@ local function setsection(tid, train, ts_id, ts, sigd) end ts.route = nil end - if tcbs.signal then + if tcbs and tcbs.signal then -- Reset route and signal -- Note that the hit-route case is already handled by cancel_route_from -- this code only handles signal at entering tcb and also triggers for non-route ts |