User Tools

Site Tools


usage:atlatc:examples:linuxforks_subway_code

Differences

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

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
usage:atlatc:examples:linuxforks_subway_code [2022-06-28 11:37]
56independent created
usage:atlatc:examples:linuxforks_subway_code [2022-06-28 23:32]
56independent [Code] Replace note in light of recent edits
Line 41: Line 41:
  
 ===== Code ===== ===== Code =====
 +The current code is as follows (<del>it's not all properly indented, much of it may have been edited in-game</del> The indentation is automatic and may have some faults). It probably started back in 2017, but has barely changed since 2019 due to maturity, stability and decreasing relevance.
 +
 <code lua> <code lua>
 -- 'subway' environment -- -- 'subway' environment --
 --F.stn_union=function(line1, prev1, prev2, this, next, doors, dps, osig, ret_sw, ret_st, nohalt, waittime) --F.stn_union=function(line1, prev1, prev2, this, next, doors, dps, osig, ret_sw, ret_st, nohalt, waittime)
-F.stationnames={ +F.stationnames = { 
-Ewb="Edenwood Beach", +    Ewb = "Edenwood Beach", 
-Ban="Bananame", +    Ban = "Bananame", 
-ctr="Coulomb Street Triangle", +    ctr = "Coulomb Street Triangle", 
-Cht="Churchill Street", +    Cht = "Churchill Street", 
-Bbe="Birch Bay East", +    Bbe = "Birch Bay East", 
-Bap="Turtle Rock", +    Bap = "Turtle Rock", 
-Icm="Ice Mountain", +    Icm = "Ice Mountain", 
-Eft="BHS10", +    Eft = "BHS10", 
-Apl="Apple Plains", +    Apl = "Apple Plains", 
-Pal="Palm Bay", +    Pal = "Palm Bay", 
-Slh="Smacker's Land of Hope and Glory", +    Slh = "Smacker's Land of Hope and Glory", 
-Lks="Leekston", +    Lks = "Leekston", 
-Ta1="Testing Area 1", +    Ta1 = "Testing Area 1", 
-Ta2="Testing Area 2", +    Ta2 = "Testing Area 2", 
-Ahr="AHRAZHUL's Station", +    Ahr = "AHRAZHUL's Station", 
-Ahz="Large Beach", +    Ahz = "Large Beach", 
-Wim="Windy Mountains", +    Wim = "Windy Mountains", 
-Dam="Szymon's Dam", +    Dam = "Szymon's Dam", 
-Wva="Windy Mountains Valley 1", +    Wva = "Windy Mountains Valley 1", 
-Wvb="Windy Mountains Valley 2", +    Wvb = "Windy Mountains Valley 2", 
-Wvc="Windy Mountains Valley 3", +    Wvc = "Windy Mountains Valley 3", 
-App="Apple Grove", +    App = "Apple Grove", 
-Dem="Desert Mountain", +    Dem = "Desert Mountain", 
-Dev="Desert View (OCP)", +    Dev = "Desert View (OCP)", 
-Lvc="Levenshtein Canyon", +    Lvc = "Levenshtein Canyon", 
-Gho="Green Hope", +    Gho = "Green Hope", 
-Snb="Snake Bend", +    Snb = "Snake Bend", 
-Adb="Adorno Boulevard", +    Adb = "Adorno Boulevard", 
-Duf="Duff Road", +    Duf = "Duff Road", 
-Wat="Something in the water", +    Wat = "Something in the water", 
-Ram="Ramanujan Street", +    Ram = "Ramanujan Street", 
-Per="Perelman Street", +    Per = "Perelman Street", 
-Trp="Trump Park", +    Trp = "Trump Park", 
-Sfs="South Forest Station", +    Sfs = "South Forest Station", 
-Lok="Jude Milhon Street", +    Lok = "Jude Milhon Street", 
-Bam="Bamboo Hills", +    Bam = "Bamboo Hills", 
-Sfa="unnamed", +    Sfa = "unnamed", 
-Gcl="Green Cliffs", +    Gcl = "Green Cliffs", 
-Dri="Dry Island", +    Dri = "Dry Island", 
-Ged="Green Edge", +    Ged = "Green Edge", 
-Ghb="Green Hill Beach", +    Ghb = "Green Hill Beach", 
-Acm="Acacia Mountains", +    Acm = "Acacia Mountains", 
-Ghm="Greenhat Mountain", +    Ghm = "Greenhat Mountain", 
-Pna="Pence Avenue", +    Pna = "Pence Avenue", 
-Dbl="Dubulti", +    Dbl = "Dubulti", 
-Sws="Schwarzschildt Street", +    Sws = "Schwarzschildt Street", 
-Mnk="Minkowsky Street", +    Mnk = "Minkowsky Street", 
-Rgs="Robert Gardon Street", +    Rgs = "Robert Gardon Street", 
-Ehl="Ehlodex", +    Ehl = "Ehlodex", 
-Lus="Lusin Street", +    Lus = "Lusin Street", 
-Lin="Lesnoi Industrial Area", +    Lin = "Lesnoi Industrial Area", 
-Boz="Booze Grove", +    Boz = "Booze Grove", 
-Mrh="Mirzakhani Street", +    Mrh = "Mirzakhani Street", 
-Plt="Planetarium", +    Plt = "Planetarium", 
-Mcf="McFly Street", +    Mcf = "McFly Street", 
-Tha="Theodor Adorno Street", +    Tha = "Theodor Adorno Street", 
-Oni="Onionland", +    Oni = "Onionland", 
-Ora="Orange Lake", +    Ora = "Orange Lake", 
-Uaa="Eiffel Street", +    Uaa = "Eiffel Street", 
-Leo="Leonhard Street", +    Leo = "Leonhard Street", 
-Bby="Birch Bay", +    Bby = "Birch Bay", 
-Stb="Stone Beach", +    Stb = "Stone Beach", 
-Jis="Jungle Island", +    Jis = "Jungle Island", 
-Ice="Eternal Ice", +    Ice = "Eternal Ice", 
-Bnt="Pierre Berton Street", +    Bnt = "Pierre Berton Street", 
-Osa="Origin Sands", +    Osa = "Origin Sands", 
-OBa="Cartesian Square", +    OBa = "Cartesian Square", 
-OOr="School", +    OOr = "School", 
-OSc="ARA", +    OSc = "ARA", 
-ONb="Intel ME Stairs", +    ONb = "Intel ME Stairs", 
-OIs="SCSI Connector Mess", +    OIs = "SCSI Connector Mess", 
-OSm="Origin Sands (Plaza de la Republica)", +    OSm = "Origin Sands (Plaza de la Republica)", 
-ioa="Cow Bridge", +    ioa = "Cow Bridge", 
-iob="Babbage Road", +    iob = "Babbage Road", 
-Wcs="Watson-Crick Street", +    Wcs = "Watson-Crick Street", 
-Rru="Rockefeller Runway", +    Rru = "Rockefeller Runway", 
-Ewd="Edenwood", +    Ewd = "Edenwood", 
-Chu="Marcuse Street Station", +    Chu = "Marcuse Street Station", 
-Erd="Erdos Street", +    Erd = "Erdos Street", 
-Uni="Museum", +    Uni = "Museum", 
-Mar="Felfa's Market (Bracket Road)", +    Mar = "Felfa's Market (Bracket Road)", 
-Wac="Watson-Crick", +    Wac = "Watson-Crick", 
-OLv="Market", +    OLv = "Market", 
-Irk="Ice Rink", +    Irk = "Ice Rink", 
-Sbr="Suburb", +    Sbr = "Suburb", 
-Unv="University", +    Unv = "University", 
-Arc="Archangel", +    Arc = "Archangel", 
-Dar="Darwin Road", +    Dar = "Darwin Road", 
-Hmi="Half-Mile Island", +    Hmi = "Half-Mile Island", 
-Zoo="Zoo", +    Zoo = "Zoo", 
-Bea="Beach", +    Bea = "Beach", 
-Yos="Yoshi Island", +    Yos = "Yoshi Island", 
-Krs="Kernighan&Ritchie Street", +    Krs = "Kernighan&Ritchie Street", 
-Rkb="Robert Koch Boulevard", +    Rkb = "Robert Koch Boulevard", 
-Rsi="Riverside", +    Rsi = "Riverside", 
-Swr="Swimming Rabbit Street", +    Swr = "Swimming Rabbit Street", 
-Wbb="Banana Forest", +    Wbb = "Banana Forest", 
-Ori="Origin", +    Ori = "Origin", 
-Snl="Snowland", +    Snl = "Snowland", 
-Sys="Ship Rock", +    Sys = "Ship Rock", 
-Rfo="Redwood forest", +    Rfo = "Redwood forest", 
-Moj="Mom Junction", +    Moj = "Mom Junction", 
-Wfr="Wolf Rock", +    Wfr = "Wolf Rock", 
-Spa="Shanielle Park", +    Spa = "Shanielle Park", 
-Thh="Treehouse Hotel", +    Thh = "Treehouse Hotel", 
-Stn="Main station", +    Stn = "Main station", 
-WB1="Riverside", +    WB1 = "Riverside", 
-WB2="Banana Forest", +    WB2 = "Banana Forest", 
-WB3="Eiffel Street", +    WB3 = "Eiffel Street", 
-WB4="Buckminster Fuller Street", +    WB4 = "Buckminster Fuller Street", 
-WB5="White Beaches", +    WB5 = "White Beaches", 
-Shn="Shanielle City", +    Shn = "Shanielle City", 
-Jus="Tom Lehrer Street", +    Jus = "Tom Lehrer Street", 
-Fre="Frege Street", +    Fre = "Frege Street", 
-Min="MinerLand", +    Min = "MinerLand", 
-Vlc="Volcano Cliffs", +    Vlc = "Volcano Cliffs", 
-Mio="Minio", +    Mio = "Minio", 
-Wpy="Water Pyramid", +    Wpy = "Water Pyramid", 
-Cat="Cathedral", +    Cat = "Cathedral", 
-Dca="Desert Canyon", +    Dca = "Desert Canyon", 
-Spn="Spawn", +    Spn = "Spawn", 
-Brn="Ministry of Transport (bernhardd)", +    Brn = "Ministry of Transport (bernhardd)", 
-Kav="Knuth Avenue", +    Kav = "Knuth Avenue", 
-Lvf="Library", +    Lvf = "Library", 
-Fms="John Horton Conway Street", +    Fms = "John Horton Conway Street", 
-Mnt="Mountain", +    Mnt = "Mountain", 
-Mnv="Mountain Valley", +    Mnv = "Mountain Valley", 
-Mnn="Mountain View", +    Mnn = "Mountain View", 
-Max="Maxwell Street", +    Max = "Maxwell Street", 
-Snp="Snowy Peak", +    Snp = "Snowy Peak", 
-Scl="ScottishLion's City", +    Scl = "ScottishLion's City", 
-Lza="Laza's City", +    Lza = "Laza's City", 
-Bld="BlackDog", +    Bld = "BlackDog", 
-Hts="Hotel Shanielle", +    Hts = "Hotel Shanielle", 
-Fmn="Euler Street", +    Fmn = "Euler Street", 
-Gpl="Market", +    Gpl = "Market", 
-Jun="Jungle", +    Jun = "Jungle", 
-Jng="Franklin Road", +    Jng = "Franklin Road", 
-Uic="Coulomb Street", +    Uic = "Coulomb Street", 
-Grs="Gram-Schmidt Street", +    Grs = "Gram-Schmidt Street", 
-Lih="Lighthouse", +    Lih = "Lighthouse", 
-Rea="Reactor", +    Rea = "Reactor", 
-Hhs="Henderson-Hasselbalch Street", +    Hhs = "Henderson-Hasselbalch Street", 
-Ack="Ackermann Avenue", +    Ack = "Ackermann Avenue", 
-Lis="Lone Island", +    Lis = "Lone Island", 
-Pyr="Pytagoras Road", +    Pyr = "Pytagoras Road", 
-Nha="North Harbour", +    Nha = "North Harbour", 
-STn="Technic Station", +    STn = "Technic Station", 
-SPo="Post Office", +    SPo = "Post Office", 
-SSw="Spawn, westbound", +    SSw = "Spawn, westbound", 
-SSe="Spawn, eastbound", +    SSe = "Spawn, eastbound", 
-SPa="Papyrus Farm", +    SPa = "Papyrus Farm", 
-STo="Tourist Info", +    STo = "Tourist Info", 
-SMi="Public Mine", +    SMi = "Public Mine", 
-MR1="Euler Street", +    MR1 = "Euler Street", 
-MSt="Main Station (Spawn)", +    MSt = "Main Station (Spawn)", 
-MOr="Marcuse Street Station (Origin)",+    MOr = "Marcuse Street Station (Origin)"
 } }
 --[[ --[[
Line 218: Line 220:
 ]] ]]
 --Warning: Expects line to be a string! --Warning: Expects line to be a string!
-local linet={ +local linet = { 
-["1"] = {W="Palm Bay", E="Windy Mountains"}, +    ["1"] = {W = "Palm Bay", E = "Windy Mountains"}, 
-["2"] = {N="Szymon's Dam", S="Onionland"}, +    ["2"] = {N = "Szymon's Dam", S = "Onionland"}, 
-["3"] = {S="Bananame", N="Large Beach"}, +    ["3"] = {S = "Bananame", N = "Large Beach"}, 
-["4"] = {E="Schwarzschildt Street", W="Ice Mountain"}, +    ["4"] = {E = "Schwarzschildt Street", W = "Ice Mountain"}, 
-["5"] = {W="Lighthouse", E="Leekston"}, +    ["5"] = {W = "Lighthouse", E = "Leekston"}, 
-["7"] = {N="Birch Bay East", S="Planetarium"},+    ["7"] = {N = "Birch Bay East", S = "Planetarium"}
 } }
 +
 F.lineterm = function(line, terminal) F.lineterm = function(line, terminal)
-if linet[line] and linet[line][terminal] then return linet[line][terminal] end +    if linet[line] and linet[line][terminal] then 
-return terminal+        return linet[line][terminal] 
 +    end 
 +    return terminal
 end end
 +
 F.lineset = function(line, terminal) F.lineset = function(line, terminal)
-  if event.train then +    if event.train then 
-    atc_set_text_outside("Line "..line.." - "..F.lineterm(line, terminal)) +        atc_set_text_outside("Line " .. line .. " - " .. F.lineterm(line, terminal)) 
-    S.line[atc_id] = line +        S.line[atc_id] = line 
-    set_line(tonumber(line)) +        set_line(tonumber(line)) 
-  end+    end
 end end
-F.rant=function() +F.rant = function() 
-  return math.random(5,8)+    return math.random(5, 8)
 end end
-F.stnname=function(cap) +F.stnname = function(cap) 
-return F.stationnames[string.sub(cap, 1, 3)] or "?"+    return F.stationnames[string.sub(cap, 1, 3)] or "?"
 end end
-F.stn=function(prev, this, next, doors, dps, osig) +F.stn = function(prev, this, next, doors, dps, osig) 
-  F.stn_union(nil, prev, nil, this, next, doors, dps, osig)+    F.stn_union(nil, prev, nil, this, next, doors, dps, osig)
 end end
  
-F.stn_return=function(prev, this, next, doors, switch, state, dps, osig, waittime) +F.stn_return = function(prev, this, next, doors, switch, state, dps, osig, waittime) 
-  F.stn_union(nil, prev, nil, this, next, doors, dps, osig, switch, state, false, waittime)+    F.stn_union(nil, prev, nil, this, next, doors, dps, osig, switch, state, false, waittime)
 end end
  
-F.stn_return_nohalt=function(prev, this, next, switch, state, dps) +F.stn_return_nohalt = function(prev, this, next, switch, state, dps) 
-  F.stn_union(nil, prev, nil, this, next, "C", dps, osig, switch, state, true)+    F.stn_union(nil, prev, nil, this, next, "C", dps, osig, switch, state, true)
 end end
  
-F.stn_return_free=function(prev, switch, state) +F.stn_return_free = function(prev, switch, state) 
-  if event.train then +    if event.train then 
-    setstate(prev, "green"+        setstate(prev, "green"
-    setstate(switch, state) +        setstate(switch, state) 
-  end+    end
 end end
  
-F.stn_nohalt=function(prev, this, next, dps, osig) +F.stn_nohalt = function(prev, this, next, dps, osig) 
-  F.stn_union(nil, prev, nil, this, next, "C", dps, osig, nil, nil, true)+    F.stn_union(nil, prev, nil, this, next, "C", dps, osig, nil, nil, true)
 end end
  
-F.union_wait=function(sect) +F.union_wait = function(sect) 
-  S.union_waiting[sect] = not depart+    S.union_waiting[sect] = not depart
 end end
  
-F.stn_union=function(line1, prev1, prev2, this, next, doors, dps, osig, ret_sw, ret_st, nohalt, waittime) +F.stn_union = function(line1, prev1, prev2, this, next, doors, dps, osig, ret_sw, ret_st, nohalt, waittime) 
-  if not atc_id then +    if not atc_id then 
-    atc_send("B0"+        atc_send("B0"
-    error("Train has disappeared!"+        error("Train has disappeared!"
-  end +    end 
-  if not atc_arrow then +    if not atc_arrow then 
-    atc_send("B0"+        atc_send("B0"
-    error("Train passed in wrong direction!"+        error("Train passed in wrong direction!"
-  end +    end 
-  depart=false +    depart = false 
-  if event.train then +    if event.train then 
-    setstate(prev1, "red"+        setstate(prev1, "red"
-    if prev2 then  setstate(prev2, "red") end +        if prev2 then 
-    atc_send("B0O"..doors)+            setstate(prev2, "red") 
 +        end 
 +        atc_send("B0O" .. doors)
  
-if atc_speed and atc_speed > 10 then +        if atc_speed and atc_speed > 10 then 
-  local dt = os.date() +            local dt = os.date() 
-  atc_set_text_outside("BrakeFail speed="..atc_speed.." when="..dt.year.."-"..dt.month.."-"..dt.day.." "..dt.hour..":"..dt.min..":"..dt.sec) +            atc_set_text_outside( 
-  error("Train "..atc_id.." has passed rail at speed of "..atc_speed) +                "BrakeFail speed=" .. 
-end+                    atc_speed .. 
 +                        " when=" .. 
 +                            dt.year .. 
 +                                "-" .. dt.month .. "-" .. dt.day .. " " .. dt.hour .. ":" .. dt.min .. ":" .. dt.sec 
 +            
 +            error("Train " .. atc_id .. " has passed rail at speed of " .. atc_speed) 
 +        end
  
-    if not nohalt then +        if not nohalt then 
-       interrupt(waittime or (ret_sw and 20 or 7), "ready"+            interrupt(waittime or (ret_sw and 20 or 7), "ready"
-       atc_set_text_inside(F.stnname(this))+            atc_set_text_inside(F.stnname(this)) 
 +        end
     end     end
-  end +    if (event.int and event.message == "ready") or (event.train and nohalt) then 
-  if (event.int and event.message=="ready") or (event.train and nohalt) then +        if getstate(this) == "green" and (not osig or getstate(osig) == "green") then 
-    if getstate(this)=="green" and (not osig or getstate(osig)=="green") then +            if ret_sw then 
-      if ret_sw then +                atc_send("OCD1B0WRS" .. (dps or "M")) 
-        atc_send("OCD1B0WRS"..(dps or "M")) +                setstate(ret_sw, ret_st)
-        setstate(ret_sw, ret_st) +
-      else +
-        atc_send("OCD1S"..(dps or "M")) +
-        setstate(prev1, "green"+
-        if line1 then --this call did not come from F.stn, do union stuff +
-            setstate(prev2, "green"+
-            if S.line[atc_id]==line1 then +
-               if S.union_waiting[prev2] then setstate(prev1, "red") end+
             else             else
-               if S.union_waiting[prev1] then setstate(prev2, "red") end+                atc_send("OCD1S" .. (dps or "M")) 
 +                setstate(prev1, "green"
 +                if line1 then --this call did not come from F.stn, do union stuff 
 +                    setstate(prev2, "green"
 +                    if S.line[atc_id] == line1 then 
 +                        if S.union_waiting[prev2] then 
 +                            setstate(prev1, "red"
 +                        end 
 +                    else 
 +                        if S.union_waiting[prev1] then 
 +                            setstate(prev2, "red") 
 +                        end 
 +                    end 
 +                end 
 +            end 
 +            setstate(this, "red"
 +            atc_set_text_inside("Next stop: " .. F.stnname(next)) 
 +            depart = true 
 +            nodepartc = nil 
 +        else 
 +            interrupt(F.rant(), "ready"
 +            nodepartc = nodepartc and nodepartc + 1 or 0 
 +            if nodepartc >= 10 then 
 +                atc_set_text_inside(F.stnname(this) .. "\nLine out of order!"
 +            else 
 +                if (not osig or getstate(osig) == "green") then 
 +                    atc_set_text_inside(F.stnname(this) .. "\nWaiting for preceding train..."
 +                else 
 +                    atc_set_text_inside(F.stnname(this) .. "\nWaiting for oncoming train..."
 +                end
             end             end
         end         end
-      end 
-      setstate(this, "red") 
-      atc_set_text_inside("Next stop: "..F.stnname(next)) 
-      depart=true 
-      nodepartc=nil 
-    else 
-       interrupt(F.rant(), "ready") 
-       nodepartc=nodepartc and nodepartc+1 or 0 
-       if nodepartc>=10 then 
-         atc_set_text_inside(F.stnname(this).."\nLine out of order!") 
-       else 
-         if (not osig or getstate(osig)=="green") then 
-           atc_set_text_inside(F.stnname(this).."\nWaiting for preceding train...") 
-         else 
-           atc_set_text_inside(F.stnname(this).."\nWaiting for oncoming train...") 
-         end 
-       end 
     end     end
-  end 
 end end
-F.pre=function(signal) +F.pre = function(signal) 
-   if getstate(signal) == "red" then +    if getstate(signal) == "red" then 
-     atc_send("B4")+        atc_send("B4")
     end     end
 end end
  
-F.uiclog = function ()  +F.uiclog = function() 
-return+    return
 end end
 --L197 --L197
  
-F.stat=function(line, init) +F.stat = function(line, init) 
---statistics +    --statistics 
--- init +    -- init 
-if init then +    if init then 
-reftrain = atc_id +        reftrain = atc_id 
-a_tbt = 30 +        a_tbt = 30 
-a_tbtmax = 30 +        a_tbtmax = 30 
-a_rtt = 500 +        a_rtt = 500 
-a_not = 0 +        a_not = 0 
-c_not = 0 +        c_not = 0 
-c_tbtmax = 0 +        c_tbtmax = 0 
-time_lt = os.time() +        time_lt = os.time() 
-time_rt=os.time() +        time_rt = os.time() 
-end +    end 
-if not a_tbtmax then a_tbtmax = 30 end +    if not a_tbtmax then 
-if not c_tbtmax then c_tbtmax = 0 end +        a_tbtmax = 30 
---real code +    end 
-if event.train then +    if not c_tbtmax then 
-local time = os.time() +        c_tbtmax = 0 
-c_not = c_not + 1 +    end 
-a_tbt = (a_tbt + (time - time_lt)) / 2 +    --real code 
-c_tbtmax = math.max(c_tbtmax, (time - time_lt)) +    if event.train then 
-if atc_id == reftrain then +        local time = os.time() 
-  a_rtt = (a_rtt*0.2 + (time - time_rt)*0.8) +        c_not = c_not + 1 
-  a_not = c_not +        a_tbt = (a_tbt + (time - time_lt)) / 2 
-  c_not = 0 +        c_tbtmax = math.max(c_tbtmax, (time - time_lt)) 
-  a_tbtmax = (a_tbtmax + c_tbtmax) / 2 +        if atc_id == reftrain then 
-  c_tbtmax = 0 +            a_rtt = (a_rtt * 0.2 + (time - time_rt) * 0.8) 
-end +            a_not = c_not 
-  digiline_send("stats", "Stat: "..line.. +            c_not = 0 
-    " NoT:"..a_not.."("..c_not..")".. +            a_tbtmax = (a_tbtmax + c_tbtmax) / 2 
-    " TbT:"..math.floor(a_tbt).."("..(time-time_lt)..")".. +            c_tbtmax = 0 
-    " Tmx:"..math.floor(a_tbtmax).."("..c_tbtmax..")".. +        end 
-    " R:"..math.floor(a_rtt).."("..(time - time_rt)..")" +        digiline_send( 
-    +            "stats", 
-time_lt = time +            "Stat: " .. 
-if atc_id == reftrain then +                line .. 
-  time_rt = time +                    " NoT:" .. 
-end +                        a_not .. 
-end+                            "(" .. 
 +                                c_not .. 
 +                                    ")" .. 
 +                                        " TbT:" .. 
 +                                            math.floor(a_tbt) .. 
 +                                                "(" .. 
 +                                                    (time - time_lt) .. 
 +                                                        ")" .. 
 +                                                            " Tmx:" .. 
 +                                                                math.floor(a_tbtmax) .. 
 +                                                                    "(" .. 
 +                                                                        c_tbtmax .. 
 +                                                                            ")" .. 
 +                                                                                " R:" .. 
 +                                                                                    math.floor(a_rtt) .. 
 +                                                                                        "(" .. (time - time_rt) .. ")" 
 +        
 +        time_lt = time 
 +        if atc_id == reftrain then 
 +            time_rt = time 
 +        end 
 +    end
 end end
  
 local function aspect_is_free(asp) local function aspect_is_free(asp)
-  if type(asp.main) == "table" then +    if type(asp.main) == "table" then 
-    return asp.main.free +        return asp.main.free 
-  else +    else 
-    return asp.main ~= 0 +        return asp.main ~= 0 
-  end+    end
 end end
  
 -- 21.1.19, the rise of tss -- 21.1.19, the rise of tss
-F.stn_ilk=function(prev, this, next, doors, dps) +F.stn_ilk = function(prev, this, next, doors, dps) 
-  depart = false +    depart = false 
-  if event.train then +    if event.train then 
-    atc_send("B0 W O"..doors) +        atc_send("B0 W O" .. doors) 
-    atc_set_text_inside(F.stnname(this)) +        atc_set_text_inside(F.stnname(this)) 
-    interrupt(7, "ready"+        interrupt(7, "ready"
-  elseif event.int then +    elseif event.int then 
-    local asp = get_aspect(this) +        local asp = get_aspect(this) 
-    if not asp then +        if not asp then 
-      atc_set_text_inside(F.stnname(this).."\nNo aspect for "..this) +            atc_set_text_inside(F.stnname(this) .. "\nNo aspect for " .. this) 
-    else +        else 
-      if aspect_is_free(asp) then +            if aspect_is_free(asp) then 
-        atc_set_text_inside("Next stop:\n"..F.stnname(next)) +                atc_set_text_inside("Next stop:\n" .. F.stnname(next)) 
-        atc_send("OC D1 S"..(dps or "M")) +                atc_send("OC D1 S" .. (dps or "M")) 
-        depart = true +                depart = true 
-        return +                return 
-      else +            else 
-        atc_set_text_inside(F.stnname(this).."\nSection ahead is blocked..."+                atc_set_text_inside(F.stnname(this) .. "\nSection ahead is blocked..."
-      end+            end 
 +        end 
 +        interrupt(7, "ready")
     end     end
-    interrupt(7, "ready") 
-  end 
 end end
  
-F.stn_ilkentry=function(prev, this, next, doors, dps) +F.stn_ilkentry = function(prev, this, next, doors, dps) 
-  F.stn_ilk(prev, this, next, doors, dps) +    F.stn_ilk(prev, this, next, doors, dps) 
-  if depart then setstate(prev, "green") end+    if depart then 
 +        setstate(prev, "green") 
 +    end
 end end
 </code> </code>
  
usage/atlatc/examples/linuxforks_subway_code.txt · Last modified: 2024-05-23 05:03 by blockhead