summaryrefslogtreecommitdiff
path: root/auto_yards/nodes/(-630,26,2454).lua
blob: d96880063471ac4adca82c239716343af9ec799d (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
-- Cannery Loco Storage
local notification_id = "CAN"
local ind = POS(-594,26,2488) --notification indicator
local sand_indicator = POS(-572,26,2515) --sand loaded indicator
local clay_indicator = POS(-570,26,2515) --clay loaded indicator
local print_notification = true

local sections = {
	clay_loading = "769966",
	sand_loading = "199126",
	dirt_unloading = "541313",
	departures = "484515"
}

local function send_train()
	if F.indicator(S.yards[notification_id].active_indicator_pos) then -- another train already in the yard. wait for it to exit first
		print("yard still active")
		schedule_in("0;2","send_train")
		return
	end
	print("Sending Train")
	local base_rc = {
		"FREIGHT",
		"CAN_LOCOSTORE",
		"EWL-W",
		"EWL",
		"S23",
		"ARC_AUTO",
		"ARC_COLLECT_CANNERY",
		"ARC_AUTO_S23N",
		"CANNERY",
		"CAN_COLLECT_DEPARTURES"
	}
	if section_occupancy(sections.clay_loading)[1] and F.indicator(clay_indicator) then -- move the loaded clay wagons to the departures track when requested
		base_rc[#base_rc+1] = "CAN_INTRA_SHUFFLE"
		base_rc[#base_rc+1] = "CAN_HS_W"
		base_rc[#base_rc+1] = "CAN_HS_W_AC"
		base_rc[#base_rc+1] = "CAN_CLASS_CLAY_LOAD"
		F.indicator(S.yards.CAN.active_indicator_pos, true) --activate the yard to prevent other trains entering while we're moving around
		print("Collecting loaded clay wagons")
	elseif section_occupancy(sections.sand_loading)[1] and F.indicator(sand_indicator) then -- move the loaded sand wagons to the departures track when requested
		base_rc[#base_rc+1] = "CAN_INTRA_SHUFFLE"
		base_rc[#base_rc+1] = "CAN_HS_W"
		base_rc[#base_rc+1] = "CAN_HS_W_AC"
		base_rc[#base_rc+1] = "CAN_CLASS_SAND_LOAD"
		F.indicator(S.yards.CAN.active_indicator_pos, true) --activate the yard to prevent other trains entering while we're moving around
		print("Collecting loaded sand wagons")
	elseif section_occupancy(sections.dirt_unloading)[1] and not section_occupancy(sections.sand_loading)[1] then -- move the unloaded dirt wagons to the sand track if there's room
		base_rc[#base_rc+1] = "CAN_INTRA_SHUFFLE"
		base_rc[#base_rc+1] = "CAN_HS_W"
		base_rc[#base_rc+1] = "CAN_HS_W_AC"
		base_rc[#base_rc+1] = "CAN_CLASS_DIRT_UNLOAD"
		F.indicator(S.yards.CAN.active_indicator_pos, true) --activate the yard to prevent other trains entering while we're moving around
		print("Respotting unloaded dirt wagons to sand loading area")
	elseif section_occupancy(sections.departures)[1] then --collect departures wagons before departing proper
		base_rc[#base_rc+1] = "CAN_REENTER_YARD"
		F.indicator(ind, false)
		print("Collecting Departures")
	else
		base_rc[#base_rc+1] = "CAN_LIGHT_EXIT"
	end
	print("rc list set")
	set_rc(table.concat(base_rc," "))
	print("rc set")
	atc_send("S0WRD2A1S4")
	F.indicator(ind,false)
	print("train sent")
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
		return
	end
	return
end

if event.schedule then
	if event.msg=="send_train" then
		send_train()
		return
	end
	return
end

if event.train then
	print("Train arrived")
	if F.indicator(ind) then
		print("indicator on. Sending Train")
		send_train()
		return
	end
	print("train movements completed")
	atc_send("B0")
	return
end