aboutsummaryrefslogtreecommitdiff
path: root/advtrains_luaautomation/environment.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_luaautomation/environment.lua')
-rw-r--r--advtrains_luaautomation/environment.lua35
1 files changed, 31 insertions, 4 deletions
diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua
index 63aa68d..a6ed2c7 100644
--- a/advtrains_luaautomation/environment.lua
+++ b/advtrains_luaautomation/environment.lua
@@ -150,9 +150,15 @@ local static_env = {
--interrupts are handled per node, position unknown. (same goes for digilines)
--however external interrupts can be set here.
interrupt_pos = function(parpos, imesg)
- local pos=atlatc.pcnaming.resolve_pos(parpos)
+ local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos")
atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg})
end,
+ train_parts = function(train_id)
+ if not train_id then return false end
+ local train = advtrains.trains[train_id]
+ if not train then return false end
+ return table.copy(train.trainparts or {})
+ end,
-- sends an atc command to train regardless of where it is in the world
atc_send_to_train = function(train_id, command)
assertt(command, "string")
@@ -164,6 +170,9 @@ local static_env = {
return false
end
end,
+ get_slowdown = function()
+ return advtrains.global_slowdown
+ end
}
-- If interlocking is present, enable route setting functions
@@ -217,11 +226,24 @@ if advtrains.interlocking then
end
static_env.get_aspect = function(signal)
local pos = atlatc.pcnaming.resolve_pos(signal)
- return advtrains.interlocking.signal_get_aspect(pos)
+ return advtrains.interlocking.signal.get_aspect_info(pos)
end
- static_env.set_aspect = function(signal, asp)
+ static_env.set_aspect = function(signal, main_asp, rem_signal)
+ if type(main_asp) == "table" then
+ error("set_aspect: Parameters of this method have changed to (signal, main_asp, rem_signal) with introduction of distant signalling: parameter 2 is now the main aspect name (a string)")
+ end
local pos = atlatc.pcnaming.resolve_pos(signal)
- return advtrains.interlocking.signal_set_aspect(pos)
+ local rem_pos = rem_signal and atlatc.pcnaming.resolve_pos(rem_signal)
+ return advtrains.interlocking.signal_set_aspect(pos, main_asp, rem_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 not response then return false end
+ return (response.trains and table.copy(response.trains)) or {}
end
end
@@ -250,6 +272,11 @@ if advtrains.lines then
}
end
+
+atlatc.register_function = function (name, f)
+ static_env[name] = f
+end
+
for _, name in pairs(safe_globals) do
static_env[name] = _G[name]
end