aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2021-05-31 16:57:09 +0200
committerywang <yw05@forksworld.de>2021-05-31 16:57:09 +0200
commitb07363971d26b78e3aa6adad38648cb7f9a19f56 (patch)
tree9adfee94cacc96b9457e7b5b25a4b71b42b6d99e
parentb60e516bac7165b91a72649e33b9707b88d33be2 (diff)
downloadadvtrains-new-ks.tar.gz
advtrains-new-ks.tar.bz2
advtrains-new-ks.zip
disable distant signaling by defaultnew-ks
Distant routesetting is not implemented yet
-rw-r--r--advtrains_interlocking/database.lua1
-rw-r--r--advtrains_interlocking/distant_signals.lua19
-rwxr-xr-xadvtrains_interlocking/tcb_ts_ui.lua15
-rwxr-xr-xadvtrains_signals_ks/init.lua29
4 files changed, 58 insertions, 6 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index ee21db9..175e86f 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -197,6 +197,7 @@ TCB data structure
route_auto = <boolean> -- When set, we will automatically re-set the route (designated by routeset)
distant = { <sigd1> ... } -- a collection of sigd that points to a side of a TCB with a distant signal for this current signal.
distant_of = { <sigd>, <index> } -- the reverse of the above field, along with the index of the entry in the list (for easier lookup)
+ distant_mode = <boolean|nil> -- distant signaling mode (see distant_signals.lua)
},
-- This is the "B" side of the TCB
[2] = { -- Variant: end of track-circuited area (initial state of TC)
diff --git a/advtrains_interlocking/distant_signals.lua b/advtrains_interlocking/distant_signals.lua
index 0da1c10..340cf74 100644
--- a/advtrains_interlocking/distant_signals.lua
+++ b/advtrains_interlocking/distant_signals.lua
@@ -1,3 +1,10 @@
+--[[
+Distant signaling modes:
+ true: set route for the next signal
+ false: do not set route for the next signal
+ nil: hide distant signal information
+]]
+
local interlocking = advtrains.interlocking
local ildb = advtrains.interlocking.db
@@ -6,7 +13,11 @@ local function update_distant(tcbs)
if not tcbs.aspect then tcbs.aspect = table.copy(interlocking.DANGER) end
local asp = tcbs.aspect
if tcbs.distant_of then
- asp.dst = (ildb.get_tcbs(tcbs.distant_of[1]).aspect or interlocking.DANGER).main
+ if tcbs.distant_mode == nil then
+ asp.dst = nil
+ else
+ asp.dst = (ildb.get_tcbs(tcbs.distant_of[1]).aspect or interlocking.DANGER).main
+ end
end
interlocking.update_signal_aspect(tcbs)
if tcbs.distant then
@@ -14,7 +25,11 @@ local function update_distant(tcbs)
for i = 1, #dst do
local s = ildb.get_tcbs(dst[i])
if not s.aspect then s.aspect = table.copy(interlocking.DANGER) end
- s.aspect.dst = asp.main
+ if s.distant_mode == nil then
+ s.aspect.dst = nil
+ else
+ s.aspect.dst = asp.main
+ end
interlocking.update_signal_aspect(s)
end
end
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index 2425bf2..f00016b 100755
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -608,7 +608,7 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
if not tcbs.signal_name then tcbs.signal_name = "Signal at "..minetest.pos_to_string(sigd.p) end
if not tcbs.routes then tcbs.routes = {} end
- local form = "size[7,10]label[0.5,0.5;Signal at "..minetest.pos_to_string(sigd.p).."]"
+ local form = "size[7,11.5]label[0.5,0.5;Signal at "..minetest.pos_to_string(sigd.p).."]"
form = form.."field[0.8,1.5;5.2,1;name;Signal name;"..minetest.formspec_escape(tcbs.signal_name).."]"
form = form.."button[5.5,1.2;1,1;setname;Set]"
@@ -675,6 +675,8 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
else
form = form.."button[0.5,9;2.5,1;arsdisable;Disable ARS]"
end
+ form = form.."checkbox[0.5,10;dstsignal;Enable distant signalling;"..(tcbs.distant_mode~=nil and "true" or "false").."]"
+ form = form.."checkbox[0.5,10.5;dstsetroute;Set route for the next signal;"..(tcbs.distant_mode and "true" or "false").."]"
elseif sigd_equal(tcbs.route_origin, sigd) then
-- something has gone wrong: tcbs.routeset should have been set...
form = form.."label[0.5,2.5;Inconsistent state: route_origin is same TCBS but no route set. Try again.]"
@@ -804,6 +806,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.noauto then
tcbs.route_auto = false
end
+
+ if fields.dstsignal then
+ if minetest.is_yes(fields.dstsignal) then
+ tcbs.distant_mode = false
+ else
+ tcbs.distant_mode = nil
+ end
+ end
+ if fields.dstsetroute then
+ tcbs.distant_mode = not tcbs.distant_mode
+ end
advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, true)
return
diff --git a/advtrains_signals_ks/init.lua b/advtrains_signals_ks/init.lua
index 3a2f4d0..ce05832 100755
--- a/advtrains_signals_ks/init.lua
+++ b/advtrains_signals_ks/init.lua
@@ -4,6 +4,14 @@
-- Note that the group value of advtrains_signal is 2, which means "step 2 of signal capabilities"
-- advtrains_signal=1 is meant for signals that do not implement set_aspect.
+local ildb = advtrains.interlocking.db
+
+local function usedst(pos)
+ local sigd = ildb.get_sigd_for_signal(pos)
+ if not sigd then return true end
+ return (ildb.get_tcbs(sigd).distant_mode ~= nil)
+end
+
local function asp_to_zs3type(asp)
local n = tonumber(asp)
if not n or n < 4 then return "off" end
@@ -59,7 +67,7 @@ local setaspectf = function(rot)
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_danger_"..rot, param2 = node.param2})
end
setzs3v(pos, nil, rot)
- else
+ elseif usedst(pos) then
if asp.dst == -1 then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_free_"..rot, param2 = node.param2})
elseif not asp.dst or asp.dst == 0 then
@@ -68,6 +76,13 @@ local setaspectf = function(rot)
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_nextslow_"..rot, param2 = node.param2})
end
setzs3v(pos, asp.dst, rot)
+ else
+ if asp.main == -1 then
+ advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_free_"..rot, param2 = node.param2})
+ else
+ advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_slow_"..rot, param2 = node.param2})
+ end
+ setzs3v(pos, nil, rot)
end
end
end
@@ -131,7 +146,11 @@ for _, rtab in ipairs({
danger = {asp = advtrains.interlocking.DANGER, n = "slow", ici=true},
slow = {
asp = function(pos)
- return { main = getzs3(pos) or -1, proceed_as_main = true, dst = 0 }
+ if usedst(pos) then
+ return { main = getzs3(pos) or -1, proceed_as_main = true, dst = 0 }
+ else
+ return { main = getzs3(pos) or 6, proceed_as_main = true }
+ end
end,
n = "nextslow"
},
@@ -143,7 +162,11 @@ for _, rtab in ipairs({
},
free = {
asp = function(pos)
- return { main = getzs3(pos) or -1, proceed_as_main = true, dst = -1 }
+ if usedst(pos) then
+ return { main = getzs3(pos) or -1, proceed_as_main = true, dst = -1 }
+ else
+ return { main = -1, proceed_as_main = true }
+ end
end,
n = "shunt"
},