Advertisement
Guest User

Reactor

a guest
Nov 14th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.37 KB | None | 0 0
  1. --os.loadAPI("colors")
  2.  
  3. reactor = peripheral.wrap("BigReactors-Reactor_0")
  4. mon = peripheral.wrap("monitor_0")
  5.  
  6. mon.setTextScale(2)
  7. mon.setBackgroundColor(colors.gray)
  8. mon.clear()
  9. mon.setCursorPos(1,1)
  10.  
  11. savingToFile = false
  12.  
  13. controlRodLevel = 0
  14. energyProducedLastTick = 0
  15. energyStored = 0
  16. cycles = 0
  17. varCount = 3
  18. reactorMultiplayer = 100
  19.  
  20. function setup()
  21.     term.clear()
  22.     term.setCursorPos(1,1)
  23.     term.write("Do you want to save to file? 1 - yes, 2 - no")
  24.     term.setCursorPos(1,2)
  25.     savingToFile = read()
  26.     term.clear()
  27.     term.setCursorPos(1,1)
  28.     term.write("What is youre multiplayer? 96 for 17kRF/t")
  29.     term.setCursorPos(1,2)
  30.     reactorMultiplayer = read()
  31.  
  32.     if (savingToFile ~= "1") then
  33.    
  34.         if (savingToFile ~= "2") then
  35.        
  36.             term.clear()
  37.             term.setCursorPos(1,2)
  38.             term.setTextColor(colors.red)
  39.             term.write("Oops, a typo, please try again")
  40.             term.setTextColor(colors.white)
  41.             sleep(2)
  42.             setup()
  43.            
  44.         end
  45.     end
  46. end
  47.  
  48. function round(num, numDecimalPlaces)
  49.   local mult = 10^(numDecimalPlaces or 0)
  50.   return math.floor(num * mult + 0.5) / mult
  51. end
  52.  
  53. function toint(n)
  54.     local s = tostring(n)
  55.     local i, j = s:find('%.')
  56.     if i then
  57.         return tonumber(s:sub(1, i-1))
  58.     else
  59.         return n
  60.     end
  61. end
  62.  
  63. setup()
  64.  
  65. while true do
  66.  
  67.     controlRodLevel = reactor.getControlRodLevel(1)
  68.     energyProducedLastTick = reactor.getEnergyProducedLastTick()
  69.     energyStored = reactor.getEnergyStored()
  70.  
  71.     varTable = {energyStored, round(energyProducedLastTick, 2), controlRodLevel}
  72.    
  73.     if(cycles == 5 and savingToFile == "1") then
  74.    
  75.         local file = fs.open("VarCC", "w")
  76.        
  77.         for i=1, varCount do
  78.    
  79.             file.writeLine(varTable[i])
  80.    
  81.         end
  82.        
  83.         file.close()
  84.        
  85.         cycles = 0
  86.     end
  87.    
  88.     if(savingToFile == "1") then
  89.    
  90.         cycles = cycles + 1
  91.        
  92.     end
  93.  
  94.     if(energyStored >= 9990000) then
  95.  
  96.         reactor.setActive(false)
  97.    
  98.     end
  99.  
  100.     if(energyStored == 0) then
  101.  
  102.         reactor.setActive(true)
  103.    
  104.     end
  105.    
  106.     if(reactorMultiplayer*energyStored*energyStored/25000000000000 >= 100) then
  107.        
  108.         reactor.setAllControlRodLevels(100)
  109.        
  110.     elseif(energyStored < 4000000) then
  111.    
  112.         reactor.setAllControlRodLevels(0)
  113.  
  114.     else
  115.  
  116.         reactor.setAllControlRodLevels(reactorMultiplayer*energyStored*energyStored/25000000000000)
  117.  
  118.     end
  119.    
  120. -------------------------------------------------------------------------  
  121.    
  122.     mon.clear()
  123.     mon.setCursorPos(1,1)
  124.    
  125.     if(true == true) then
  126.    
  127.         mon.setTextColor(colors.green)
  128.         mon.write("Reactor Active")
  129.    
  130.     else
  131.  
  132.         mon.setTextColor(colors.red)
  133.         mon.write("Reactor Inactive")
  134.    
  135.     end
  136.  
  137.     mon.setTextColor(colors.white)
  138.    
  139. -------------------------------------------------------------------------  
  140.  
  141.     if(energyStored >= 3000000) then
  142.    
  143.         mon.setTextColor(colors.green)
  144.    
  145.     else
  146.  
  147.         mon.setTextColor(colors.red)
  148.    
  149.     end
  150.  
  151.     mon.setCursorPos(1,2)
  152.     mon.write("Reactor Storage")
  153.     mon.setTextColor(colors.white)
  154.     mon.write(": ".. tostring(round(energyStored / 10000000 * 100),0) .."%")
  155.    
  156. -------------------------------------------------------------------------  
  157.    
  158.     mon.setCursorPos(1,3)
  159.    
  160.     if(energyStored <= 3000000) then
  161.    
  162.         mon.setTextColor(colors.red)
  163.    
  164.     else
  165.  
  166.         mon.setTextColor(colors.green)
  167.    
  168.     end
  169.    
  170.     mon.write("Buffer:")
  171.     mon.setTextColor(colors.white)
  172.     mon.write(energyStored.. "RF")
  173.    
  174. -------------------------------------------------------------------------
  175.  
  176.     mon.setCursorPos(1,4)
  177.    
  178.     if(energyProducedLastTick >= 10000) then
  179.    
  180.         mon.setTextColor(colors.red)
  181.    
  182.     else
  183.  
  184.         mon.setTextColor(colors.green)
  185.    
  186.     end
  187.    
  188.     mon.write("Usage:")
  189.     mon.setTextColor(colors.white)
  190.     mon.write(round(energyProducedLastTick)/1000 .."kRF/t")
  191.    
  192. -------------------------------------------------------------------------
  193.  
  194.     if(reactor.getControlRodLevel(1) >= 50) then
  195.    
  196.         mon.setTextColor(colors.green)
  197.    
  198.     else
  199.  
  200.         mon.setTextColor(colors.red)
  201.    
  202.     end
  203.  
  204.     mon.setCursorPos(1,5)
  205.     mon.write("Control Rods")
  206.     mon.setTextColor(colors.white)
  207.     mon.write(":".. controlRodLevel.. "%")
  208.    
  209. -------------------------------------------------------------------------
  210.  
  211.     term.clear()
  212.     term.setCursorPos(1,1)
  213.     term.write("energy in buffer: " ..energyStored)
  214.     term.setCursorPos(1,2)
  215.     term.write("cycle number: " ..cycles)
  216.     term.setCursorPos(1,3)
  217.     term.write("control Rods: ".. 96*energyStored*energyStored/25000000000000)
  218.     term.setCursorPos(1,4)
  219.     term.write("ReactorMultiplayer: ".. reactorMultiplayer)
  220.     sleep(1)
  221. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement