Advertisement
Plazter

Big Reactors UPDATED -Automation

Aug 24th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.85 KB | None | 0 0
  1. component = require("component")
  2. reactor = component.br_reactor
  3. event = require("event")
  4. term = require("term")
  5. gpu = component.gpu
  6. event = require("event")
  7. keyboard = require("keyboard")
  8.  
  9. ------------------
  10.  
  11. -- Color table --
  12. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  13. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  14. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  15. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  16. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  17. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  18. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  19. -------------------------
  20.  
  21. -- Settings for screen --
  22. --gpu.setBackground(colors.black)
  23. --gpu.setForeground(colors.orange)
  24. gpu.setResolution(50,20)
  25. term.clear()
  26. -------------------------
  27. --Vars --
  28. auto = false
  29. numm = 100
  30. targetP = 30 -- This is the target percentage the computer will strive for to keep in the reactor
  31. Border_bg = colors.white
  32. Default_bg = colors.gray
  33. text_col = colors.white
  34. status_col = colors.black
  35. type = nil
  36. AutoSteam = false
  37. targetSteam = 2000
  38.  
  39. ------------------------------------------------------------------------------------------------------------------
  40.                                                  --[[ FUNCTIONS ]]--
  41. ------------------------------------------------------------------------------------------------------------------
  42. DisplayGeneration = {
  43.           [3] = "Reactor type....: ",
  44.           [4] = "RF Production...: ",
  45.           [5] = "RF Stored.......: ",
  46.           [6] = "Fuel use........: "
  47.           }
  48. DisplaySteam    = {
  49.           [3] = "Reactor Type....:",
  50.           [4] = "Water Amount....:",
  51.           [5] = "Steam Amount....:",
  52.           [6] = "Steam Per Tick..:",
  53.           [7] = "Fuel use........:",
  54.           [8] = "Temperature.....:"
  55.           }
  56.  
  57. function guiBorders(x,y,len,height,str) -- BORDER FUNC FOR GUI
  58.   gpu.setBackground(Border_bg)
  59.   gpu.fill(x,y,len,height,str)
  60.   gpu.setBackground(Default_bg)
  61. end
  62.  
  63. function GUI() -- SETS THE GUI LAYOUT (GRAPHICAL USER INTERFACE)
  64.   gpu.setBackground(Default_bg)
  65.   term.clear()
  66.   w,  h = gpu.getResolution()
  67.   guiBorders(1,1,w,1," ")
  68.     for i = 1,h do
  69.       guiBorders(1,i,1,1," ")
  70.       guiBorders(w,i,1,1," ")
  71.     end
  72.   guiBorders(1,h,w,1," ")
  73.   gpu.setForeground(text_col)
  74. end
  75.  
  76. function Center(y,text) -- CENTERS TEXT  
  77.   w, h = gpu.getResolution()
  78.   term.setCursor((w-string.len(text))/2+1, y)
  79.   term.write(text)
  80. end
  81.  
  82. function getType()
  83.   if reactor.isActivelyCooled() == true then
  84.     type = true
  85.   else
  86.     type = false
  87.   end
  88. end
  89.  
  90. function info(y,title) -- Rewriting of gpu.set
  91.   gpu.set(2,y,title)
  92. end
  93.  
  94. function displayGen()
  95.   Center(2,"Reactor Info")
  96.   Center(10, "On - Off - Auto")
  97.   term.setCursor(3,2)
  98.   for k,v in pairs(DisplayGeneration) do  
  99.     info(k,v)
  100.   end
  101. end
  102.  
  103. function displaySteam()
  104.   Center(2,"Reactor Info")
  105.   Center(10, "On - Off - Auto")
  106.   term.setCursor(3,2)
  107.   for k,v in pairs(DisplaySteam) do
  108.     info(k,v)
  109.   end
  110. end
  111.  
  112. function infoUpdate(y, text) -- Text for function UPDATE
  113.   w, h = gpu.getResolution()
  114.   place = (w-string.len(text))-2
  115.   gpu.set(place, y, text)
  116. end
  117.  
  118. function UpdateGen()
  119.   RP = math.floor((reactor.getEnergyStored()/reactor.getEnergyCapacity()*100))
  120.   if type == false then
  121.     infoUpdate(3, "Passive")
  122.     infoUpdate(4, "    "..gen .." RF/T")
  123.     infoUpdate(5, "    "..stored .."/".. maxRF .."(".. RP .."%) RF")
  124.     infoUpdate(6, "    "..FuelConsumption .." mB")
  125.   else
  126.     infoUpdate(3, "Active")
  127.     infoUpdate(4, "    ".. water .." mB")
  128.     infoUpdate(5, "    ".. STEAM .." mB")
  129.     infoUpdate(6, "    ".. steamGen .." mB/t")
  130.     infoUpdate(7, "    ".. FuelConsumption .." mb")
  131.     infoUpdate(8, "    ".. math.floor(reactor.getCasingTemperature()+0.5) .." C")
  132.   end
  133. end
  134.  
  135. function autoGen()
  136.     if auto == true then
  137.         if reactor.getEnergyStored() >= (reactor.getEnergyCapacity() / 100 * 10) then
  138.             reactor.setAllControlRodLevels(100)
  139.             stat = false
  140.             numm = 100
  141.         elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 5) then
  142.             startinit()
  143.             reactor.setAllControlRodLevels(numm)
  144.             stat = true
  145.         elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 2) then
  146.             reactor.setAllControlRodLevels(0)
  147.             stat = true
  148.         end
  149.     end
  150. end
  151.  
  152. function autoSteam()
  153.     if AutoSteam == true then  
  154.         -- Adjust Rods here till it makes 2k mb/t, or target Steam.
  155.         if reactor.getHotFluidProducedLastTick() <= tonumber(targetSteam) then
  156.             startinit()
  157.             reactor.setAllControlRodLevels(numm)
  158.         end
  159.     elseif AutoSteam == false then
  160.         -- Set To manual mode.
  161.     end
  162. end
  163.  
  164. function ButtonPress()
  165.   if type == true then -- Actively Cooled Reactor button part
  166.     if x ~= nil and y ~= nil then
  167.       if x >= 17 and x <= 20 and y == 10 then
  168.             gpu.setBackground(status_col)
  169.             gpu.set(17, 10, " On ")
  170.                 reactor.setAllControlRodLevels(0)
  171.             gpu.setBackground(Default_bg)
  172.             gpu.set(21,10, "- Off - Auto ")
  173.       elseif x >= 22 and x <= 26 and y == 10 then
  174.             gpu.setBackground(status_col)
  175.             gpu.set(22, 10, " Off ")
  176.                 reactor.setAllControlRodLevels(100)
  177.                 AutoSteam = false
  178.             gpu.setBackground(Default_bg)
  179.             gpu.set(17,10, " On -")
  180.             gpu.setBackground(Default_bg)
  181.             gpu.set(27,10,"- Auto ")
  182.         elseif x >= 28 and x <= 33 and y == 10 then
  183.             gpu.setBackground(status_col)
  184.             gpu.set(28,10," Auto ")
  185.                 AutoSteam = true
  186.             gpu.setBackground(Default_bg)
  187.             gpu.set(17, 10, " On - Off -")
  188.         end
  189.     end
  190.   elseif type == false then
  191.     if x ~= nil and y ~= nil then
  192.       if x >= 17 and x <= 20 and y == 10 then
  193.             gpu.setBackground(status_col)
  194.             gpu.set(17, 10, " On ")
  195.                 reactor.setAllControlRodLevels(0)
  196.             gpu.setBackground(Default_bg)
  197.             gpu.set(21,10, "- Off - Auto ")
  198.       elseif x >= 22 and x <= 26 and y == 10 then
  199.             gpu.setBackground(status_col)
  200.             gpu.set(22, 10, " Off ")
  201.                 reactor.setAllControlRodLevels(100)
  202.                 auto = false
  203.             gpu.setBackground(Default_bg)
  204.             gpu.set(17,10, " On -")
  205.             gpu.setBackground(Default_bg)
  206.             gpu.set(27,10,"- Auto ")
  207.         elseif x >= 28 and x <= 33 and y == 10 then
  208.             gpu.setBackground(status_col)
  209.             gpu.set(28,10," Auto ")
  210.                 auto = true
  211.             gpu.setBackground(Default_bg)
  212.             gpu.set(17, 10, " On - Off -")
  213.       end
  214.     end
  215.   end
  216. end
  217.  
  218.    
  219. function check()
  220.   if type == true then
  221.     term.clear()
  222.     displaySteam()
  223.   else
  224.     term.clear()
  225.     displayGen()
  226.   end
  227. end
  228.  
  229. function startinit()
  230.     os.sleep(.3)
  231.     numm  = numm - 5
  232. end
  233. ------------------------
  234.  
  235. -- Main Loop --
  236. getType()
  237. term.clear()
  238. GUI()
  239. if type == false then
  240.   displayGen()
  241.   else
  242.   displaySteam()
  243. end
  244.  
  245. while true do
  246.   -- Updating vars --
  247.   -- Generation --
  248.   gen = string.format("%.2f", reactor.getEnergyProducedLastTick())
  249.   stored = reactor.getEnergyStored()
  250.   maxRF = reactor.getEnergyCapacity()
  251.   -----------------
  252.   -- Steam --
  253.   STEAM = string.format("%.2f", reactor.getHotFluidAmount())
  254.   steamGen = string.format("%.2f", reactor.getHotFluidProducedLastTick())
  255.   water = string.format("%.2f", reactor.getCoolantAmount())
  256.   ----------------
  257.   -- Standard info --
  258.   FuelConsumption = string.format("%.2f", reactor.getFuelConsumedLastTick())
  259.   ------------------
  260. --  check()
  261.   UpdateGen()
  262.   autoGen()
  263.   autoSteam()
  264.  
  265.  
  266.   _,_,x,y = event.pull(1, "touch")    
  267.    ButtonPress()
  268.       if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
  269.         term.clear()
  270.         w,h = gpu.maxResolution()
  271.         gpu.setResolution(w,h)
  272.         os.exit()
  273.       end
  274. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement