aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/database.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/database.lua')
-rw-r--r--advtrains_interlocking/database.lua15
1 files changed, 11 insertions, 4 deletions
diff --git a/advtrains_interlocking/database.lua b/advtrains_interlocking/database.lua
index 299f6cc..12853c0 100644
--- a/advtrains_interlocking/database.lua
+++ b/advtrains_interlocking/database.lua
@@ -434,16 +434,17 @@ end
-- Utilize the traverser to find the track section at the specified position
-- Returns:
-- ts_id, origin - the first found ts and the sigd of the found tcb
--- nil - there were no TCBs in TRAVERSER_MAX range of the position, or track ends were reached
--- false - the first found TCB stated End-Of-Interlocking
+-- nil - there were no TCBs in TRAVERSER_MAX range of the position
+-- false - the first found TCB stated End-Of-Interlocking, or track ends were reached
function ildb.get_ts_at_pos(pos)
local node_ok, conns, rhe = advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
if not node_ok then
error("get_ts_at_pos but node is NOK: "..minetest.pos_to_string(pos))
end
+ local limit_hit = false
local found_tcbs = {}
for connid, conn in ipairs(conns) do -- Note: a breadth-first-search would be better for performance
- traverser(found_tcbs, pos, conns, connid, 0, 1)
+ limit_hit = limit_hit or traverser(found_tcbs, pos, conns, connid, 0, 1)
if #found_tcbs >= 1 then
local tcbs = ildb.get_tcbs(found_tcbs[1])
local ts
@@ -454,7 +455,13 @@ function ildb.get_ts_at_pos(pos)
end
end
end
- return nil
+ if limit_hit then
+ -- there was at least one limit hit
+ return nil
+ else
+ -- all traverser ends were track ends
+ return false
+ end
end