summaryrefslogtreecommitdiff
path: root/durt/nodes/(-743,18,2424).lua
blob: 3c5008c60884cc760e8f316555c8da19171a88c8 (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
-- Automatic bouncer for headshunts, assuming longer headshunt than train length. Arrow points into headshunt
local rev_rc = "CAN_REENTER_YARD"
local rm_rc = true
-- local autocouple = "ARC_LOAD_HS_N_AC"
-- local rm_cpl_rc = true

__approach_callback_mode = 1

if event.approach and not event.has_entered then
	if not F.has_rc("CAN_REENTER_YARD") then return end
	atc_set_lzb_tsr(3)
	atc_set_ars_disable(true)
	return
end

if event.train then
	if not atc_arrow then --train has bounced
		-- if F.has_rc(autocouple) then
		-- 	atc_send("CplS0WD2S1")
		-- 	if rm_cpl_rc then F.remove_rc({autocouple}) end
		-- end
		return
	end
	
	if not F.has_rc(rev_rc) then --not our train. disregard
		atc_set_ars_disable(false)
		return
	end
	if rm_rc then F.remove_rc({rev_rc}) end
	atc_send("S3")
	schedule_in(";01",atc_id)
	return
end

if event.schedule then
	if not atc_id then --bounce the train that just passed
		atc_send_to_train(event.msg,"B0WRD1A1S3")
	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")
		end
	end
end