Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --*******************************************************************
- --*Notes:
- --*
- --*
- --*
- --*
- --*
- --*
- --*
- --*
- --****************
- --*Initializing *
- --****************
- --Variables Setup
- cvar = 0 -- used for counting
- numlanes = 7 -- used as a sanity check when rolling though the lanes
- lanecolors = {} -- stores lane color info
- lanestat = {} -- stores lane status
- lanedock = {} -- stores if the train in that lane is in the unload area or ready to release
- lanelocked = {} -- stores if a lane is manually shutdown
- lanescreen = {} -- stores the monitor list for the lane displays
- yardscram = 0 -- stores state for emergency shutdown process
- exitlane = 0 -- stores which lane is good to be released.
- traincount = 395 -- train count since last computer reset
- id=0 -- not implemented yet
- countmessage=0 -- not implemented yet
- tempmonitor=""
- -- values assigned to each color transferred to a linked variable for easy access
- -- entrylanecolors = colors.black
- lanecolors[1] = colors.white
- lanecolors[2] = colors.orange
- lanecolors[3] = colors.magenta
- lanecolors[4] = colors.lightBlue
- lanecolors[5] = colors.yellow
- lanecolors[6] = colors.lime
- lanecolors[7] = colors.pink
- exitlanecolor = colors.black
- traincountercolor = colors.red
- laneclearcolor = colors.green
- laneunloadingcolor = colors.orange
- lanewaitingcolor = colors.yellow
- lanelockedcolor = colors.red
- lockedlanesx1 = {2,24,44,64,84,104,124} --workaround for floating point glitch on locked lane monitors
- lockedlanesx2 = {22,42,62,82,102,122,142} --workaround for floating point glitch on locked lane monitors
- --Monitor setup
- local original_terminal = term.current()
- --main display
- local monitor = peripheral.wrap("monitor_11")
- term.redirect(monitor)
- monitor.clear()
- monitor.setTextScale(1)
- --Locked lane display
- local monitor2 = peripheral.wrap("monitor_10")
- monitor2.clear()
- monitor2.setTextScale(.5)
- --lane displays
- lanescreen[1] = peripheral.wrap("monitor_3")
- lanescreen[2] = peripheral.wrap("monitor_4")
- lanescreen[3] = peripheral.wrap("monitor_5")
- lanescreen[4] = peripheral.wrap("monitor_6")
- lanescreen[5] = peripheral.wrap("monitor_7")
- lanescreen[6] = peripheral.wrap("monitor_2")
- lanescreen[7] = peripheral.wrap("monitor_8")
- m1x, m1y = monitor.getSize() --screen size grab for automated sizing
- lsx, lsy = lanescreen[1].getSize() --screen size grab for automated sizing
- --m2x, m2y = monitor2.getSize() --disabled/not used due to floating point bug
- --******************************************************************************************
- --*Functions - are defined in the beginning and can be called from within the main loop *
- --******************************************************************************************
- function scanlanes() --process lanes and assign status to variables.
- for cvar = 1,numlanes,1 do -- uses a counter to roll through each lane and check for the status. The status is then assigned to a variable for storage
- if rs.testBundledInput("left", lanecolors[cvar]) == true then lanestat[cvar] = false else lanestat[cvar] = true end -- check for occupied lanes
- if rs.testBundledInput("bottom", lanecolors[cvar]) == true then lanedock[cvar] = false else lanedock[cvar] = true end -- see if occupied train is in unloading or exit sections
- if rs.testBundledInput("back", lanecolors[cvar]) == true then lanelocked[cvar] = true else lanelocked[cvar] = false end -- check to see if any lanes have been manually locked out
- end
- end
- function release(releaselane) --process the release on the current selected exit lane. (also updates status displays
- term.setTextColor(colors.white)
- monitordraw(monitor, 2,6+((releaselane-1)*3),70,6+((releaselane-1)*3)+1,colors.blue, 5, 7+((releaselane-1)*3), "Lane: " .. releaselane .. " Released")
- rs.setBundledOutput("right", lanecolors[releaselane]) --sets the output to release a lane
- sleep(3) --delay to allow time for train to move into exit lane
- rs.setBundledOutput("right", 0) -- reset release
- end
- function monitordraw (display, x1, y1, x2, y2, lanecolor, textx, texty, lanetext)
- term.redirect(display)
- paintutils.drawFilledBox(x1,y1,x2,y2,lanecolor)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(textx, texty)
- print(lanetext)
- monitor.setBackgroundColor(colors.black)
- term.redirect(monitor)
- end
- function drawupdate()
- monitor.clear()
- paintutils.drawFilledBox(1,1,110,5,colors.blue)
- paintutils.drawFilledBox(3,3,27,4,colors.black)
- paintutils.drawFilledBox(33,3,55,4,colors.black)
- term.setCursorPos(3,3)
- monitor.setTextColor(colors.white)
- print("Train Station Monitoring")
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(33,3)
- print("Trains Since Reset: " .. traincount)
- --Draw Main Monitor lanes
- for j=1,numlanes,1 do
- if lanelocked[j] == true then
- monitordraw(monitor, 2,6+((j-1)*3),70,6+((j-1)*3)+1,lanelockedcolor, 5, 7+((j-1)*3), "Lane: " .. j .. " Locked down")
- else
- if lanestat[j] == true then
- if lanedock[j] == true then
- monitordraw(monitor, 2,6+((j-1)*3),70,6+((j-1)*3)+1,laneunloadingcolor, 5, 7+((j-1)*3), "Lane: " .. j .. " Unloading")
- else
- monitordraw(monitor, 2,6+((j-1)*3),70,6+((j-1)*3)+1,lanewaitingcolor, 5, 7+((j-1)*3), "Lane: " .. j .. " Waiting for Release") end
- else
- monitordraw(monitor, 2,6+((j-1)*3),70,6+((j-1)*3)+1,laneclearcolor, 5, 7+((j-1)*3), "Lane: " .. j .. " Vacant") end
- end
- end
- -- Draw Lane Lock displays
- term.redirect(monitor2)
- term.setBackgroundColor(colors.black)
- term.clear()
- for j = 1,numlanes,1 do
- if lanelocked[j] == true then
- --monitordraw(monitor2,lockedlanesx1[j],1,lockedlanesx2[j],10,colors.red, lockedlanesx1[j]+2,5, "Lane: ".. j.. " Locked")
- paintutils.drawFilledBox(lockedlanesx1[j],1,lockedlanesx2[j],10,colors.red)
- monitor2.setTextColor(colors.white)
- monitor2.setCursorPos(lockedlanesx1[j]+2,5)
- print("Lane".. j.. ": Locked")
- else
- --monitordraw(monitor2,lockedlanesx1[j],1,lockedlanesx2[j],9,colors.greeb, lockedlanesx1[j]+2,5, "Lane: ".. j.. " Open")
- paintutils.drawFilledBox(lockedlanesx1[j],1,lockedlanesx2[j],10,colors.green)
- monitor2.setTextColor(colors.white)
- monitor2.setCursorPos(lockedlanesx1[j]+2,5)
- print("Lane".. j.. ": Open")
- end
- end
- -- draw lanesigns
- for j = 1, numlanes, 1 do
- term.redirect(lanescreen[j])
- if lanelocked[j] == true then
- term.setBackgroundColor(lanelockedcolor)
- term.clear()
- term.setCursorPos(2,5)
- print("Lane ".. j)
- else
- if lanestat[j] == true then
- if lanedock[j] == true then
- term.setBackgroundColor(laneunloadingcolor)
- term.clear()
- term.setCursorPos(2,5)
- print("Lane ".. j)
- else
- term.setBackgroundColor(lanewaitingcolor)
- term.clear()
- term.setCursorPos(2,5)
- print("Lane ".. j)
- end
- else
- term.setBackgroundColor(laneclearcolor)
- term.clear()
- term.setCursorPos(2,5)
- print("Lane ".. j)
- end
- end
- end
- term.redirect(monitor)
- end
- function counterincrement()
- traincount=traincount+1
- while (rs.testBundledInput("bottom",traincountercolor)) do
- sleep(.1)
- end
- end
- --****************
- --*Main Loop *
- --****************
- while(true) do
- scanlanes() -- check to see what lanes are full
- exitlane=exitlane+1
- if rs.testBundledInput("bottom",traincountercolor) == true then counterincrement() end
- if exitlane>numlanes then exitlane=1 end
- if rs.testBundledInput("left", exitlanecolor) == false then -- make sure the exit lane is clear.
- if lanestat[exitlane] == true then -- check if there is a train in the current tested lane.
- if lanedock[exitlane] == false then --if there is a lane but it is in the unloading area then skip to the next one
- if lanelocked[exitlane] == false then
- release(exitlane) -- if it meets all conditions then release
- end
- end
- end
- end
- drawupdate() -- update display
- sleep(.3)
- end
Advertisement
Add Comment
Please, Sign In to add comment