aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/train_sections.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/train_sections.lua')
-rw-r--r--advtrains_interlocking/train_sections.lua37
1 files changed, 19 insertions, 18 deletions
diff --git a/advtrains_interlocking/train_sections.lua b/advtrains_interlocking/train_sections.lua
index 757f36a..083676b 100644
--- a/advtrains_interlocking/train_sections.lua
+++ b/advtrains_interlocking/train_sections.lua
@@ -75,7 +75,10 @@ local function setsection(tid, train, ts_id, ts, sigd)
end
-- routes
- local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ local tcbs
+ if sigd then
+ tcbs = advtrains.interlocking.db.get_tcbs(sigd)
+ end
-- route setting - clear route state
if ts.route then
@@ -86,24 +89,22 @@ local function setsection(tid, train, ts_id, ts, sigd)
advtrains.interlocking.route.cancel_route_from(ts.route.origin)
atwarn("Route was cancelled.")
else
- -- train entered route regularily. Reset route and signal
- tcbs.route_committed = nil
- tcbs.route_comitted = nil -- TODO compatibility cleanup
- tcbs.aspect = nil
- tcbs.route_origin = nil
- advtrains.interlocking.update_signal_aspect(tcbs)
- if tcbs.signal and sigd_equal(ts.route.entry, ts.route.origin) then
- if tcbs.route_auto and tcbs.routeset then
- --atdebug("Resetting route (",ts.route.origin,")")
- advtrains.interlocking.route.update_route(ts.route.origin, tcbs)
- else
- tcbs.routeset = nil
- end
- end
+ -- train entered route regularily.
end
ts.route = nil
end
- if tcbs.signal then
+ if tcbs and tcbs.signal then
+ -- Reset route and signal
+ -- Note that the hit-route case is already handled by cancel_route_from
+ -- this code only handles signal at entering tcb and also triggers for non-route ts
+ tcbs.route_committed = nil
+ tcbs.route_aspect = nil
+ tcbs.route_remote = nil
+ tcbs.route_origin = nil
+ if not tcbs.route_auto then
+ tcbs.routeset = nil
+ end
+ advtrains.interlocking.signal.update_route_aspect(tcbs)
advtrains.interlocking.route.update_route(sigd, tcbs)
end
end
@@ -167,13 +168,13 @@ 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 ts_id, origin = ildb.get_ts_at_pos(pos)
+ 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)
if ts then
setsection(id, train, ts_id, ts, origin)
else
- atwarn("ILDB corruption: TCB",origin," has invalid TS reference")
+ atwarn("While placing train, TS didnt exist ",ts_id)
end
-- Make train a shunt move
train.is_shunt = true