From 23d524df71e66c443345a043c9767b7c947d5a5c Mon Sep 17 00:00:00 2001 From: Maverick2797 Date: Sun, 4 Jul 2021 16:34:04 +0800 Subject: 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. --- advtrains_luaautomation/environment.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) mode change 100644 => 100755 advtrains_luaautomation/environment.lua (limited to 'advtrains_luaautomation/environment.lua') diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua old mode 100644 new mode 100755 index e93b9c3..6b1a283 --- 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: -- cgit v1.2.3