aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains_interlocking/signal_api.lua23
-rwxr-xr-xadvtrains_interlocking/tcb_ts_ui.lua28
2 files changed, 28 insertions, 23 deletions
diff --git a/advtrains_interlocking/signal_api.lua b/advtrains_interlocking/signal_api.lua
index 65fc787..eddf9da 100644
--- a/advtrains_interlocking/signal_api.lua
+++ b/advtrains_interlocking/signal_api.lua
@@ -419,12 +419,29 @@ end
----------------
function signal.can_dig(pos)
- return not advtrains.interlocking.db.get_sigd_for_signal(pos)
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ if tcbs.routeset then
+ return false
+ end
+ end
+ return true
end
-function signal.after_dig(pos)
+function signal.after_dig(pos, oldnode, oldmetadata, player)
+ -- unassign signal if necessary
+ local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
+ if sigd then
+ local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ advtrains.interlocking.db.set_sigd_for_signal(pos, nil)
+ tcbs.signal = nil
+ tcbs.route_aspect = nil
+ tcbs.route_remote = nil
+ minetest.chat_send_player(player:get_player_name(), "Signal has been unassigned. Name and routes are kept for reuse.")
+ end
-- TODO clear influence point
- advtrains.interlocking.signal.clear_aspect(pos)
+ advtrains.interlocking.signal.unregister_aspect(pos)
end
function signal.on_rightclick(pos, node, player, itemstack, pointed_thing)
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index 60be5f3..bdb0a18 100755
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -639,8 +639,8 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
end
end
if hasprivs then
- form = form.."button[0.5,8;2.5,1;newroute;New Route]"
- form = form.."button[ 3,8;2.5,1;unassign;Unassign Signal]"
+ form = form.."button[0.5,8;2.5,1;smartroute;Smart Route]"
+ form = form.."button[ 3,8;2.5,1;newroute;New (Manual)]"
form = form..string.format("checkbox[0.5,8.75;ars;Automatic routesetting;%s]", not tcbs.ars_disabled)
end
elseif sigd_equal(tcbs.route_origin, sigd) then
@@ -730,6 +730,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
tcbs.ars_ignore_next = nil
return
end
+ if fields.smartroute and hasprivs then
+ advtrains.interlocking.smartroute.init(pname, sigd)
+ minetest.close_formspec(pname, formname)
+ tcbs.ars_ignore_next = nil
+ return
+ end
if sel_rte and tcbs.routes[sel_rte] then
if fields.setroute then
ilrs.update_route(sigd, tcbs, sel_rte)
@@ -748,24 +754,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
- if fields.unassign and hasprivs 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.route_aspect = nil
- tcbs.route_remote = 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
-
if fields.ars then
tcbs.ars_disabled = not minetest.is_yes(fields.ars)
end