SHARE
TWEET

LiquidControl

a guest Jan 19th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local com = peripheral.wrap("back")
  2. local display = peripheral.wrap("right")
  3. local tanks = {
  4.   coolantA1 = "rcirontankvalvetile_2",
  5.   coolantB1 = "rcirontankvalvetile_3",
  6.   coolantS = "rcirontankvalvetile_4",
  7.   distilledA1 = "rcirontankvalvetile_5",
  8.   distilledB1 = "rcirontankvalvetile_1",
  9.   distilledS = "rcirontankvalvetile_6"
  10. }
  11. function tryTankLevel(tank)
  12.   return com.callRemote(tank, "getTankInfo")[1].contents.amount
  13. end
  14. function getTankLevel(tank)
  15.   local empty, level = pcall(tryTankLevel, tank)
  16.   if (not empty) then
  17.     return 0
  18.   else
  19.     return level
  20.   end
  21. end
  22. local colorValue = 0
  23. function toggleColor(color)
  24.   if (rs.testBundledInput("bottom", color)) then
  25.     rs.setBundledOutput("bottom", colorValue - color)
  26.     colorValue = colorValue - color
  27.   else
  28.     rs.setBundledOutput("bottom", colorValue + color)
  29.     colorValue = colorValue + color
  30.   end
  31. end
  32. function printAtMonitor(x, y, color, text)
  33.   display.setTextColor(color)
  34.   display.setCursorPos(x, y)
  35.   display.write(text)
  36. end
  37. function printAt(x,y,color,text)
  38.   term.setTextColor(color)
  39.   term.setCursorPos(x, y)
  40.   term.write(text)
  41. end
  42. function signalToColor(signal)
  43.   if (signal) then
  44.     return colors.lime
  45.   else
  46.     return colors.red
  47.   end
  48. end
  49. function reactorDisplay()
  50.   local run = true
  51.   while true do
  52.     local coolant = {
  53.       tankA1 = getTankLevel(tanks.coolantA1),
  54.       tankB1 = getTankLevel(tanks.coolantB1),
  55.       tankA2 = 0,
  56.       tankB2 = 0,
  57.       tankA3 = 0,
  58.       tankB3 = 0,
  59.       tankA4 = 0,
  60.       tankB4 = 0,
  61.       tankS = getTankLevel(tanks.coolantS),
  62.       SA1 = rs.testBundledInput("top", 1),
  63.       A1A2 = rs.testBundledInput("top", 2),
  64.       A2A3 = rs.testBundledInput("top", 4),
  65.       A3A4 = rs.testBundledInput("top", 8),
  66.       A4S = rs.testBundledInput("top", 16),
  67.       SB1 = rs.testBundledInput("top", 32),
  68.       B1B2 = rs.testBundledInput("top", 64),
  69.       B2B3 = rs.testBundledInput("top", 128),
  70.       B3B4 = rs.testBundledInput("top", 256),
  71.       B4S = rs.testBundledInput("top", 512)
  72.     }
  73.     local distilled = {
  74.       tankA1 = getTankLevel(tanks.distilledA1),
  75.       tankB1 = getTankLevel(tanks.distilledB1),
  76.       tankA2 = 0,
  77.       tankB2 = 0,
  78.       tankA3 = 0,
  79.       tankB3 = 0,
  80.       tankA4 = 0,
  81.       tankB4 = 0,
  82.       tankS = getTankLevel(tanks.distilledS),
  83.       SA1 = rs.testBundledInput("bottom", 1),
  84.       A1A2 = rs.testBundledInput("bottom", 2),
  85.       A2A3 = rs.testBundledInput("bottom", 4),
  86.       A3A4 = rs.testBundledInput("bottom", 8),
  87.       A4S = rs.testBundledInput("bottom", 16),
  88.       SB1 = rs.testBundledInput("bottom", 32),
  89.       B1B2 = rs.testBundledInput("bottom", 64),
  90.       B2B3 = rs.testBundledInput("bottom", 128),
  91.       B3B4 = rs.testBundledInput("bottom", 256),
  92.       B4S = rs.testBundledInput("bottom", 512)
  93.     }
  94.     display.clear()
  95.     printAtMonitor(1,1,colors.white,"Coolant:")
  96.     printAtMonitor(2,2,colors.cyan, "S: "..coolant.tankS)
  97.     printAtMonitor(2,4,colors.cyan, "1A: "..coolant.tankA1)
  98.     printAtMonitor(2,5,colors.cyan, "1B: "..coolant.tankB1)
  99.     printAtMonitor(2,6,colors.cyan, "2A: "..coolant.tankA2)
  100.     printAtMonitor(2,7,colors.cyan, "2B: "..coolant.tankB2)
  101.     printAtMonitor(2,8,colors.cyan, "3A: "..coolant.tankA3)
  102.     printAtMonitor(2,9,colors.cyan, "3B: "..coolant.tankB3)
  103.     printAtMonitor(2,10,colors.cyan, "4A: "..coolant.tankA4)
  104.     printAtMonitor(2,11,colors.cyan, "4B: "..coolant.tankB4)
  105.     printAtMonitor(1,2,signalToColor(coolant.SA1), "v")
  106.     printAtMonitor(1,3,signalToColor(coolant.SB1), "v")
  107.     printAtMonitor(1,4,signalToColor(coolant.A1A2), "v")
  108.     printAtMonitor(1,5,signalToColor(coolant.B1B2), "v")
  109.     printAtMonitor(1,6,signalToColor(coolant.A2A3), "v")
  110.     printAtMonitor(1,7,signalToColor(coolant.B2B3), "v")
  111.     printAtMonitor(1,8,signalToColor(coolant.A3A4), "v")
  112.     printAtMonitor(1,9,signalToColor(coolant.B3B4), "v")
  113.     printAtMonitor(1,10,signalToColor(coolant.A4S), "^")
  114.     printAtMonitor(1,11,signalToColor(coolant.B4S), "^")
  115.    
  116.     printAtMonitor(14,1,colors.white,"Distilled:")
  117.     printAtMonitor(15,2,colors.lightBlue, "S: "..distilled.tankS)
  118.     printAtMonitor(15,4,colors.lightBlue, "1A: "..distilled.tankA1)
  119.     printAtMonitor(15,5,colors.lightBlue, "1B: "..distilled.tankB1)
  120.     printAtMonitor(15,6,colors.lightBlue, "2A: "..distilled.tankA2)
  121.     printAtMonitor(15,7,colors.lightBlue, "2B: "..distilled.tankB2)
  122.     printAtMonitor(15,8,colors.lightBlue, "3A: "..distilled.tankA3)
  123.     printAtMonitor(15,9,colors.lightBlue, "3B: "..distilled.tankB3)
  124.     printAtMonitor(15,10,colors.lightBlue, "4A: "..distilled.tankA4)
  125.     printAtMonitor(15,11,colors.lightBlue, "4B: "..distilled.tankB4)
  126.     printAtMonitor(14,2,signalToColor(distilled.SA1), "v")
  127.     printAtMonitor(14,3,signalToColor(distilled.SB1), "v")
  128.     printAtMonitor(14,4,signalToColor(distilled.A1A2), "v")
  129.     printAtMonitor(14,5,signalToColor(distilled.B1B2), "v")
  130.     printAtMonitor(14,6,signalToColor(distilled.A2A3), "v")
  131.     printAtMonitor(14,7,signalToColor(distilled.B2B3), "v")
  132.     printAtMonitor(14,8,signalToColor(distilled.A3A4), "v")
  133.     printAtMonitor(14,9,signalToColor(distilled.B3B4), "v")
  134.     printAtMonitor(14,10,signalToColor(distilled.A4S), "^")
  135.     printAtMonitor(14,11,signalToColor(distilled.B4S), "^")
  136.    
  137.    
  138.     if (run) then
  139.       printAtMonitor(1,12, colors.white, "Running")
  140.     end
  141.     run = not run
  142.     sleep(1)
  143.   end
  144. end
  145. function transferLiquid(start, target)
  146.   local output2 = 0
  147.   local output10 = 0
  148.   while (not start == target) do
  149.     output2 = output2 + 10^start
  150.     output10 = output10 + 2^start
  151.     start = start + 1
  152.   end
  153.   if (string.sub(""..output2,1,5) == "11111") then
  154.     output10 = output10 -31
  155.   end
  156.   if (string.sub(""..output2,6,10) == "11111")then
  157.     output10 = output10 -992
  158.   end
  159.   return output10
  160. end
  161. function selectPump()
  162.   local line = 1
  163.   while true do
  164.     local pumps = {"S ","1A","2A","3A","4A","1B","2B","3B","4B"}
  165.     for i=1,9 do
  166.       term.setCursorPos(2,i + 1)
  167.       term.clearLine()
  168.       printAt(2, i + 1, colors.white, pumps[i])
  169.     end
  170.  printAt(1,line+1,colors.white,"[")
  171.  printAt(4,line+1,colors.white,"]")
  172.     local event, key = os.pullEvent("key")
  173.     if (key == 200) then
  174.       line = line -1
  175.       if (line == 0) then
  176.         line = 1
  177.       end
  178.     end
  179.     if (key == 208) then
  180.       line = line + 1
  181.       if (line == 10) then
  182.         line = 9
  183.       end
  184.     end
  185.     if (key == 28) then
  186.       if (line > 5) then
  187.         return line + 1
  188.       else
  189.         return line
  190.     end
  191.   end
  192. end
  193. end
  194. function selection()
  195.   local pumps = {"S ","1A","2A","3A","4A","S ","1B","2B","3B","4B"}
  196.   local coolant = {
  197.     start = 0,
  198.     target = 0,
  199.     on = false
  200.   }
  201.   local distilled = {
  202.     start = 0,
  203.     target = 0,
  204.     on = false
  205.   }
  206.   local cursor = {0,0}
  207.  while (true) do
  208.     term.clear()
  209.     printAt(1,1,colors.white,"Coolant   "..pumps[coolant.start + 1].."->"..pumps[coolant.target + 1].."     ")
  210.     printAt(1,2,colors.white,"Distilled "..pumps[distilled.start + 1].."->"..pumps[distilled.target + 1].."     ")
  211.  if (cursor[1]==0) then
  212.    printAt(10,1+cursor[2],colors.white,"[")
  213.    printAt(17,1+cursor[2],colors.white,"]")
  214.  else
  215.    printAt(17,1+cursor[2],colors.white,"[")
  216.    printAt(21,1+cursor[2],colors.white,"]")
  217.  end
  218. if (coolant.on) then
  219.       printAt(18,1,colors.green,"On")
  220.     else
  221.       printAt(18,1,colors.red,"Off")
  222.     end
  223.     if (distilled.on) then
  224.       printAt(18,2,colors.green,"On")
  225.     else
  226.       printAt(18,2,colors.red,"Off")
  227.     end
  228.     local event, key = os.pullEvent("key")
  229.     if (key == 203) then
  230.       cursor[1] = 0
  231.     end
  232.     if (key == 205) then
  233.       cursor[1] = 1
  234.     end
  235.     if (key == 200) then
  236.       cursor[2] = 0
  237.     end
  238.     if (key == 208) then
  239.       cursor[2] = 1
  240.     end
  241.     if (key == 28) then
  242.       if (cursor[1] == 0) then
  243.         if (cursor[2] == 0) then
  244.           term.clear()
  245.     printAt(1,1, colors.white, "Coolant:   ->")
  246.           coolant.start = selectPump() - 1
  247.           printAt(10,1, colors.white, pumps[coolant.start + 1])
  248.           coolant.target = selectPump() - 1
  249.         else
  250.           printAt(1,1, colors.white, "Distilled:   ->")
  251.           distilled.start = selectPump() - 1
  252.           printAt(12,1, colors.white, pumps[distilled.start + 1])
  253.           distilled.target = selectPump() - 1
  254.         end
  255.       else
  256.         if (cursor[2] == 0) then
  257.           coolant.on = not coolant.on
  258.         else
  259.           distilled.on = not distilled.on
  260.         end
  261.       end
  262.       if (coolant.on) then
  263.         rs.setBundledOutput("top", transferLiquid(coolant.start, coolant.target))
  264.       else
  265.         rs.setBundledOutput("top", 0)
  266.    end
  267.       if (distilled.on) then
  268.         rs.setBundledOutput("bottom", transferLiquid(distilled.start, distilled.target))
  269.       else
  270.         rs.setBundledOutput("bottom", 0)
  271.       end
  272.     end
  273.   end
  274. end
  275. parallel.waitForAny(reactorDisplay, selection)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top