aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2024-11-25 23:39:56 +0100
committerorwell <orwell@bleipb.de>2024-11-25 23:39:56 +0100
commit2bfc24ef27ea4098a93cc025b513afe1b8c4ee1f (patch)
tree7e7c455211aee066f6b8c00ff3309715d1b83543
parenta8d53ea2484463f7fc8329cb67b56e4d0f321dbd (diff)
downloadadvtrains-2bfc24ef27ea4098a93cc025b513afe1b8c4ee1f.tar.gz
advtrains-2bfc24ef27ea4098a93cc025b513afe1b8c4ee1f.tar.bz2
advtrains-2bfc24ef27ea4098a93cc025b513afe1b8c4ee1f.zip
Auto-assign signal to TCB if it finds one ahead of the influence point
-rw-r--r--advtrains/helpers.lua2
-rw-r--r--advtrains_interlocking/signal_aspect_ui.lua26
2 files changed, 27 insertions, 1 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua
index d7e691d..172cf07 100644
--- a/advtrains/helpers.lua
+++ b/advtrains/helpers.lua
@@ -578,7 +578,7 @@ local trackiter_mt = {
-- initial_pos: the initial track position of the track iterator
-- initial_connid: the connection index in which to traverse. If nil, adds a "branch" for every connection of the track (traverse in all directions)
-- limit: maximum distance from the start point after which the traverser stops
--- follow_all: if true, follows all branches at multi-connection tracks, even the ones pointing backwards or the crossing track on crossings. If false, follows only switches in driving direction.
+-- follow_all: NOT IMPLEMENTED (supposed: if true, follows all branches at multi-connection tracks, even the ones pointing backwards or the crossing track on crossings. If false, follows only switches in driving direction.)
-- Functions of the returned TrackIterator can be called via the Lua : notation, such as ti:next_track()
-- If only the main track needs to be followed, use only the ti:next_track() function and do not call ti:next_branch().
diff --git a/advtrains_interlocking/signal_aspect_ui.lua b/advtrains_interlocking/signal_aspect_ui.lua
index 39aab17..9f2675f 100644
--- a/advtrains_interlocking/signal_aspect_ui.lua
+++ b/advtrains_interlocking/signal_aspect_ui.lua
@@ -186,6 +186,30 @@ function advtrains.interlocking.init_distant_assign(pos, pname)
players_assign_distant[pname] = pos
end
+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 apos, aconnid = ti:next_branch()
+ while apos do
+ -- check for presence of a tcb
+ local tcb = advtrains.interlocking.db.get_tcb(apos)
+ if tcb then
+ -- check on the pointing connid whether it has a signal already
+ if not tcb[aconnid].signal then
+ -- go ahead and assign
+ local sigd = { p=apos, s=aconnid }
+ advtrains.interlocking.db.assign_signal_to_tcbs(signalpos, sigd)
+ minetest.chat_send_player(pname, "Assigned signal to the TCB at "..core.pos_to_string(apos))
+ advtrains.interlocking.show_tcb_marker(apos)
+ advtrains.interlocking.show_signalling_form(sigd, pname)
+ end
+ -- in all cases return
+ return
+ end
+ apos, aconnid = ti:next_track()
+ end
+ -- if we end up here limit is up
+end
+
minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
local pname = player:get_player_name()
if not minetest.check_player_privs(pname, "interlocking") then
@@ -207,6 +231,8 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
advtrains.interlocking.db.set_ip_signal(pts, plconnid, signalpos)
ipmarker(pos, plconnid)
minetest.chat_send_player(pname, "Configuring Signal: Successfully set influence point")
+ -- Try to find a TCB ahead and auto assign this signal there
+ try_auto_assign_to_tcb(signalpos, pos, plconnid, pname)
else
minetest.chat_send_player(pname, "Configuring Signal: Influence point of another signal is already present!")
end