Advertisement
Guest User

turbine

a guest
Oct 4th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. local turbines = {peripheral.find("BigReactors-Turbine")}
  2. local reactor = peripheral.find("BigReactors-Reactor")
  3. local mon = peripheral.find("monitor")
  4. local cap = peripheral.find("tile_blockcapacitorbank_name")
  5. local capCount = 27
  6. local capMax = 25000000
  7. local turbineMax = 10000000
  8.  
  9. function clear()
  10.   mon.setBackgroundColor(colors.black)
  11.   mon.clear()
  12.   mon.setCursorPos(1,1)
  13. end
  14.  
  15. function draw_line(x, y, length, color)
  16.     mon.setBackgroundColor(color)
  17.     mon.setCursorPos(x,y)
  18.     mon.write(string.rep(" ", length))
  19. end
  20.  
  21. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  22.   draw_line(x, y, length, bg_color)
  23.   local barSize = math.floor((minVal/maxVal) * length)
  24.   draw_line(x, y, barSize, bar_color)
  25. end
  26.  
  27. function draw_text(x, y, text, text_color, bg_color)
  28.   mon.setBackgroundColor(bg_color)
  29.   mon.setTextColor(text_color)
  30.   mon.setCursorPos(x,y)
  31.   mon.write(text)
  32. end
  33.  
  34. while true do
  35.  
  36. local maxEnergy = (capCount * capMax) + (turbineMax * #turbines)
  37. local energyStored = cap.getEnergyStored() * capCount
  38. local percentage = math.ceil((energyStored / maxEnergy) * 100)
  39. local steam = reactor.getHotFluidAmount()
  40. local steamMax = reactor.getHotFluidAmountMax()
  41. local steamPercent = math.ceil(steam / steamMax) * 100
  42. local controlLevel = reactor.getControlRodLevel(1)
  43. local reactorActive = false
  44.  
  45.     if percentage < 20 then
  46.         if reactor.getActive == false then
  47.             reactor.setActive(true)
  48.         end
  49.         for k,v in ipairs(turbines) do
  50.             if v.getActive() == false then
  51.                 v.setActive(true)
  52.                 v.setVentOverflow()
  53.                 v.setFluidFlowRateMax(2000)
  54.                 v.setInductorEngaged(false)
  55.             end
  56.         end
  57.     end
  58.    
  59.     if percentage <= 90 then
  60.         if reactorActive == true then
  61.             if steamPercent < 80 then
  62.                 reactor.setAllControlRodLevels(controlLevel + 5)
  63.             end
  64.             if steamPercent == 100 then
  65.                 reactor.setAllControlRodLevels(controlLevel -1)
  66.             end
  67.             for k,v in ipairs(turbines) do
  68.                 local speed = v.getRotorSpeed()
  69.                 local flowRate = v.getFluidFlowRateMax()
  70.                 if v.getInductorEngaged == false then
  71.                     if speed >= 1500 then
  72.                         v.setInductorEngaged(true)
  73.                     end
  74.                     if speed < 1800 then
  75.                         v.setFluidFlowRateMax(flowRate+1)
  76.                     end
  77.                     if speed > 1815 then
  78.                         v.setFluidFlowRate(flowRate-1)
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.     end
  84.    
  85.     if percentage > 90 then
  86.         reactor.setActive(false)
  87.         reactor.setAllControlRodLevels(100)
  88.         for k,v in ipairs(turbines) do
  89.             v.setActive(false)
  90.             v.setVentOff(false)
  91.             v.setFluidFlowRateMax(0)
  92.         end
  93.     end
  94. --render
  95. clear()
  96. draw_line(1,1,61,colors.green)
  97. draw_line(1,2,61,colors.green)
  98. draw_text(20,2, "Reaktor-System", colors.blue, colors.green)
  99. draw_line(1,3,61,colors.green)
  100. draw_text(2,5, "Energiestatus: "..percentage.."%",colors.white, colors.black)
  101. progress_bar(2,6,59,energyStored,maxEnergy,colors.red,colors.gray)
  102. sleep(1)
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement