summaryrefslogtreecommitdiff
path: root/m4/init_code.lua
diff options
context:
space:
mode:
authorautocommitter <autocommitter@linux-forks.de>2024-10-15 22:37:32 +0200
committerautocommitter <autocommitter@linux-forks.de>2024-10-15 22:37:32 +0200
commit5c7f77725394d47ce0b907aabf885ea207a507bd (patch)
treea1ff9c67ef8f225a259e4c6f4c163a45c58bb870 /m4/init_code.lua
parentb435d1b1b26db6f7c4f3eb589ecf1ed3bb79b57e (diff)
downloadluaatc_envs-5c7f77725394d47ce0b907aabf885ea207a507bd.tar.gz
luaatc_envs-5c7f77725394d47ce0b907aabf885ea207a507bd.tar.bz2
luaatc_envs-5c7f77725394d47ce0b907aabf885ea207a507bd.zip
State at 2024-10-15
Diffstat (limited to 'm4/init_code.lua')
-rw-r--r--m4/init_code.lua96
1 files changed, 96 insertions, 0 deletions
diff --git a/m4/init_code.lua b/m4/init_code.lua
new file mode 100644
index 0000000..8133311
--- /dev/null
+++ b/m4/init_code.lua
@@ -0,0 +1,96 @@
+--env-m4.lua
+if S.trains == nil then S.trains = {} end
+if S.d == nil then S.d = {} end
+if S.datetime == nil then S.datetime = "" end
+if S.stop_display == nil then S.stop_display = false end
+
+F.print = function (str) if F.debug then print("".. (str or "nil") ) end end
+F.isempty = function (s) return s == nil or s == "" end
+F.get_rc_safe = function() return get_rc() or "" end
+F.get_line_safe = function() return get_line() or "" end
+F.get_train_length_safe = function() return train_length() or 0 end
+F.avg = function(t)
+ local sum = 0
+ local count = 0
+ for k,v in pairs(t) do
+ if type(v) == "number" then
+ sum = sum + v
+ count = count + 1
+ end
+ end
+ return (sum / count)
+end
+
+if event.init then
+ F.debug = true
+ F.printAllTrainsInfo = true
+ F.max_displays = 4
+ F.print("Initialized")
+end
+
+F.does_train_have_rc = function(wanted_rc)
+ local rc = F.get_rc_safe()
+ if rc:match(wanted_rc) then return true end
+end
+
+--old splitter and cpl for demo
+function F.cpllooparound(ln)
+ if not (event.train) then
+ return
+ end
+ if not (F.get_line_safe() == ln) then return end
+
+ if "ENGINE" == F.get_rc_safe() then
+ atc_send("CplS0WRSM")
+ set_rc("")
+ return
+ end
+
+ split_at_index(F.get_train_length_safe()-1,"A0S0") --Stopping the wagons is handled here by SO
+ set_rc("ENGINE")
+ atc_send("A1")
+
+end
+
+--new ones
+function F.split_looparound(ln)
+ if not (event.train) then return end
+ if not (F.get_line_safe() == ln) then return end
+
+ split_at_index(F.get_train_length_safe()-1,"A0S0OC") --Stopping the wagons is handled here by SO
+ set_rc("ENGINE")
+ atc_send("A1")
+
+end
+
+function F.split_looparound_left(ln)
+ if not (event.train) then return end
+ if not (F.get_line_safe() == ln) then return end
+
+ split_at_index(F.get_train_length_safe()-1,"A0S0OL") --Stopping the wagons is handled here by SO
+ set_rc("ENGINE")
+ atc_send("A1")
+
+end
+function F.split_looparound_right(ln)
+ if not (event.train) then return end
+ if not (F.get_line_safe() == ln) then return end
+
+ split_at_index(F.get_train_length_safe()-1,"A0S0OR") --Stopping the wagons is handled here by SO
+ set_rc("ENGINE")
+ atc_send("A1")
+
+end
+
+function F.cpl_looparound(ln)
+ if not (event.train) then return end
+ if not (F.get_line_safe() == ln) then return end
+
+ if "ENGINE" == F.get_rc_safe() then
+ atc_send("CplS0WD2RS4")
+ set_rc("")
+ return
+ end
+
+end
+--end of new cpl functions