summaryrefslogtreecommitdiff
path: root/Tyard/nodes/(-4011,12,-2646).lua
blob: 3c9efc37d625e658cfdeb20d4cb6233c3d96e83d (plain)
1
--arrow points into yard
-- config'd for Southbound entrance (North end of yard)
local dir = "N"
local entrance_signal = "Tyard_Enter_"..dir

-- train enters from mainline. stop at signal to be safe
if event.train and atc_arrow then atc_send("B0") end

if atc_arrow then
	local rc = get_rc() or ""
	-- allow for manual working
	if rc:match("TYARD_NOSHUNT") then return end
	
	if S.yard_active then -- send train to "waiting"
		if can_set_route(entrance_signal,"WAITING") then
			set_route(entrance_signal,"WAITING")
			atc_set_text_outside("Waiting for yard to clear")
			atc_send("S6")
		else
			interrupt(5,"recheck")
		end
	else -- send train to "pickup"
		S.yard_active = true
		step_fc()
		local rc = get_rc() or ""
		S.rc = rc
		
		--check for RTS
		if S.single_dir == true or S.rc:match("TY_RTS") then
			S.dir = dir
			--working end = entrance dir
			S.RTS = true
			set_rc("AROUND_"..S.dir)
		else
			--invert S.dir
			--working end ~= entrance end
			if dir == "N" then
				S.dir = "S" 
			else
				S.dir = "N"
			end
		end
		
		set_route(entrance_signal,"PICKUP")
		atc_set_text_outside("Proceeding to Classification Yard")
		atc_send("S4")
	end
else -- train exiting
	set_rc(S.rc)
	S.yard_active = nil
	S.rc = nil
	S.dir = nil
	unset_autocouple()
	atc_send("SM")
end