Advertisement
Plazter

BigReactor Ongoing

Apr 25th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.83 KB | None | 0 0
  1. --[[ Some usefull commands
  2. getFuelAmount
  3. getFuelAmountMax
  4. getFuelConsumedLastTick
  5. getActive
  6. getCaseingTemperature
  7. getControlRodLevel
  8. getEnergyCapacity
  9. getEnergyProducedLastTick
  10. GetEnergyStored
  11. setAllControlRodLevels
  12. --]]
  13.  
  14. --[[ NOTE
  15. // With automode on the code will try to keep
  16. // around 10% RF in its internal storage, it does this by regulating the control rod
  17. // after the demand OF rf, moving up slowly. due note that the 10% is changeable in the var
  18. // "targetP"
  19. --]]
  20.  
  21.  
  22. -- Wrapping and requireing essentials API's and components --
  23. component = require("component")
  24. reactor = component.br_reactor
  25. event = require("event")
  26. term = require("term")
  27. gpu = component.gpu
  28. event = require("event")
  29. keyboard = require("keyboard")
  30.  
  31. ------------------
  32.  
  33. -- Color table --
  34. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  35. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  36. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  37. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  38. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  39. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  40. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  41. -------------------------
  42.  
  43. -- Settings for screen --
  44. gpu.setBackground(colors.black)
  45. gpu.setForeground(colors.orange)
  46. gpu.setResolution(50,10)
  47. term.clear()
  48. -------------------------
  49. --Vars --
  50. auto = false
  51. numm = 100
  52. targetP = 30 -- This is the target percentage the computer will strive for to keep in the reactor
  53. --
  54. -- Functions --
  55. Border_bg = colors.white
  56. Default_bg = colors.gray
  57. text_col = colors.white
  58. status_col = colors.black
  59. failsafe = true
  60. failSafeTemp = 6400
  61. auto = failSafeTemp
  62. startt = nil
  63. ------------------------------------------------------------------------------------------------------------------
  64.                                                  --[[ FUNCTIONS ]]--
  65. ------------------------------------------------------------------------------------------------------------------
  66. function guiBorders(x,y,len,height,str) -- BORDER FUNC FOR GUI
  67.   gpu.setBackground(Border_bg)
  68.   gpu.fill(x,y,len,height,str)
  69.   gpu.setBackground(Default_bg)
  70. end
  71.  
  72. function GUI() -- SETS THE GUI LAYOUT (GRAPHICAL USER INTERFACE)
  73.   gpu.setBackground(Default_bg)
  74.   term.clear()
  75.   w,  h = gpu.getResolution()
  76.   guiBorders(1,1,w,1," ")
  77.     for i = 1,h do
  78.       --guiBorders(1,i,1,1," ")
  79.       --guiBorders(w,i,1,1," ")
  80.     end
  81.   guiBorders(1,h,w,1," ")
  82.   gpu.setForeground(text_col)
  83. end
  84.  
  85. function Center(y,text) -- CENTERS TEXT  
  86.   w, h = gpu.getResolution()
  87.   term.setCursor((w-string.len(text))/2+1, y)
  88.   term.write(text)
  89. end
  90.  
  91. function info(y,title) -- Rewriting of gpu.set
  92.   gpu.set(2,y,title)
  93. end
  94.  
  95.     function display()
  96.         RP = math.floor((reactor.getEnergyStored()/reactor.getEnergyCapacity()*100))
  97.         if auto == false then  
  98.             if stat == true  then
  99.                 gpu.set(19,2, "ON             ")
  100.             else
  101.                 gpu.set(19,2, "OFF            ")
  102.             end
  103.         elseif auto == true then
  104.             gpu.set(19,2, "----         ")
  105.         end
  106.         Center(2,"Reactor Info")
  107.         info(3,"Reactor status..: ")
  108.         info(4, "RF Production...: ".. string.format("%.2f", reactor.getEnergyProducedLastTick()).." RF/T          ")
  109.         info(5, "RF Internal.....: ".. reactor.getEnergyStored() .."/"..reactor.getEnergyCapacity().."(".. RP .."%) RF          ")
  110.         info(6, "Fuel use........: ".. string.format("%.2f", reactor.getFuelConsumedLastTick()) .."mB")
  111.         --[[gpu.setBackground(colors.white)
  112.         gpu.setForeground(colors.black)
  113.         gpu.set(2,6, " ON ")
  114.         gpu.set(6,6, " OFF ")
  115.         gpu.set(11,6, " Auto ")
  116.         gpu.setBackground(colors.black)
  117.         gpu.set(17,6,"      ")
  118.         gpu.setBackground(colors.black)
  119.         gpu.setForeground(colors.orange)--]]
  120.   end
  121.  
  122. function buttonPress()
  123.     if x~=nil and y ~= nil then
  124.         if x >= 1 and x <= 4 and y == 6 then
  125.             if auto == false then
  126.                 gpu.setBackground(colors.black)
  127.                 gpu.set(2,6," ON ")
  128.                 reactor.setAllControlRodLevels(0)
  129.                 stat = true
  130.             end
  131.         elseif x >= 5 and x <= 9 and y == 6 then
  132.             if auto == false then
  133.                 gpu.setBackground(colors.black)
  134.                 gpu.set(5,6,"  OFF ")
  135.                 reactor.setAllControlRodLevels(100)
  136.                 stat=false
  137.             end
  138.         elseif x >= 11 and x <= 17 and y == 6 then
  139.             if auto == false then
  140.                 auto = true
  141.             else
  142.                 auto = false
  143.             end
  144.         end
  145.     end
  146. end
  147.  
  148. function autoMode()
  149.     if auto == true then
  150.         gpu.set(1,6, "         ")
  151.         gpu.set(9,6, "AUTO MODE ON")
  152.             if reactor.getEnergyStored() >= (reactor.getEnergyCapacity() / 100 * 10) then
  153.                 reactor.setAllControlRodLevels(100)
  154.                 stat = false
  155.                 numm = 100
  156.             elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 10) then
  157.                 startinit()
  158.                 reactor.setAllControlRodLevels(numm)
  159.                 stat = true
  160.             elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity()/100 * 2) then
  161.                 reactor.setAllControlRodLevels(0)
  162.                 stat = true
  163.              end
  164.     end
  165. end  
  166.  
  167. function startinit()
  168.     os.sleep(.3)
  169.     numm  = numm - 5
  170. end
  171. ------------------------
  172.  
  173. -- Main Loop --
  174. term.clear()
  175. GUI()
  176. while true do
  177.     display()
  178.     autoMode()
  179.     gpu.set(1,15, tostring(auto))
  180.    
  181.     _,_,x,y = event.pull(1, "touch")    
  182.         buttonPress()
  183.         if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
  184.             term.clear()
  185.             w,h = gpu.maxResolution()
  186.             gpu.setResolution(w,h)
  187.             os.exit()
  188.         end
  189.   os.sleep(0.5)
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement