Stravides

Poop

Nov 30th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.76 KB | None | 0 0
  1. print("Initializing program...");
  2.  
  3. if not os.loadAPI("FC_API") then
  4.     error("Missing FC_API")
  5. end
  6.  
  7. function wrapThis(thing)
  8.         local wrapped, f = nil, 0
  9.         while wrapped == nil and f <= 100 do
  10.                 wrapped = peripheral.wrap(thing.."_"..f)
  11.                 f = f + 1
  12.         end
  13.  
  14.         if wrapped == nil then
  15.                 side = getDeviceSide(thing)
  16.                 if side ~= nil then
  17.                         return peripheral.wrap(side)
  18.                 else
  19.                         return nil
  20.                 end
  21.         else
  22.                 return wrapped
  23.         end
  24. end
  25.  
  26. local function print(str, x, y)
  27.         term.setCursorPos(x, y)
  28.         term.write(str)
  29. end
  30. -- Done helper functions
  31. -- Then initialize the monitor
  32. local monitor = peripheral.wrap("top")
  33. local monitorx, monitory = monitor.getSize()
  34. if monitorx ~= 29 or monitory ~= 12 then
  35.         error("Monitor is the wrong size! Needs to be 3x2.")
  36. end
  37.  
  38. if  monitor then
  39.         --error("No Monitor Attached")
  40.         term.clear()
  41.         term.setCursorPos(1,1)
  42.         term.write("Display redirected to Monitor")
  43.         term.redirect(monitor)
  44. end
  45.  
  46. -- Let's connect to the reactor peripheral
  47. local reactor = peripheral.wrap("BigReactors-Reactor_2")
  48. if reactor == nil then
  49.         error("Can't find reactor.")
  50. end
  51.  
  52. local xClick, yClick = 0,0
  53. local loopTime = 1
  54. local adjustamount = 5
  55. local dataLogging = false
  56. local basecontrolrodlevel = 0
  57.  
  58. --Load saved data
  59. file = fs.open("ReactorOptions", "r")
  60. if file then
  61.         basecontrolrodlevel = tonumber(file.readLine())
  62.         file.close()
  63. end
  64. if not file then
  65.         basecontrolrodlevel = 40
  66. end
  67.  
  68. --Save some stuff
  69. local function save()
  70.     file = fs.open("ReactorOptions", "w")
  71.     file.writeLine(rodpercentage)
  72.     file.close()
  73. end
  74.  
  75. reactor.setAllControlRodLevels(basecontrolrodlevel)
  76.  
  77. FC_API.clearMonitor("EZ-NUKE Control")
  78.  
  79. --Done initializing
  80.  
  81. local function displayBars()
  82.        
  83.         -- Draw some cool lines
  84.         term.setBackgroundColor(colors.black)
  85.         local width, height = term.getSize()
  86.  
  87.         for i=3, 5 do
  88.                 term.setCursorPos(22, i)
  89.                 term.write("|")
  90.         end
  91.        
  92.         for i=1, width do
  93.                 term.setCursorPos(i, 2)
  94.                 term.write("-")
  95.         end
  96.        
  97.         for i=1, width do
  98.                 term.setCursorPos(i, 6)
  99.                 term.write("-")
  100.         end
  101.        
  102.         -- Draw some text
  103.        
  104.         fuelstring = "Fuel: "
  105.         tempstring = "Temp: "
  106.         energystring = "Producing: "
  107.        
  108.         local padding = math.max(string.len(fuelstring), string.len(tempstring),string.len(energystring))
  109.        
  110.         fuelpercentage = math.ceil(reactor.getFuelAmount()/reactor.getFuelAmountMax()*100)
  111.         print(fuelstring,2,3)
  112.         print(fuelpercentage.." %",padding+2,3)
  113.        
  114.         energy = reactor.getEnergyProducedLastTick()
  115.         print(energystring,2,4)
  116.         print(math.ceil(energy).."RF/t",padding+2,4)
  117.        
  118.         reactortemp = reactor.getFuelTemperature()
  119.         print(tempstring,2,5)
  120.         print(reactortemp.." C",padding+2,5)
  121.        
  122.         -- Decrease rod button: 22X, 4Y
  123.         -- Increase rod button: 28X, 4Y
  124.        
  125.         local rodamount = reactor.getNumberOfControlRods() - 1
  126.         local rodtotal = 0
  127.         for i=0, rodamount do
  128.                 rodtotal = rodtotal + reactor.getControlRodLevel(i)
  129.         end
  130.         rodpercentage = math.ceil(rodtotal/(rodamount+1))
  131.        
  132.         print("Control",23,3)
  133.         print("<     >",23,4)
  134.         print(rodpercentage,25,4)
  135.         print("percent",23,5)
  136.        
  137.         if (xClick == 22  and yClick == 4) then
  138.                 --Decrease rod level by amount
  139.                 newrodpercentage = rodpercentage - adjustamount
  140.                 if newrodpercentage < 0 then
  141.                         newrodpercentage = 0
  142.                 end
  143.                 xClick, yClick = 0,0
  144.                 reactor.setAllControlRodLevels(newrodpercentage)
  145.         end
  146.        
  147.         if (xClick == 28  and yClick == 4) then
  148.                 --Increase rod level by amount
  149.                 newrodpercentage = rodpercentage + adjustamount
  150.                 if newrodpercentage > 100 then
  151.                         newrodpercentage = 100
  152.                 end
  153.                 xClick, yClick = 0,0
  154.                 reactor.setAllControlRodLevels(newrodpercentage)
  155.         end
  156.        
  157.         local energystorage = reactor.getEnergyStored()
  158.         storagepercent = math.floor(energystorage/10000000*100)
  159.         paintutils.drawLine(2, 8, 28, 8, colors.gray)
  160.         if storagepercent > 4 then
  161.                 paintutils.drawLine(2, 8, math.floor(26*storagepercent/100)+2, 8, colors.yellow)
  162.         elseif storagepercent > 0 then
  163.                 paintutils.drawPixel(2,8,colors.yellow)
  164.         end
  165.         term.setBackgroundColor(colors.black)
  166.         print("Energy",2,7)
  167.         print(storagepercent, width-(string.len(storagepercent)+3),7)
  168.         print("%",28,7)
  169.         term.setBackgroundColor(colors.black)
  170.        
  171. end
  172.  
  173.  
  174. function reactorStatus()
  175.         local width, height = term.getSize()
  176.         local str = ""
  177.         if reactor.getConnected() then
  178.                 if reactor.getActive() then
  179.                         str = "ONLINE"
  180.                         term.setTextColor(colors.green)
  181.                 else
  182.                         if autoStart then
  183.                                 reactor.setActive(true)
  184.                         end
  185.                         str = "OFFLINE"
  186.                         term.setTextColor(colors.red)
  187.                 end
  188.                
  189.                 if(xClick >= (width - string.len(str) - 1) and xClick <= (width-1)) then
  190.                         if yClick == 1 and not autoStart then
  191.                                 reactor.setActive(not reactor.getActive())
  192.                                 xClick, yClick = 0,0
  193.                         end
  194.                 end    
  195.                
  196.         else
  197.                 str = "DISCONNECTED"
  198.                 term.setTextColor(colors.red)
  199.         end    
  200.        
  201.         print(str, width - string.len(str) - 1, 1)
  202.         term.setTextColor(colors.white)
  203. end
  204.  
  205.  
  206. function main()
  207.         while not finished do
  208.                 FC_API.clearMonitor("EZ-NUKE control")
  209.                 reactorStatus()
  210.                 if reactor.getConnected() then
  211.                         displayBars()
  212.                         save()
  213.                         sleep(loopTime)
  214.                 end
  215.         end
  216. end
  217.  
  218. function eventHandler()
  219.         while not finished do
  220.                 event, arg1, arg2, arg3 = os.pullEvent()
  221.                
  222.                 if event == "monitor_touch" then
  223.                         xClick, yClick = math.floor(arg2), math.floor(arg3)
  224.                         -- Draw debug stuff
  225.                         --print("Monitor touch X: "..xClick.." Y: "..yClick, 1, 10)
  226.                 elseif event == "mouse_click" and not monitor then
  227.                         xClick, yClick = math.floor(arg2), math.floor(arg3)
  228.                         --print("Mouse click X: "..xClick.." Y: "..yClick, 1, 11)
  229.                 elseif event == "char" and not inManualMode then
  230.                         local ch = string.lower(arg1)
  231.                         if ch == "q" then
  232.                                 finished = true
  233.                         elseif ch == "r" then
  234.                                 finished = true
  235.                                 os.reboot()
  236.                         end
  237.                 end
  238.         end
  239. end
  240.  
  241. while not finished do
  242.         parallel.waitForAny(eventHandler, main)
  243.         sleep(loopTime)
  244. end
  245.  
  246. term.clear()
  247. term.setCursorPos(1,1)
  248. FC_API.restoreNativeTerminal()
  249. term.clear()
  250. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment