Advertisement
davedumas0

Untitled

May 28th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.06 KB | None | 0 0
  1. --================
  2. -- PART 1 START
  3. --================
  4.  
  5. -- Load the components
  6. local component = require("component")
  7. local gpu = component.gpu
  8. local sides = require("sides")
  9. local computer = require("computer")
  10. local term = require("term")
  11. -- Load the energy cube
  12. local energyCube = component.elite_energy_cube
  13. local engine_4_bank_2 = "14470fcc-cb6d-4acd-90c1-4975ed9ce48f"
  14. local engine_3_bank_2 = "fcd32370-6b57-4c50-b224-97afb2598de6"
  15. local engine_2_bank_2 = "f04fbbe0-fd11-4748-9eaf-a95d7a1409ec"
  16. local engine_1_bank_2 = "fa76b96e-5c83-4944-be81-4d2ceb3dbb61"
  17. local engine_1_bank_1 = "08a57843-b7b5-4a5f-be68-6693ede070ef"
  18. local engine_2_bank_1 = "a72b707d-9902-4b4e-b33d-c59c91057cd4"
  19. local engine_3_bank_1 = "9ad89be2-98f6-488f-b07c-e6438f3a639e"
  20. local engine_4_bank_1 = "bebbcce8-435f-448c-a6bd-5b5e8566c39c"
  21.  
  22.  
  23. -- Variables
  24. local energy = 0
  25. local maxEnergy = 0
  26.  
  27. local fluidLevel = 0
  28. local maxFluidLevel = 0
  29.  
  30. -- Thresholds for bundled wire outputs
  31. local offThreshold = 11000000 -- Energy threshold to turn the engine off
  32. local onThreshold = 1800000 -- Energy threshold to turn the engine on
  33. local totalDischarge = 0
  34. local totalCharge = 0
  35. local dischargeCount = 0
  36. local chargeCount = 0
  37.  
  38.  
  39.  
  40.  
  41. -- Progress bar object
  42. local progressBar = {
  43. x = 25,
  44. y = 6,
  45. width = 120,
  46. height = 5,
  47. progress = 0,
  48. maxProgress = 100,
  49. backgroundColor = 0x808080,
  50. filledColor = 0x00BFFF,
  51. shadowColor = 0x404040,
  52. highlightColor = 0xFFFFFF,
  53. orientation = "horizontal" -- Default orientation is horizontal
  54. }
  55.  
  56. function progressBar:load(x, y, width, height, maxProgress)
  57. self.x = x or self.x
  58. self.y = y or self.y
  59. self.width = width or self.width
  60. self.height = height or self.height
  61. self.maxProgress = maxProgress or self.maxProgress
  62. self.orientation = orientation or self.orientation
  63. end
  64.  
  65. -- Progress bar update
  66. function progressBar:update(progress)
  67. self.progress = progress
  68. end
  69.  
  70. -- Progress bar draw
  71. function progressBar:draw()
  72. local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
  73.  
  74. -- Set color for filled part
  75. gpu.setBackground(0x00BFFF)
  76. gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
  77.  
  78. -- Set color for unfilled part
  79. gpu.setBackground(0x808080)
  80. gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
  81.  
  82. -- Draw threshold line
  83. local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x
  84. local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x
  85. gpu.setBackground(0xFF0000) -- Red color for off threshold
  86. gpu.fill(offThresholdX, self.y + self.height / 2, 1, 1, ' ')
  87. gpu.setBackground(0x00FF00) -- Green color for on threshold
  88. gpu.fill(onThresholdX, self.y + self.height / 2, 1, 1, ' ')
  89.  
  90. -- Reset color to white
  91. gpu.setBackground(0xFFFFFF)
  92. end
  93.  
  94. -- Fluid tank object
  95. local fluidTank = {
  96. x = 120,
  97. y = 5,
  98. width = 15,
  99. height = 8,
  100. tankCapacity = 0,
  101. fluidAmount = 0,
  102. fluidName = "",
  103. }
  104.  
  105. -- Fluid tank load
  106. function fluidTank:load()
  107. self.tankCapacity = tankController.getTankCapacity(1)
  108. local fluidInTank = tankController.getFluidInTank(1)
  109. if fluidInTank[1] then
  110. self.fluidAmount = fluidInTank[1].amount
  111. self.fluidName = fluidInTank[1].name
  112. else
  113. self.fluidAmount = 0
  114. self.fluidName = "Empty"
  115. end
  116. end
  117.  
  118.  
  119. -- Fluid tank update
  120. function fluidTank:update()
  121. self.fluidAmount = tankController.getTankLevel(1)
  122. local fluidInTank = tankController.getFluidInTank(1)
  123. if fluidInTank[1] then
  124. self.fluidName = fluidInTank[1].name
  125. else
  126. self.fluidName = "Empty"
  127. end
  128. end
  129.  
  130. -- Fluid tank draw
  131. function fluidTank:draw()
  132. -- Calculate fluid level height
  133. local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
  134. if fluidLevelHeight > self.height - 2 then
  135. fluidLevelHeight = self.height - 2
  136. end
  137. -- Draw fluid tank background
  138. gpu.setBackground(0x808080)
  139. gpu.fill(self.x, self.y, self.width, self.height, ' ')
  140.  
  141. -- Draw fluid level if tank is not empty
  142. if self.fluidAmount > 1 then
  143. gpu.setBackground(0xFFFF00)
  144. gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
  145. gpu.setBackground(0x000000)
  146.  
  147. end
  148.  
  149. -- Draw unfilled part of the tank
  150. gpu.setBackground(0x000000)
  151. gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
  152.  
  153. -- Draw fluid name and amount
  154.  
  155. gpu.setForeground(0xFFFFFF)
  156. gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
  157. gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
  158. end
  159.  
  160. --================
  161. -- PART 1 END
  162. --================
  163.  
  164. --================
  165. -- PART 2 START
  166. --================
  167.  
  168.  
  169.  
  170.  
  171.  
  172. -- Engine object
  173. local engine = {
  174.  
  175. body = {x = 100, y = 11, width = 1, height = 3, color = 0xFFFFFF},
  176. head = {x = 100+1, y = 11, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  177. core = {x = 100+1, y = 11+1, width = 4, height = 1, color = 0x8B4513},
  178. infoPanel = {x = 100+6, y = 11, width = 33, height = 14, color = 0xC0C0C0},
  179. }
  180.  
  181. engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  182. engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  183. engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  184. engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  185. engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  186. engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  187. engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  188. engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  189. engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  190. engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  191. engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
  192. engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
  193.  
  194.  
  195. engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  196. engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  197. engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  198. engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  199. engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  200. engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  201. engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  202. engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  203. engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  204. engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  205. engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
  206. engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
  207.  
  208.  
  209. -- Engine load
  210. function engine:load()
  211. self.core.x = engine.core.x
  212. self.core.y = engine.core.y
  213. self.body.x = engine.body.x
  214. self.body.y = engine.body.y
  215. self.head.x = engine.head.x
  216. self.head.y = engine.head.y
  217. self.infoPanelContent = engine.infoPanelContent
  218. self.infoPanel.x = engine.infoPanel.x
  219. self.infoPanel.y = engine.infoPanel.y
  220. end
  221.  
  222. function resetCycle()
  223. totalDischarge = 0
  224. totalCharge = 0
  225. dischargeCount = 0
  226. chargeCount = 0
  227. end
  228.  
  229.  
  230. -- Engine update
  231. function engine:update()
  232. if self.movement == nil then
  233. self.movement = 0
  234. self.direction = true
  235. end
  236.  
  237. if self.direction then
  238. self.head.x = self.head.x + 1
  239. else
  240. self.head.x = self.head.x - 1
  241. end
  242.  
  243. self.movement = self.movement + 1
  244.  
  245. if self.movement >= 3 then
  246. self.movement = 0
  247. self.direction = not self.direction
  248. resetCycle() -- Reset the cycle when the engine completes a cycle
  249. end
  250. engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  251. engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  252. engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  253. engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  254. engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  255. engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  256. engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  257. engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  258. engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  259. engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  260. engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
  261. engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
  262.  
  263.  
  264. engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  265. engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  266. engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  267. engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  268. engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  269. engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  270. engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  271. engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  272. engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  273. engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  274. engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
  275. engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
  276.  
  277.  
  278. end
  279.  
  280. --================
  281. -- PART 2 END
  282. --================
  283.  
  284.  
  285. --================
  286. -- PART 3 START
  287. --================
  288.  
  289.  
  290. -- Engine draw
  291. function engine:draw()
  292. -- Draw core
  293. gpu.setBackground(self.core.color)
  294. gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  295. -- Draw body
  296. gpu.setBackground(self.body.color)
  297. gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
  298. -- Draw head
  299. gpu.setBackground(self.head.color)
  300. gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
  301. gpu.setBackground(self.infoPanel.color)
  302. gpu.fill(self.infoPanel.x, self.infoPanel.y, self.infoPanel.width, self.infoPanel.height, ' ')
  303.  
  304. gpu.setForeground(0x228B22)
  305. term.setCursor(self.infoPanel.x+(self.infoPanel.width/2)-string.len("engine bank 1")/2, self.infoPanel.y)
  306. term.write("engine bank 1")
  307.  
  308. gpu.setForeground(0x000000)
  309.  
  310. term.setCursor(self.infoPanel.x+1, self.infoPanel.y+1)
  311. term.write("engine 1 fuel type:"..engine_1_bank_1_fuel.name)
  312.  
  313. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 fuel:")+5)/2, self.infoPanel.y+2)
  314. term.write("engine 1 fuel:"..engine_1_bank_1_fuel.amount)
  315.  
  316. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 coolant:")+5)/2, self.infoPanel.y+3)
  317. term.write("engine 1 coolant:"..engine_1_bank_1_coolant.amount)
  318.  
  319. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 fuel:")+5)/2, self.infoPanel.y+5)
  320. term.write("engine 2 fuel:"..engine_2_bank_1_fuel.amount)
  321.  
  322. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 coolant:")+5)/2, self.infoPanel.y+6)
  323. term.write("engine 2 coolant:"..engine_2_bank_1_coolant.amount)
  324.  
  325. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 fuel:")+5)/2, self.infoPanel.y+8)
  326. term.write("engine 3 fuel:"..engine_3_bank_1_fuel.amount)
  327.  
  328. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 coolant:")+5)/2, self.infoPanel.y+9)
  329. term.write("engine 3 coolant:"..engine_3_bank_1_coolant.amount)
  330.  
  331. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 fuel:")+5)/2, self.infoPanel.y+11)
  332. term.write("engine 4 fuel:"..engine_4_bank_1_fuel.amount)
  333.  
  334. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 coolant:")+5)/2, self.infoPanel.y+12)
  335. term.write("engine 4 coolant:"..engine_4_bank_1_coolant.amount)
  336.  
  337. gpu.setBackground(self.infoPanel.color)
  338. gpu.fill(self.infoPanel.x, self.infoPanel.y+self.infoPanel.height+1, self.infoPanel.width, self.infoPanel.height, ' ')
  339.  
  340. gpu.setForeground(0x228B22)
  341. term.setCursor(self.infoPanel.x+(self.infoPanel.width/2)-string.len("engine bank 2")/2, self.infoPanel.y+self.infoPanel.height+1)
  342. term.write("engine bank 2")
  343.  
  344. gpu.setForeground(0x000000)
  345.  
  346. term.setCursor(self.infoPanel.x+1, self.infoPanel.y+1+self.infoPanel.height+1)
  347. term.write("engine 1 fuel type:"..engine_1_bank_2_fuel.name)
  348.  
  349. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 fuel:")+5)/2, self.infoPanel.y+2+self.infoPanel.height+1)
  350. term.write("engine 1 fuel:"..engine_1_bank_2_fuel.amount)
  351.  
  352. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 1 coolant:")+5)/2, self.infoPanel.y+3+self.infoPanel.height+1)
  353. term.write("engine 1 coolant:"..engine_1_bank_2_coolant.amount)
  354.  
  355. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 fuel:")+5)/2, self.infoPanel.y+5+self.infoPanel.height+1)
  356. term.write("engine 2 fuel:"..engine_2_bank_2_fuel.amount)
  357.  
  358. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 2 coolant:")+5)/2, self.infoPanel.y+6+self.infoPanel.height+1)
  359. term.write("engine 2 coolant:"..engine_2_bank_2_coolant.amount)
  360.  
  361. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 fuel:")+5)/2, self.infoPanel.y+8+self.infoPanel.height+1)
  362. term.write("engine 3 fuel:"..engine_3_bank_2_fuel.amount)
  363.  
  364. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 3 coolant:")+5)/2, self.infoPanel.y+9+self.infoPanel.height+1)
  365. term.write("engine 3 coolant:"..engine_3_bank_2_coolant.amount)
  366.  
  367. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 fuel:")+5)/2, self.infoPanel.y+11+self.infoPanel.height+1)
  368. term.write("engine 4 fuel:"..engine_4_bank_2_fuel.amount)
  369.  
  370. term.setCursor(self.infoPanel.x+self.infoPanel.width/2-(string.len("engine 4 coolant:")+5)/2, self.infoPanel.y+12+self.infoPanel.height+1)
  371. term.write("engine 4 coolant:"..engine_4_bank_2_coolant.amount)
  372.  
  373. -- Reset color to white
  374. gpu.setBackground(0xFFFFFF)
  375.  
  376.  
  377. end
  378.  
  379. --================
  380. -- PART 3 END
  381. --================
  382.  
  383. --================
  384. -- PART 4 START
  385. --================
  386.  
  387.  
  388.  
  389. local graph = {
  390. x = progressBar.x,
  391. y = progressBar.y + progressBar.height + 10,
  392. width = progressBar.width,
  393. height = 10,
  394. data = {},
  395. maxDataPoints = 100,
  396. }
  397.  
  398. -- Graph add data
  399. function graph:addData(value)
  400. table.insert(self.data, 1, value)
  401. if #self.data > self.maxDataPoints then
  402. table.remove(self.data)
  403. end
  404. end
  405.  
  406. -- Graph draw
  407. function graph:draw()
  408. -- Draw graph background
  409. gpu.setBackground(0x808080)
  410. gpu.fill(self.x, self.y, self.width, self.height, ' ')
  411.  
  412. -- Calculate scale and offset for mapping data to graph coordinates
  413. local minData = math.min(table.unpack(self.data))
  414. local maxData = math.max(table.unpack(self.data))
  415. local scale = (maxData - minData) / self.height
  416. local xOffset = self.width / (#self.data - 1)
  417.  
  418. -- Draw data points
  419. gpu.setBackground(0x00BFFF)
  420. for i = 2, #self.data do
  421. local x1 = self.x + (i - 2) * xOffset
  422. local x2 = self.x + (i - 1) * xOffset
  423. local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
  424. local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
  425. gpu.fill(x1, y1, 1, 1, ' ')
  426. gpu.fill(x2, y2, 1, 1, ' ')
  427. gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  428. end
  429.  
  430. -- Reset color to white
  431. gpu.setBackground(0xFFFFFF)
  432. end
  433.  
  434.  
  435.  
  436.  
  437. -- Function to enable a specific bank of bundled wire outputs connected to engines
  438. local function enableWireBank(bank)
  439. component.redstone.setBundledOutput(3, bank, 255)
  440. end
  441.  
  442. -- Function to disable a specific bank of bundled wire outputs connected to engines
  443. local function disableWireBank(bank)
  444. component.redstone.setBundledOutput(3, bank, 0)
  445. end
  446.  
  447. -- Function to enable a specific bank of bundled wire outputs connected to fuel tank
  448. local function enableFuelPump(bank)
  449. component.redstone.setBundledOutput(1, bank, 255)
  450. end
  451.  
  452. -- Function to disable a specific bank of bundled wire outputs connected to engines
  453. local function disableFuelPump(bank)
  454. component.redstone.setBundledOutput(1, bank, 0)
  455. end
  456.  
  457. --[[
  458. ╔════════════════════════════╗
  459. ║ MAIN PROGRAM INITIALIZATION║
  460. ╚════════════════════════════╝
  461. --]]
  462. function load()
  463. maxEnergy = energyCube.getMaxEnergyStored()
  464. gpu.setResolution(160, 50) -- Set screen resolution
  465. progressBar:load(25, 6, 65, 10, maxEnergy) -- Initialize progress bar
  466. engine:load() -- Initialize engine
  467. --fluidTank:load()
  468. end
  469.  
  470. --================
  471. -- PART 4 END
  472. --================
  473.  
  474. --================
  475. -- PART 5 START
  476. --================
  477.  
  478.  
  479. --[[
  480. ╔═══════════════════════╗
  481. ║ MAIN PROGRAM LOOP ║
  482. ╚═══════════════════════╝
  483. --]]
  484. local energySamples = {} -- Table to store energy samples
  485. local sampleRate = 10 -- Number of ticks between energy samples
  486. local maxSamples = 10 -- Maximum number of energy samples to keep
  487. local dischargeRate = 0 -- Energy discharge rate
  488. local chargeRate = 0 -- Energy charge rate
  489.  
  490. local sampleSize = 10 -- Number of samples to use when calculating average rates
  491. local chargeRateSamples = {} -- Table to store charge rate samples
  492. local dischargeRateSamples = {} -- Table to store discharge rate samples
  493.  
  494. function update()
  495. -- Check bundled inputs
  496. local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  497. local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  498.  
  499. -- Check if animation should run
  500. local shouldAnimate = orangeInput > 1 or whiteInput > 1
  501.  
  502. -- Update energy and progress bar
  503. energy = energyCube.getEnergyStored()
  504. progressBar:update(energy)
  505.  
  506. -- Calculate discharge and charge rates
  507. local currentTick = computer.uptime()
  508. local lastSample = energySamples[#energySamples]
  509. if lastSample then
  510. local deltaTime = currentTick - lastSample.tick
  511. local deltaEnergy = energy - lastSample.energy
  512.  
  513. if deltaTime > 0 then
  514. if deltaEnergy > 0 then
  515. chargeRate = deltaEnergy / deltaTime
  516. dischargeRate = 0
  517. elseif deltaEnergy < 0 then
  518. dischargeRate = -deltaEnergy / deltaTime
  519. chargeRate = 0
  520. end
  521. end
  522. if deltaEnergy > 0 then
  523. chargeRate = deltaEnergy / deltaTime
  524. totalCharge = totalCharge + chargeRate
  525. chargeCount = chargeCount + 1
  526. dischargeRate = 0
  527. elseif deltaEnergy < 0 then
  528. dischargeRate = -deltaEnergy / deltaTime
  529. totalDischarge = totalDischarge + dischargeRate
  530. dischargeCount = dischargeCount + 1
  531. chargeRate = 0
  532. end
  533. end
  534.  
  535. -- Store energy sample
  536. table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  537. if #energySamples > maxSamples then
  538. table.remove(energySamples)
  539. end
  540.  
  541. if shouldAnimate then
  542. engine:update()
  543. end
  544.  
  545. -- Check thresholds and set bundled wire outputs
  546. if energy <= onThreshold then
  547. -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  548. enableWireBank(0)
  549. enableWireBank(1) -- Disable orange wire output
  550. elseif energy >= offThreshold then
  551. -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  552. disableWireBank(0) -- Disable orange wire output
  553. disableWireBank(1) -- Disable white wire output
  554.  
  555. end
  556. --fluidTank:update()
  557.  
  558. end
  559.  
  560. --================
  561. -- PART 5 END
  562. --================
  563.  
  564.  
  565. --================
  566. --FINAL PART START
  567. --================
  568.  
  569.  
  570. function draw()
  571. -- Clear screen
  572. gpu.setBackground(0x000000)
  573. gpu.setForeground(0xFFFFFF)
  574. gpu.fill(1, 1, 160, 50, ' ')
  575. progressBar:draw()
  576. gpu.setBackground(0x000000)
  577. gpu.setForeground(0xFFFFFF)
  578. gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2, progressBar.y + progressBar.height + 1, "Current Energy: " .. tostring(energy))
  579. gpu.set(progressBar.x+progressBar.width/2-string.len("Max Energy: ")+8/2, progressBar.y + progressBar.height + 2, "Max Energy: " .. tostring(maxEnergy))
  580. engine:draw()
  581.  
  582. -- Render discharge and charge rates
  583. local boxX = 25
  584. local boxY = progressBar.y + progressBar.height + 10
  585. local boxWidth = 48
  586. local boxHeight = 6
  587. local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  588. local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  589.  
  590. -- Draw gray box
  591. gpu.setBackground(0x808080)
  592. gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
  593.  
  594. local averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  595. local averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  596.  
  597. local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  598. gpu.setBackground(0x808080)
  599. gpu.setForeground(0xFFFFFF)
  600. gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  601.  
  602. local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  603. gpu.setBackground(0x808080)
  604. gpu.setForeground(0xFFFFFF)
  605. gpu.set(boxX + 2, boxY + 4, averageChargeText)
  606.  
  607.  
  608. -- Render discharge rate
  609. local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
  610. gpu.setBackground(0x808080)
  611. gpu.setForeground(0xFFFFFF)
  612. gpu.set(boxX + 2, boxY + 1, dischargeText)
  613.  
  614. -- Render charge rate
  615. local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
  616. gpu.setBackground(0x808080)
  617. gpu.setForeground(0xFFFFFF)
  618. gpu.set(boxX + 2, boxY + 2, chargeText)
  619. local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  620. gpu.setBackground(0x808080)
  621. gpu.setForeground(0xFFFFFF)
  622. gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  623.  
  624. local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  625. gpu.setBackground(0x808080)
  626. gpu.setForeground(0xFFFFFF)
  627. gpu.set(boxX + 2, boxY + 4, averageChargeText)
  628. -- Reset color to white
  629. gpu.setBackground(0xFFFFFF)
  630. --fluidTank:draw()
  631. end
  632.  
  633. --[[
  634. ╔═══════════════════════════╗
  635. ║MAIN PROGRAM INITIALIZATION║
  636. ╚═══════════════════════════╝
  637. --]]
  638. function main()
  639. load()
  640. while true do
  641. update()
  642. draw()
  643. os.sleep(0.0) -- Wait for 0.1 seconds before updating again
  644. end
  645. end
  646.  
  647. -- Run the program
  648. main()
  649.  
  650. --================
  651. --FINAL PART END
  652. --================
  653.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement