summaryrefslogtreecommitdiff
path: root/durt/nodes/(1864,17,4296).lua
blob: 0136ea7af40473385d5872529f5bf9888385e77c (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
local dir = "SHOVE" --indicates which part of the train leaves the station: HEAD, SHOVE
local movelist = {
	SHOVE = { --loco first into platform, shove the outbound
		"OAF_REV_"..dir,
		"OAF_HS_N",
		"OAF_SB_TK2",
		"OAF_HS_S2",
		"OAF_HS_S2_AC",
		"OAF_NB_TK1_SHUNT",
		"OAF_runaround_rejoin",
	},
	HEAD = { --shoved into platform, loco first outbound
		"OAF_REV_"..dir,
		"OAF_HS_N",
		"OAF_SB_TK3",
		"OAF_HS_S",
		"OAF_HS_S_AC",
		"OAF_NB_TK2_SHUNT",
		"OAF_runaround_rejoin",
	}
}

print("==================================")
print(dir)

if event.train then
	if not atc_arrow then
		if F.has_rc("OAF_runaround_rejoin") then --loco has returned, shove through to ensure past signal IP
			schedule_in(";05",atc_id)
			print("SHOVE THROUGH")
			return
		end
		return
	end
	if not F.has_rc("OAF_BRANCH_REVERSE") then return end
	if not F.has_rc("OAF_runaround_rejoin") then
		print("BEGIN")
		atc_send("S0WOL")
		schedule_in(";03",atc_id) --semi-realistic decoupling time
		return
	end
	if not F.has_rc("OAF_REV_"..dir) then return end
	F.remove_rc(movelist[dir])
	F.add_rc("OAF_BRANCH_REVERSE_RECOUPLED")
	schedule_in(";05",atc_id) --semi-realistic recoupling time
	print("REJOIN")
	return
end

if event.schedule then
	print("Arrow: "..tostring(atc_arrow))
	print("ID: "..tostring(atc_id))
	print("msg: "..tostring(event.msg))
	if atc_id and atc_id ~= event.msg then return end --somehow another train snuck in??? or we've coupled weird over the track
	if not atc_id then --loco has returned, should have already coupled and shoved through as buffers would have been over track to begin with
		atc_send_to_train(event.msg,"B0WRD1A1S1")
		return
	end
	if not F.has_rc("OAF_BRANCH_REVERSE") then return end --probably not our train anyway ???

	if dir == "HEAD" and atc_arrow ~= true then --!!!!!! previously managed to get valid atc_id and arrow == nil when using (atc_arrow == false)
		schedule_in(";01", atc_id) --keep clock going to ensure rejoining loco has coupled
		print("CLOCK")
		return
	end

	if not F.has_rc("OAF_BRANCH_REVERSE_RECOUPLED") then
		if dir == "SHOVE" then -- loco first into platform, run around to shove out
			-- split_off_locomotive("S0OLA0",2) --ideally each pax wagon has a generic FC, but not likely as few people use them at all
			if train_length() > 1 then
				split_at_index(2,"S0OLA0")
				atc_send("S3")
				F.add_rc(movelist[dir])
			else
				-- don't bother splitting, there's nothing to split anyway!
				-- depart light (fallback)
				F.add_rc("OAF_BRANCH_REVERSE_DONE") --triggers the ARS to depart
				atc_send("SM")
				print("DEPARTING LIGHT")
			end
		else --dir == "HEAD" --shoved into platform, run around to put loco first
			F.add_rc(movelist[dir])
			if train_length() > 1 then
				split_at_index(train_length(),"S0WRA1S3")
				F.remove_rc(movelist[dir])
				atc_send("S0WROR")
			else --don't bother splitting, there's nothing to split anyway!
				F.add_rc("OAF_BRANCH_REVERSE_DONE") --triggers the ARS to depart
				atc_send("SM")
				print("DEPARTING LIGHT")
			end
		end
		print("SPLIT")
		return
	end
	F.remove_rc("OAF_BRANCH_REVERSE_RECOUPLED") 
	F.add_rc("OAF_BRANCH_REVERSE_DONE") --triggers the ARS to depart
	atc_send("SM")
	print("DEPARTING")
	return
end