diff options
author | orwell96 <orwell@bleipb.de> | 2019-01-15 17:23:03 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2019-01-15 17:23:03 +0100 |
commit | 3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d (patch) | |
tree | 6427527fd2d3fe84ad41b49368fe0b3b868f6980 /advtrains_interlocking | |
parent | 12f8e26cb47f2dc365c69ff721b4c3faf348c61d (diff) | |
download | advtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.tar.gz advtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.tar.bz2 advtrains-3ce98cae9aa588fba0be1e86fc81e7ca6040bd9d.zip |
Actual working ARS
Diffstat (limited to 'advtrains_interlocking')
-rw-r--r-- | advtrains_interlocking/ars.lua | 40 | ||||
-rw-r--r-- | advtrains_interlocking/lzb.lua | 10 | ||||
-rw-r--r-- | advtrains_interlocking/routesetting.lua | 5 |
3 files changed, 53 insertions, 2 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 diff --git a/advtrains_interlocking/lzb.lua b/advtrains_interlocking/lzb.lua index 51d597b..1f9589e 100644 --- a/advtrains_interlocking/lzb.lua +++ b/advtrains_interlocking/lzb.lua @@ -4,7 +4,7 @@ local function approach_callback(parpos, train_id, train, index) local pos = advtrains.round_vector_floor_y(parpos) - + local node=pnode or advtrains.ndb.get_node(pos) local ndef=minetest.registered_nodes[node.name] if ndef and ndef.advtrains and ndef.advtrains.on_train_approach then @@ -88,6 +88,14 @@ local function look_ahead(id, train) -- check for signal local asp, spos = il.db.get_ip_signal_asp(pts, cn) + + -- do ARS if needed + if spos then + local sigd = il.db.get_sigd_for_signal(spos) + if sigd then + il.ars_check(sigd, train) + end + end --atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht) if asp then local nspd = 0 diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua index 1edc631..7b08c4e 100644 --- a/advtrains_interlocking/routesetting.lua +++ b/advtrains_interlocking/routesetting.lua @@ -262,7 +262,10 @@ end -- TCBS Routesetting helper: generic update function for -- route setting - +-- Call this function to set and cancel routes! +-- sigd, tcbs: self-explanatory +-- newrte: If a new route should be set, the route index of it (in tcbs.routes). nil otherwise +-- cancel: true in combination with newrte=nil causes cancellation of the current route. function ilrs.update_route(sigd, tcbs, newrte, cancel) -- in general, always show danger signal tcbs.aspect = nil |