Advertisement
Guest User

ReactorControl

a guest
Apr 4th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.79 KB | None | 0 0
  1. local com = peripheral.wrap("back")
  2. local display = peripheral.wrap("right")
  3. local tanks = {
  4.   reactor = "reactor_fluid_port_0",
  5.   coolantA = "rcirontankvalvetile_2",
  6.   coolantB = "rcirontankvalvetile_3",
  7.   distilledA = "rcirontankvalvetile_5",
  8.   distilledB = "rcirontankvalvetile_1"
  9. }
  10. function tryTankLevel(tank)
  11.   return com.callRemote(tank, "getTankInfo")[1].contents.amount
  12. end
  13. function getReactorHot()
  14.   local empty, level = pcall(function () return com.callRemote(tanks.reactor, "getTankInfo")[2].contents.amount end)
  15.   if (not empty) then
  16.     return 0
  17.   else
  18.     return level
  19.   end
  20. end
  21. function getReactorCold()
  22.   local empty, level = pcall(function () return com.callRemote(tanks.reactor, "getTankInfo")[1].contents.amount end)
  23.   if (not empty) then
  24.     return 0
  25.   else
  26.     return level
  27.   end
  28. end
  29. function getTankLevel(tank)
  30.   local empty, level = pcall(tryTankLevel, tank)
  31.   if (not empty) then
  32.     return 0
  33.   else
  34.     return level
  35.   end
  36. end
  37. local colorValue = 0
  38. function toggleColor(color)
  39.   if (rs.testBundledInput("bottom", color)) then
  40.     rs.setBundledOutput("bottom", colorValue - color)
  41.     colorValue = colorValue - color
  42.   else
  43.     rs.setBundledOutput("bottom", colorValue + color)
  44.     colorValue = colorValue + color
  45.   end
  46. end
  47. function printAtMonitor(x, y, color, text)
  48.   display.setTextColor(color)
  49.   display.setCursorPos(x, y)
  50.   display.write(text)
  51. end
  52. function printAt(x,y,color,text)
  53.   term.setTextColor(color)
  54.   term.setCursorPos(x, y)
  55.   term.write(text)
  56. end
  57. function reactorDisplay()
  58.   local run = true
  59.   while true do
  60.     local ReactorCold = getReactorCold()
  61.     local ReactorHot = getReactorHot()
  62.     local ReactorOn = rs.testBundledInput("bottom", colors.green)
  63.     local coolant = {
  64.       tankA = getTankLevel(tanks.coolantA),
  65.       tankB = getTankLevel(tanks.coolantB),
  66.       A1 = rs.testBundledInput("bottom", colors.white),
  67.       A2 = rs.testBundledInput("bottom", colors.orange),
  68.       B1 = rs.testBundledInput("bottom", colors.magenta),
  69.       B2 = rs.testBundledInput("bottom", colors.lightBlue)
  70.     }
  71.     local distilled = {
  72.       tankA = getTankLevel(tanks.distilledA),
  73.       tankB = getTankLevel(tanks.distilledB),
  74.       A1 = rs.testBundledInput("bottom", colors.yellow),
  75.       A2 = rs.testBundledInput("bottom", colors.lime),
  76.       B1 = rs.testBundledInput("bottom", colors.pink),
  77.       B2 = rs.testBundledInput("bottom", colors.gray)
  78.     }
  79.     local turbine = {
  80.       A1 = rs.testBundledInput("bottom", colors.cyan),
  81.       A2 = rs.testBundledInput("bottom", colors.purple),
  82.       B1 = rs.testBundledInput("bottom", colors.blue),
  83.       B2 = rs.testBundledInput("bottom", colors.brown)
  84.     }
  85.     display.clear()
  86.     printAtMonitor(1,1,colors.white,"Reactor Levels:")
  87.     printAtMonitor(2,2,colors.red, "Hot: "..ReactorHot)
  88.     printAtMonitor(2,3,colors.cyan, "Cold: "..ReactorCold)
  89.     printAtMonitor(1,4,colors.white, "Tank Levels:")
  90.     printAtMonitor(2,5,colors.cyan, "CoolA: "..coolant.tankA)
  91.     printAtMonitor(2,6,colors.cyan, "CoolB: "..coolant.tankB)
  92.     printAtMonitor(2,7,colors.lightBlue, "DistA: "..distilled.tankA)
  93.     printAtMonitor(2,8,colors.lightBlue, "DistB: "..distilled.tankB)
  94.     printAtMonitor(1,9, colors.white, "Turbines:")
  95.     printAtMonitor(2,10, colors.yellow, "A1[   ] B1[   ]")
  96.     printAtMonitor(2,11, colors.yellow, "A2[   ] B2[   ]")
  97.     if (turbine.A1) then
  98.       printAtMonitor(5,10, colors.lime, "On")
  99.     else
  100.       printAtMonitor(5,10, colors.red, "Off")
  101.     end
  102.     if (turbine.A2) then
  103.       printAtMonitor(5,11, colors.lime, "On")
  104.     else
  105.       printAtMonitor(5,11, colors.red, "Off")
  106.     end
  107.     if (turbine.B1) then
  108.       printAtMonitor(13,10, colors.lime, "On")
  109.     else
  110.       printAtMonitor(13,10, colors.red, "Off")
  111.     end
  112.     if (turbine.B2) then
  113.       printAtMonitor(13,11, colors.lime, "On")
  114.     else
  115.       printAtMonitor(13,11, colors.red, "Off")
  116.     end
  117.     printAtMonitor(26,4,colors.white, "-------")
  118.     printAtMonitor(19,5,colors.white, "---    |     |    ---")
  119.     printAtMonitor(19,6,colors.white, "|A|    |     |    |B|")
  120.     printAtMonitor(19,7,colors.white, "---    |     |    ---")
  121.     printAtMonitor(26,8,colors.white, "-------")
  122.     printAtMonitor(19,1,colors.cyan, "--[   ]")
  123.     printAtMonitor(26,1,colors.red, "--   --")
  124.     printAtMonitor(33,1,colors.cyan, "[   ]--")
  125.     printAtMonitor(19,2,colors.cyan, "|")
  126.     printAtMonitor(27,2,colors.red, "|   |")
  127.     printAtMonitor(29,2,colors.white,"1")
  128.     printAtMonitor(39,2,colors.cyan, "|")
  129.     printAtMonitor(19,3,colors.cyan, "|")
  130.     printAtMonitor(27,3,colors.red, "|   |")
  131.     printAtMonitor(39,3,colors.cyan, "|")
  132.     printAtMonitor(19,4,colors.cyan, "|")
  133.     printAtMonitor(39,4,colors.cyan, "|")
  134.     printAtMonitor(22,5,colors.cyan, "----")
  135.     printAtMonitor(33,5,colors.cyan, "----")
  136.     printAtMonitor(22,7,colors.cyan, "----")
  137.     printAtMonitor(33,7,colors.cyan, "----")
  138.     printAtMonitor(19,8,colors.cyan, "|")
  139.     printAtMonitor(39,8,colors.cyan, "|")
  140.     printAtMonitor(19,9,colors.cyan, "|")
  141.     printAtMonitor(27,9,colors.red, "|   |")
  142.     printAtMonitor(39,9,colors.cyan, "|")
  143.     printAtMonitor(19,10,colors.cyan, "|")
  144.     printAtMonitor(27,10,colors.red, "|   |")
  145.     printAtMonitor(29,10,colors.white, "2")
  146.     printAtMonitor(39,10,colors.cyan, "|")
  147.     printAtMonitor(19,11,colors.cyan, "--[   ]")
  148.     printAtMonitor(26,11,colors.red, "--   --")
  149.     printAtMonitor(33,11,colors.cyan, "[   ]--")
  150.     printAtMonitor(20,3,colors.lightBlue, "-[   ]")
  151.     printAtMonitor(20,4,colors.lightBlue, "| |")
  152.     printAtMonitor(33,3,colors.lightBlue, "[   ]-")
  153.     printAtMonitor(36,4,colors.lightBlue, "| |")
  154.     printAtMonitor(20,8,colors.lightBlue, "| |")
  155.     printAtMonitor(20,9,colors.lightBlue, "-[   ]")
  156.     printAtMonitor(36,8,colors.lightBlue, "| |")
  157.     printAtMonitor(33,9,colors.lightBlue, "[   ]-")
  158.     if (coolant.A1) then
  159.       printAtMonitor(22,1,colors.lime, "On")
  160.     else
  161.       printAtMonitor(22,1,colors.red, "Off")
  162.     end
  163.     if (coolant.A2) then
  164.       printAtMonitor(22,11,colors.lime, "On")
  165.     else
  166.       printAtMonitor(22,11,colors.red, "Off")
  167.     end
  168.     if (coolant.B1) then
  169.       printAtMonitor(34,1,colors.lime, "On")
  170.     else
  171.       printAtMonitor(34,1,colors.red, "Off")
  172.     end
  173.     if (coolant.B2) then
  174.       printAtMonitor(34,11,colors.lime, "On")
  175.     else
  176.       printAtMonitor(34,11,colors.red, "Off")
  177.     end
  178.     if (ReactorOn) then
  179.       printAtMonitor(28,6,colors.lime, "On")
  180.     else
  181.       printAtMonitor(28,6,colors.red, "Off")
  182.     end
  183.     if (distilled.A1) then
  184.       printAtMonitor(22,3,colors.lime, "On")
  185.     else
  186.       printAtMonitor(22,3,colors.red, "Off")
  187.     end
  188.     if (distilled.A2) then
  189.       printAtMonitor(22,9,colors.lime, "On")
  190.     else
  191.       printAtMonitor(22,9,colors.red, "Off")
  192.     end
  193.     if (distilled.B1) then
  194.       printAtMonitor(34,3,colors.lime,"On")
  195.     else
  196.       printAtMonitor(34,3,colors.red,"Off")
  197.     end
  198.     if (distilled.B2) then
  199.       printAtMonitor(34,9,colors.lime,"On")
  200.     else
  201.       printAtMonitor(34,9,colors.red,"Off")
  202.     end
  203.     if (run) then
  204.       printAtMonitor(1,12, colors.white, "Running")
  205.     end
  206.     run = not run
  207.     sleep(1)
  208.   end
  209. end
  210.  
  211. function reactorControls()
  212.   local cursor = 1
  213.   local states = {"Off","Off","Off","Off","Off","Off","Off","Off","Off"}
  214.   rs.setBundledOutput("bottom", 0)
  215.   rs.setOutput("left", false)
  216.   while true do
  217.     term.clear()
  218.     printAt(1,1,colors.white,"Monitor")
  219.     printAt(1,2,colors.white, "CoolantA1")
  220.     printAt(1,3,colors.white, "CoolantA2")
  221.     printAt(1,4,colors.white, "CoolantB1")
  222.     printAt(1,5,colors.white, "CoolantB2")
  223.     printAt(1,6,colors.white, "DistilledA1")
  224.     printAt(1,7,colors.white, "DistilledA2")
  225.     printAt(1,8,colors.white, "DistilledB1")
  226.     printAt(1,9,colors.white, "DistilledB2")
  227.     printAt(1,10,colors.white, "RemoveCells")
  228.     printAt(1,11,colors.white, "Shutdown")
  229.     printAt(12,cursor, colors.white, "[   ]")
  230.     for i = 1,9 do
  231.       if (states[i] == "Off") then
  232.         printAt(13,i,colors.red, states[i])
  233.       else
  234.         printAt(13,i,colors.lime, states[i])
  235.       end
  236.     end
  237.     local event, keyNum = os.pullEvent("key")
  238.     if (keyNum == 200) then
  239.       cursor = cursor - 1
  240.       if (cursor == 0) then
  241.         cursor = 11
  242.       end
  243.     end
  244.     if (keyNum == 208) then
  245.       cursor = cursor + 1
  246.       if (cursor == 12) then
  247.         cursor = 1
  248.       end
  249.     end
  250.     if (keyNum == 28) then
  251.       if (cursor == 1) then
  252.         rs.setOutput("left", not rs.getOutput("left"))
  253.       end
  254.       if (cursor == 2) then
  255.         toggleColor(colors.white)
  256.       end
  257.       if (cursor == 3) then
  258.         toggleColor(colors.orange)
  259.       end
  260.       if (cursor == 4) then
  261.         toggleColor(colors.magenta)
  262.       end
  263.       if (cursor == 5) then
  264.         toggleColor(colors.lightBlue)
  265.       end
  266.       if (cursor == 6) then
  267.         toggleColor(colors.yellow)
  268.       end
  269.       if (cursor == 7) then
  270.         toggleColor(colors.lime)
  271.       end
  272.       if (cursor == 8) then
  273.         toggleColor(colors.pink)
  274.       end
  275.       if (cursor == 9) then
  276.         toggleColor(colors.gray)
  277.       end
  278.       if (cursor == 10 and not rs.testBundledInput("bottom", colors.green)) then
  279.         toggleColor(colors.black)
  280.         term.clear()
  281.         printAt(1,1,colors.white, "Removing Depleted Cells")
  282.         sleep(7)
  283.         toggleColor(colors.black)
  284.       end
  285.       if (cursor == 11 and not rs.testBundledInput("bottom", colors.green)) then
  286.         rs.setBundledOutput("bottom", 0)
  287.         term.clear()
  288.         printAt(1,1,colors.white, "Goodbye!")
  289.         sleep(1)
  290.         term.clear()
  291.         return
  292.       end
  293.       if (cursor < 10 and states[cursor] == "Off") then
  294.         states[cursor] = "On"
  295.       else
  296.         states[cursor] = "Off"
  297.       end
  298.     end
  299.   end
  300. end
  301. parallel.waitForAny(reactorControls,reactorDisplay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement