From c5162349ed82ccbde82a8f870a45e7cc5c0c5e65 Mon Sep 17 00:00:00 2001 From: autocommitter Date: Mon, 22 Apr 2024 14:57:00 +0200 Subject: State at 2022-04-23 --- Tyard/nodes/(-4027,12,-2655).lua | 47 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'Tyard/nodes/(-4027,12,-2655).lua') diff --git a/Tyard/nodes/(-4027,12,-2655).lua b/Tyard/nodes/(-4027,12,-2655).lua index 5634403..b7ed9c7 100644 --- a/Tyard/nodes/(-4027,12,-2655).lua +++ b/Tyard/nodes/(-4027,12,-2655).lua @@ -4,40 +4,51 @@ local this_dir = true if F.yard_active() then if atc_arrow then -- loco is at working end F.remove_rc({"TY_PICKUP"}) - if F.has_rc("TY_ARRIVE") then --first pass, prep train for working + if F.has_rc("TY_ARRIVE") and F.dir() == this_dir then --first pass, prep train for working F.remove_rc({"TY_AROUND"}) + if not F.get_rc_safe():match("TY_LOCOS_%d+") or not F.get_rc_safe():match("TY_WAGONS_%d+") then + local full_length = train_length() + split_off_locomotive("A0B0") + F.add_rc({"TY_HEADSHUNT"}) -- train will end up going through headshunt no matter what. there shouldn't be any trains entering that pass straight through. + if train_length() == full_length then --train is either only here for collection or there's no FC's in the wagons. can't differentiate + local lane = F.get_rc_safe():match("TY_COLLECT_(%S+)") or "" + F.add_rc({"TY_LAST_CLASS","TY_CLASS_"..lane}) -- direct train to correct lane for collection + else --identify and save loco:wagon ratio, then bounce back from headshunt. it's easier than trying to reconnect + F.add_rc({"TY_LOCOS_"..train_length(), "TY_WAGONS_"..(full_length-train_length()),"TY_PICKUP"}) + end + return -- train has departed for headshunt + end if F.has_rc("TY_RTS") then F.dir(not F.dir()) F.remove_rc({"TY_RTS"}) F.add_rc({"TY_HEADSHUNT","TY_AROUND"}) -- send loco around to the other end split_off_locomotive("A0B0") atc_set_ars_disable(false) - return + return -- train has departed for RTS loop end F.remove_rc({"TY_ARRIVE"}) step_fc() end if this_dir == F.dir() then --train has bounced and is ready to classify wagon(s) - local t_len = train_length() - local lane = split_at_fc("A0B0",3) - if t_len ~= train_length() then -- train still has wagons to classify - F.add_rc({"TY_CLASS_"..lane}) -- to be pattern matched when leaving lane - else -- train_length is the same as it was before it tried to split_at_fc, hence it's just the loco - if not F.has_rc("TY_LAST_CLASS") then - F.add_rc({"TY_CLASS_"..lane,"TY_LAST_CLASS"}) - else - local collect = F.get_rc_safe():match("TY_COLLECT_(%S+)") - if not collect then - F.add_rc({"TY_DEPART"}) -- run engines-light to the exit, we're not collecting anything - else - F.add_rc({"TY_FINAL_COLLECT","TY_CLASS_"..collect}) --loco is to collect lane before departing. TY_DEPART to be set by EOL - end - end + -- local pre_split = train_length() + local lane = split_at_fc("A0B0",3) -- where to classify this rake + local locos = tonumber(F.get_rc_safe():match("TY_LOCOS_(%d+)")) or 1 --saved loco count + local wagons = tonumber(F.get_rc_safe():match("TY_WAGONS_(%d+)")) or 0 -- wagon_count from last classification split + local this_rake = train_length() - locos-- subtract these wagons from the overall wagon count + if this_rake == wagons then -- mark for last_classification + F.add_rc({"TY_LAST_CLASS"}) + end + if lane ~= "" then + F.add_rc({"TY_CLASS_"..lane}) + end + for v in F.get_rc_safe():gmatch("(TY_WAGONS_%d+)") do + F.remove_rc({v}) end - F.add_rc({"TY_HEADSHUNT"}) + F.add_rc({"TY_HEADSHUNT","TY_WAGONS_"..wagons-this_rake}) atc_set_ars_disable(false) set_autocouple() else --bounce train back towards working end + atc_set_ars_disable(true) atc_send("S0WRD1S3") unset_autocouple() end -- cgit v1.2.3