From 21b3997259ef9559c56e114e1733049dd2ebe8ac Mon Sep 17 00:00:00 2001 From: autocommitter Date: Mon, 22 Apr 2024 14:57:38 +0200 Subject: State at 2022-06-11 --- auto_yards/init_code.lua | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'auto_yards') diff --git a/auto_yards/init_code.lua b/auto_yards/init_code.lua index 2c3d631..6286947 100644 --- a/auto_yards/init_code.lua +++ b/auto_yards/init_code.lua @@ -3,20 +3,31 @@ -- Yard Information if event.init then S.yards = { + --[[ yard info template + yard_id = { + active_indicator_pos = POS(), + dir_indicator_pos = POS(), + error_indicator_pos = POS(), + headshunt_max = number, + }, + ]]-- TY = { active_indicator_pos = POS(-4025,14,-2659), dir_indicator_pos = POS(-4025,13,-2665), error_indicator_pos = POS(-4025,13,-2671), + headshunt_max = 5, }, BY = { active_indicator_pos = POS(-2002,3,-1099), dir_indicator_pos = POS(-2009,3,-1099), error_indicator_pos = POS(-1999,3,-1099), + headshunt_max = 5, }, IP = { active_indicator_pos = POS(1179,16,3848), dir_indicator_pos = POS(1179,16,3855), error_indicator_pos = POS(1179,16,3850), + headshunt_max = 5, }, -- HY = { -- active_indicator_pos = POS(-4025,14,-2659), @@ -133,9 +144,15 @@ F.yard_arrival = function(yard_id,this_dir) -- arrow points towards yard if F.has_rc(yard_id.."_NOSHUNT") then return end local function enter_yard() + if not atc_id then + F.indicator(yard.error_indicator_pos,true) + end F.indicator(yard.dir_indicator_pos,this_dir) F.indicator(yard.active_indicator_pos,true) F.add_rc({yard_id.."_ARRIVE"}) + if F.has_rc(yard_id.."_RTS") then --save the RTS flag as it's removed during the arrival procedure + F.add_rc({yard_id.."_HAS_RTS"}) + end atc_set_ars_disable(false) atc_send("S6") return @@ -210,7 +227,7 @@ F.classification = function(yard_id, this_dir) -- arrow points towards headshunt end if this_dir == F.indicator(yard.dir_indicator_pos) then --train has bounced and is ready to classify wagon(s) -- local pre_split = train_length() - local lane = split_at_fc("A0B0",5) -- where to classify this rake -- headshunt length + local lane = split_at_fc("A0B0",yard.headshunt_max) -- where to classify this rake -- headshunt length local locos = tonumber(F.get_rc_safe():match(yard_id.."_LOCOS_(%d+)")) or 1 --saved loco count local wagons = tonumber(F.get_rc_safe():match(yard_id.."_WAGONS_(%d+)")) or 0 -- wagon_count from last classification split local this_rake = train_length() - locos-- subtract these wagons from the overall wagon count @@ -257,15 +274,23 @@ F.headshunt_yard = function(yard_id,this_dir) -- arrow points toward yard schedule_in(";01",atc_id) return else - local collect,next_collect = F.get_rc_safe():match(yard_id.."_COLLECT_(%S+)") - if collect then --train needs to collect a rake from the yard before departing - F.add_rc({yard_id.."_CLASS_"..collect}) - if not next_collect then - F.add_rc({yard_id.."_FINAL_COLLECT"}) + if get_line() ~= "LHF" then -- LHF trains will always only collect the * lane for that direction. This code is for other trains + local collect,next_collect = F.get_rc_safe():match(yard_id.."_COLLECT_(%S+)") + if collect then --train needs to collect a rake from the yard before departing + F.add_rc({yard_id.."_CLASS_"..collect}) + if not next_collect then + F.add_rc({yard_id.."_FINAL_COLLECT"}) + end + schedule_in(";01",atc_id) + return end + else -- CLASS_* should never be set in ARS, instead being left to the * route + F.add_rc({yard_id.."_FINAL_COLLECT", yard_id.."_CLASS_*"}) schedule_in(";01",atc_id) return end + + end --else let train proceed forward to the exit controller without a rake @@ -322,6 +347,10 @@ F.headshunt_exit = function(yard_id,this_dir) -- arrow points out of yard F.remove_rc({yard_id.."_FINAL_COLLECT",yard_id.."_DEPART"}) F.remove_rc_match(yard_id.."_LOCOS_%d+") F.remove_rc_match(yard_id.."_WAGONS_%d+") + if F.has_rc(yard_id.."_HAS_RTS") then --reinsert the RTS flag to fully return RC list to starting + F.remove_rc(yard_id.."_HAS_RTS") + F.add_rc({yard_id.."_RTS"}) + end atc_set_ars_disable(false) -- set_route(exit_signal,"Exit Yard") atc_send("S6D10SM") -- cgit v1.2.3