Advertisement
Guest User

v4

a guest
Apr 26th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.87 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. --Vars --
  44. auto = false
  45. numm = 100
  46. targetP = 30 -- This is the target percentage the computer will strive for to keep in the reactor
  47. Border_bg = colors.englishGreen
  48. Default_bg = colors.lightGray
  49. text_col = colors.black
  50. --
  51. -- Settings for screen --
  52. gpu.setResolution(60,20)
  53.  
  54. -------------------------
  55. -- Functions --
  56.  
  57. function guiBorders(x,y,len,height,str)
  58.   gpu.setBackground(Border_bg)
  59.   gpu.fill(x,y,len,height,str)
  60.   gpu.setBackground(Default_bg)
  61. end
  62.  
  63. function GUI()
  64.   gpu.setBackground(Default_bg)
  65.   w,  h = gpu.getResolution()
  66.   guiBorders(1,1,w,1," ")
  67.   for i = 1,h do
  68.     guiBorders(1,i,1,1," ")
  69.     guiBorders(w,i,1,1," ")
  70.   end
  71.   guiBorders(1,h,w,1," ")
  72. gpu.setForeground(text_col)
  73. end
  74. function Center(y,text)
  75.   w, h = gpu.getResolution()
  76.   term.setCursor((w-string.len(text))/2+1, y)
  77.   term.write(text)
  78. end
  79.  
  80.     function display()
  81.       RP = math.floor((reactor.getEnergyStored()/reactor.getEnergyCapacity()*100))
  82.       if auto == false then  
  83.         if stat == true  then
  84.             Center(4, " ON ")
  85.         else
  86.             Center(4, "OFF ")
  87.         end
  88.       elseif auto == true then
  89.           Center(4, "AUTO")
  90.       end
  91.       Center(2, "----Reactor Info---- ")
  92.       gpu.set(3,3, "Mode............: ")
  93.       --Function buttonPress
  94.       gpu.set(3,6, "RF Production...: ")
  95.       Center(7, string.format("%.2f", reactor.getEnergyProducedLastTick()).." RF/T     ")
  96.      
  97.       gpu.set(3,9, "RF Internal.....: ")
  98.       Center(10, reactor.getEnergyStored() .."/"..reactor.getEnergyCapacity().."(".. RP .."%) RF ")
  99.      
  100.       gpu.set(3,12, "Fuel use........: ")
  101.       Center(13, string.format("%.2f", reactor.getFuelConsumedLastTick()) .."mB")
  102.      
  103.       Center(16,"Mode Selection")
  104.       gpu.setBackground(colors.white)
  105.       gpu.setForeground(text_col)
  106.       gpu.set(15,17, " ON ")
  107.       gpu.set(25,17, " OFF ")
  108.       gpu.set(35,17, " Auto ")
  109.       gpu.setBackground(Default_bg)
  110.       gpu.set(17,7,"      ")
  111.       gpu.setBackground(Default_bg)
  112.       gpu.setForeground(text_col)
  113.   end
  114.  
  115. function buttonPress()
  116.     if x~=nil and y ~= nil then
  117.       if x >= 14 and x <= 17 and y == 17 then
  118.           if auto == false then
  119.             reactor.setAllControlRodLevels(0)
  120.             stat = true
  121.           end
  122.       elseif x >= 24 and x <= 30 and y == 17 then
  123.           if auto == false then
  124.             reactor.setAllControlRodLevels(100)
  125.             stat=false
  126.           end
  127.       elseif x >= 34 and x <= 36 and y == 17 then
  128.           if auto == false then
  129.               auto = true
  130.           else
  131.               auto = false
  132.           end
  133.       end
  134.     end
  135. end
  136.  
  137. function autoMode()
  138.   if auto == true then
  139.     if reactor.getEnergyStored() >= (reactor.getEnergyCapacity() / 100)*tonumber(targetP) then
  140.             reactor.setAllControlRodLevels(100)
  141.             stat = false
  142.             numm = 100
  143.         elseif reactor.getEnergyStored() <= (reactor.getEnergyCapacity() / 100)*tonumber(targetP) then
  144.             startinit()
  145.             reactor.setAllControlRodLevels(numm)
  146.             stat = true
  147.         end
  148.   end
  149. end  
  150.  
  151. function startinit()
  152.     os.sleep(.3)
  153.     numm  = numm - 5
  154. end
  155. ------------------------
  156.  
  157. -- Main Loop --
  158. gpu.setBackground(Default_bg)
  159. term.clear()
  160. while true do
  161.     GUI()
  162.     display()
  163.     autoMode()
  164.    
  165.    
  166.     _,_,x,y = event.pull(1, "touch")    
  167.       buttonPress()
  168.       if keyboard.isKeyDown(keyboard.keys.w) and keyboard.isControlDown() then
  169.           term.clear()
  170.           w,h = gpu.maxResolution()
  171.           gpu.setResolution(w,h)
  172.           os.exit()
  173.       end
  174.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement