--StationmasterCG by Communeguy --Purpose-rolled Train-Sorting Application --Depends on Railcraft for hardware. --Code documentation in comments. --Hardware documentation at pastebin: ##Code## --DevNotes commented at end. --Begin Config Block. These are the only variables the user should manipulate! local sSide = "left" -- side with the Sensor Line attached. local rSide = "right" -- side with the Railcraft Line attached. local mSide = "monitor_0" -- side with the monitor attached, or address of the monitor if networked. local tSide = "bottom" -- Trigger sensor side local cSide = "top" -- side with the check receiver. local train1 = "Kobold Delver" -- name of first train. local train2 = "Eshu's Bounty" local train3 = "Hardscrabble Shuttle" local train4 = "Sidhe Heighliner" --Additional Variable Defaults. Don't touch. local v = "Alpha 2" local a = 1 local p1 = "Unknown" local p2 = "Unknown" local p3 = "Unknown" local p4 = "Unknown" local bypass = false local incoming = "string" --Functions redefined for brevity and utility. local function set1() --Set functions trigger the switch tracks they are assigned to. rs.setBundledOutput(rSide, colors.combine(rs.getBundledOutput(rSide), colors.orange)) end local function set2() rs.setBundledOutput(rSide, colors.combine(rs.getBundledOutput(rSide), colors.lightBlue)) end local function set3() rs.setBundledOutput(rSide, colors.combine(rs.getBundledOutput(rSide), colors.lime)) end local function set4() rs.setBundledOutput(rSide, colors.combine(rs.getBundledOutput(rSide), colors.gray)) end local function sig1() --Sig functions check to see if there is something on the platform. return rs.testBundledInput(rSide, colors.white) end local function sig2() return rs.testBundledInput(rSide, colors.magenta) end local function sig3() return rs.testBundledInput(rSide, colors.yellow) end local function sig4() return rs.testBundledInput(rSide, colors.pink) end local function det1() -- Det functions are checking to see if any of the Routing Detectors tripped on the train, as part of IDing it. return rs.testBundledInput(sSide, colors.white) end local function det2() return rs.testBundledInput(sSide, colors.orange) end local function det3() return rs.testBundledInput(sSide, colors.magenta) end local function det4() return rs.testBundledInput(sSide, colors.lightBlue) end local function release() --releases the holding track rs.setBundledOutput(sSide, colors.yellow) end local function hold() -- holds the train to the holding track. rs.setBundledOutput(sSide,0) end local function check() -- checks that the signal blocks are correctly assigned. return rs.getInput(cSide) end local function switch() -- Tests the state of the signal blocks and handles their switches accordingly rs.setBundledOutput(rSide, colors.black) if sig1() == true then set1() end if sig2() == true then set2() end if sig3() == true then set3() end if sig4() == true then set4() end end local function park() -- where's the train going? if sig1() == true then p1 = incoming bypass = false elseif sig2() == true then p2 = incoming bypass = false elseif sig3() == true then p3 = incoming bypass = false elseif sig4() == true then p4 = incoming bypass = false else bypass = true end end local function checkDepartures() -- has anyone left? if sig1() == true then p1 = "Vacant" end if sig2() == true then p2 = "Vacant" end if sig3() == true then p3 = "Vacant" end if sig4() == true then p4 = "Vacant" end end --Initialization local m = peripheral.wrap(mSide) -- wraps the monitor and pushes the outputs to it. term.redirect(m) sleep (45) --Allows time for the world to load if that is why the program is loading. --Actual program execution while true do if check() == true then --throws an error if the signal is faulty. print("Welcome to Stationmaster CG" .. v) print("Signal Assignment Error. Please verify and relaunch") sleep(45) os.reboot() else hold() switch() -- initialises the state of the platform switches sleep(2) -- Prevents those redstone changes from triggering the system checkDepartures() -- makes sure trains that have left are noted before printing. term.clear() term.setCursorPos(1,1) print("Welcome to Stationmaster CG " .. v) print("Platform #1: " .. p1) print("Platform #2: " .. p2) print("Platform #3: " .. p3) print("Platform #4: " .. p4) if bypass == true then print(incoming .. "has bypassed the station due to unavailable space. Sorry about that.") end os.pullEvent("redstone") if det1() == true then --IEI determining which train just arrived. incoming = train1 elseif det2() == true then incoming = train2 elseif det3() == true then incoming = train3 elseif det4() == true then incoming = train4 else incoming = "Unknown" end park() -- where will this train go? Works because it will always go in ascending order of available sets. release() -- lets the train go where it needs to. sleep(10) -- lets it get there. end end