Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --StationmasterCG by Communeguy
- --Purpose-rolled Train-Sorting Application
- --Depends on Railcraft for hardware.
- --Documentation in line.
- --Begin Config Block
- local v = "Pre Alpha"
- --Assign some redstone
- local check = rs.getInput("top") -- Relies on a hard-wired logical test to make sure all signal blocks are properly assigned.
- 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.
- local function set1() rs.setBundledOutput("right", colors.orange) end -- the assumption is made that said recievers output on green.
- local det1 = rs.testBundledInput("left", colors.white) -- Checking a detector on the approach track to see if its Routing Table was triggered.
- local sig2 = rs.testBundledInput("right", colors.magenta)
- local function set2() rs.setBundledOutput("right", colors.combine(rs.getBundledOutput("right"), colors.lightBlue)) end
- local det2 = rs.testBundledInput("left", colors.orange) -- Detectors are on a different section than the exit track to prevent bad logic.
- local sig3 = rs.testBundledInput("right", colors.yellow)
- 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
- local det3 = rs.testBundledInput("left", colors.magenta)
- local sig4 = rs.testBundledInput("right", colors.pink)
- local function set4() rs.setBundledOutput("right", colors.combine(rs.getBundledOutput("right"), colors.gray)) end
- local det4 = rs.testBundledInput("left", colors.lightBlue)
- local function hold() rs.setBundledOutput("left", colors.yellow) end-- controls a holding track.
- --Assign Train Names
- 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
- local train2 = "Eshu's Bounty"
- local train3 = "Fleetfoot Trod"
- local train4 = "Boggan Shortline"
- local mSide = "monitor_0" -- side on which your monitor is connected.
- --defaulting some variables.
- local p1 = "Unknown"
- local p2 = "Unknown"
- local p3 = "Unknown"
- local p4 = "Unknown"
- local running = true
- --Pre-Op initialization begins.
- local m = peripheral.wrap(mSide)
- term.redirect(m)
- --Operating Loop
- while true do -- the computer starts up or program returns
- rs.setBundledOutput("left", 0) -- removes power from the holding rail, locking the train.
- rs.setBundledOutput("right", 0) -- removes power from all track switches, causing a bypass.
- if check == true then -- check inputs a signal if there is a problem.
- print("Welcome to StationmasterCG " .. v) -- Automatically displays the version number
- print("Error: Signal Blocks Absent. Verify and Reset")
- sleep(30) -- The system will auto-reset after 30 seconds to check again for the signal blocks
- term.clear()
- term.setCursorPos(1,1)
- else
- print("Welcome to StationmasterCG " .. v) -- puts the version number back where it belongs
- sleep(2)
- os.pullEvent("redstone") -- sleeps for a redstone signal trigger. Can only be caused by a train travelling over the detectors in this case
- if sig1 == true then
- set1()
- end
- 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.
- set2()
- end
- if sig3 == true then
- set3()
- end
- if sig4 == true then
- set4()
- end
- if det1 == true then -- Checks to see if the train was the first train, and where it is going.
- if sig1 == true then -- Then tries to find out where it is going. Trains are sorted in ascending order of platform number
- local p1 = train1
- elseif sig2 == true then
- local p2 = train1
- elseif sig3 == true then
- local p3 = train1
- elseif sig4 == true then
- local p4 = train1
- end
- elseif det2 == true then -- has to be done for each signal input
- if sig1 == true then
- local p1 = train2
- elseif sig2 == true then
- local p2 = train2
- elseif sig3 == true then
- local p3 = train2
- elseif sig4 == true then
- local p4 = train2
- end
- elseif det3 == true then
- if sig1 == true then
- local p1 = train3
- elseif sig2 == true then
- local p2 = train3
- elseif sig3 == true then
- local p3 = train3
- elseif sig4 == true then
- local p4 = train3
- end
- elseif det4 == true then
- if sig1 == true then
- local p1 = train4
- elseif sig2 == true then
- local p2 = train4
- elseif sig3 == true then
- local p3 = train4
- elseif sig4 == true then
- local p4 = train4
- end
- else
- if sig1 == true then
- local p1 = "Unrecognised"
- elseif sig2 == true then
- local p2 = "Unrecognised"
- elseif sig3 == true then
- local p3 = "Unrecognised"
- else local p4 = "Unrecognised"
- end
- end
- sleep(2)
- hold() -- unlocks the train so that it can move to the right platform. If no platform is available it will bypass.
- print("I haven't slept yet")
- term.clear()
- term.setCursorPos(1,1)
- sleep(10) --give the system time to put the trains where they go.
- print("I am done sleeping")
- if sig1 == true then -- setting empty platforms to say so now that the train is at its destination platform.
- local p1 = "Vacant"
- end
- if sig2 == true then
- local p2 = "Vacant"
- end
- if sig3 == true then
- local p3 = "Vacant"
- end
- if sig4 == true then
- p4 = "Vacant"
- end
- print("Platform 1: " .. p1) --Displays which trains are where.
- print("Platform 2: " .. p2)
- print("Platform 3: " .. p3)
- print("Platform 4: " .. p4)
- end
- end
- --Improvements desired:
- ---Announce arrivals during the m.Print phase at the end of the loop using a world speaker.
- ---Bypass detection/notification sub.
- ---Since Peripherals++ is installed, speach and noteblock pattern synthesis at site to announce train arrival.
Advertisement
Add Comment
Please, Sign In to add comment