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
|
F.crossings={
BeethvV = 3,
EldersValley = 4,
AckLvcross=2,
ML1_unnamed=2,
ML1_Scl1=4,
freightrwa = 2,
smlpatha = 2,
spneul = 10,
spneul_jnc = 7,
MOriStn = 4,
MSouthForest1509 = 2,
SF1Station = 5,
SF1West = 2,
SF1SouthWest = 4,
Snb=3,
LovelaceAve = 5,
Onionland = 2,
PH_West = 4,
PH_WestS = 2,
gardonst = 4,
Trs_Church = 3,
NRG = 6,
}
--[[ Setting up level crossings:
1. choose a name
2. add that into the crossings table, with the number of crossing signs to trigger
3. name the crossing signs <name><number>
4. for each rail in each direction, add an F.on() and an F.off() rail
F.on(<name>, <directionAndRail>)
F.off(<name>, <directionAndRail>)
where directionAndRail is another identifier.
Always point the arrows in the direction the train is driving.
]]--
if not S.crossst then S.crossst={} end
--Point arrows in driving direction!
function F.on(cross, inst, inv)
if atc_arrow~=inv then
local num=F.crossings[cross]
if not S.crossst[cross] then S.crossst[cross]={} end
S.crossst[cross][inst]=true
for i=1,num do
setstate(cross..i, "on")
end
end
end
function F.off(cross, inst, inv)
if atc_arrow~=inv then
local num=F.crossings[cross]
S.crossst[cross][inst]=nil
for _,_ in pairs(S.crossst[cross]) do return end
for i=1,num do
setstate(cross..i, "off")
end
end
end
function F.on_nt(cross, inst, inv)
if atc_arrow~=inv then
if not S.crossst[cross] then S.crossst[cross]={} end
S.crossst[cross][inst]=true
local i=1
while is_passive(cross..i) do
setstate(cross..i, "on")
i=i+1
end
end
end
function F.off_nt(cross, inst, inv)
if atc_arrow~=inv then
S.crossst[cross][inst]=nil
for _,_ in pairs(S.crossst[cross]) do return end
local i=1
while is_passive(cross..i) do
setstate(cross..i, "off")
i=i+1
end
end
end
|