summaryrefslogtreecommitdiff
path: root/nlvcross/init_code.lua
blob: 465ce8f38daaef74518d6283ca1d55c30906db29 (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
F.crossings={
  ML1_unnamed=2,
  ML1_Scl1=2,
  freightrwa = 2,
  smlpatha = 2,
  spneul = 10,
  spneul_jnc = 7,
  MOriStn = 4,
  MSouthForest1509 = 2,
  SF1Station = 5,
  SF1West = 2,
  SF1SouthWest = 4,
  Snb=3,
  LovelaceAve = 6,
  Onionland = 2,
  PH_West = 4,
  PH_WestS = 2,
  gardonst = 4,
}
--[[ 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