aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking
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 /advtrains_interlocking
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
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r--advtrains_interlocking/signal_aspect_ui.lua26
1 files changed, 26 insertions, 0 deletions
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