Advertisement
VGToolBox

Teleport Room ComputerCraft Code

Sep 1st, 2012
1,859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.07 KB | None | 0 0
  1. local S_DOOR_CLOSE_VALUE = "Close"
  2. local S_DOOR_OPEN_VALUE = "Open"
  3. local S_TP_WALL_UP_VALUE = "up"
  4. local S_TP_WALL_DOWN_VALUE = "down"
  5. local S_NETHER_OPEN_VALUE = "Open"
  6. local S_NETHER_CLOSED_VALUE = "Close"
  7. local S_ALARM_ON_VALUE = "on"
  8. local S_ALARM_OFF_VALUE = "off"
  9. local S_MONITOR_ON_VALUE = "on"
  10. local S_MONITOR_OFF_VALUE = "off"
  11.  
  12. local versionNumber = "1.0"
  13.  
  14. local loadingChars = {"/","|","\\","-"}
  15. local loadingPos = {x = 0, y = 0,active = false}
  16.  
  17. local inputChar = "q"
  18.  
  19. local consoleWidth, consoleHeight = term.getSize()
  20. consoleWidth, consoleHeight = consoleWidth - 1, consoleHeight - 1
  21. local consoleWidthCentre = math.floor(consoleWidth * 0.5) + 2
  22. local consoleHeightCentre = math.floor(consoleHeight * 0.5)
  23.  
  24.  
  25. local sSaveFile = "roomProperties.txt"
  26.  
  27. local sDoorStatus = ""
  28. local sTeleportStatus = ""
  29. local sPortalStatus = ""
  30. local sAlarmStatus = ""
  31. local sMonitorStatus = ""
  32.  
  33. local refreshTimer = nil
  34. local fastRender = false
  35.  
  36. local tDoorControls = {}
  37. tDoorControls.iMoveOut = colors.lightBlue
  38. tDoorControls.iMoveIn = colors.white
  39. tDoorControls.iOpen = colors.green
  40. tDoorControls.iClose = colors.lime
  41. tDoorControls.iInput = colors.red
  42. tDoorControls.iAlarm = colors.orange
  43. tDoorControls.timer = nil
  44.  
  45. local tTeleportControls = {}
  46. tTeleportControls.iWallUp = colors.black
  47. tTeleportControls.iWallDown = colors.brown
  48. tTeleportControls.iTeleport = colors.blue
  49. tTeleportControls.iAlarm = colors.gray
  50.  
  51. local tPortalControls = {}
  52. tPortalControls.iUp = colors.pink
  53. tPortalControls.iDown = colors.cyan
  54. tPortalControls.iIgnite = colors.yellow
  55.  
  56. local tPeripherals = sensors.getPeripherals()
  57. local pMonitor = nil
  58. local nMonWidth = nil
  59. local nMonHeight = nil
  60. local nMonHalfW = nil
  61. local nMonHalfH = nil
  62.  
  63. if tPeripherals.monitor then
  64.     pMonitor = peripheral.wrap(tPeripherals.monitor)
  65.     pMonitor.setTextScale(4)
  66.     nMonWidth, nMonHeight = pMonitor.getSize()
  67.     nMonHalfW = nMonWidth * 0.5
  68.     nMonHalfH = nMonHeight * 0.5
  69. end
  70.  
  71. local mode = 0
  72. local debugMode = false
  73.  
  74.  
  75. --Utility functions-\/-----------------------------------------------------------------------------
  76.  
  77. function slowWriteAt(x,y,str)
  78.     term.setCursorPos(x ,y)
  79.     textutils.slowWrite(str,60)
  80. end
  81.  
  82. function drawAllBoxes(boxes)
  83.  
  84.     for i, v in ipairs(boxes) do
  85.         v:draw()
  86.     end
  87.  
  88. end
  89.  
  90. function writeAllText(texts, slow)
  91.  
  92.     for i, v in ipairs(texts) do
  93.         if not slow then
  94.             v:write()
  95.         else
  96.             v:slowWrite()
  97.         end
  98.     end
  99.  
  100. end
  101.  
  102. function pulseOutput(sColour, n)
  103.  
  104.     for i = 1, n do
  105.  
  106.         rs.setBundledOutput("bottom", colors.combine(rs.getBundledOutput("bottom"), sColour))
  107.         sleep(0.45)
  108.         rs.setBundledOutput("bottom", colors.subtract(rs.getBundledOutput("bottom"), sColour))
  109.         sleep(0.45)
  110.  
  111.     end
  112. end
  113.  
  114. function showLoading()
  115.  
  116.     local i = 1
  117.     if loadingPos.active then
  118.         error("Something is already loading")
  119.     end
  120.  
  121.     loadingPos.active = true
  122.  
  123.     if loadingPos.x < 1 or loadingPos.y < 1 then
  124.         error("loadingPos not set")
  125.     end
  126.  
  127.     repeat
  128.         term.setCursorPos(loadingPos.x, loadingPos.y)
  129.         print(loadingChars[i])
  130.         i = (i < #loadingChars) and i + 1 or 1
  131.         sleep(0.2)
  132.     until not loadingPos.active
  133.  
  134.     term.setCursorPos(loadingPos.x, loadingPos.y)
  135.     print(" ")
  136.     loadingPos.x, loadingPos.y = 0, 0
  137.  
  138.  
  139. end
  140.  
  141. function stopLoading()
  142.  
  143.     loadingPos.active = false
  144.  
  145. end
  146.  
  147. function debug(val)
  148.  
  149.     if debugMode then
  150.  
  151.         oldx, oldy = term.getCursorPos()
  152.         term.setCursorPos(6, consoleHeight)
  153.         print(val)
  154.         sleep(3)
  155.         term.setCursorPos(oldx, oldy)
  156.     end
  157. end
  158.  
  159. --Utility functions-/\-----------------------------------------------------------------------------
  160.  
  161.  
  162.  
  163. --Class constructors-\/----------------------------------------------------------------------------
  164.  
  165. function newBox(x, y, width, height)
  166.  
  167.     --creates a box with drawing and erasing methods
  168.  
  169.     local function drawBox(box)
  170.  
  171.         --renders a box onscreen at correct location and size, accepts box "class" as argument
  172.         local hChar = "|"
  173.         local vChar = "-"
  174.         local cornerChar = "O"
  175.         local currentChar = ""
  176.  
  177.         if not box.x or not box.y or not box.width or not box.height then
  178.  
  179.         --exit without attempting to render the box
  180.         return 0
  181.         end
  182.  
  183.         --print("y is "..y)
  184.  
  185.         for i = box.x, x + box.width do
  186.  
  187.             if i == x or i == x + width then
  188.                 currentChar = cornerChar
  189.             else
  190.                 currentChar = vChar
  191.             end
  192.  
  193.             sensorsUI.writeAt(i, y, currentChar)
  194.             sensorsUI.writeAt(i, y + height, currentChar)
  195.         end
  196.  
  197.         for i = y + 1, y + box.height - 1 do
  198.  
  199.             currentChar = hChar
  200.             sensorsUI.writeAt(x, i, currentChar)
  201.             sensorsUI.writeAt(x + width, i, currentChar)
  202.         end
  203.  
  204.     end
  205.  
  206.     local function eraseBox(box)
  207.  
  208.         --clears the area that box sits in. Can be used to create a box in negative space
  209.  
  210.         if not box.x or not box.y or not box.width or not box.height then
  211.  
  212.             --exit without attempting to render the box
  213.             return 0
  214.         end
  215.  
  216.         for i = box.x, x + box.width do
  217.             sensorsUI.writeAt(i, y, "")
  218.             sensorsUI.writeAt(i, y + height, "")
  219.         end
  220.  
  221.         for i = y + 1, y + box.hight - 1 do
  222.             sensorsUI.writeAt(x, i, "")
  223.             sensorsUI.writeAt(x + width, i, "")
  224.         end
  225.  
  226.     end
  227.  
  228.     local box = {x = x, y = y, width = width, height = height, draw = drawBox, erase = eraseBox}
  229.  
  230.     return box
  231.  
  232. end
  233.  
  234.  
  235. function newText(string, x, y, alignment, renderImmediate)
  236.  
  237.     local function renderText(text)
  238.         --renders text onscreen at correct alignment, accepts text "class" as argument
  239.         text.alignment = text.alignment or "left"
  240.  
  241.         if text.alignment == "left" then
  242.             sensorsUI.writeAt(text.x,text.y,text.string)
  243.  
  244.         elseif alignment == "centre" then
  245.             sensorsUI.writeAt(text.x - #text.string * 0.5, text.y, text.string)
  246.  
  247.         elseif alignment == "right" then
  248.             sensorsUI.writeAt(text.x - #text.string, text.y, text.string)
  249.  
  250.         else
  251.  
  252.             error(text.alignment..' alignment for string "'..text.string..'" is not a valid alignment')
  253.         end
  254.     end
  255.  
  256.     local function slowRenderText(text)
  257.  
  258.         --slow renders text onscreen at correct alignment, accepts text "class" as argument
  259.         text.alignment = text.alignment or "left"
  260.  
  261.         if text.alignment == "left" then
  262.             slowWriteAt(text.x,text.y,text.string)
  263.  
  264.         elseif alignment == "centre" then
  265.             slowWriteAt(text.x - #text.string * 0.5, text.y, text.string)
  266.  
  267.         elseif alignment == "right" then
  268.             slowWriteAt(text.x - #text.string, text.y, text.string)
  269.  
  270.         else
  271.  
  272.             error(text.alignment..' alignment for string "'..text.string..'" is not a valid alignment')
  273.         end
  274.  
  275.     end
  276.  
  277.     local function deleteText(text)
  278.  
  279.         text.alignment = text.alignment or "left"
  280.         text.string = string.rep(" ", #text.string)
  281.  
  282.         if text.alignment == "left" then
  283.             sensorsUI.writeAt(text.x,text.y,text.string)
  284.  
  285.         elseif alignment == "centre" then
  286.             sensorsUI.writeAt(text.x - #text.string * 0.5, text.y, text.string)
  287.  
  288.         elseif alignment == "right" then
  289.             sensorsUI.writeAt(text.x - #text.string, text.y, text.string)
  290.  
  291.         else
  292.  
  293.             error(text.alignment..' alignment for string "'..text.string..'" is not a valid alignment')
  294.         end
  295.  
  296.     end
  297.  
  298.     local function slowDeleteText(text)
  299.  
  300.         text.alignment = text.alignment or "left"
  301.         text.string = string.rep(" ", #text.string)
  302.  
  303.         if text.alignment == "left" then
  304.             slowWriteAt(text.x,text.y,text.string)
  305.  
  306.         elseif alignment == "centre" then
  307.             slowWriteAt(text.x - #text.string * 0.5, text.y, text.string)
  308.  
  309.         elseif alignment == "right" then
  310.             slowWriteAt(text.x - #text.string, text.y, text.string)
  311.  
  312.         else
  313.  
  314.             error(text.alignment..' alignment for string "'..text.string..'" is not a valid alignment')
  315.         end
  316.  
  317.     end
  318.  
  319.     local function getLength(text)
  320.  
  321.         return #text.string
  322.  
  323.     end
  324.  
  325.  
  326.     renderImmediate = renderImmediate or "false"
  327.  
  328.     local text = {}
  329.     text.alignment = alignment or "left"
  330.     text.string = string or "blank"
  331.     text.x = x or 1
  332.     text.y = y or 1
  333.     text.write = renderText
  334.     text.slowWrite = slowRenderText
  335.     text.delete = deleteText
  336.     text.slowDelete = slowDeleteText
  337.     text.length = getLength
  338.  
  339.     if renderImmediate == "now" then
  340.         text:write()
  341.     elseif renderImmediate == "slow" then
  342.         text:slowWrite()
  343.     end
  344.  
  345.     return text
  346.  
  347. end
  348.  
  349. --Class constructors-/\----------------------------------------------------------------------------
  350.  
  351.  
  352. local tConsStringsStatic = {}
  353. tConsStringsStatic[1] = newText("Teleportation Controls Room", consoleWidthCentre, 2, "centre")
  354. tConsStringsStatic[2] = newText("version "..versionNumber, consoleWidthCentre, tConsStringsStatic[1].y + 1, "centre")
  355.  
  356. --boxes that need to be rendered evert tick
  357. local tConsoleBoxes = {}
  358. tConsoleBoxes[1] = newBox(1, 1, consoleWidth, consoleHeight)
  359. tConsoleBoxes[2] = newBox(1, 4, consoleWidth, consoleHeight - 5)
  360. tConsoleBoxes[3] = newBox((consoleWidthCentre - #tConsStringsStatic[1].string * 0.5) - 2, 1, #tConsStringsStatic[1].string + 3, 3)
  361.  
  362. local sSensorSide = nil
  363. local sSensorName = nil
  364. local sProbe = nil
  365. local sTarget = nil
  366.  
  367. if sensors then
  368.     sSensorSide = sensors.getController()
  369.     sSensorName = sensors.getSensors(sSensorSide)[1]
  370.     sProbe = sensors.getProbes(sSensorSide, sSensorName)[3]
  371.     sTarget = sensors.getAvailableTargetsforProbe(sSensorSide,sSensorName,sProbe)[1]
  372.  
  373. end
  374.  
  375. local inputText = newText("Input Choice> ",2,consoleHeight, "left")
  376.  
  377. function main()
  378.  
  379.     repeat
  380.  
  381.         renderOptions()
  382.  
  383.        
  384.  
  385.         local inputType, input = getInput()
  386.         local exitLoop = false
  387.         --assert(false)
  388.  
  389.         fastRender = false
  390.  
  391.         term.clear()
  392.         drawAllBoxes(tConsoleBoxes)
  393.         writeAllText(tConsStringsStatic)
  394.  
  395.         if inputType == "redstone" then
  396.             if colors.test(rs.getBundledInput("bottom"), tDoorControls.iInput) then
  397.                 toggleDoor()
  398.             end
  399.  
  400.         elseif inputType == "timer" then
  401.  
  402.             if input == tDoorControls.timer then
  403.                 toggleDoor()
  404.  
  405.             elseif input == refreshTimer then
  406.                 fastRender = true
  407.             end
  408.  
  409.         else
  410.  
  411.             if mode == 0 then
  412.  
  413.                 if input == "1" then
  414.  
  415.                     toggleDoor()
  416.  
  417.                     --pcall(toggleDoor)
  418.  
  419.                 elseif input == "2" then
  420.  
  421.                     teleportSequence()
  422.  
  423.                     --pcall(teleportSequence)
  424.  
  425.                 elseif input == "3" then
  426.  
  427.                     togglePortal()
  428.  
  429.                 elseif input == "4" then
  430.                    
  431.                    
  432.  
  433.                 end
  434.             else
  435.                 if input == "1" then
  436.  
  437.                 elseif input == "2" then
  438.  
  439.                 elseif input == "3" then
  440.  
  441.                 elseif input == "4" then
  442.  
  443.                 end
  444.             end
  445.         end
  446.  
  447.     until exitLoop
  448. end
  449.  
  450. function renderOptions()
  451.  
  452.     term.clear()
  453.  
  454.     local doorOption = (sDoorStatus == S_DOOR_OPEN_VALUE) and S_DOOR_CLOSE_VALUE or S_DOOR_OPEN_VALUE
  455.     local portalOption = (sPortalStatus == S_NETHER_OPEN_VALUE and S_NETHER_CLOSED_VALUE) or S_NETHER_OPEN_VALUE
  456.  
  457.     writeAllText(tConsStringsStatic)
  458.     drawAllBoxes(tConsoleBoxes)
  459.     --writeAllText(tConsStringsStatic)
  460.    
  461.     if mode == 0 then
  462.  
  463.         local rightMargin = 5
  464.  
  465.         local longestStr = 0
  466.         local optionsText = {}
  467.         optionsText.doorText = doorOption.." Security Doors:"
  468.         optionsText.teleportText = "Begin Teleport Sequence:"
  469.         optionsText.portalText = portalOption.." Nether Portal:"
  470.         optionsText.manualText = "Manual System Controls:"
  471.         optionsText.shutDownText = "Reset System"
  472.  
  473.         for k, v in pairs(optionsText) do
  474.             longestStr = (longestStr < #v) and #v or longestStr
  475.         end
  476.  
  477.         longestStr = longestStr + 5
  478.  
  479.         local options = {}
  480.  
  481.         local textX = math.floor(consoleWidthCentre - longestStr * 0.5) - rightMargin
  482.         options[1] = newText("Options", consoleWidthCentre  - rightMargin, 6, "centre")
  483.         options[2] = newText(optionsText.doorText, textX, 8, "left")
  484.         options[3] = newText("1", textX + longestStr, 8, "left")
  485.         options[4] = newText(optionsText.teleportText, textX, 9, "left")
  486.         options[5] = newText("2", textX + longestStr, 9, "left")
  487.         options[6] = newText(optionsText.portalText, textX, 10, "left")
  488.         options[7] = newText("3", textX + longestStr, 10, "left")
  489.         --options[8] = newText(optionsText.manualText, textX, 11, "left")
  490.         --options[9] = newText("4", textX + longestStr, 11, "left")
  491.         options[8] = newText(optionsText.shutDownText, textX, 13, "left")
  492.         options[9] = newText("4", textX + longestStr, 13, "left")
  493.  
  494.         local optionsBox = newBox(textX - 2, 5, longestStr + 4, 2)
  495.  
  496.         if sensorsUI then
  497.  
  498.             --We're interested in maxStorage and energy
  499.             local tReadings = sensors.getSensorReadingAsDict(sSensorSide,sSensorName,sTarget,sProbe)
  500.             sensorsUI.vBar(textX + longestStr + 6,consoleHeight - 2,consoleHeight - 9,"Power",tReadings.energy,tReadings.maxStorage)
  501.             drawAllBoxes(tConsoleBoxes)
  502.             local barBox = newBox(consoleWidth - 9, 4, 10, consoleHeight - 5)
  503.             barBox:draw()
  504.  
  505.         end
  506.  
  507.         optionsBox:draw()
  508.  
  509.         writeAllText(options, not (debugMode or fastRender))
  510.        
  511.  
  512.     else
  513.  
  514.         --Support for a different mode goes here.
  515.        
  516.     end
  517.  
  518. end
  519.  
  520.  
  521. function renderCountdown(n)
  522.  
  523.     if sMonitorStatus == S_MONITOR_ON_VALUE and pMonitor then
  524.  
  525.         term.redirect(pMonitor)
  526.         sensorsUI.writeAt(1,1,tostring(n))
  527.         term.restore()
  528.  
  529.     end
  530. end
  531.  
  532. function getInput()
  533.  
  534.     --ask for input
  535.     if not fastRender then
  536.  
  537.         inputText:slowWrite()
  538.  
  539.     end
  540.  
  541.     inputText:write()
  542.  
  543.     local e, key = nil, nil
  544.  
  545.     refreshTimer = os.startTimer(1)
  546.  
  547.     repeat
  548.         e, key = os.pullEvent()
  549.     until e == "redstone" or e == "char" or key == tDoorControls.timer or key == refreshTimer
  550.    
  551.     if e == "char" then
  552.         term.write(" "..key)
  553.         sleep(0.7)
  554.     end
  555.  
  556.     return e, key
  557.  
  558. end
  559.  
  560. function writeStatus()
  561.  
  562.     --save statuses
  563.  
  564.     local hWrite = fs.open(sSaveFile, "w")
  565.     hWrite.write(sDoorStatus.."\n")
  566.     hWrite.write(sTeleportStatus.."\n")
  567.     hWrite.write(sPortalStatus.."\n")
  568.     hWrite.write(sAlarmStatus.."\n")
  569.     hWrite.write(sMonitorStatus.."\n")
  570.     hWrite.close()
  571.  
  572. end
  573.  
  574. function resetSystem()
  575.  
  576.     newText("Resetting system ", 6, y, "left", "slow")
  577.  
  578. end
  579.  
  580. function resetEverything()
  581.  
  582.     if sPortalStatus == S_NETHER_OPEN_VALUE then
  583.         setOutput(tTeleportControls.iAlarm, true)
  584.         setOutput(tPortalControls.iIgnite, false)
  585.         closePortal()
  586.         setOutput(tTeleportControls.iAlarm, false)
  587.         sPortalStatus = S_NETHER_CLOSED_VALUE
  588.     end
  589.     if sDoorStatus == S_DOOR_OPEN_VALUE then
  590.         setOutput(tDoorControls.iAlarm, true)
  591.         closeDoor()
  592.         setOutput(tDoorControls.iAlarm, false)
  593.     end
  594.  
  595.     os.reboot()
  596.  
  597. end
  598.  
  599. function toggleDoor()
  600.  
  601.     if sDoorStatus == S_DOOR_OPEN_VALUE then
  602.         closeDoorSequence()
  603.     else
  604.         --Check if Nether Portal is open, if so, quickly close it.
  605.         if sPortalStatus == S_NETHER_OPEN_VALUE then
  606.             setOutput(tTeleportControls.iAlarm, true)
  607.             setOutput(tPortalControls.iIgnite, false)
  608.             closePortal()
  609.             setOutput(tTeleportControls.iAlarm, false)
  610.             sPortalStatus = S_NETHER_CLOSED_VALUE
  611.         end
  612.  
  613.         openDoorSequence()
  614.  
  615.     end
  616.  
  617.     writeStatus()
  618.  
  619. end
  620.  
  621. function openDoorSequence()
  622.  
  623.     debug("in openDoor")
  624.  
  625.     setOutput(tDoorControls.iAlarm, true)
  626.     sAlarmStatus = S_ALARM_ON_VALUE
  627.  
  628.     sleep(0.5)
  629.  
  630.     local y = 6
  631.  
  632.     local openingText = newText("Opening Door ", 6, y, "left", "slow")
  633.  
  634.     loadingPos.x, loadingPos.y = term.getCursorPos()
  635.     parallel.waitForAll(showLoading, openDoor)
  636.  
  637.     sleep(0.5)
  638.  
  639.     setOutput(tDoorControls.iAlarm, false)
  640.     sAlarmStatus = S_ALARM_OFF_VALUE
  641.  
  642.     openingText:slowDelete()
  643.     openingText = newText("Door Open", 6, y, "left", "slow")
  644.     sleep(0.5)
  645.     openingText:slowDelete()
  646.     sDoorStatus = S_DOOR_OPEN_VALUE
  647.  
  648.     sleep(1)
  649.  
  650.     fastRender = true
  651.  
  652. end
  653.  
  654. function closeDoorSequence()
  655.  
  656.     setOutput(tDoorControls.iAlarm, true)
  657.     sAlarmStatus = S_ALARM_ON_VALUE
  658.  
  659.     sleep(0.5)
  660.  
  661.     local openingText = newText("Closing Door ", 3, 6, "left", "slow")
  662.     loadingPos.x, loadingPos.y = term.getCursorPos()
  663.     parallel.waitForAll(showLoading, closeDoor)
  664.  
  665.     sleep(0.5)
  666.  
  667.     setOutput(tDoorControls.iAlarm, false)
  668.     sAlarmStatus = S_ALARM_OFF_VALUE
  669.  
  670.     openingText:slowDelete()
  671.     openingText = newText("Door Closed", 3, 6, "left", "slow")
  672.     sleep(0.5)
  673.     openingText:slowDelete()
  674.     sDoorStatus = S_DOOR_CLOSE_VALUE
  675.  
  676.     sleep(1)
  677.  
  678.  
  679. end
  680.  
  681.  
  682. function openDoor()
  683.  
  684.     fDelay = 20
  685.  
  686.     pulseOutput(tDoorControls.iMoveOut,1)
  687.     sleep(0.4)
  688.     pulseOutput(tDoorControls.iOpen, 4)
  689.  
  690.     sDoorStatus = S_DOOR_OPEN_VALUE
  691.     writeStatus()
  692.     stopLoading()
  693.  
  694.     if fDelay then
  695.         tDoorControls.timer = os.startTimer(fDelay)
  696.     end
  697.  
  698. end
  699.  
  700. function closeDoor()
  701.  
  702.     tDoorControls.timer = nil
  703.  
  704.     pulseOutput(tDoorControls.iClose, 4)
  705.     sleep(0.4)
  706.     pulseOutput(tDoorControls.iMoveIn, 1)
  707.  
  708.     sDoorStatus = S_DOOR_CLOSE_VALUE
  709.     writeStatus()
  710.     stopLoading()
  711.  
  712. end
  713.  
  714. function teleportSequence()
  715.  
  716.     local y = 6
  717.     local guardText = ""
  718.     local keptText = {}
  719.  
  720.     if sDoorStatus ~= S_DOOR_CLOSE_VALUE then
  721.         closeDoorSequence()
  722.     end
  723.  
  724.     if sPortalStatus ~= S_NETHER_CLOSED_VALUE then
  725.         closePortalSequence()
  726.     end
  727.  
  728.     setOutput(tTeleportControls.iAlarm, true)
  729.     sTPAlarmStatus = S_ALARM_ON_VALUE
  730.  
  731.     sleep(0.5)
  732.  
  733.     guardText = newText("Closing Teleport Chamber in "..5, 3, y, "left", "slow")
  734.     renderCountdown(5)
  735.  
  736.     for i = 5, 0, -1 do
  737.         guardText = newText("Closing Teleport Chamber in "..i, 3, y, "left", "now")
  738.         pMonitor.clear()
  739.         renderCountdown(i)
  740.         sleep(1)
  741.     end
  742.  
  743.     pMonitor.clear()
  744.  
  745.     guardText:slowDelete()
  746.  
  747.     guardText = newText("Closing Teleport Chamber ", 3, y, "left", "slow")
  748.  
  749.     loadingPos.x, loadingPos.y = term.getCursorPos()
  750.     parallel.waitForAll(showLoading, closeTeleport)
  751.  
  752.     sleep(0.5)
  753.  
  754.     setOutput(tTeleportControls.iAlarm, false)
  755.     sTPAlarmStatus = S_ALARM_OFF_VALUE
  756.  
  757.     guardText:slowDelete()
  758.     keptText[1] = newText("Teleport Chamber Closed", 3, y, "left", "slow")
  759.     sTeleportStatus = S_TP_WALL_UP_VALUE
  760.  
  761.     --updatesave save file
  762.     writeStatus()
  763.  
  764.     sleep(1)
  765.  
  766.     y = y + 2
  767.  
  768.     guardText = newText("Teleporting Target in "..3, 3, y, "left", "slow")
  769.     renderCountdown(3)
  770.  
  771.     for i = 3, 0, -1 do
  772.         guardText = newText("Teleporting Target in "..i, 3, y, "left", "now")
  773.         pMonitor.clear()
  774.         renderCountdown(i)
  775.         sleep(1)
  776.     end
  777.  
  778.     pMonitor.clear()
  779.  
  780.     activateTeleport()
  781.  
  782.     guardText:slowDelete()
  783.  
  784.     keptText[2] = newText("Target Teleported", 3, y, "left", "slow")
  785.  
  786.     sleep(1)
  787.  
  788.     y = y + 2
  789.  
  790.     setOutput(tTeleportControls.iAlarm, true)
  791.     sTPAlarmStatus = S_ALARM_ON_VALUE
  792.  
  793.    
  794.  
  795.     guardText = newText("Opening Teleport Chamber ", 3, y, "left", "slow")
  796.  
  797.     loadingPos.x, loadingPos.y = term.getCursorPos()
  798.     parallel.waitForAll(showLoading, openTeleport)
  799.  
  800.  
  801.     sleep(0.5)
  802.  
  803.     setOutput(tTeleportControls.iAlarm, false)
  804.     sTPAlarmStatus = S_ALARM_OFF_VALUE
  805.  
  806.     guardText:slowDelete()
  807.     keptText[3] = newText("Teleport Chamber Open", 3, y, "left" ,"slow")
  808.     sTeleportStatus = S_TP_WALL_DOWN_VALUE
  809.  
  810.     --updatesave save file
  811.     writeStatus()
  812.  
  813.     sleep(0.5)
  814.  
  815.     for i = 1, #keptText do
  816.  
  817.         keptText[i]:slowDelete()
  818.  
  819.     end
  820.  
  821. end
  822.  
  823. function openTeleport()
  824.  
  825.     pulseOutput(tTeleportControls.iWallDown, 4)
  826.     sTeleportStatus = S_TP_WALL_DOWN_VALUE
  827.     writeStatus()
  828.     stopLoading()
  829.  
  830. end
  831.  
  832. function closeTeleport()
  833.  
  834.     pulseOutput(tTeleportControls.iWallUp, 4)
  835.     sTeleportStatus = S_TP_WALL_UP_VALUE
  836.     writeStatus()
  837.     stopLoading()
  838.  
  839. end
  840.  
  841. function togglePortal()
  842.  
  843.     if sPortalStatus == S_NETHER_OPEN_VALUE then
  844.         closePortalSequence()
  845.     else
  846.         openPortalSequence()
  847.     end
  848.  
  849.     writeStatus()
  850.  
  851. end
  852.  
  853. function openPortalSequence()
  854.  
  855.     local y = 6
  856.     local guardText = ""
  857.     local keptText = {}
  858.  
  859.     if sDoorStatus ~= S_DOOR_CLOSE_VALUE then
  860.         closeDoorSequence()
  861.     end
  862.  
  863.     setOutput(tTeleportControls.iAlarm, true)
  864.     sTPAlarmStatus = S_ALARM_ON_VALUE
  865.  
  866.     sleep(0.5)
  867.  
  868.     guardText = newText("Raising Nether Portal in "..5, 3, y, "left", "slow")
  869.     renderCountdown(5)
  870.  
  871.     for i = 5, 0, -1 do
  872.         guardText = newText("Raising Nether Portal in "..i, 3, y, "left", "now")
  873.         pMonitor.clear()
  874.         renderCountdown(i)
  875.         sleep(1)
  876.     end
  877.  
  878.     pMonitor.clear()
  879.  
  880.     guardText:slowDelete()
  881.  
  882.     guardText = newText("Nether Portal Raising ", 3, y, "left", "slow")
  883.  
  884.     loadingPos.x, loadingPos.y = term.getCursorPos()
  885.     parallel.waitForAll(showLoading, openPortal)
  886.  
  887.     sleep(0.5)
  888.  
  889.     setOutput(tTeleportControls.iAlarm, false)
  890.     sTPAlarmStatus = S_ALARM_OFF_VALUE
  891.  
  892.     guardText:slowDelete()
  893.     keptText[1] = newText("Nether Portal Raised", 3, y, "left", "slow")
  894.     sPortalStatus = S_NETHER_OPEN_VALUE
  895.  
  896.     --updatesave save file
  897.     writeStatus()
  898.  
  899.     sleep(1)
  900.  
  901.     y = y + 2
  902.  
  903.     guardText = newText("Attempting to Ignite Portal in "..3, 3, y, "left", "slow")
  904.     renderCountdown(3)
  905.  
  906.     for i = 3, 0, -1 do
  907.         guardText = newText("Attempting to Ignite Portal in "..i, 3, y, "left", "now")
  908.         pMonitor.clear()
  909.         renderCountdown(i)
  910.         sleep(1)
  911.     end
  912.  
  913.     pMonitor.clear()
  914.  
  915.     guardText:slowDelete()
  916.  
  917.     setOutput(tPortalControls.iIgnite, true)
  918.  
  919.     keptText[2] = newText("Portal Ignited", 3, y, "left", "slow")
  920.  
  921.     sleep(1)
  922.  
  923.     for i = 1, #keptText do
  924.  
  925.         keptText[i]:slowDelete()
  926.  
  927.     end
  928.  
  929. end
  930.  
  931. function openPortal()
  932.  
  933.     pulseOutput(tPortalControls.iUp, 6)
  934.     stopLoading()
  935.  
  936. end
  937.  
  938. function closePortalSequence()
  939.  
  940.     local y = 6
  941.     local guardText = ""
  942.     local keptText = {}
  943.  
  944.     if sDoorStatus ~= S_DOOR_CLOSE_VALUE then
  945.         closeDoorSequence()
  946.     end
  947.  
  948.     guardText = newText("Closing Portal in "..3, 3, y, "left", "slow")
  949.     renderCountdown(3)
  950.  
  951.     for i = 3, 0, -1 do
  952.         guardText = newText("Closing Portal in "..i, 3, y, "left", "now")
  953.         pMonitor.clear()
  954.         renderCountdown(i)
  955.         sleep(1)
  956.     end
  957.  
  958.     pMonitor.clear()
  959.  
  960.     setOutput(tPortalControls.iIgnite, false)
  961.  
  962.     guardText:slowDelete()
  963.  
  964.     keptText[1] = newText("Portal Closed", 3, y, "left", "slow")
  965.  
  966.     sleep(0.5)
  967.  
  968.     y = y + 2
  969.  
  970.     setOutput(tTeleportControls.iAlarm, true)
  971.     sTPAlarmStatus = S_ALARM_ON_VALUE
  972.  
  973.     sleep(1)
  974.  
  975.     guardText = newText("Lowering Nether Portal in "..5, 3, y, "left", "slow")
  976.     renderCountdown(5)
  977.  
  978.     for i = 5, 0, -1 do
  979.         guardText = newText("Lowering Nether Portal in "..i, 3, y, "left", "now")
  980.         pMonitor.clear()
  981.         renderCountdown(i)
  982.         sleep(1)
  983.     end
  984.  
  985.     pMonitor.clear()
  986.  
  987.     guardText:slowDelete()
  988.  
  989.     guardText = newText("Nether Portal Lowering ", 3, y, "left", "slow")
  990.  
  991.     loadingPos.x, loadingPos.y = term.getCursorPos()
  992.     parallel.waitForAll(showLoading, closePortal)
  993.  
  994.     sleep(1)
  995.  
  996.     setOutput(tTeleportControls.iAlarm, false)
  997.     sTPAlarmStatus = S_ALARM_OFF_VALUE
  998.  
  999.     guardText:slowDelete()
  1000.     keptText[2] = newText("Nether Portal Lowered", 3, y, "left", "slow")
  1001.     sPortalStatus = S_NETHER_CLOSED_VALUE
  1002.  
  1003.     --updatesave save file
  1004.     writeStatus()
  1005.  
  1006.     sleep(1)
  1007.  
  1008.     for i = 1, #keptText do
  1009.  
  1010.         keptText[i]:slowDelete()
  1011.  
  1012.     end
  1013.  
  1014. end
  1015.  
  1016. function closePortal()
  1017.  
  1018.     pulseOutput(tPortalControls.iDown, 6)
  1019.     stopLoading()
  1020.  
  1021. end
  1022.  
  1023. function activateTeleport()
  1024.  
  1025.     pulseOutput(tTeleportControls.iTeleport, 1)
  1026.  
  1027. end
  1028.  
  1029. function setOutput(colour, bool)
  1030.  
  1031.     if bool then
  1032.         rs.setBundledOutput("bottom", colors.combine(rs.getBundledOutput("bottom"), colour))
  1033.     else
  1034.         rs.setBundledOutput("bottom", colors.subtract(rs.getBundledOutput("bottom"), colour))
  1035.     end
  1036. end
  1037.  
  1038. function toMonitor(startX, startY, sString)
  1039.  
  1040.  
  1041.  
  1042. end
  1043.  
  1044. if fs.exists(sSaveFile) then
  1045.  
  1046.     --Check to see if save file exists and open it to save out all of the current saved statuses
  1047.  
  1048.     local hRead = assert(fs.open(sSaveFile, "r")) --Will crash the program if the file cannot be opened
  1049.     sDoorStatus = hRead.readLine()
  1050.     sTeleportStatus = hRead.readLine()
  1051.     sPortalStatus = hRead.readLine()
  1052.     sAlarmStatus = hRead.readLine()
  1053.     sMonitorStatus = hRead.readLine()
  1054.     sTPAlarmStatus = hRead.readLine()
  1055.     hRead.close()
  1056.  
  1057.     if sDoorStatus == S_DOOR_OPEN_VALUE then
  1058.         tDoorControls.timer = os.startTimer(20)
  1059.     end
  1060.  
  1061. else
  1062.  
  1063.     --set everything to the default values if there is no save file
  1064.  
  1065.     sDoorStatus = S_DOOR_CLOSE_VALUE
  1066.     sTeleportStatus = S_TP_WALL_DOWN_VALUE
  1067.     sPortalStatus = S_NETHER_CLOSED_VALUE
  1068.     sAlarmStatus = S_ALARM_OFF_VALUE
  1069.     sMonitorStatus = S_MONITOR_ON_VALUE
  1070.     sTPAlarmStatus = S_ALARM_OFF_VALUE
  1071.  
  1072.     closeDoor()
  1073.     openTeleport()
  1074.     --closePortal()
  1075.     --deactivatePortal()
  1076.     setOutput(tTeleportControls.iAlarm, false)
  1077.  
  1078.     writeStatus()
  1079.  
  1080. end
  1081.  
  1082.  
  1083.  
  1084. --run the program
  1085.  
  1086. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement