Advertisement
Guest User

LiquidControl

a guest
Apr 4th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.97 KB | None | 0 0
  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 start ~= target do
  149.     output2 = output2 + math.pow(10,start)
  150.     output10 = output10 + math.pow(2,start)
  151.     start = start + 1
  152.  if start == 10 then
  153.  start = 0
  154.  end
  155.   end
  156. --  if (string.sub(""..output2,1,5) == "11111") then
  157. --  output10 = output10 -32
  158. --  end
  159. --  if (string.sub(""..output2,6,10) == "11111")then
  160. --    output10 = output10 -992
  161. --  end
  162.   if (colors.test(output10,1) and colors.test(output10,2) and colors.test(output10,4) and colors.test(output10,8) and colors.test(output10,16)) then
  163.     output10 = output10 - 31
  164.   end
  165.   if (colors.test(output10,32) and colors.test(output10,64) and colors.test(output10,128) and colors.test(output10,256) and colors.test(output10,512)) then
  166.     output10 = output10 - 992
  167.   end
  168.   return output10
  169. end
  170. function selectPump()
  171.   local line = 1
  172.   while true do
  173.     local pumps = {"S ","1A","2A","3A","4A","1B","2B","3B","4B"}
  174.     for i=1,9 do
  175.       term.setCursorPos(2,i + 1)
  176.       term.clearLine()
  177.       printAt(2, i + 1, colors.white, pumps[i])
  178.     end
  179.  printAt(1,line+1,colors.white,"[")
  180.  printAt(4,line+1,colors.white,"]")
  181.     local event, key = os.pullEvent("key")
  182.     if (key == 200) then
  183.       line = line -1
  184.       if (line == 0) then
  185.         line = 1
  186.       end
  187.     end
  188.     if (key == 208) then
  189.       line = line + 1
  190.       if (line == 10) then
  191.         line = 9
  192.       end
  193.     end
  194.     if (key == 28) then
  195.       if (line > 5) then
  196.         return line + 1
  197.       else
  198.         return line
  199.     end
  200.   end
  201. end
  202. end
  203. function selection()
  204.   local pumps = {"S ","1A","2A","3A","4A","S ","1B","2B","3B","4B"}
  205.   local coolant = {
  206.     start = 0,
  207.     target = 0,
  208.     on = false
  209.   }
  210.   local distilled = {
  211.     start = 0,
  212.     target = 0,
  213.     on = false
  214.   }
  215.   local cursor = {0,0}
  216.  while (true) do
  217.     term.clear()
  218.     printAt(1,1,colors.white,"Coolant   "..pumps[coolant.start + 1].."->"..pumps[coolant.target + 1].."     ")
  219.     printAt(1,2,colors.white,"Distilled "..pumps[distilled.start + 1].."->"..pumps[distilled.target + 1].."     ")
  220.  if (cursor[1]==0) then
  221.    printAt(10,1+cursor[2],colors.white,"[")
  222.    printAt(17,1+cursor[2],colors.white,"]")
  223.  else
  224.    printAt(17,1+cursor[2],colors.white,"[")
  225.    printAt(21,1+cursor[2],colors.white,"]")
  226.  end
  227. if (coolant.on) then
  228.       printAt(18,1,colors.green,"On")
  229.     else
  230.       printAt(18,1,colors.red,"Off")
  231.     end
  232.     if (distilled.on) then
  233.       printAt(18,2,colors.green,"On")
  234.     else
  235.       printAt(18,2,colors.red,"Off")
  236.     end
  237.     local event, key = os.pullEvent("key")
  238.     if (key == 203) then
  239.       cursor[1] = 0
  240.     end
  241.     if (key == 205) then
  242.       cursor[1] = 1
  243.     end
  244.     if (key == 200) then
  245.       cursor[2] = 0
  246.     end
  247.     if (key == 208) then
  248.       cursor[2] = 1
  249.     end
  250.     if (key == 28) then
  251.       if (cursor[1] == 0) then
  252.         if (cursor[2] == 0) then
  253.           term.clear()
  254.     printAt(1,1, colors.white, "Coolant:   ->")
  255.           coolant.start = selectPump() - 1
  256.           printAt(10,1, colors.white, pumps[coolant.start + 1])
  257.           coolant.target = selectPump() - 1
  258.         else
  259.           printAt(1,1, colors.white, "Distilled:   ->")
  260.           distilled.start = selectPump() - 1
  261.           printAt(12,1, colors.white, pumps[distilled.start + 1])
  262.           distilled.target = selectPump() - 1
  263.         end
  264.       else
  265.         if (cursor[2] == 0) then
  266.           coolant.on = not coolant.on
  267.         else
  268.           distilled.on = not distilled.on
  269.         end
  270.       end
  271.       if (coolant.on) then
  272.         rs.setBundledOutput("top", transferLiquid(coolant.start, coolant.target))
  273.       else
  274.         rs.setBundledOutput("top", 0)
  275.    end
  276.       if (distilled.on) then
  277.         rs.setBundledOutput("bottom", transferLiquid(distilled.start, distilled.target))
  278.       else
  279.         rs.setBundledOutput("bottom", 0)
  280.       end
  281.     end
  282.   end
  283. end
  284. parallel.waitForAny(reactorDisplay, selection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement