summaryrefslogtreecommitdiff
path: root/ers_mtn
diff options
context:
space:
mode:
authorautocommitter <autocommitter@linux-forks.de>2024-04-22 15:00:40 +0200
committerautocommitter <autocommitter@linux-forks.de>2024-04-22 15:00:40 +0200
commit2e97492f1b8d577c2cdc0505c7f4e34d82fea8bf (patch)
tree065b8b48759151a3129eff9934abe6cad0f2ae1f /ers_mtn
parentb397e03fc6e1f2a2ff9885b525d01e3695f9c771 (diff)
downloadluaatc_envs-2e97492f1b8d577c2cdc0505c7f4e34d82fea8bf.tar.gz
luaatc_envs-2e97492f1b8d577c2cdc0505c7f4e34d82fea8bf.tar.bz2
luaatc_envs-2e97492f1b8d577c2cdc0505c7f4e34d82fea8bf.zip
State at 2023-07-26
Diffstat (limited to 'ers_mtn')
-rw-r--r--ers_mtn/init_code.lua214
-rw-r--r--ers_mtn/nodes/(1787,3,1264).lua15
-rw-r--r--ers_mtn/nodes/(1793,3,1264).lua15
-rw-r--r--ers_mtn/nodes/(1820,15,1223).lua10
-rw-r--r--ers_mtn/nodes/(1843,116,1259).lua11
-rw-r--r--ers_mtn/nodes/(1859,116,1259).lua11
-rw-r--r--ers_mtn/nodes/(1878,119,1237).lua9
-rw-r--r--ers_mtn/nodes/(1895,30,1201).lua11
-rw-r--r--ers_mtn/nodes/(1896,137,1246).lua11
-rw-r--r--ers_mtn/nodes/(1918,101,1257).lua11
-rw-r--r--ers_mtn/nodes/(1920,45,1224).lua11
-rw-r--r--ers_mtn/nodes/(1924,45,1224).lua11
-rw-r--r--ers_mtn/nodes/(1939,45,1212).lua11
-rw-r--r--ers_mtn/nodes/(1940,54,1251).lua11
-rw-r--r--ers_mtn/nodes/(1947,45,1209).lua11
-rw-r--r--ers_mtn/nodes/(1949,100,1254).lua11
-rw-r--r--ers_mtn/nodes/(1978,61,1261).lua11
-rw-r--r--ers_mtn/nodes/(2015,80,1217).lua11
18 files changed, 354 insertions, 52 deletions
diff --git a/ers_mtn/init_code.lua b/ers_mtn/init_code.lua
index 6e52905..6f346c5 100644
--- a/ers_mtn/init_code.lua
+++ b/ers_mtn/init_code.lua
@@ -1,39 +1,199 @@
+-- environment_ers_mtn.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 = 3
+ F.print("Initialized")
+end
--- Gleis A
--- 1787,3,1264
-
--- Gleis B
--- 1793,3,1264
-
--- erste Brücke
--- 1820,15,1223
-
-
-local gleisliste = {
-{ "gleisa", "Gleis A",{1787,3,1264} },
-{ "gleisb", "Gleis B", {1793,3,1264} },
-{ "erstebruecke", "erste Bruecke", {1820,15,1223 } },
-{ "kniebeuge", "Kniebeugebahnhof", { 1896, 137, 1246 } },
-}
-
-
-
+--[[
+ EXAMPLE: F.has_rc("LILSHUNTER", F.get_rc_safe() )
+ Merged F.has_rc and F.does_train_have_rc
+ F.does_train_have_rc is deprecated
+]]
+F.has_rc = function(query,rc_list) -- query = string, single entry
+ for word in rc_list:gmatch("[^%s]+") do
+ if word == query then return true end
+ end
+ return false
+end
+F.send_route = function(passive_name, route, show_print)
+ local message = ""
+ local return_value = false
+ if can_set_route(passive_name, route) then
+ set_route(passive_name, route)
+ message = passive_name .. " has been set to " .. route
+ return_value = true
+ else
+ message = route .. " cannot be set for " .. passive_name .. ". Try another."
+ return_value = false
+ end
+ if show_print == true then F.print(message) end
+ return return_value
+end
-S.atctracks = {}
+F.save_train = function(pos)
+ if not atc_id then return end
+ if S.trains then
+ if F.isempty(pos) then
+ pos_string = ""
+ else
+ pos_string = pos["x"] .. "," .. pos["y"] .. "," .. pos["z"]
+ end
+ if F.has_rc("FAREAST", F.get_rc_safe()) then
+ S.trains[atc_id] = { ["id"] = atc_id, ["rc"] = F.get_rc_safe(), ["ln"] = F.get_line_safe(), ["cars_count"] = F.get_train_length_safe(), ["pos"] = pos_string }
+ -- F.print("Train ID: " .. S.trains[atc_id]["id"] .. " at " .. S.trains[atc_id]["pos"])
+ -- remote_track = POS(30919,13,1812)
+ -- interrupt_pos(remote_track, "display")
+ end
+ end
+end
+F.get_real_split_count = function(train_length_count, split_count)
+ if split_count then
+ if split_count == "all" then
+ return 2
+ else
+ F.print("train_length_count (" .. train_length_count .. ") - split_count (" .. split_count .. ")")
+ train_length_count = train_length_count + 1
+ split_count = train_length_count - split_count
+ return split_count
+ end
+ else
+ return nil
+ end
+end
-for _,e in ipairs(gleisliste) do
- S.atctracks[e[1]] = e[2]
+F.delete_train_info = function(train_id)
+ if S.trains[train_id] then
+ S.trains[train_id] = nil
+ F.print("Deleted train id: " .. train_id)
+ end
end
+F.clear_main_depot_displays = function() for i = 1, F.max_displays, 1 do digiline_send("train_display" .. i, " ") end end
+F.send_update_displays = function() for i = 1, F.max_displays, 1 do digiline_send("train_display" .. i, "Updating...") end end
-S.daten = {}
+F.date_formatted = function()
+ date = os.date("%Y-%m-%d")
+ return date
+end
-S.section = {}
+F.time_formatted = function()
+ time = os.date("*t")
+ return string.format("%02d:%02d:%02d %s", time.hour, time.min, time.sec, (time.isdst and "CEST") or "CET")
+end
+F.list_trains = function(print_info)
+ if S.trains then
+ number_of_displays = F.max_displays
+ F.clear_main_depot_displays()
+ number_of_displays = number_of_displays + 1
+ count_keys = 0
+ trains_table = {}
+ for k in pairs(S.trains) do
+ table.insert(trains_table, k)
+ count_keys = count_keys + 1
+ end
+ table.sort(trains_table)
+ -- x = number_of_displays - count_keys
+ x = 1
+
+ for _, k in ipairs(trains_table) do
+ if S.trains[k] then
+ v = S.trains[k]
+ if F.has_rc("LILSHUNTER", v["rc"]) or F.has_rc("LIL", v["rc"]) then
+ F.delete_train_info(v["id"])
+ else
+ if v["ln"] == nil or v["ln"] == "" then
+ line_number = ""
+ else
+ line_number = "| LN: [" .. v["ln"] .. "]"
+ end
+ if v["pos"] == nil or v["pos"] == "" then
+ pos_string = ""
+ else
+ pos_string = "| POS: [" .. v["pos"] .. "]"
+ end
+ if v["rc"] == nil or v["rc"] == "" then
+ rc_display = ""
+ else
+ rc_list = v["rc"]
+ rc_list_cleansed = ""
+ rc_list_unknown = ""
+ rc_list_table = {}
+ if F.has_rc("ERSTAZI", rc_list) and F.has_rc("FREIGHT", rc_list) then
+ rc_list_cleansed = "ERSTAZI FREIGHT |"
+ else
+ rc_list_cleansed = "NO E,F |"
+ end
+ for rc in rc_list:gmatch("[^%s]+") do
+ if rc == "ERSTAZI" or rc == "FREIGHT" then
+ -- leaving for future use
+ do_nothing = true
+ else
+ rc_list_unknown = rc_list_unknown .. " " .. rc
+ end
+ end
+ rc_display = ""
+ if not F.isempty(rc_list_unknown) then
+ rc_display = rc_display .. "| RC:" .. rc_list_unknown
+ end
+ end
+ if v["cars_count"] == nil or v["cars_count"] == "" then
+ cars_count_display = " Len: 0"
+ else
+ cars_count = tonumber(v["cars_count"])
+ cars_count_display = " Len: " .. cars_count
+ end
+ message = " ID: " .. v["id"] .. cars_count_display .. rc_display .. line_number .. pos_string
+ if x > 0 then digiline_send("train_display" .. x, message) end
+ if print_info then
+ F.print(x .. ": " .. message)
+ end
+ x = x + 1
+ end
+ end
+ end
+
+ -- S.datetime = os.date("%Y-%m-%d %H:%M:%S")
+ -- digiline_send("time", " \n " .. S.datetime)
+
+ else
+ if print_info then
+ F.print("no trains saved in S.trains")
+ end
+ end
+end
-F.update = function()
-return
-end \ No newline at end of file
+F.slow_train_down = function(id)
+ result = atc_send_to_train(id, "B1")
+ if result == false then
+ F.print("Train ID " .. id .. " does not exist")
+ else
+ F.print("Train ID " .. id .. " is slowed down to B1")
+ end
+end
diff --git a/ers_mtn/nodes/(1787,3,1264).lua b/ers_mtn/nodes/(1787,3,1264).lua
index aa971c6..ffb0e06 100644
--- a/ers_mtn/nodes/(1787,3,1264).lua
+++ b/ers_mtn/nodes/(1787,3,1264).lua
@@ -2,15 +2,10 @@
--
-- 1787,3,1264
+-- far_luaatctrack_spot_check_01.lua
-if event.type == "train" then
- if atc_arrow then
- S.section.gleis_a = nil
- S.section.tal = event.id
- else
- S.section.gleis_a = event.id
- S.section.tal = nil
- end
- F.update()
- return
+if event.train then
+ local posTable = POS( 1787,3,1264 )
+ F.save_train(posTable)
+ return
end \ No newline at end of file
diff --git a/ers_mtn/nodes/(1793,3,1264).lua b/ers_mtn/nodes/(1793,3,1264).lua
index 084819f..8a0ff45 100644
--- a/ers_mtn/nodes/(1793,3,1264).lua
+++ b/ers_mtn/nodes/(1793,3,1264).lua
@@ -2,15 +2,10 @@
--
-- 1793,3,1264
+-- far_luaatctrack_spot_check_01.lua
-if event.type == "train" then
- if atc_arrow then
- S.section.gleis_b = nil
- S.section.tal = event.id
- else
- S.section.gleis_b = event.id
- S.section.tal = nil
- end
- F.update()
- return
+if event.train then
+ local posTable = POS( 1793,3,1264 )
+ F.save_train(posTable)
+ return
end \ No newline at end of file
diff --git a/ers_mtn/nodes/(1820,15,1223).lua b/ers_mtn/nodes/(1820,15,1223).lua
index 6e759ad..813d66c 100644
--- a/ers_mtn/nodes/(1820,15,1223).lua
+++ b/ers_mtn/nodes/(1820,15,1223).lua
@@ -1,3 +1,11 @@
--
--
--- 1820,15,1223 \ No newline at end of file
+-- 1820,15,1223
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1820,15,1223 )
+ F.save_train(posTable)
+ return
+end \ No newline at end of file
diff --git a/ers_mtn/nodes/(1843,116,1259).lua b/ers_mtn/nodes/(1843,116,1259).lua
new file mode 100644
index 0000000..2ffbff6
--- /dev/null
+++ b/ers_mtn/nodes/(1843,116,1259).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1843,116,1259
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1843,116,1259 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1859,116,1259).lua b/ers_mtn/nodes/(1859,116,1259).lua
new file mode 100644
index 0000000..5725f93
--- /dev/null
+++ b/ers_mtn/nodes/(1859,116,1259).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1859,116,1259
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1859,116,1259 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1878,119,1237).lua b/ers_mtn/nodes/(1878,119,1237).lua
index 812195b..fd88a95 100644
--- a/ers_mtn/nodes/(1878,119,1237).lua
+++ b/ers_mtn/nodes/(1878,119,1237).lua
@@ -1,4 +1,11 @@
--
--
-- 1878,119,1237
---
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1878,119,1237 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1895,30,1201).lua b/ers_mtn/nodes/(1895,30,1201).lua
new file mode 100644
index 0000000..dda3a2b
--- /dev/null
+++ b/ers_mtn/nodes/(1895,30,1201).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1895,30,1201
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1895,30,1201 )
+ F.save_train(posTable)
+ return
+end \ No newline at end of file
diff --git a/ers_mtn/nodes/(1896,137,1246).lua b/ers_mtn/nodes/(1896,137,1246).lua
index d0cf0ba..10221f5 100644
--- a/ers_mtn/nodes/(1896,137,1246).lua
+++ b/ers_mtn/nodes/(1896,137,1246).lua
@@ -1,6 +1,11 @@
--
--
--- 1896, 137, 1246
---
+-- 1896,137,1246
+
+-- far_luaatctrack_spot_check_01.lua
--- "kniebeuge", { 1896, 137, 1246 } \ No newline at end of file
+if event.train then
+ local posTable = POS( 1896,137,1246 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1918,101,1257).lua b/ers_mtn/nodes/(1918,101,1257).lua
new file mode 100644
index 0000000..ca9ed87
--- /dev/null
+++ b/ers_mtn/nodes/(1918,101,1257).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1918,101,1257
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1918,101,1257 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1920,45,1224).lua b/ers_mtn/nodes/(1920,45,1224).lua
new file mode 100644
index 0000000..bfeef31
--- /dev/null
+++ b/ers_mtn/nodes/(1920,45,1224).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1920,45,1224
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1920,45,1224 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1924,45,1224).lua b/ers_mtn/nodes/(1924,45,1224).lua
new file mode 100644
index 0000000..44e457e
--- /dev/null
+++ b/ers_mtn/nodes/(1924,45,1224).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1924,45,1224
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1924,45,1224 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1939,45,1212).lua b/ers_mtn/nodes/(1939,45,1212).lua
new file mode 100644
index 0000000..2d12777
--- /dev/null
+++ b/ers_mtn/nodes/(1939,45,1212).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1939,45,1212
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1939,45,1212 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1940,54,1251).lua b/ers_mtn/nodes/(1940,54,1251).lua
new file mode 100644
index 0000000..74ef0d2
--- /dev/null
+++ b/ers_mtn/nodes/(1940,54,1251).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1940,54,1251
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1940,54,1251 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1947,45,1209).lua b/ers_mtn/nodes/(1947,45,1209).lua
new file mode 100644
index 0000000..606243c
--- /dev/null
+++ b/ers_mtn/nodes/(1947,45,1209).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1947,45,1209
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1947,45,1209 )
+ F.save_train(posTable)
+ return
+end \ No newline at end of file
diff --git a/ers_mtn/nodes/(1949,100,1254).lua b/ers_mtn/nodes/(1949,100,1254).lua
new file mode 100644
index 0000000..35db00c
--- /dev/null
+++ b/ers_mtn/nodes/(1949,100,1254).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1949,100,1254
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1949,100,1254 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(1978,61,1261).lua b/ers_mtn/nodes/(1978,61,1261).lua
new file mode 100644
index 0000000..59419f5
--- /dev/null
+++ b/ers_mtn/nodes/(1978,61,1261).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 1978,61,1261
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 1978,61,1261 )
+ F.save_train(posTable)
+ return
+end
diff --git a/ers_mtn/nodes/(2015,80,1217).lua b/ers_mtn/nodes/(2015,80,1217).lua
new file mode 100644
index 0000000..239e5d6
--- /dev/null
+++ b/ers_mtn/nodes/(2015,80,1217).lua
@@ -0,0 +1,11 @@
+--
+--
+-- 2015,80,1217
+
+-- far_luaatctrack_spot_check_01.lua
+
+if event.train then
+ local posTable = POS( 2015,80,1217 )
+ F.save_train(posTable)
+ return
+end