Advertisement
The3vilM0nk3y

reactor3

Jun 29th, 2015
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.94 KB | None | 0 0
  1. local onLevel = .20
  2. local offLevel = .70
  3. local reactor = peripheral.find("BigReactors-Reactor")
  4. local m = peripheral.find("monitor")
  5. local x,y = m.getSize()
  6. local numbars = 0
  7. local p = 0
  8. local level = 0
  9. local lastLevel = 0
  10. local change = 0
  11. local numRods = reactor.getNumberOfControlRods()
  12. local controlLevel = reactor.getControlRodLevel(0)
  13. m.setTextScale(1)
  14.  
  15. function getPowerUsage()
  16.   return math.floor(reactor.getEnergyProducedLastTick() - change)
  17. end
  18. function checkValue()
  19.   if controlLevel > 100 then
  20.     controlLevel = 100
  21.   elseif controlLevel < 0 then
  22.     controlLevel = 0
  23.   end
  24. end
  25. function checkFiles()
  26.   if not fs.exists("startup") then
  27.     startFile = fs.open("startup", "w")
  28.     startFile.write("multishell.launch({}, \"reactor\")")
  29.     startFile.close()
  30.   end
  31.   if not fs.exists("update") then
  32.     shell.run("pastebin","get","Eet6QXQh","update")
  33.   end
  34. end
  35. function center(s)
  36.   cx,cy = term.getCursorPos()
  37.   term.setCursorPos((x/2) - (string.len(s)/2),cy)
  38.   print(s)
  39. end
  40. checkFiles()
  41. while true do
  42.   level = reactor.getEnergyStored()
  43.   x,y = m.getSize()
  44.   if level/10000000 < onLevel then
  45.     reactor.setActive(true)
  46.   end
  47.   if level/10000000 > offLevel then
  48.     reactor.setActive(false)
  49.   end
  50.   term.clear()
  51.   term.setCursorPos(1,1)
  52.   print("Current Level - " .. level)
  53.   print("Powered = " .. tostring(reactor.getActive()))
  54.   print("Number of Control Rods - " .. numRods)
  55.   print("\nHit Q to reboot Program.\nHit U to update.")
  56.   print("Program written by RedStoner_Pro")
  57.  
  58.   timer = os.startTimer(1)
  59.   computer = term.redirect(m)
  60.   term.clear()
  61.   term.setCursorPos(1,1)
  62.   center("Reactor Manager Monitor")
  63.   -- Power Bar
  64.   p = level/10000000
  65.   numBars = math.floor((x-4)*p)
  66.   print("Energy")
  67.   term.write(" |")
  68.   term.setBackgroundColor(colors.red)
  69.   if p > offLevel then
  70.     term.setBackgroundColor(colors.green)
  71.   elseif p > onLevel then
  72.     term.setBackgroundColor(colors.yellow)
  73.   end
  74.   for i=1,numBars do
  75.     term.write(" ")
  76.   end
  77.   term.setBackgroundColor(colors.black)
  78.   cx,cy= term.getCursorPos()
  79.   term.setCursorPos(x-1,cy)
  80.   print("|")
  81.   sLevel = level .. " / 10000000"
  82.   center(sLevel)
  83.   -- Fuel
  84.   fP = reactor.getFuelAmount()/reactor.getFuelAmountMax()
  85.   numFBars = math.floor((x-4)*fP)
  86.   print("Fuel Amount")
  87.   term.write(" |")
  88.   term.setBackgroundColor(colors.yellow)
  89.   for i=1,numFBars do
  90.     term.write(" ")
  91.   end
  92.   term.setBackgroundColor(colors.black)
  93.   cx,cy= term.getCursorPos()
  94.   term.setCursorPos(x-1,cy)
  95.   print("|")
  96.   center(math.floor(reactor.getFuelAmount()) .. "/" .. math.floor(reactor.getFuelAmountMax()) )
  97.   -- Case Temp
  98.   caseP = reactor.getCasingTemperature()/2000
  99.   numCaseBars = math.floor((x-4)*caseP)
  100.   print("Case Temperature")
  101.   term.write(" |")
  102.   if reactor.getCasingTemperature() > 980 then
  103.     term.setBackgroundColor(colors.red)
  104.   elseif reactor.getCasingTemperature() > 650 then
  105.     term.setBackgroundColor(colors.green)
  106.   else
  107.     term.setBackgroundColor(colors.blue)
  108.   end
  109.   for i=1,numCaseBars do
  110.     term.write(" ")
  111.   end
  112.   term.setBackgroundColor(colors.black)
  113.   cx,cy= term.getCursorPos()
  114.   term.setCursorPos(x-1,cy)
  115.   print("|")
  116.   center(math.floor(reactor.getCasingTemperature()) .. " Celcius")
  117.   --Fuel Temp
  118.   fuelP = reactor.getCasingTemperature()/2000
  119.   numFuelBars = math.floor((x-4)*fuelP)
  120.   print("Fuel Temperature")
  121.   term.write(" |")
  122.   if reactor.getFuelTemperature() > 980 then
  123.     term.setBackgroundColor(colors.red)
  124.   elseif reactor.getFuelTemperature() > 650 then
  125.     term.setBackgroundColor(colors.green)
  126.   else
  127.     term.setBackgroundColor(colors.blue)
  128.   end
  129.   for i=1,numFuelBars do
  130.     term.write(" ")
  131.   end
  132.   term.setBackgroundColor(colors.black)
  133.   cx,cy= term.getCursorPos()
  134.   term.setCursorPos(x-1,cy)
  135.   print("|")
  136.   center(math.floor(reactor.getFuelTemperature()) .. " Celcius")
  137.   -- Stats
  138.   change = math.floor((level - lastLevel)/20)
  139.   print("Fuel Usage = " .. reactor.getFuelConsumedLastTick() .. " mB/t")
  140.   print("RF/T Created = " .. math.floor(reactor.getEnergyProducedLastTick()))
  141.   print("RF/T Used = " .. getPowerUsage())
  142.   print("RF/T Internal Change = " .. change)
  143.   -- Control Rod Modifiers
  144.   term.setCursorPos(1,y-1)
  145.   center("Control Rod Level = " .. controlLevel)
  146.   term.setBackgroundColor(colors.red)
  147.   term.setCursorPos(2,y)
  148.   term.write(" -1 ")
  149.   term.setCursorPos(7,y)
  150.   term.write(" -10 ")
  151.   term.setCursorPos((x/2-1),y)
  152.   if reactor.getActive() then
  153.     term.setBackgroundColor(colors.green)
  154.   else
  155.     term.setBackgroundColor(colors.red)
  156.   end
  157.   term.write("POWER")
  158.   term.setBackgroundColor(colors.green)
  159.   term.setCursorPos(x-4,y)
  160.   term.write(" +1 ")
  161.   term.setCursorPos(x-10,y)
  162.   term.write(" +10 ")
  163.   term.setBackgroundColor(colors.black)
  164.   lastLevel = level
  165.   term.redirect(computer)
  166.   e = "nottimer"
  167.   while e ~= "timer" do
  168.     e,p1,p2,p3 = os.pullEvent()
  169.     if e == "timer" then
  170.       break
  171.     elseif e == "key" and p1 == 16 then
  172.       os.reboot()
  173.       break
  174.     elseif e == "key" and p1 == 22 then
  175.       shell.run("update")
  176.     elseif e == "monitor_touch" then
  177.       if p3 == y then
  178.         if p2 >= 2 and p2 <= 5 then
  179.           controlLevel = controlLevel - 1
  180.           checkValue()
  181.           reactor.setAllControlRodLevels(controlLevel)
  182.         elseif p2 >= 7 and p2 <= 11 then
  183.           controlLevel = controlLevel - 10
  184.           checkValue()
  185.           reactor.setAllControlRodLevels(controlLevel)
  186.         elseif p2 >= x-10 and p2 <= x-6 then
  187.           controlLevel = controlLevel + 10
  188.           checkValue()
  189.           reactor.setAllControlRodLevels(controlLevel)
  190.         elseif p2 >= x-4 and p2 <= x-1 then
  191.           controlLevel = controlLevel + 1
  192.           checkValue()
  193.           reactor.setAllControlRodLevels(controlLevel)
  194.         elseif p2 >= x/2-1 and p2 <= x/2+3 then
  195.           if reactor.getActive() then
  196.             reactor.setActive(false)
  197.           else
  198.             reactor.setActive(true)
  199.           end
  200.         end
  201.       end  
  202.     end
  203.   end
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement