diff options
Diffstat (limited to 'advtrains_interlocking/database.lua')
-rw-r--r-- | advtrains_interlocking/database.lua | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua index ee21db9..c5ae906 100644 --- a/advtrains_interlocking/database.lua +++ b/advtrains_interlocking/database.lua @@ -131,6 +131,12 @@ function ildb.load(data) if data.npr_rails then advtrains.interlocking.npr_rails = data.npr_rails end + if data.supposed_aspects then + advtrains.interlocking.load_supposed_aspects(data.supposed_aspects) + end + if data.distant then + advtrains.distant.load(data.distant) + end --COMPATIBILITY to Signal aspect format -- TODO remove in time... @@ -173,6 +179,8 @@ function ildb.save() rs_callbacks = advtrains.interlocking.route.rte_callbacks, influence_points = influence_points, npr_rails = advtrains.interlocking.npr_rails, + supposed_aspects = advtrains.interlocking.save_supposed_aspects(), + distant = advtrains.distant.save(), } end @@ -195,8 +203,6 @@ TCB data structure signal_name = <string> -- The human-readable name of the signal, only for documenting purposes routes = { <route definition> } -- a collection of routes from this signal route_auto = <boolean> -- When set, we will automatically re-set the route (designated by routeset) - distant = { <sigd1> ... } -- a collection of sigd that points to a side of a TCB with a distant signal for this current signal. - distant_of = { <sigd>, <index> } -- the reverse of the above field, along with the index of the entry in the list (for easier lookup) }, -- This is the "B" side of the TCB [2] = { -- Variant: end of track-circuited area (initial state of TC) @@ -636,6 +642,28 @@ function ildb.get_ip_by_signalpos(spos) end end end +function ildb.check_for_duplicate_ip(spos) + local main_ip_found = false + -- first pass: check for duplicates + for pts,tab in pairs(influence_points) do + for connid,pos in pairs(tab) do + if vector.equals(pos, spos) then + if main_ip_found then + atwarn("Signal at",spos,": Deleting duplicate signal influence point at",pts,"/",connid) + tab[connid] = nil + end + main_ip_found = true + end + end + end + -- second pass: delete empty tables + for pts,tab in pairs(influence_points) do + if not tab[1] and not tab[2] then -- only those two connids may exist + influence_points[pts] = nil + end + end +end + -- clear signal assignment given the signal position function ildb.clear_ip_by_signalpos(spos) local pts, connid = ildb.get_ip_by_signalpos(spos) |