User Tools

Site Tools


usage:atlatc:examples:level_crossing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
usage:atlatc:examples:level_crossing [2022-07-04 05:14]
blockhead list alternatives; add an untested implementation based on lifo's
usage:atlatc:examples:level_crossing [2022-07-04 12:07]
56independent Just had to say this
Line 95: Line 95:
 -- locals for speed -- locals for speed
 local acwd_occupation = S.acwd_occupation or {} --safe to re-run init code local acwd_occupation = S.acwd_occupation or {} --safe to re-run init code
-local occs_present = false +if next(acwd_occupation) == nil then
-for k,v in pairs(tdo +
-  occs_present true +
-  break +
-end +
- +
--- Every occupation entry is a table of train IDs occupying it. +
-if not occs_present then+
   for location, numcrossings in pairs(acwd_occupation) do   for location, numcrossings in pairs(acwd_occupation) do
 +    -- Every occupation entry is a table of train IDs occupying it.
     acwd_occupation[location] = {}     acwd_occupation[location] = {}
   end   end
Line 156: Line 150:
   -- There must be no trains on any approach to the crossing to   -- There must be no trains on any approach to the crossing to
   -- be able to clear it and disable the warning devices.   -- be able to clear it and disable the warning devices.
-  local train_on_crossing = false +  if next(acwd_occupation[crossing]) == nil then
-  for approach, train_id in pairs(acwd_occupation[crossing]) do +
-      train_on_crossing true +
-      break +
-  end +
-   +
-  if not train_on_crossing then+
     for wd=1,n do     for wd=1,n do
       setstate(crossing .. tostring(wd), "off")       setstate(crossing .. tostring(wd), "off")
Line 169: Line 157:
 end end
  
 +</code>
 +
 +===== Implementation 3 =====
 +<code lua>
 +-- The safest level crossing is no crossing. The path passes above or below the track and does not force people to cross the track. This track just keeps a train at mainline programming.
 +
 +atc_send("OCA1SM")
 </code> </code>
usage/atlatc/examples/level_crossing.txt · Last modified: 2022-07-04 13:31 by 56independent