aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/database.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-11-14 17:31:04 +0100
committerorwell96 <orwell@bleipb.de>2021-11-14 17:32:20 +0100
commit358bff47b2325a76808f80bfd8c06b684a6efbb8 (patch)
treead56853aeab13d93f86a662ea92910e252749b5f /advtrains_interlocking/database.lua
parent546ae49167d0eabe4617e7506ade97d2cf489d55 (diff)
downloadadvtrains-358bff47b2325a76808f80bfd8c06b684a6efbb8.tar.gz
advtrains-358bff47b2325a76808f80bfd8c06b684a6efbb8.tar.bz2
advtrains-358bff47b2325a76808f80bfd8c06b684a6efbb8.zip
Interlocking: Correct duplicate influence points semi-automaticallyrelease-2.4.0
Searches and deletes duplicate influence points for the same signal when "Influence Point" formspec is opened.
Diffstat (limited to 'advtrains_interlocking/database.lua')
-rw-r--r--advtrains_interlocking/database.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index a35d446..6787c50 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -634,6 +634,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)