aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorY. Wang <y5nw@protonmail.com>2025-10-04 21:25:43 +0000
committerorwell <orwell@bleipb.de>2026-01-29 21:54:50 +0100
commitbb2e1241b73bb6250f3fa1778525eb58501e22b5 (patch)
tree52c5201e333f9ed51e701c2d86204ca259c27036
parent862611d89b304c502dd600eed308eb4ad5fbf528 (diff)
Indicate routesetting trigger if a route is set
A player observed an issue with a certain setup where ARS is constantly triggered and the route cannot (easily) be canceled. This patch helps troubleshoot this issue by indicating the specific cause for routesetting (in particular, which train triggered ARS).
-rw-r--r--advtrains_interlocking/ars.lua3
-rw-r--r--advtrains_interlocking/routesetting.lua7
-rwxr-xr-xadvtrains_interlocking/tcb_ts_ui.lua9
-rw-r--r--advtrains_luaautomation/environment.lua4
4 files changed, 16 insertions, 7 deletions
diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua
index 393878a..99401d4 100644
--- a/advtrains_interlocking/ars.lua
+++ b/advtrains_interlocking/ars.lua
@@ -70,6 +70,7 @@
]]
local il = advtrains.interlocking
+local S = il.translate
local function parse_trainlen(tlstr)
mins, maxs = string.match(tlstr, "^(%d*)%-(%d+)$")
@@ -385,7 +386,7 @@ function advtrains.interlocking.ars_check(signalpos, train, trig_from_dst)
--atdebug("Ars setting ",rteid)
--delay routesetting, it should not occur inside train step
-- using after here is OK because that gets called on every path recalculation
- minetest.after(0, il.route.update_route, sigd, tcbs, rteid, nil)
+ minetest.after(0, il.route.update_route, sigd, tcbs, rteid, nil, S("Train @1", train.id))
end
end
end
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index 2332040..eec1460 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -329,6 +329,7 @@ function ilrs.cancel_route_from(sigd)
c_tcbs.route_aspect = nil
c_tcbs.route_remote = nil
c_tcbs.routeset = nil
+ c_tcbs.routeset_trigger = nil
c_tcbs.route_auto = nil
c_tcbs.route_origin = nil
@@ -369,7 +370,8 @@ end
-- sigd, tcbs: self-explanatory
-- newrte: If a new route should be set, the route index of it (in tcbs.routes). Can also be a table (multi-ars). nil otherwise
-- cancel: true in combination with newrte=nil causes cancellation of the current route.
-function ilrs.update_route(sigd, tcbs, newrte, cancel)
+-- trigger: The reason for setting the route
+function ilrs.update_route(sigd, tcbs, newrte, cancel, trigger)
--atdebug("Update_Route for",sigd,tcbs.signal_name)
local has_changed_aspect = false
if tcbs.route_origin and not sigd_equal(tcbs.route_origin, sigd) then
@@ -388,6 +390,7 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
tcbs.route_remote = nil
has_changed_aspect = true
tcbs.routeset = nil
+ tcbs.routeset_trigger = nil
tcbs.route_auto = nil
end
if newrte or tcbs.routeset then
@@ -399,11 +402,13 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
error("update_route got multi-ARS with empty table, this is not allowed")
end
tcbs.routeset = newrte
+ tcbs.routeset_trigger = trigger
else
if type(tcbs.routeset)=="table" and not next(tcbs.routeset) then
-- just unset, don't error
atwarn(sigd, "had multi-ARS route set with empty list! Cancelled!")
tcbs.routeset = nil
+ tcbs.routeset_trigger = nil
return
end
end
diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua
index c9cae07..a44fd66 100755
--- a/advtrains_interlocking/tcb_ts_ui.lua
+++ b/advtrains_interlocking/tcb_ts_ui.lua
@@ -858,12 +858,13 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, calle
form = form.."label[0.5,2.5;"..S("A route is requested from this signal:").."]"
form = form.."label[0.5,3.0;"..minetest.formspec_escape(rte.name).."]"
end
+ form = form .. "label[0.5,3.5;" .. core.formspec_escape(S("Routesetting trigger: @1", tcbs.routeset_trigger or S("Unknown reason"))) .. "]"
if tcbs.route_committed then
- form = form.."label[0.5,3.5;"..S("Route has been set.").."]"
+ form = form.."label[0.5,4;"..S("Route has been set.").."]"
else
- form = form.."label[0.5,3.5;"..S("Waiting for route to be set...").."]"
+ form = form.."label[0.5,4;"..S("Waiting for route to be set...").."]"
if tcbs.route_rsn then
- form = form.."label[0.5,4;"..minetest.formspec_escape(tcbs.route_rsn).."]"
+ form = form.."label[0.5,4.5;"..minetest.formspec_escape(tcbs.route_rsn).."]"
end
end
if not tcbs.route_auto then
@@ -1044,7 +1045,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if sel_rte and tcbs.routes[sel_rte] then
if fields.setroute then
- ilrs.update_route(sigd, tcbs, sel_rte)
+ ilrs.update_route(sigd, tcbs, sel_rte, nil, S("Manual routesetting by @1", pname))
end
if fields.dsproute then
local t = os.clock()
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 184d346..50eca7c 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -1,6 +1,8 @@
-------------
-- lua sandboxed environment
+local S = atlatc.translate
+
-- function to cross out functions and userdata.
-- modified from dump()
function atlatc.remove_invalid_data(o, nested)
@@ -218,7 +220,7 @@ if advtrains.interlocking then
end
static_env.set_route = function(signal, route_name)
local pos, sigd, tcbs, routeid, route = gen_checks(signal, route_name)
- return advtrains.interlocking.route.update_route(sigd, tcbs, routeid)
+ return advtrains.interlocking.route.update_route(sigd, tcbs, routeid, nil, S("LuaATC component"))
end
static_env.cancel_route = function(signal)
local pos, sigd, tcbs, routeid, route = gen_checks(signal, "", true)