aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains/signals.lua63
-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
6 files changed, 122 insertions, 10 deletions
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index 53145f5..2caec79 100644
--- a/advtrains/signals.lua
+++ b/advtrains/signals.lua
@@ -1,9 +1,15 @@
--advtrains by orwell96
--signals.lua
---this code /should/ work but does not.
local mrules_wallsignal = advtrains.meseconrules
+local function can_dig_func(pos)
+ if advtrains.interlocking then
+ return advtrains.interlocking.signal_can_dig(pos)
+ end
+ return true
+end
+
for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
@@ -33,6 +39,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
not_blocking_trains=1,
not_in_creative_inventory=crea,
save_in_at_nodedb=1,
+ advtrains_signal = 2,
},
mesecons = {effector = {
rules=advtrains.meseconrules,
@@ -41,12 +48,28 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
end
}},
on_rightclick=function(pos, node, player)
- if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
+ local pname = player:get_player_name()
+ local sigd = advtrains.interlocking and advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ advtrains.interlocking.show_signalling_form(sigd, pname)
+ elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
end
end,
+ -- new signal API
+ advtrains = {
+ set_aspect = function(pos, node, asp)
+ if asp.main.free then
+ advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_on_"..rotation, param2 = node.param2}, true)
+ else
+ advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_off_"..rotation, param2 = node.param2}, true)
+ end
+ end
+ },
+ can_dig = can_dig_func,
})
advtrains.trackplacer.add_worked("advtrains:retrosignal", r, rotation, nil)
+
minetest.register_node("advtrains:signal_"..r..rotation, {
drawtype = "mesh",
paramtype="light",
@@ -66,6 +89,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
not_blocking_trains=1,
not_in_creative_inventory=crea,
save_in_at_nodedb=1,
+ advtrains_signal = 2,
},
light_source = 1,
sunlight_propagates=true,
@@ -84,10 +108,25 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
end,
},
on_rightclick=function(pos, node, player)
- if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
+ local pname = player:get_player_name()
+ local sigd = advtrains.interlocking and advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ advtrains.interlocking.show_signalling_form(sigd, pname)
+ elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_"..f.as..rotation, param2 = node.param2}, true)
end
end,
+ -- new signal API
+ advtrains = {
+ set_aspect = function(pos, node, asp)
+ if asp.main.free then
+ advtrains.ndb.swap_node(pos, {name = "advtrains:signal_on_"..rotation, param2 = node.param2}, true)
+ else
+ advtrains.ndb.swap_node(pos, {name = "advtrains:signal_off_"..rotation, param2 = node.param2}, true)
+ end
+ end
+ },
+ can_dig = can_dig_func,
})
advtrains.trackplacer.add_worked("advtrains:signal", r, rotation, nil)
end
@@ -115,6 +154,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
not_blocking_trains=1,
not_in_creative_inventory=crea,
save_in_at_nodedb=1,
+ advtrains_signal = 2,
},
light_source = 1,
sunlight_propagates=true,
@@ -133,10 +173,25 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
end,
},
on_rightclick=function(pos, node, player)
- if advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
+ local pname = player:get_player_name()
+ local sigd = advtrains.interlocking and advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ advtrains.interlocking.show_signalling_form(sigd, pname)
+ elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_"..f.as, param2 = node.param2}, true)
end
end,
+ -- new signal API
+ advtrains = {
+ set_aspect = function(pos, node, asp)
+ if asp.main.free then
+ advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_on", param2 = node.param2}, true)
+ else
+ advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_off", param2 = node.param2}, true)
+ end
+ end
+ },
+ can_dig = can_dig_func,
})
end
end
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