Communeguy

Stationmaster CG WIP

Aug 7th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.78 KB | None | 0 0
  1. --StationmasterCG by Communeguy
  2. --Purpose-rolled Train-Sorting Application
  3. --Depends on Railcraft for hardware.
  4. --Documentation in line.
  5.  
  6. --Begin Config Block
  7. local v = "Pre Alpha"
  8.     --Assign some redstone
  9. local check = rs.getInput("top") -- Relies on a hard-wired logical test to make sure all signal blocks are properly assigned.
  10. local sig1 = rs.testBundledInput("right", colors.white) -- A single bundled cable (project:Red) is used to both read the signal recievers and power the switches for each lane.
  11. local function set1() rs.setBundledOutput("right", colors.orange) end -- the assumption is made that said recievers output on green.
  12. local det1 = rs.testBundledInput("left", colors.white) -- Checking a detector on the approach track to see if its Routing Table was triggered.
  13. local sig2 = rs.testBundledInput("right", colors.magenta)
  14. local function set2() rs.setBundledOutput("right", colors.combine(rs.getBundledOutput("right"), colors.lightBlue)) end
  15. local det2 = rs.testBundledInput("left", colors.orange) -- Detectors are on a different section than the exit track to prevent bad logic.
  16. local sig3 = rs.testBundledInput("right", colors.yellow)
  17. local function set3() rs.setBundledOutput("right", colors.combine(rs.getBundledOutput("right"), colors.lime)) end -- must combine this way to get the correct output per bundle
  18. local det3 = rs.testBundledInput("left", colors.magenta)
  19. local sig4 = rs.testBundledInput("right", colors.pink)
  20. local function set4() rs.setBundledOutput("right", colors.combine(rs.getBundledOutput("right"), colors.gray)) end
  21. local det4 = rs.testBundledInput("left", colors.lightBlue)
  22. local function hold() rs.setBundledOutput("left", colors.yellow) end-- controls a holding track.
  23.     --Assign Train Names
  24. local train1 = "Kobold Delver" -- numbers are not by platform number. May be as many as needed but you will have to assign extra #red commands
  25. local train2 = "Eshu's Bounty"
  26. local train3 = "Fleetfoot Trod"
  27. local train4 = "Boggan Shortline"
  28. local mSide = "monitor_0" -- side on which your monitor is connected.
  29.  
  30. --defaulting some variables.
  31. local p1 = "Unknown"
  32. local p2 = "Unknown"
  33. local p3 = "Unknown"
  34. local p4 = "Unknown"
  35. local running = true
  36.  
  37. --Pre-Op initialization begins.
  38. local m = peripheral.wrap(mSide)
  39. term.redirect(m)
  40.  
  41. --Operating Loop
  42. while true do -- the computer starts up or program returns
  43.     rs.setBundledOutput("left", 0) -- removes power from the holding rail, locking the train.
  44.     rs.setBundledOutput("right", 0) -- removes power from all track switches, causing a bypass.
  45.     if check == true then -- check inputs a signal if there is a problem.
  46.     print("Welcome to StationmasterCG " .. v) -- Automatically displays the version number
  47.     print("Error: Signal Blocks Absent. Verify and Reset")
  48.     sleep(30) -- The system will auto-reset after 30 seconds to check again for the signal blocks
  49.     term.clear()
  50.     term.setCursorPos(1,1)
  51.     else
  52.         print("Welcome to StationmasterCG " .. v) -- puts the version number back where it belongs
  53.     sleep(2)
  54.     os.pullEvent("redstone") -- sleeps for a redstone signal trigger. Can only be caused by a train travelling over the detectors in this case
  55.     if sig1 == true then
  56.         set1()
  57.     end
  58.     if sig2 == true then -- checks each platform. If the platform is free (#sig true), then the switch (#set) is put into position to divert a train there.
  59.         set2()
  60.     end
  61.     if sig3 == true then
  62.         set3()
  63.     end
  64.     if sig4 == true then
  65.         set4()
  66.     end
  67.         if det1 == true then -- Checks to see if the train was the first train, and where it is going.
  68.             if sig1 == true then -- Then tries to find out where it is going. Trains are sorted in ascending order of platform number
  69.                 local p1 = train1
  70.             elseif sig2 == true then
  71.                 local p2 = train1
  72.             elseif sig3 == true then
  73.                 local p3 = train1
  74.             elseif sig4 == true then
  75.                 local p4 = train1
  76.             end
  77.         elseif det2 == true then -- has to be done for each signal input
  78.             if sig1 == true then
  79.                     local p1 = train2
  80.                 elseif sig2 == true then
  81.                     local p2 = train2
  82.                 elseif sig3 == true then
  83.                     local p3 = train2
  84.                 elseif sig4 == true then
  85.                     local p4 = train2
  86.                 end
  87.         elseif det3 == true then
  88.             if sig1 == true then
  89.                     local p1 = train3
  90.                 elseif sig2 == true then
  91.                     local p2 = train3
  92.                 elseif sig3 == true then
  93.                     local p3 = train3
  94.                 elseif sig4 == true then
  95.                     local p4 = train3
  96.                 end
  97.         elseif det4 == true then
  98.             if sig1 == true then
  99.                     local p1 = train4
  100.                 elseif sig2 == true then
  101.                     local p2 = train4
  102.                 elseif sig3 == true then
  103.                     local p3 = train4
  104.                 elseif sig4 == true then
  105.                     local p4 = train4
  106.                 end
  107.         else
  108.             if sig1 == true then
  109.                     local p1 = "Unrecognised"
  110.                 elseif sig2 == true then
  111.                     local p2 = "Unrecognised"
  112.                 elseif sig3 == true then
  113.                     local p3 = "Unrecognised"
  114.                 else local p4 = "Unrecognised"
  115.             end
  116.         end
  117.         sleep(2)
  118.         hold() -- unlocks the train so that it can move to the right platform. If no platform is available it will bypass.
  119.         print("I haven't slept yet")
  120.         term.clear()
  121.     term.setCursorPos(1,1)
  122.         sleep(10) --give the system time to put the trains where they go.
  123.         print("I am done sleeping")
  124.     if sig1 == true then -- setting empty platforms to say so now that the train is at its destination platform.
  125.     local p1 = "Vacant"
  126.     end
  127.     if sig2 == true then
  128.     local p2 = "Vacant"
  129.     end
  130.     if sig3 == true then
  131.     local p3 = "Vacant"
  132.     end
  133.     if sig4 == true then
  134.     p4 = "Vacant"
  135.     end
  136.     print("Platform 1: " .. p1) --Displays which trains are where.
  137.     print("Platform 2: " .. p2)
  138.     print("Platform 3: " .. p3)
  139.     print("Platform 4: " .. p4)
  140.     end
  141. end
  142.  
  143. --Improvements desired:
  144. ---Announce arrivals during the m.Print phase at the end of the loop using a world speaker.
  145. ---Bypass detection/notification sub.
  146. ---Since Peripherals++ is installed, speach and noteblock pattern synthesis at site to announce train arrival.
Advertisement
Add Comment
Please, Sign In to add comment