summaryrefslogtreecommitdiff
path: root/Tyard/nodes/(-4100,12,-2742).lua
blob: 8ed965e8b7a0db680b78b33a9cb147f15b6dc200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- Headshunt Controller
-- Note: may need customising due to track layout
local this_dir = false -- true = F.dir arrow points north. atc_arrow points towards yard

if not F.yard_active() then return end

__approach_callback_mode = 1
if event.approach and not event.has_entered then
	atc_set_ars_disable(true)
	atc_set_lzb_tsr(1)
	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)
		F.remove_rc({"TY_HEADSHUNT"})
		if not F.has_rc("TY_FINAL_COLLECT") then
			if not F.has_rc("TY_DEPART") then
				schedule_in(";01",atc_id)
				return
			else
				local collect = F.get_rc_safe():match("TY_COLLECT_(%S+)")
				if collect then --train needs to collect a rake from the yard before departing
					F.add_rc({"TY_FINAL_COLLECT","TY_CLASS_"..collect})
					schedule_in(";01",atc_id)
					return
				end
			end
			
			 --else let train proceed forward to the exit controller without a rake
		end --else train has already collected rake. let it exit yard
	else --train has bounced
		if F.has_rc("TY_AROUND") then
			if this_dir == F.dir() then --send train to Classification
				F.remove_rc({"TY_AROUND"})
				F.add_rc({"TY_PICKUP"})
				atc_set_ars_disable(false)
				return
			end --if at wrong end, do nothing. train will follow TY_AROUND ARS to relevant headshunt
		end -- if doesn't have TY_AROUND then let ARS classify the train
		
		atc_set_ars_disable(false)
	end
	return
end

if event.schedule then
	if not atc_id then --bounce the train that just passed
		atc_send_to_train(event.msg,"B0WRD1S3A1")
	else
		if atc_id == event.msg then --train hasn't fully passed yet, wait a bit longer
			schedule_in(";01",atc_id)
		else -- somehow another train crossed the controller before the first one returned. Unlikely but possible
			atc_send_to_train(event.msg,"BBOL")
			atc_send("BBOL")
			F.error(true)
		end
	end
	return
end