From ac853fa04d0d8a6489320dfe7dbd60c9371d756b Mon Sep 17 00:00:00 2001 From: autocommitter Date: Mon, 22 Apr 2024 14:57:43 +0200 Subject: State at 2022-06-19 --- auto_yards/init_code.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'auto_yards/init_code.lua') 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 -- cgit v1.2.3