summaryrefslogtreecommitdiff
path: root/auto_yards/nodes/(-1982,17,780).lua
blob: 072f902a9e941134f6c0d029be4f7272d0086928 (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
local yard_id = "ARC"


if event.train then
	if F.has_rc("ARC_LIGHT_EXIT") then return end
	if F.has_rc("ARC_NOSHUNT") then return end
	
	if train_length() == 1 then -- eliminates near half the trains
		if F.has_rc("ARC_LOCOSTORE") then -- specifies only the relevant train
			if F.has_rc("ARC_DEPART") and F.has_rc("ARC_FINAL_COLLECT") and F.has_rc("ARC_HEADSHUNT") then --only activate if train is set to depart anyway
				if not atc_arrow then -- train is pointing towards exit. let it pass and the reverse it
					atc_set_ars_disable(true)
					schedule_in(";01",atc_id) -- prepare to reverse the train
					return
				else --train has reversed. send it to the siding and deactivate the yard
					F.remove_rc({"ARC_DEPART","ARC_FINAL_COLLECT"})
					F.add_rc("ARC_send_to_locostore")
					atc_set_ars_disable(false)
					F.indicator(S.yards[yard_id].active_indicator_pos, false)
					S.yards[yard_id].departure_time = rwt.now()
					S.yards[yard_id].departure_length = S.yards[yard_id].arrival_length
					
					if S.yards[yard_id].notify_pos then
						interrupt_pos(S.yards[yard_id].notify_pos,"notify")
					end
					return
				end
			end
		end
	end
end

if event.schedule then --this is a duplicate of the reversing schedule in the env anyway
	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")
			F.indicator(yard.error_indicator_pos,true)
		end
	end
	return
end



-- if all else fails, do a normal headshunt_yard function
F.headshunt_yard("ARC",true)