Advertisement
Guest User

reactor.lua

a guest
Jun 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. monitors = {peripheral.find("monitor")}
  2. mon = monitors[1]
  3. monT = monitors[2]
  4. monR = monitors[3]
  5.  
  6. monX, monY = mon.getSize()
  7. monTX, monTY = monT.getSize()
  8.  
  9. reactors = {peripheral.find("BigReactors-Reactor")}
  10.  
  11. if reactors == nil then
  12.     error("Kein Reaktor gefunden!")
  13. end
  14.  
  15. reactor = reactors[1]
  16. eReactor = reactors[2]
  17.  
  18. if reactor.isActivelyCooled() == false then
  19.     reactor = reactors[2]
  20.     eReactors = reactors[1]    
  21. end
  22.  
  23. turbines = {peripheral.find("BigReactors-Turbine")}
  24. if turbines == nil then
  25.     error("Keine Turbine gefunden!")
  26. end
  27.  
  28. function clear()
  29.     for counter = 1, #monitors do
  30.         monitor = monitors[counter]
  31.         monitor.setBackgroundColor(colors.black)
  32.         monitor.clear()
  33.         monitor.setCursorPos(1,1)
  34.     end
  35. end
  36.  
  37. function drawText(monitor,x , y, text, color_txt, color_bg)
  38.     monitor.setBackgroundColor(color_bg)
  39.     monitor.setTextColor(color_txt)
  40.     monitor.setCursorPos(x,y)
  41.     monitor.write(text)
  42. end
  43.  
  44. function drawLine(monitor, x, y, length, size, color_bar)
  45.     for yPos = y, y+size-1 do
  46.         monitor.setBackgroundColor(color_bar)
  47.         monitor.setCursorPos(x,yPos)
  48.         monitor.write(string.rep(" ",length))
  49.     end
  50. end
  51.  
  52. function getRodPro()
  53.     rodPro = 0
  54.    
  55.     for rodIndex = 0,reactor.getNumberOfControlRods()-1 do
  56.         rodPro = rodPro + reactor.getControlRodLevel(rodIndex)
  57.     end
  58.  
  59.     return 1-((rodPro / reactor.getNumberOfControlRods())/100.0)
  60. end
  61.  
  62. function getTurbineSpeedPro(turbine)
  63.     speed = turbine.getRotorSpeed()
  64.     if speed > 3500 then
  65.         speed = 3500
  66.     end
  67.     return speed/3500.0
  68. end
  69.  
  70. function adjustReactor()
  71.     if reactor.getCasingTemperature() > 2000 then
  72.         reducedRod()
  73.     end
  74.    
  75.     if reactor.getCasingTemperature() < 1000 then
  76.         higherRod()
  77.     end
  78. end
  79.  
  80. function reducedRod()
  81.     for rodIndex = 0, reactor.getNumberOfControlRods()-1 do
  82.        
  83.         if reactor.getControlRodLevel(rodIndex) < 100 then
  84.             reactor.setControlRodLevel(rodIndex, reactor.getControlRodLevel(rodIndex)+10)
  85.             break
  86.         end
  87.    
  88.     end    
  89. end
  90.  
  91. function higherRod()
  92.     for rodIndex = 0, reactor.getNumberOfControlRods()-1 do
  93.    
  94.         if reactor.getControlRodLevel(rodIndex) > 0 then
  95.             reactor.setControlRodLevel(rodIndex, reactor.getControlRodLevel(rodIndex)-10)
  96.             break
  97.         end
  98.     end
  99. end
  100.  
  101. function adjustTurbine(turbine)
  102.     rate = turbine.getFluidFlowRateMax()
  103.     if turbine.getEnergyStored() > 900000 then
  104.         if rate > 0 then
  105.             rate = rate - 100
  106.         end
  107.         turbine.setFluidFlowRateMax(rate)
  108.     end
  109.    
  110.     if turbine.getEnergyStored() < 400000 then
  111.         if rate < 2000 then
  112.             rate = rate + 100
  113.         end
  114.         turbine.setFluidFlowRateMax(rate)
  115.     end
  116. end
  117.  
  118. function getEnergie()
  119.     energie = 0
  120.     for counter = 1, #turbines do
  121.         turbine = turbines[counter]
  122.         energie = energie + turbine.getEnergyStored()
  123.     end
  124.     return energie
  125. end
  126.  
  127. function manageEReactor()
  128.     if getEnergie() == 0 then
  129.         higherEReactor()
  130.     else
  131.         lowerEReactor()
  132.     end
  133. end
  134.  
  135. function higherEReactor()
  136.    
  137. end
  138.  
  139. while true do
  140.     clear()
  141.     drawText(mon,monX/2,1,"Reactor", colors.green, colors.black)
  142.    
  143.     length = monX-2
  144.     drawLine(mon,2,2,length,2,colors.gray)
  145.     drawLine(mon,2,2,length*getRodPro(),2,colors.green)
  146.    
  147.     adjustReactor()
  148.    
  149.     for turbineCounter = 1, #turbines do
  150.    
  151.         turbine = turbines[turbineCounter]
  152.         startPos = (turbineCounter-1)*4
  153.        
  154.         drawText(monT, monX/2,startPos+1,"Turbine", colors.green,colors.black)
  155.         drawLine(monT, 2,startPos+2,length,2,colors.gray)
  156.         drawLine(monT, 2,startPos+2,length*getTurbineSpeedPro(turbine),2,colors.blue)
  157.        
  158.         adjustTurbine(turbine)
  159.     end
  160.    
  161.     drawText(mon, monX/2, 5, "Heat", colors.orange, colors.black)
  162.     drawLine(mon, 2, 6, length, 2, colors.gray)
  163.     if reactor.getCasingTemperature() <= 2000 then
  164.         drawLine(mon, 2, 6, length*(reactor.getCasingTemperature()/2000), 2, colors.orange)
  165.     else
  166.         drawLine(mon, 2, 6, length, 2, colors.red)
  167.     end
  168.    
  169.    
  170.     drawText(mon, monX/2,monY-3,"Energie", colors.red, colors.black)
  171.     drawLine(mon, 2,monY-2,length,2,colors.gray)
  172.     drawLine(mon, 2,monY-2,length*(getEnergie()/(#turbines*1000000)), 2, colors.red)
  173.        
  174.     manageEReactor()
  175.                                                                                                  
  176.     os.sleep(1)
  177. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement