summaryrefslogtreecommitdiff
path: root/durt/nodes/(-3543,8,-2282).lua
blob: a2adaf781436535c2598ca392d29e8408973dc3a (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
local dir = "east"
local split_indicators = {['east']=POS(-3539,9,-2282),['west']=POS(-3592,9,-2282)}

local inv_dir = (dir=="east" and "west" or "east")

__approach_callback_mode = 2


if event.approach and not event.has_entered then
	if not F.get_rc_safe():match("logging_pickup") then return end
	
	atc_set_ars_disable(true)
	atc_set_lzb_tsr(1)
end

if event.train then
print(F.get_rc_safe())
	if not F.get_rc_safe():match("logging_pickup") then return end
	if getstate(split_indicators[inv_dir]) == "green" then return end -- train is busy from the other end. ignore for now
print(1)
	if atc_arrow == true then
print(2)
		local state = getstate(split_indicators[dir])
print("state " ..tostring(state))
print(3)
		if state == "red" then
			local split_length = F.get_rc_safe():match("logging_split(%d+)") or 0
print("split length: "..split_length)
			split_at_index(split_length+2,"A0B0")
			set_rc(F.get_rc_safe().." Treefarm_headshunt_"..dir.." Treefarm_loading")
			atc_send("S3")
			atc_set_ars_disable(false)
			setstate(split_indicators[dir],"green")
		elseif state == "green" then
			atc_send("S5D10SM")
			setstate(split_indicators[dir],"red")
			F.remove_rc({"Treefarm_headshunt_"..dir,"Treefarm_loading","Treefarm_rejoin_"..dir,"Treefarm_collect"})
		end
	else
		if F.get_rc_safe():match("Treefarm_rejoin_"..dir) then
			atc_set_ars_disable(true)
			schedule_in(";01",atc_id)
			return
		end
	end
end

if event.schedule then
	if event.msg == atc_id then
		schedule_in(";01",event.msg)
		return
	else
		atc_send_to_train(event.msg,"B0WRA1S3")
		return
	end
end