diff options
Diffstat (limited to 'advtrains_interlocking/ars.lua')
-rw-r--r-- | advtrains_interlocking/ars.lua | 40 |
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 |