Advertisement
Notsoup

EBRM

Apr 1st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. --[[ "EBRM" stands for Efficiency Based Reactor Monitor, and it works
  2. only with Big Reactors reactors. It displays power levels, allows for
  3. easy on and off functionality, and the ability to change control rod
  4. levels with the click of a button.
  5. ]]--
  6.  
  7. local component = require("component")
  8. local event = require("event")
  9. local reactor = component.br_reactor
  10. local gpu = component.gpu
  11. local screen = component.screen
  12. local term = require("term")
  13.  
  14. --Display
  15.  
  16. local oldBG = 0x000000
  17. local oldFG = 0xFFFFFF
  18.  
  19. function gpuOldColors()
  20. gpu.setBackground(oldBG, false)
  21. gpu.setForeground(oldFG, false)
  22. end
  23.  
  24. function clearScreen()
  25. local oldColor = gpu.getBackground(false)
  26. local w, h = gpu.getResolution()
  27. gpu.setBackground(0x000000, false)
  28. gpu.fill(1, 1, w, h, " ")
  29. gpu.setBackground( oldColor, false)
  30. term.setCursor(1, 1)
  31. end
  32.  
  33. function checkAspectRatio()
  34. local w, h = screen.getAspectRatio()
  35. local neededWidth = 3
  36. local neededHeight = 3
  37. if (w == neededWidth and h == neededHeight) then
  38. return true
  39. else
  40. return false
  41. end
  42. end
  43.  
  44. function checkComponents()
  45. if (component.isAvailable("br_reactor") == true and component.isAvailable("screen") == true) then
  46. return true
  47. else
  48. return false
  49. end
  50. end
  51.  
  52. function generateDividers()
  53. gpu.setBackground(oldBG, false)
  54. gpu.setForeground(0x3a3a3a, false)
  55. gpu.fill(1, 1, 1, 25, "|")
  56. gpu.fill(50, 1, 1, 25, "|")
  57. gpu.fill(25, 1, 1, 25, "|")
  58. gpu.fill(26, 1, 1, 25, "|")
  59. gpu.fill(1, 1, 50, 1, "=")
  60. gpu.fill(1, 25, 50, 1, "=")
  61. gpu.fill(26, 4, 25, 1, "=")
  62. end
  63.  
  64. function generateTitles()
  65. gpuOldColors()
  66. term.setCursor(27, 2)
  67. print(" EFFICIENCY BASED")
  68. term.setCursor(27, 3)
  69. print(" REACTOR MONITOR")
  70. term.setCursor(28, 6)
  71. print("Energy Stored:")
  72. term.setCursor(28, 8)
  73. print("RF/t:")
  74. term.setCursor(28, 10)
  75. print("Fuel Level:")
  76. term.setCursor(28, 12)
  77. print("Fuel MAX:")
  78. term.setCursor(28, 14)
  79. print("Control Rods:")
  80. term.setCursor(28, 16)
  81. print("Temperature:")
  82. end
  83.  
  84. local grey = 0x3a3a3a
  85. local darkred = 0x660800
  86. local darkyellow = 0x66611f
  87.  
  88. function generateBars()
  89. gpu.setBackground(grey, false)
  90. gpu.setForeground(oldFG, false)
  91. gpu.fill(3, 2, 5, 23, " ")
  92. gpu.setBackground(darkred, false)
  93. gpu.fill(4, 3, 3, 21, " ")
  94. gpu.setBackground(grey, false)
  95. gpu.fill(9, 2, 5, 23, " ")
  96. gpu.setBackground(darkyellow, false)
  97. gpu.fill(10, 3, 3, 21, " ")
  98. gpu.setBackground(grey, false)
  99. gpu.fill(15, 2, 5, 23, " ")
  100. gpu.setBackground(0x5e4a58, false)
  101. gpu.fill(16, 3, 3, 21, " ")
  102. gpu.setBackground(grey, false)
  103. gpu.fill(21, 21, 3, 3, " ")
  104. gpu.fill(21, 17, 3, 3, " ")
  105. term.setCursor(22, 18)
  106. print("+")
  107. term.setCursor(22, 22)
  108. print("-")
  109. gpuOldColors()
  110. end
  111.  
  112. local green = 0x06e015
  113. local red = 0xd10300
  114.  
  115. function buttonOnOff()
  116. if (reactor.getActive() == true) then
  117. gpu.setBackground(green, false)
  118. gpu.setForeground(0xFFFFFF, false)
  119. term.setCursor(41, 24)
  120. print(" DISABLE ")
  121. else
  122. gpu.setBackground(red, false)
  123. gpu.setForeground(0xFFFFFF, false)
  124. term.setCursor(41, 24)
  125. print(" ENABLE ")
  126. end
  127. gpu.setBackground(0x000000, false)
  128. end
  129.  
  130. --Initialization
  131.  
  132. clearScreen()
  133. checkComponents()
  134. if (checkComponents() == false) then
  135. print("You do not have all the required components for this program. Please restart your computer.")
  136. end
  137. checkAspectRatio()
  138. if (checkAspectRatio() == true) then
  139. gpu.setResolution(50, 25)
  140. clearScreen()
  141. print("Screen Resolution set to 50, 25.")
  142. os.sleep(1)
  143. clearScreen()
  144. else
  145. clearScreen()
  146. print("You must have a 3x3 screen to use EBRM! Please restart your computer.")
  147. end
  148. generateDividers()
  149. generateTitles()
  150. generateBars()
  151. buttonOnOff()
  152.  
  153. --Reactor Stats and Functions
  154. local RF = math.floor(reactor.getEnergyProducedLastTick())
  155.  
  156. ReactorStats = {}
  157.  
  158. function reactorCheckStats()
  159. ReactorStats["EnergyAmt"] = reactor.getEnergyStored()
  160. ReactorStats["FuelAmt"] = reactor.getFuelAmount()
  161. ReactorStats["FuelMax"] = reactor.getFuelAmountMax()
  162. ReactorStats["FuelPercent"] = math.floor((ReactorStats["FuelMax"] / ReactorStats["FuelAmt"]) * 100)
  163. ReactorStats["ControlRodLvl"] = reactor.getControlRodLevel(1)
  164. ReactorStats["RF"] = math.floor(reactor.getEnergyProducedLastTick())
  165. ReactorStats["FuelTemp"] = reactor.getFuelTemperature()
  166. end
  167.  
  168. local percentFuelLevel = math.floor((reactor.getFuelAmountMax() / reactor.getFuelAmount()) * 10)
  169.  
  170. function reactorPrintStats()
  171. gpu.setBackground(oldBG, false)
  172. gpu.setForeground(green, false)
  173. term.setCursor(42, 6)
  174. print(" ")
  175. term.setCursor(42, 6)
  176. print(ReactorStats["EnergyAmt"])
  177. term.setCursor(42, 8)
  178. print(" ")
  179. term.setCursor(42, 8)
  180. print(ReactorStats["RF"])
  181. term.setCursor(42, 10)
  182. print(" ")
  183. term.setCursor(42, 10)
  184. print(ReactorStats["FuelPercent"] .. "%")
  185. term.setCursor(42, 12)
  186. print(ReactorStats["FuelMax"])
  187. term.setCursor(42, 14)
  188. print(" ")
  189. term.setCursor(42, 14)
  190. print(ReactorStats["ControlRodLvl"] .. "%")
  191. term.setCursor(42, 16)
  192. print(math.ceil(ReactorStats["FuelTemp"]) .. "C")
  193. gpuOldColors()
  194. end
  195.  
  196. function reactorSetControlRodLvl(ControlButton)
  197. if ControlButton == 1 then
  198. if ReactorStats["ControlRodLvl"] <= 90 then
  199. reactor.setAllControlRodLevels(ReactorStats["ControlRodLvl"] + 10)
  200. end
  201. end
  202. if ControlButton == 2 then
  203. if ReactorStats["ControlRodLvl"] >= 10 then
  204. reactor.setAllControlRodLevels(ReactorStats["ControlRodLvl"] - 10)
  205. end
  206. end
  207. end
  208.  
  209. --Bars
  210.  
  211. local barHeightMax = 21
  212. local barY1 = 3
  213. local barY2 = 23
  214.  
  215. function barsFuel(fuelCurrent)
  216.  
  217. end
  218.  
  219. function bars(val1, valMax, barX, color)
  220. gpu.setBackground(color, false)
  221. local barPercent = math.ceil((val1 / valMax) * 100)
  222. local barHeight = math.ceil(barHeightMax * (barPercent / 100))
  223. local barSub = barY2 - (barHeight - 1)
  224. for barY = 23, barSub, -1 do
  225. gpu.set(barX, barY, " ")
  226. end
  227. gpuOldColors()
  228. end
  229.  
  230. function barsControl(controlrodsCurrent)
  231.  
  232. end
  233.  
  234. --Main Loop
  235.  
  236. local ebrmStatus = true
  237.  
  238. function buttonPress()
  239. if (reactor.getActive() == true) then
  240. reactor.setActive(false)
  241. buttonOnOff()
  242. else
  243. reactor.setActive(true)
  244. buttonOnOff()
  245. end
  246. end
  247.  
  248. while ebrmStatus == true do
  249. local event, address, arg1, arg2, arg3 = event.pull(0.02)
  250. if (event == nil) then
  251. reactorCheckStats()
  252. reactorPrintStats()
  253. generateBars()
  254. bars(ReactorStats["EnergyAmt"], 10000000, 4, red)
  255. bars(ReactorStats["FuelAmt"], ReactorStats["FuelMax"], 10, 0xe4f248)
  256. bars(ReactorStats["FuelTemp"], 2000, 16, 0xd66e13)
  257. elseif event == "touch" and arg1 >= 41 and arg1 <= 49 and arg2 == 24 then
  258. buttonPress()
  259. elseif event == "touch" and arg1 >= 21 and arg1 <= 23 and arg2 >= 17 and arg2 <= 19 then
  260. reactorSetControlRodLvl(1)
  261. elseif event == "touch" and arg1 >= 21 and arg1 <= 23 and arg2 >= 21 and arg2 <= 23 then
  262. reactorSetControlRodLvl(2)
  263. end
  264. end
  265.  
  266. --[[ TODO:
  267. -Spacers / dividers
  268. -energy level
  269. -fuel level
  270. -fuel rod percent level
  271. -reactor status
  272. -reactor on/off control
  273. -RF/t
  274. -Bar Graph
  275. -Control Rod Control
  276. Automatic Control Mode
  277. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement