summaryrefslogtreecommitdiff
path: root/auto_yards/nodes/(-630,26,2454).lua
blob: 4e694845fa1c2c7123c63a67ec749432d03ae031 (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
-- Cannery Loco Storage
local notification_id = "CAN"
local ind = POS(-594,26,2488) --notification indicator
local sand_indicator = POS(-572,26,2515) --sand indicator
local print_notification = true

local sections = {
	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.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
	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
	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