aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r--advtrains_interlocking/demosignals.lua9
-rw-r--r--advtrains_interlocking/routesetting.lua19
-rw-r--r--advtrains_interlocking/signal_api.lua14
-rw-r--r--advtrains_interlocking/tcb_ts_ui.lua23
-rw-r--r--advtrains_interlocking/train_related.lua4
5 files changed, 63 insertions, 6 deletions
diff --git a/advtrains_interlocking/demosignals.lua b/advtrains_interlocking/demosignals.lua
index d5d5c4f..c19b578 100644
--- a/advtrains_interlocking/demosignals.lua
+++ b/advtrains_interlocking/demosignals.lua
@@ -31,7 +31,8 @@ minetest.register_node("advtrains_interlocking:ds_danger", {
end
end
},
- on_rightclick = advtrains.interlocking.signal_rc_handler
+ on_rightclick = advtrains.interlocking.signal_rc_handler,
+ can_dig = advtrains.interlocking.signal_can_dig,
})
minetest.register_node("advtrains_interlocking:ds_free", {
description = "Demo signal at Free",
@@ -59,7 +60,8 @@ minetest.register_node("advtrains_interlocking:ds_free", {
end
end
},
- on_rightclick = advtrains.interlocking.signal_rc_handler
+ on_rightclick = advtrains.interlocking.signal_rc_handler,
+ can_dig = advtrains.interlocking.signal_can_dig,
})
minetest.register_node("advtrains_interlocking:ds_slow", {
description = "Demo signal at Slow",
@@ -87,6 +89,7 @@ minetest.register_node("advtrains_interlocking:ds_slow", {
end
end
},
- on_rightclick = advtrains.interlocking.signal_rc_handler
+ on_rightclick = advtrains.interlocking.signal_rc_handler,
+ can_dig = advtrains.interlocking.signal_can_dig,
})
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index b98b234..1e516a6 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -225,10 +225,27 @@ function ilrs.cancel_route_from(sigd)
end
end
+local asp_generic_free = {
+ main = {
+ free = true,
+ speed = 100,
+ },
+ shunt = {
+ free = false,
+ },
+ dst = {
+ free = true,
+ speed = 100,
+ },
+ info = {}
+}
+
-- TCBS Routesetting helper: generic update function for
-- route setting
function ilrs.update_route(sigd, tcbs, newrte, cancel)
+ -- in general, always show danger signal
+ tcbs.aspect = nil
if (newrte and tcbs.routeset and tcbs.routeset ~= newrte) or cancel then
if tcbs.route_committed then
atdebug("Cancelling:",tcbs.routeset)
@@ -259,8 +276,10 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
atdebug("Committed Route:",tcbs.routeset)
tcbs.route_committed = true
tcbs.route_rsn = false
+ tcbs.aspect = asp_generic_free
end
end
+ advtrains.interlocking.update_signal_aspect(tcbs)
end
-- Try to re-set routes that conflicted with this point
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 17799ae..cd1ab54 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -21,7 +21,7 @@ asp = {
}
Signals API:
groups = {
- advtrains_signal = 1,
+ advtrains_signal = 2,
save_in_at_nodedb = 1,
}
advtrains = {
@@ -30,6 +30,7 @@ advtrains = {
end
}
on_rightclick = advtrains.interlocking.signal_rc_handler
+can_dig = advtrains.interlocking.signal_can_dig
]]--
@@ -48,6 +49,17 @@ local DANGER = {
info = {}
}
+function advtrains.interlocking.update_signal_aspect(tcbs)
+ if tcbs.signal then
+ local asp = tcbs.aspect or DANGER
+ advtrains.interlocking.signal_set_aspect(tcbs.signal, asp)
+ end
+end
+
+function advtrains.interlocking.signal_can_dig(pos)
+ return not advtrains.interlocking.db.get_sigd_for_signal(pos)
+end
+
function advtrains.interlocking.signal_set_aspect(pos, asp)
local node=advtrains.ndb.get_node(pos)
local ndef=minetest.registered_nodes[node.name]
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index 2aa246b..ab7de34 100644
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -142,7 +142,6 @@ minetest.register_on_punchnode(function(pos, node, player, pointed_thing)
end
end)
-
-- TCB Form
local function mktcbformspec(tcbs, btnpref, offset, pname)
@@ -457,6 +456,11 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte)
if tcbs.routeset then
local rte = tcbs.routes[tcbs.routeset]
+ if not rte then
+ atwarn("Unknown route set from signal!")
+ tcbs.routeset = nil
+ return
+ end
form = form.."label[0.5,2.5;A route is requested from this signal:]"
form = form.."label[0.5,3.0;"..rte.name.."]"
if tcbs.route_committed then
@@ -552,6 +556,23 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
+ if fields.unassign then
+ -- unassigning the signal from the tcbs
+ -- only when no route is set.
+ -- Routes and name remain saved, in case the player wants to reassign a new signal
+ if not tcbs.routeset then
+ local signal_pos = tcbs.signal
+ ildb.set_sigd_for_signal(signal_pos, nil)
+ tcbs.signal = nil
+ tcbs.aspect = nil
+ minetest.close_formspec(pname, formname)
+ minetest.chat_send_player(pname, "Signal has been unassigned. Name and routes are kept for reuse.")
+ return
+ else
+ minetest.chat_send_player(pname, "Please cancel route first!")
+ end
+ end
+
advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte)
return
end
diff --git a/advtrains_interlocking/train_related.lua b/advtrains_interlocking/train_related.lua
index c2eeae6..ebeda9f 100644
--- a/advtrains_interlocking/train_related.lua
+++ b/advtrains_interlocking/train_related.lua
@@ -76,11 +76,13 @@ local function setsection(tid, train, ts_id, ts, origin)
-- route setting - clear route state
if ts.route then
if ts.route.first then
+ -- this is the first route section. clear route status from origin sigd
local tcbs = advtrains.interlocking.db.get_tcbs(ts.route.origin)
if tcbs then
- --TODO callbacks
tcbs.routeset = nil
tcbs.route_committed = nil
+ tcbs.aspect = nil
+ advtrains.interlocking.update_signal_aspect(tcbs)
end
end
ts.route = nil