summaryrefslogtreecommitdiff
path: root/auto_yards/nodes/(-630,26,2454).lua
blob: 5715c3403362282d76723f3241b64ffbe8488d41 (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
62
63
64
65
66
67
68
69
70
71
72
73
local notification_id = "CAN"
local ind = POS(-594,26,2488)
local shuffle_ind = POS(-594,26,2487)
local print_notification = true
local function send_train()
	set_rc("FREIGHT CAN_LOCOSTORE CAN_LIGHT_EXIT EWL-W EWL S23 ARC_AUTO ARC_RTS ARC_COLLECT_CANNERY ARC_AUTO_S23N CANNERY CAN_RTS CAN_COLLECT_ARC")
	atc_send("S0WRD2A1S4")
	F.indicator(ind,false)
end

local function shuffle_wagons()
	F.indicator(S.yards[notification_id].active_indicator_pos, true) --stop other trains entering the yard
	F.indicator(S.yards[notification_id].dir_indicator_pos,true)
	F.indicator(shuffle_ind,false)
	F.indicator(ind,true)
	S.yards[notification_id].shuffle_stage = 1 -- set a shuffle stage counter
	set_rc("CAN_LOCOSTORE CAN_SHUFFLE")
	atc_send("S0WRD2A1S4") --send train to headshunt
	return
end

if event.ext_int then
	if event.message == "notify" then
		if print_notification then print(rwt.to_string(rwt.now()).. " "..notification_id.." RX Notification") end
		if F.indicator(ind) then return end
		if atc_id then
			send_train()
			return
		else
			F.indicator(ind,true)
			return
		end
	elseif event.message == "shuffle" then
		if atc_id then
			if not F.indicator(S.yards[notification_id].active_indicator_pos) then
				shuffle_wagons()
				return
			end
			schedule_in(":05","shuffle")
			return
		else
			F.indicator(shuffle_ind,true)
			return
		end
	end
	return
end

if event.schedule then
	if event.message=="shuffle" then
		if not F.idicator(S.yards[notification_id].active_indicator_pos) then
			shuffle_wagons()
			return
		end
		schedule_in(":05","shuffle")
		return
	end
	return
end

if event.train then
	unset_autocouple()
	if F.indicator(shuffle_ind) then
		shuffle_wagons()
		return
	end
	if F.indicator(ind) then
		send_train()
		return
	end
	atc_send("B0")
	return
end