aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/ars.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-01-15 17:23:03 +0100
committerorwell96 <orwell@bleipb.de>2019-01-15 17:23:03 +0100
commit3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d (patch)
tree6427527fd2d3fe84ad41b49368fe0b3b868f6980 /advtrains_interlocking/ars.lua
parent12f8e26cb47f2dc365c69ff721b4c3faf348c61d (diff)
downloadadvtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.tar.gz
advtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.tar.bz2
advtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.zip
Actual working ARS
Diffstat (limited to 'advtrains_interlocking/ars.lua')
-rw-r--r--advtrains_interlocking/ars.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua
index db67a93..80ed638 100644
--- a/advtrains_interlocking/ars.lua
+++ b/advtrains_interlocking/ars.lua
@@ -20,3 +20,43 @@
{default=true} -> *
See also route_ui.lua
]]
+
+local il = advtrains.interlocking
+
+
+local function find_rtematch(routes, train)
+ local default
+ local line = train.line
+ local routingcode
+ for rteid, route in ipairs(routes) do
+ if route.ars then
+ if route.ars.default then
+ default = rteid
+ else
+ for arskey, arsent in ipairs(route.ars) do
+ if arsent.ln and line and arsent.ln == line then
+ return rteid
+ elseif arsent.rc and routingcode and string.match(" "..routingcode.." ", " "..arsent.rc.." ", nil, true) then
+ return rteid
+ end
+ end
+ end
+ end
+ end
+ return default
+end
+
+function advtrains.interlocking.ars_check(sigd, train)
+ local tcbs = il.db.get_tcbs(sigd)
+ if not tcbs or not tcbs.routes then return end
+
+ if tcbs.routeset then
+ -- ARS is not in effect when a route is already set
+ return
+ end
+
+ local rteid = find_rtematch(tcbs.routes, train)
+ if rteid then
+ il.route.update_route(sigd, tcbs, rteid, nil)
+ end
+end