aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell <orwell@bleipb.de>2025-07-05 11:22:25 +0200
committerorwell <orwell@bleipb.de>2025-07-05 11:22:25 +0200
commit93b5ec0eff2228a07c62355b990248b5f6824aad (patch)
treeb1a56d3ea20b7347b969b220bbfa5ab1c17d2b10
parent8724d23395890611e6ce2a70efb76ecb6c7f03cd (diff)
parent0d1ddb0feb549afbc2e020efb9646f216721a7b8 (diff)
downloadadvtrains-93b5ec0eff2228a07c62355b990248b5f6824aad.tar.gz
advtrains-93b5ec0eff2228a07c62355b990248b5f6824aad.tar.bz2
advtrains-93b5ec0eff2228a07c62355b990248b5f6824aad.zip
Merge branch 'master' into cesky-hvozd-new
-rw-r--r--advtrains_interlocking/ars.lua44
-rw-r--r--advtrains_interlocking/route_prog.lua15
-rw-r--r--advtrains_interlocking/route_ui.lua9
-rw-r--r--advtrains_interlocking/train_sections.lua2
4 files changed, 63 insertions, 7 deletions
diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua
index 5182cd3..393878a 100644
--- a/advtrains_interlocking/ars.lua
+++ b/advtrains_interlocking/ars.lua
@@ -7,7 +7,8 @@
ars = {
[n] = {
ln = "<line>" -- either line
- rc = "<routingcode>" -- or routingcode
+ rc = "<routingcode>" -- or routingcode
+ tl = {min=1, max=2} -- or train length in meters
n = true/false -- true = logical not (matches everything that does not have this line/rc)
conj = { -- and conjunction, optional. This must be true in addition to the main rule
ln=... / rc=... / n=... -- like toplevel
@@ -70,6 +71,26 @@
local il = advtrains.interlocking
+local function parse_trainlen(tlstr)
+ mins, maxs = string.match(tlstr, "^(%d*)%-(%d+)$")
+ if mins and maxs then
+ return {min=tonumber(mins), max=tonumber(maxs)}
+ end
+ return {min=tonumber(tlstr)}
+ -- if it's not parseable at all it will return an empty table which means invalid
+end
+local function trainlen_to_str(tl)
+ if tl.min and tl.max then
+ return tl.min.."-"..tl.max
+ elseif tl.min then
+ return tl.min
+ elseif tl.max then
+ return "0-"..tl.max
+ else
+ return "?"
+ end
+end
+
local function conj_to_text(conj, txt)
while conj do
@@ -81,6 +102,8 @@ local function conj_to_text(conj, txt)
txt[#txt+1] = "& "..n.."LN "..conj.ln
elseif conj.rc then
txt[#txt+1] = "& "..n.."RC "..conj.rc
+ elseif conj.tl then
+ txt[#txt+1] = "& "..n.."TL "..trainlen_to_str(conj.tl)
end
conj = conj.conj
end
@@ -107,6 +130,8 @@ function il.ars_to_text(arstab)
txt[#txt+1] = prio..n.."LN "..arsent.ln
elseif arsent.rc then
txt[#txt+1] = prio..n.."RC "..arsent.rc
+ elseif arsent.tl then
+ txt[#txt+1] = prio..n.."TL "..trainlen_to_str(arsent.tl)
elseif arsent.c then
txt[#txt+1] = "#"..arsent.c
end
@@ -125,11 +150,13 @@ function il.ars_to_text(arstab)
end
local function parse_ruleexp(line)
- local excl, key, val = string.match(line, "^%s*(!?)%s*([RL][CN])%s+(.+)%s*$")
+ local excl, key, val = string.match(line, "^%s*(!?)%s*([RLT][CNL])%s+(.+)%s*$")
if key == "RC" then
return {rc=val, n=(excl=="!")}
elseif key == "LN" then
return {ln=val, n=(excl=="!")}
+ elseif key == "TL" then
+ return {tl=parse_trainlen(val), n=(excl=="!")}
end
end
@@ -204,6 +231,19 @@ local function match_arsent(arsent, train)
local routingcode = train.routingcode
rule_matches = routingcode and string.find(" "..routingcode.." ", " "..arsent.rc.." ", nil, true)
if arsent.n then rule_matches = not rule_matches end
+ elseif arsent.tl then
+ local trainlen = train.trainlen
+ local lmin, lmax = arsent.tl.min, arsent.tl.max
+ if lmin and lmax then
+ rule_matches = (trainlen >= lmin) and (trainlen < lmax)
+ elseif lmin then
+ rule_matches = (trainlen >= lmin)
+ elseif lmax then
+ rule_matches = (trainlen < lmax)
+ else
+ -- errorneous entry never matches
+ end
+ if arsent.n then rule_matches = not rule_matches end
end
if rule_matches then
-- if the entry has a conjunction, go on checking
diff --git a/advtrains_interlocking/route_prog.lua b/advtrains_interlocking/route_prog.lua
index b080945..96bd211 100644
--- a/advtrains_interlocking/route_prog.lua
+++ b/advtrains_interlocking/route_prog.lua
@@ -267,6 +267,8 @@ local function finishrpform(pname)
local rp = player_rte_prog[pname]
if not rp then return end
+ rp.route.use_rscache = true
+
local form = "size[7,6]label[0.5,0.5;"..S("Finish programming route").."]"
local terminal = get_last_route_item(rp.origin, rp.route)
if terminal then
@@ -286,8 +288,8 @@ local function finishrpform(pname)
form = form .. "label[0.5,2 ;"..S("non-interlocked area").."]"
end
form = form.."field[0.8,3.5;5.2,1;name;"..S("Enter Route Name")..";]"
- form = form.."button_exit[0.5,4.5; 5,1;save;"..S("Save Route").."]"
-
+ form = form.."checkbox[0.8,4.0;use_rscache;"..S("Auto lock turnouts")..";true]"
+ form = form.."button_exit[0.5,5.0; 5,1;save;"..S("Save Route").."]"
minetest.show_formspec(pname, "at_il_routepf", form)
end
@@ -484,6 +486,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if formname == "at_il_routepf" then
+ -- if it's the checkbox that changed handle before returning (stupid checkboxes)
+ if fields.use_rscache then
+ local rp = player_rte_prog[pname]
+ if rp then
+ rp.route.use_rscache = core.is_yes(fields.use_rscache)
+ end
+ end
if not fields.save or not fields.name then return end
if fields.name == "" then
-- show form again
@@ -507,8 +516,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local terminal = get_last_route_item(rp.origin, rp.route)
rp.route.terminal = terminal
rp.route.name = fields.name
- -- new routes now always use the rscache
- rp.route.use_rscache = true
table.insert(tcbs.routes, rp.route)
diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua
index d1bae63..9ecc947 100644
--- a/advtrains_interlocking/route_ui.lua
+++ b/advtrains_interlocking/route_ui.lua
@@ -106,6 +106,8 @@ function atil.show_route_edit_form(pname, sigd, routeid, sel_rpartidx)
itab(i, "E (none)", "end", nil)
end
+ itab(i, S("(More Options)"), "advanced", nil)
+
if not sel_rpartidx then sel_rpartidx = 1 end
form = form.."textlist[0.5,2;3.5,3.9;routelog;"..table.concat(tab, ",")..";"..(sel_rpartidx or 1)..";false]"
@@ -153,6 +155,10 @@ function atil.show_route_edit_form(pname, sigd, routeid, sel_rpartidx)
-- checkbox for call-on
form = form..string.format("checkbox[4.5,4.0;se_callon;"..S("Call-on (section may be occupied)")..";%s]", rseg.call_on)
end
+ elseif sel_rpart and sel_rpart.advanced then
+ form = form..F.label(4.5, 2, S("Advanced Options:"))
+ -- checkbox for call-on
+ form = form..string.format("checkbox[4.5,4.0;ad_use_rscache;"..S("Auto lock turnouts")..";%s]", route.use_rscache)
elseif sel_rpart and sel_rpart.err then
form = form.."textarea[4.5,2.5;4,4;errorta;"..S("Error:")..";"..tab[sel_rpartidx].."]"
else
@@ -253,6 +259,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
end
+ if fields.ad_use_rscache then
+ route.use_rscache = minetest.is_yes(fields.ad_use_rscache)
+ end
--if fields.noautogen then
-- route.smartroute_generated = nil
diff --git a/advtrains_interlocking/train_sections.lua b/advtrains_interlocking/train_sections.lua
index a1ee87f..dab9cae 100644
--- a/advtrains_interlocking/train_sections.lua
+++ b/advtrains_interlocking/train_sections.lua
@@ -189,7 +189,7 @@ end)
advtrains.te_register_on_create(function(id, train)
-- let's see what track sections we find here
local index = atround(train.index)
- local pos = advtrains.path_get(train, index)
+ local pos = advtrains.round_vector_floor_y(advtrains.path_get(train, index))
local ts_id = ildb.check_and_repair_ts_at_pos(pos, 1) -- passing connid 1 - that always exists
if ts_id then
local ts = ildb.get_ts(ts_id)