aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/environment.lua
diff options
context:
space:
mode:
authorMaverick2797 <git.maverick2797@gmail.com>2021-07-04 16:34:04 +0800
committerorwell96 <orwell@bleipb.de>2021-12-29 21:16:32 +0100
commit23d524df71e66c443345a043c9767b7c947d5a5c (patch)
treee374a0c7afa40e78030d0a7ac1576bb9e9f2edde /advtrains_luaautomation/environment.lua
parent5912f778e1e4ed568a0874bc200d71f258624390 (diff)
downloadadvtrains-23d524df71e66c443345a043c9767b7c947d5a5c.tar.gz
advtrains-23d524df71e66c443345a043c9767b7c947d5a5c.tar.bz2
advtrains-23d524df71e66c443345a043c9767b7c947d5a5c.zip
Luaautomation: add section_occupancy()
Returns a table of train ids for the specified section. Returns nil if the section id is not provided.. Returns false if the section id is invalid. Returns an empty table if the section id is valid but empty of trains.
Diffstat (limited to 'advtrains_luaautomation/environment.lua')
-rwxr-xr-x[-rw-r--r--]advtrains_luaautomation/environment.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index e93b9c3..6b1a283 100644..100755
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -223,6 +223,18 @@ if advtrains.interlocking then
local pos = atlatc.pcnaming.resolve_pos(signal)
return advtrains.interlocking.signal_set_aspect(pos)
end
+
+ --section_occupancy()
+ static_env.section_occupancy = function(ts_id)
+ if not ts_id then return nil end
+ ts_id = tostring(ts_id)
+ local response = advtrains.interlocking.db.get_ts(ts_id)
+ if response == nil then
+ return false
+ else
+ return response.trains
+ end
+ end
end
-- Lines-specific: