aboutsummaryrefslogtreecommitdiff
path: root/advtrains/occupation.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/occupation.lua')
-rw-r--r--advtrains/occupation.lua20
1 files changed, 19 insertions, 1 deletions
diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua
index dd0235a..568f308 100644
--- a/advtrains/occupation.lua
+++ b/advtrains/occupation.lua
@@ -208,7 +208,7 @@ function o.get_occupations(train, index)
return r, pos
end
-- Gets a mapping of train id's to indexes of trains that stand or drive over
--- returns (table with train_id->index), position
+-- returns (table with train_id->index)
function o.get_trains_at(ppos)
local pos = advtrains.round_vector_floor_y(ppos)
local t = occget(pos)
@@ -226,4 +226,22 @@ function o.get_trains_at(ppos)
return r
end
+-- Gets a mapping of train id's to indexes of trains that have a path
+-- generated over this node
+-- returns (table with train_id->index)
+function o.get_trains_over(ppos)
+ local pos = advtrains.round_vector_floor_y(ppos)
+ local t = occget(pos)
+ if not t then return {} end
+ local r = {}
+ local i = 1
+ while t[i] do
+ local train = advtrains.trains[t[i]]
+ local idx = t[i+1]
+ r[t[i]] = idx
+ i = i + 2
+ end
+ return r
+end
+
advtrains.occ = o