summaryrefslogtreecommitdiff
path: root/auto_yards
diff options
context:
space:
mode:
Diffstat (limited to 'auto_yards')
-rw-r--r--auto_yards/init_code.lua25
-rw-r--r--auto_yards/nodes/(-2004,2,-1101).lua23
-rw-r--r--auto_yards/nodes/(416,17,5).lua27
3 files changed, 73 insertions, 2 deletions
diff --git a/auto_yards/init_code.lua b/auto_yards/init_code.lua
index cdeacce..6e4551f 100644
--- a/auto_yards/init_code.lua
+++ b/auto_yards/init_code.lua
@@ -8,7 +8,10 @@ if event.init then
active_indicator_pos = POS(),
dir_indicator_pos = POS(),
error_indicator_pos = POS(),
+ ext_notify_pos = POS(),
+ notify = table,
headshunt_max = number,
+
},
]]--
TY = {
@@ -21,6 +24,8 @@ if event.init then
active_indicator_pos = POS(-2002,3,-1099),
dir_indicator_pos = POS(-2009,3,-1101),
error_indicator_pos = POS(-1999,3,-1099),
+ ext_notify_pos = POS(-2004,2,-1101),
+ notify = {},
headshunt_max = 5,
},
IP = {
@@ -40,7 +45,11 @@ end
-- Utility Functions
F.indicator = function(indicator,set)
if set ~= nil then
- setstate(indicator,(set and "on") or "off")
+ if type(set) == string then
+ setstate(indicator,set)
+ else
+ setstate(indicator,(set and "on") or "off")
+ end
end
return (getstate(indicator) == "on") or false
end
@@ -156,7 +165,6 @@ F.yard_arrival = function(yard_id,this_dir) -- arrow points towards yard
F.add_rc({yard_id.."_HAS_RTS"})
rts = true
end
- step_fc()
atc_set_ars_disable(false)
atc_send("S6")
print("Train "..atc_id.." enters yard ".. yard_id.." from the "..tostring(this_dir).." direction and "..((rts and "will") or "won't").." return in the same direction")
@@ -352,6 +360,7 @@ F.headshunt_exit = function(yard_id,this_dir) -- arrow points out of yard
F.remove_rc(yard_id.."_HAS_RTS")
F.add_rc({yard_id.."_RTS"})
end
+ step_fc()
atc_set_ars_disable(false)
atc_send("S6D10SM")
schedule_in(";05","deactivate_check") -- wait a little to ensure train is clear from headshunt to deactivate yard
@@ -368,6 +377,7 @@ F.headshunt_exit = function(yard_id,this_dir) -- arrow points out of yard
if event.msg == "deactivate_check" then
if not atc_id then
F.indicator(yard.active_indicator_pos,false)
+ if yard.ext_notify_pos then interrupt_pos(yard.ext_notify_pos,{command="EXIT"}) end
print(yard_id.." yard Disabled")
else
schedule_in(";05","deactivate_check")
@@ -401,6 +411,17 @@ F.lane_EOL = function(yard_id,this_dir) -- arrow points towards headshunt
else
if F.indicator(yard.dir_indicator_pos) == this_dir then
--train is clasifying wagons, let it pass and couple to the rest of the rake
+ --send a notification to the yard controller to trigger external functions
+ if yard.ext_notify_pos then
+ local fc = F.get_rc_safe():match(yard_id.."_CLASS_(%S+)") or nil
+ if fc then
+ if F.has_rc(yard_id.."_COLLECT_"..fc) then
+ interrupt_pos(yard.ext_notify_pos,{command="COLLECTED",msg=fc})
+ else
+ interrupt_pos(yard.ext_notify_pos,{command="NOTIFY",msg=fc})
+ end
+ end
+ end
F.remove_rc_match(yard_id.."_CLASS_%S+")
else --this should never come into play as it means the train has entered from the wrong end somehow
atc_send("BBOL") --stop the train and open the doors (if available) to signify assistance required
diff --git a/auto_yards/nodes/(-2004,2,-1101).lua b/auto_yards/nodes/(-2004,2,-1101).lua
new file mode 100644
index 0000000..c39016a
--- /dev/null
+++ b/auto_yards/nodes/(-2004,2,-1101).lua
@@ -0,0 +1,23 @@
+local yard_id = "BY"
+local subs = {
+ ['S27'] = POS(-1512,8,-2613)
+}
+if event.ext_int then
+ print(event)
+ local m = event.message
+ if m.command == "NOTIFY" then -- store the notifications in the yards's S table entry for mass-dispatch
+ if m.msg == "*" then return end -- no need to notify for the LHF train's collect moves
+ S.yards[yard_id].notify[m.msg] = true
+ return
+ end
+ if m.command == "COLLECTED" then
+ S.yards[yard_id].notify[m.msg] = nil
+ return
+ end
+ if m.command == "EXIT" then
+ for k in pairs(S.yards[yard_id].notify) do
+ if subs[k] then interrupt_pos(subs[k],{command="NOTIFY",msg=k}) end
+ end
+ return
+ end
+end \ No newline at end of file
diff --git a/auto_yards/nodes/(416,17,5).lua b/auto_yards/nodes/(416,17,5).lua
new file mode 100644
index 0000000..e8c1b0e
--- /dev/null
+++ b/auto_yards/nodes/(416,17,5).lua
@@ -0,0 +1,27 @@
+local stack = function(t,channel,num_screens)
+ for i=0,math.ceil(#t/4) do
+ local calc = i*4
+ local working_t = {t[calc+1],t[calc+2],t[calc+3],t[calc+4]}
+ local message = table.concat(working_t,"\n")
+ if i+1 > num_screens then return end
+ digiline_send(channel..i+1,message)
+ end
+end
+
+if event.channel=="clock" or event.punch then
+ local txt = {"-- AUTOMATIC YARD STATUS --","Railway Time: "..rwt.to_string(rwt.now(),true),"LHF Trains: 719814"," ========================"}
+ local s
+ for yard_id,info in pairs(S.yards) do
+ table.insert(txt, yard_id.." - Active: " .. tostring(F.indicator(info.active_indicator_pos)))
+ table.insert(txt," Direction: " .. tostring(F.indicator(info.dir_indicator_pos)))
+ table.insert(txt," Error: ".. tostring(F.indicator(info.error_indicator_pos)))
+ if info.notify and info.notify[1] then
+ table.insert(txt,"Notify: "..table.concat(info.notify,", "))
+ else
+ table.insert(txt,"Notify: N/A")
+ end
+ end
+
+ stack(txt,"yard_status",4)
+ return
+end \ No newline at end of file