summaryrefslogtreecommitdiff
path: root/Crossroads/init_code.lua
diff options
context:
space:
mode:
authorautocommitter <autocommitter@linux-forks.de>2024-04-22 15:02:54 +0200
committerautocommitter <autocommitter@linux-forks.de>2024-04-22 15:02:54 +0200
commitc9e1df06b462e513057ac3e0e7489c74b56e2af8 (patch)
tree629d1d58755d5eae678b2ca19249727682581fbc /Crossroads/init_code.lua
parent983c42157ac3dff23df2d693d1d972179ab00232 (diff)
downloadluaatc_envs-c9e1df06b462e513057ac3e0e7489c74b56e2af8.tar.gz
luaatc_envs-c9e1df06b462e513057ac3e0e7489c74b56e2af8.tar.bz2
luaatc_envs-c9e1df06b462e513057ac3e0e7489c74b56e2af8.zip
State at 2023-11-07
Diffstat (limited to 'Crossroads/init_code.lua')
-rw-r--r--Crossroads/init_code.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/Crossroads/init_code.lua b/Crossroads/init_code.lua
index 67c2544..067c474 100644
--- a/Crossroads/init_code.lua
+++ b/Crossroads/init_code.lua
@@ -22,6 +22,52 @@ function F.error(errorcode)
error(F.errlist[errorcode])
end
+-- Level crossing handling
+if not S.crossings then S.crossings = {} end
+
+local crossing_light_count = {
+ NRG_1 = 2,
+ NRG_2 = 4,
+ NRG_3 = 3,
+ NRG_4 = 2,
+ NRG_5 = 4,
+}
+
+local function update_light(loc, k, v)
+ local t = S.crossings[loc]
+ if not t then
+ t = {}
+ S.crossings[loc] = t
+ end
+ t[k] = v
+ local val = "on"
+ if next(t) == nil then
+ val = "off"
+ end
+ local pfx = loc .. "_"
+ local count = crossing_light_count[loc]
+ if not count then return end
+ for i = 1, count do
+ setstate(pfx .. i, val)
+ end
+end
+
+function F.x_on(t)
+ if event.type ~= "train" then return end
+ if not atc_arrow then return end
+ for loc, k in pairs(t) do
+ update_light(loc, k, true)
+ end
+end
+
+function F.x_off(t)
+ if event.type ~= "train" then return end
+ if not atc_arrow then return end
+ for loc, k in pairs(t) do
+ update_light(loc, k, nil)
+ end
+end
+
--[[ F.stnbasic - Basis for all station functions:
(By default, nil is defined as false or "no changes")
stn = Station Code