aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/routesetting.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/routesetting.lua')
-rw-r--r--advtrains_interlocking/routesetting.lua50
1 files changed, 33 insertions, 17 deletions
diff --git a/advtrains_interlocking/routesetting.lua b/advtrains_interlocking/routesetting.lua
index d801608..9973569 100644
--- a/advtrains_interlocking/routesetting.lua
+++ b/advtrains_interlocking/routesetting.lua
@@ -44,13 +44,18 @@ function ilrs.set_route(signal, route, try)
local i = 1
local rtename = route.name
local signalname = ildb.get_tcbs(signal).signal_name
- local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp, p_ssigd
+ local c_tcbs, c_ts_id, c_ts, c_rseg, c_lckp
+ local signals = {}
+ local nodst
while c_sigd and i<=#route do
c_tcbs = ildb.get_tcbs(c_sigd)
if not c_tcbs then
if not try then atwarn("Did not find TCBS",c_sigd,"while setting route",rtename,"of",signal) end
return false, "No TCB found at "..sigd_to_string(c_sigd)..". Please reconfigure route!"
end
+ if i == 1 then
+ nodst = c_tcbs.nodst
+ end
c_ts_id = c_tcbs.ts_id
if not c_ts_id then
if not try then atwarn("Encountered End-Of-Interlocking while setting route",rtename,"of",signal) end
@@ -112,16 +117,9 @@ function ilrs.set_route(signal, route, try)
}
if c_tcbs.signal then
c_tcbs.route_committed = true
- local asp = route.aspect or advtrains.interlocking.GENERIC_FREE
- asp.dst = nil
- c_tcbs.aspect = asp
+ c_tcbs.aspect = route.aspect or advtrains.interlocking.FULL_FREE
c_tcbs.route_origin = signal
- advtrains.interlocking.distant.update(c_tcbs)
- -- Update the previous distant signal
- if p_ssigd then
- advtrains.interlocking.distant.assign(c_sigd, p_ssigd)
- end
- p_ssigd = c_sigd
+ signals[#signals+1] = c_tcbs
end
end
-- advance
@@ -130,15 +128,25 @@ function ilrs.set_route(signal, route, try)
i = i + 1
end
- if c_sigd and p_ssigd then
+ -- Distant signaling
+ local lastsig = nil
+ if c_sigd then
local e_tcbs = ildb.get_tcbs(c_sigd)
- if e_tcbs.signal then
- if p_stcb then
- p_stcb.aspect.dst = (e_tcbs.aspect or advtrains.interlocking.DANGER).main
- advtrains.interlocking.update_signal_aspect(p_stcb)
+ local pos = e_tcbs and e_tcbs.signal
+ if pos then
+ lastsig = pos
+ end
+ end
+ for i = #signals, 1, -1 do
+ if lastsig then
+ local tcbs = signals[i]
+ local pos = tcbs.signal
+ local _, assigned_by = advtrains.distant.get_main(pos)
+ if (not nodst) and (not assigned_by or assigned_by == "routesetting") then
+ advtrains.distant.assign(lastsig, pos, "routesetting", true)
end
+ advtrains.interlocking.update_signal_aspect(tcbs, i ~= 1)
end
- advtrains.interlocking.distant.assign(c_sigd, p_ssigd)
end
return true
@@ -247,6 +255,13 @@ function ilrs.cancel_route_from(sigd)
c_tcbs.route_auto = nil
c_tcbs.route_origin = nil
+ if c_tcbs.signal then
+ local pos = c_tcbs.signal
+ local _, assigned_by = advtrains.distant.get_main(pos)
+ if assigned_by == "routesetting" then
+ advtrains.distant.unassign_dst(pos, true)
+ end
+ end
advtrains.interlocking.update_signal_aspect(c_tcbs)
c_ts_id = c_tcbs.ts_id
@@ -326,7 +341,8 @@ function ilrs.update_route(sigd, tcbs, newrte, cancel)
end
else
--atdebug("Committed Route:",tcbs.routeset)
- has_changed_aspect = true
+ -- set_route now sets the signal aspects
+ --has_changed_aspect = true
end
end
if has_changed_aspect then