Advertisement
chardog

Reactor v2.2.2

Dec 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.83 KB | None | 0 0
  1. reactors = {peripheral.find("BigReactors-Reactor")}
  2. reactor = reactors[1]
  3. reactors = nil
  4. --reactor.setActive(false)
  5. minBuffer = 1000000
  6. --maxBuffer = 9000000
  7. reactorActive = reactor.getActive()
  8. monitor1 = peripheral.wrap("top")
  9. line = 1
  10. w,h = monitor1.getSize()
  11. bufferFullness = 0
  12.  
  13. numberOfCells = 0
  14. energyCells = {peripheral.find("tile_thermalexpansion_cell_resonant_name")}
  15. for _ in pairs(energyCells) do numberOfCells = numberOfCells + 1 end
  16. maxEnergy = 10000000 + numberOfCells * 80000000 --80m per cell and 10m for the reactor
  17.  
  18. maxBuffer = maxEnergy - 1000000
  19.  
  20. --run this each loop before getBackground
  21. function getTotalEnergy()
  22.     local en = 0
  23.     en = en + reactor.getEnergyStored()
  24.     for i = 1, numberOfCells, 1 do
  25.         en = en + energyCells[i].getEnergyStored()
  26.     end
  27.     return en
  28. end
  29.  
  30. totalEnergy = getTotalEnergy()
  31.  
  32. --returns background when given x position
  33. function getCharacterBackground(pos)
  34.     if pos > w * totalEnergy / maxEnergy then
  35.         return "4"
  36.     else
  37.         return "5"
  38.     end
  39. end
  40.  
  41. --calculates the background for word at a specific position, returns a string
  42. function getBackground(first, last)
  43.     local bg = ""
  44.     local i = first
  45.     repeat
  46.         bg = bg .. getCharacterBackground(i)
  47.         i = i + 1
  48.     until i > last
  49.     return bg
  50. end
  51.  
  52. function fillSpace(first, last)
  53.     local spaces = ""
  54.     local charClr = ""
  55.     local i = first
  56.     repeat
  57.         spaces = spaces .. " "
  58.         charClr = charClr .. "0"
  59.         i = i + 1
  60.     until i > last
  61.     monitor1.blit(spaces, charClr, getBackground(first, last))
  62. end
  63.  
  64. function finishLine()
  65.     local x,y = monitor1.getCursorPos()
  66.     fillSpace(x, w)
  67. end
  68.  
  69. function textWithBackground(lnStr)
  70.     local x,y = monitor1.getCursorPos()
  71.     local charClr = ""
  72.     for i = 1, string.len(lnStr), 1 do
  73.         charClr = charClr .. "f"
  74.     end
  75.     bg = getBackground(x, x + string.len(lnStr) - 1)
  76.     monitor1.blit(lnStr, charClr, bg)
  77. end
  78.  
  79. function fullLine(lnStr)
  80.     textWithBackground(lnStr)
  81.     finishLine()
  82. end
  83.  
  84. lineStr = ""
  85.  
  86. print("Starting up...")
  87.  
  88. while true do
  89.     line = 0
  90.     monitor1.clear()
  91.    
  92.     totalEnergy = getTotalEnergy()
  93.     print(totalEnergy)
  94.  
  95.     monitor1.setCursorPos(1, 1 + line)
  96.     monitor1.write("Reactor Status: ")
  97.     if (reactorActive) then
  98.         monitor1.blit("ACTIVE", "dddddd", "ffffff")
  99.     else
  100.         monitor1.blit("INACTIVE", "eeeeeeee", "ffffffff")
  101.     end
  102.     line = line + 1
  103.  
  104.     monitor1.setCursorPos(1, 1 + line)
  105.     monitor1.write("Energy: " .. totalEnergy .. "/" .. maxEnergy .. " RF")
  106.     line = line + 1
  107.    
  108.     monitor1.setCursorPos(1, 1 + line)
  109.     textWithBackground("Test!")
  110.     finishLine()
  111.     line = line + 1
  112.    
  113.     monitor1.setCursorPos(1, 1 + line)
  114.     fullLine("IT IS ALIVE!")
  115.    
  116.    
  117.     --monitor1.setCursorPos(1, 1 + line)
  118.     --bufferFullness = 10 * totalEnergy / maxEnergy
  119.     --for i = 1, bufferFullness, 1 do
  120.     --    monitor1.blit(" ","5","5")
  121.     --end
  122.     --for i = 1, 10 - bufferFullness, 1 do
  123.     --    monitor1.blit(" ","4","4")
  124.     --end
  125.     --line = line + 1
  126.  
  127.     if (reactorActive) then
  128.         if (totalEnergy > maxBuffer) then
  129.             reactor.setActive(false)
  130.             reactorActive = false
  131.             print("Buffer full, shutting down")
  132.             monitor1.setCursorPos(w / 2 - 6, h / 2)
  133.             monitor1.blit("Shutting Down...", "dddddddddddddddd", "0000000000000000")
  134.             os.sleep(10)
  135.         end
  136.     else
  137.         if (totalEnergy < minBuffer) then
  138.             reactor.setActive(true)
  139.             reactorActive = true
  140.             print("Buffer empty, restarting reactor")
  141.             monitor1.setCursorPos(w / 2 - 6, h / 2)
  142.             monitor1.blit("Starting Up...", "dddddddddddddd", "00000000000000")
  143.             os.sleep(10)
  144.         end
  145.     end
  146.    
  147.     os.sleep(5)
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement