From c081129fe040d2dd62d36777ec5eeae315fd0928 Mon Sep 17 00:00:00 2001 From: orwell Date: Sun, 1 Dec 2024 23:51:41 +0100 Subject: Misc Fixes found during play --- advtrains/trackplacer.lua | 6 +++--- advtrains_interlocking/database.lua | 6 +++--- advtrains_interlocking/signal_aspect_ui.lua | 15 ++++++++++++++- advtrains_interlocking/tcb_ts_ui.lua | 11 +++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/advtrains/trackplacer.lua b/advtrains/trackplacer.lua index 1543209..3278b8c 100644 --- a/advtrains/trackplacer.lua +++ b/advtrains/trackplacer.lua @@ -152,10 +152,10 @@ local function check_or_bend_rail(origin, dir, pname, commit) end end -local function track_place_node(pos, node, ndef, pname) +local function track_place_node(pos, node, ndef_p, pname) --atdebug("track_place_node: ",pos, node) advtrains.ndb.swap_node(pos, node) - local ndef = minetest.registered_nodes[node.name] + local ndef = ndef_p or minetest.registered_nodes[node.name] if ndef and ndef.after_place_node then -- resolve player again local player = pname and core.get_player_by_name(pname) or nil @@ -202,7 +202,7 @@ function tp.place_track(pos, tpg, pname, yaw) if node then check_or_bend_rail(pos, conn1, pname, true) check_or_bend_rail(pos, conn2, pname, true) - track_place_node(pos, node, pname) -- calls after_place_node implicitly + track_place_node(pos, node, nil, pname) -- calls after_place_node implicitly return true end end diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index 75247de..c05e69a 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -701,7 +701,7 @@ local function recursively_find_routes(s_pos, s_connid, locks_found, result_tabl local pos, connid, bconnid = ti:next_branch() pos, connid, bconnid = ti:next_track()-- step once to get ahead of previous turnout local last_pos - repeat + while pos do -- this stops the loop when either the track end is reached or the limit is hit local node = advtrains.ndb.get_node_or_nil(pos) --atdebug("Walk ",pos, "nodename", node.name, "entering at conn",bconnid) local ndef = minetest.registered_nodes[node.name] @@ -739,7 +739,7 @@ local function recursively_find_routes(s_pos, s_connid, locks_found, result_tabl -- Go forward last_pos = pos pos, connid, bconnid = ti:next_track() - until not pos -- this stops the loop when either the track end is reached or the limit is hit + end --atdebug("recursively_find_routes: Reached track end or limit at", last_pos, ". This path is not saved, returning") end @@ -832,7 +832,7 @@ function ildb.remove_tcb_at(pos, pname, skip_tsrepair) advtrains.interlocking.remove_tcb_marker(pos) -- If needed, merge the track sections here if not skip_tsrepair then - ildb.check_and_repair_ts_at_pos(pos, pname) + ildb.check_and_repair_ts_at_pos(pos, nil, pname) end return true end diff --git a/advtrains_interlocking/signal_aspect_ui.lua b/advtrains_interlocking/signal_aspect_ui.lua index 9f2675f..25abb2d 100644 --- a/advtrains_interlocking/signal_aspect_ui.lua +++ b/advtrains_interlocking/signal_aspect_ui.lua @@ -186,8 +186,11 @@ function advtrains.interlocking.init_distant_assign(pos, pname) players_assign_distant[pname] = pos end +-- Tries to automatically find a TCB to assign to the signal, or a main signal if this is a pure distant signal and another signal is found before the TCB local function try_auto_assign_to_tcb(signalpos, pos, connid, pname) - local ti = advtrains.get_track_iterator(pos, connid, 6, false) -- maximum 6 track nodes ahead + local pure_distant = advtrains.interlocking.signal.get_signal_cap_level(signalpos) == 2 -- exactly 2: pure distant sig + local is_past_first = false + local ti = advtrains.get_track_iterator(pos, connid, pure_distant and 150 or 16, false) -- maximum 16 track nodes ahead local apos, aconnid = ti:next_branch() while apos do -- check for presence of a tcb @@ -204,8 +207,18 @@ local function try_auto_assign_to_tcb(signalpos, pos, connid, pname) end -- in all cases return return + elseif pure_distant and is_past_first then + -- try to find another signal's influence point here which could be the remote of a distant signal + local pts = advtrains.roundfloorpts(apos) + local mainsig = advtrains.interlocking.db.get_ip_signal(pts, aconnid) + if mainsig and advtrains.interlocking.signal.get_signal_cap_level(mainsig) >= 3 then + advtrains.interlocking.signal.set_aspect(signalpos, "_default", mainsig) + minetest.chat_send_player(pname, "Assigned distant signal to the main signal at "..core.pos_to_string(mainsig)) + return + end end apos, aconnid = ti:next_track() + is_past_first = true end -- if we end up here limit is up end diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 54ffe9b..87e56ca 100755 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -768,6 +768,7 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle form = form.."button[0.5,6; 5,1;setroute;Set Route]" form = form.."button[0.5,7;2,1;dsproute;Show]" if hasprivs then + form = form.."button[2.5,7;1,1;setarsdefault;Set Def.]" form = form.."button[3.5,7;2,1;editroute;Edit]" if sel_rte > 1 then form = form .. "button[5.5,4;0.5,0.3;moveup;↑]" @@ -984,6 +985,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) advtrains.interlocking.show_route_edit_form(pname, sigd, sel_rte) return end + if fields.setarsdefault and hasprivs then + for rid, route in ipairs(tcbs.routes) do + local isdefault = rid == sel_rte + if route.ars then + route.ars.default = isdefault + elseif isdefault then + route.ars = {default = true} + end + end + end end end -- cgit v1.2.3