summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_yards/init_code.lua55
1 files changed, 34 insertions, 21 deletions
diff --git a/auto_yards/init_code.lua b/auto_yards/init_code.lua
index 1ac90df..d2f0c74 100644
--- a/auto_yards/init_code.lua
+++ b/auto_yards/init_code.lua
@@ -88,7 +88,7 @@ F.remove_rc = function(rc_list,arrow_mode) -- rc_list = string eg: "rc1 rc2 rc3"
rc_remove[word] = true
end
elseif type(rc_list) == "table" then
- for word in pairs(rc_list) do
+ for _,word in pairs(rc_list) do
rc_remove[word] = true
end
end
@@ -155,6 +155,7 @@ F.yard_arrival = function(yard_id,this_dir) -- arrow points towards yard
local function enter_yard()
F.indicator(yard.dir_indicator_pos,this_dir)
+ F.indicator(yard.active_indicator_pos,true)
F.add_rc({yard_id.."_ARRIVE"})
atc_set_ars_disable(false)
atc_send("S6")
@@ -189,6 +190,9 @@ end
F.classification = function(yard_id, this_dir) -- arrow points towards headshunt
local yard = S.yards[yard_id] --yard ref
+
+ if not F.indicator(yard.active_indicator_pos) then return end
+ if F.has_rc(yard_id.."_NOSHUNT") then return end
-- this_dir == true for north end, false for south end
if F.indicator(yard.active_indicator_pos) then
@@ -196,26 +200,27 @@ F.classification = function(yard_id, this_dir) -- arrow points towards headshunt
F.remove_rc({yard_id.."_PICKUP"})
if F.has_rc(yard_id.."_ARRIVE") and F.indicator(yard.dir_indicator_pos) == this_dir then --first pass, prep train for working
F.remove_rc({yard_id.."_AROUND"})
- if not F.has_rc_match(yard_id.."_LOCOS_%d+") or not F.has_rc_match(yard_id.."_WAGONS_%d+") then
+ if not F.get_rc_safe():match(yard_id.."_LOCOS_%d+") or not F.get_rc_safe():match(yard_id.."_WAGONS_%d+") then
local full_length = train_length()
- split_off_locomotive("A0B0")
- F.add_rc({yard_id.."_HEADSHUNT"}) -- train will end up going through headshunt no matter what. there shouldn't be any trains entering that pass straight through.
+ split_off_locomotive("A0B0") -- 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(yard_id.."_COLLECT_(%S+)") or ""
F.add_rc({yard_id.."_LAST_CLASS",yard_id.."_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({yard_id.."_LOCOS_"..train_length(), yard_id.."_WAGONS_"..(full_length-train_length()),yard_id.."_PICKUP"})
+ F.add_rc({yard_id.."_LOCOS_"..train_length(), yard_id.."_WAGONS_"..(full_length-train_length())})
end
- return -- train has departed for headshunt
- end
- if F.has_rc(yard_id.."_RTS") then
- F.indicator(yard.dir_indicator_pos,not F.indicator(yard.dir_indicator_pos))
- F.remove_rc({yard_id.."_RTS"})
- F.add_rc({yard_id.."_AROUND"}) -- send loco around to the other end
- split_off_locomotive("A0B0")
- atc_set_ars_disable(false)
- return -- train has departed for RTS loop
- end
+
+
+ if not F.has_rc(yard_id.."_RTS") then
+ F.add_rc({yard_id.."_HEADSHUNT",yard_id.."_PICKUP"})
+ else
+ F.indicator(yard.dir_indicator_pos,not F.indicator(yard.dir_indicator_pos))
+ F.remove_rc({yard_id.."_RTS"})
+ F.add_rc({yard_id.."_AROUND"}) -- send loco around to the other end
+ atc_set_ars_disable(false)
+ end
+ return -- train has departed for headshunt/around
+ end --else train has arrived from wagon count and headshunt/around
F.remove_rc({yard_id.."_ARRIVE"})
step_fc()
end
@@ -231,7 +236,7 @@ F.classification = function(yard_id, this_dir) -- arrow points towards headshunt
if lane ~= "" then
F.add_rc({yard_id.."_CLASS_"..lane})
end
- F.remove_match(yard_id.."_WAGONS_%d+")
+ F.remove_rc_match(yard_id.."_WAGONS_%d+")
F.add_rc({yard_id.."_HEADSHUNT",yard_id.."_WAGONS_"..wagons-this_rake})
atc_set_ars_disable(false)
set_autocouple()
@@ -248,8 +253,6 @@ end
F.headshunt_yard = function(yard_id,this_dir) -- arrow points toward yard
local yard = S.yards[yard_id] --yard ref
-
- if not F.indicator(yard.active_indicator_pos) then return end
__approach_callback_mode = 1
if event.approach and not event.has_entered then
@@ -258,6 +261,9 @@ F.headshunt_yard = function(yard_id,this_dir) -- arrow points toward yard
return
end
+ if not F.indicator(yard.active_indicator_pos) then return end
+ if F.has_rc(yard_id.."_NOSHUNT") then return end
+
if event.train then
if not atc_arrow then --train has entered headshunt from yard. bounce or depart
atc_set_ars_disable(true)
@@ -267,9 +273,12 @@ F.headshunt_yard = function(yard_id,this_dir) -- arrow points toward yard
schedule_in(";01",atc_id)
return
else
- local collect = F.get_rc_safe():match(yard_id.."_COLLECT_(%S+)")
+ 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.."_FINAL_COLLECT",yard_id.."_CLASS_"..collect})
+ 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
@@ -311,7 +320,6 @@ end
F.headshunt_exit = function(yard_id,this_dir) -- arrow points out of yard
local yard = S.yards[yard_id] --yard ref
- if not F.indicator(yard.active_indicator_pos) then return end
__approach_callback_mode = 1
if event.approach and not event.has_entered then
atc_set_ars_disable(true)
@@ -319,6 +327,9 @@ F.headshunt_exit = function(yard_id,this_dir) -- arrow points out of yard
return
end
+ if not F.indicator(yard.active_indicator_pos) then return end
+ if F.has_rc(yard_id.."_NOSHUNT") then return end
+
if event.train then
if atc_arrow and (F.indicator(yard.dir_indicator_pos) == this_dir) then
if F.has_rc(yard_id.."_DEPART") then
@@ -357,6 +368,8 @@ F.lane_EOL = function(yard_id,this_dir) -- arrow points towards headshunt
local yard = S.yards[yard_id] --yard ref
if not F.indicator(yard.active_indicator_pos) then return end
+ if F.has_rc(yard_id.."_NOSHUNT") then return end
+
if atc_arrow then
if F.indicator(yard.dir_indicator_pos) == this_dir then --train has bounced and needs to leave the rake or depart with it
if F.has_rc(yard_id.."_LAST_CLASS") then -- this is the last clasification move