Advertisement
davedumas0

power_1.4.lua

Jun 2nd, 2023
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.53 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 = 9298000 -- Energy threshold to turn the engine on
  33.  
  34.  
  35.  
  36. -- Function to enable a specific bank of bundled wire outputs connected to engines
  37. local function enableWireBank(bank)
  38.     component.redstone.setBundledOutput(3, bank, 255)
  39. end
  40.  
  41. -- Function to disable a specific bank of bundled wire outputs connected to engines
  42. local function disableWireBank(bank)
  43.     component.redstone.setBundledOutput(3, bank, 0)
  44. end
  45.  
  46. -- Function to enable a specific bank of bundled wire outputs connected to fuel tank
  47. local function enableFuelPump(bank)
  48.     component.redstone.setBundledOutput(1, bank, 255)
  49. end
  50.  
  51. -- Function to disable a specific bank of bundled wire outputs connected to engines
  52. local function disableFuelPump(bank)
  53.     component.redstone.setBundledOutput(1, bank, 0)
  54. end
  55.  
  56.  
  57. -- Progress bar object
  58. local progressBar = {
  59.     x = 25,
  60.     y = 6,
  61.     width = 120,
  62.     height = 10,
  63.     progress = 0,
  64.     maxProgress = 100,
  65.     backgroundColor = 0x808080,
  66.     filledColor = 0x00BFFF,
  67.     shadowColor = 0x404040,
  68.     highlightColor = 0xFFFFFF,
  69.     orientation = "horizontal" -- Default orientation is horizontal
  70. }
  71.  
  72. function progressBar:load(x, y, width, height, maxProgress)
  73.     self.x = x or self.x
  74.     self.y = y or self.y
  75.     self.width = width or self.width
  76.     self.height = height or self.height
  77.     self.maxProgress = maxProgress or self.maxProgress
  78.     self.orientation = orientation or self.orientation
  79. end
  80.  
  81.  
  82.  
  83. -- Progress bar draw
  84. function progressBar:draw()
  85.     local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
  86.  
  87.     -- Set color for filled part
  88.     gpu.setBackground(0x00BFFF)
  89.     gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
  90.    
  91.     -- Set color for unfilled part
  92.     gpu.setBackground(0x808080)
  93.     gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
  94.  
  95.     -- Draw threshold line
  96.     local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x+1
  97.     local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x+1
  98.     gpu.setBackground(0xFF0000) -- Red color for off threshold
  99.     gpu.fill(offThresholdX, self.y , 1, self.height, ' ')
  100.     gpu.setBackground(0x00FF00) -- Green color for on threshold
  101.     gpu.fill(onThresholdX, self.y, 1, self.height, ' ')
  102.    
  103.     -- Reset color to white
  104.     gpu.setBackground(0xFFFFFF)
  105. end
  106.  
  107. -- Progress bar update
  108. function progressBar:update(progress)
  109.     self.progress = progress
  110.     progressBar:draw()
  111.  
  112. end
  113.  
  114.  
  115. -- Fluid tank object
  116. local fluidTank = {
  117.     x = 120,
  118.     y = 5,
  119.     width = 15,
  120.     height = 8,
  121.     tankCapacity = 0,
  122.     fluidAmount = 0,
  123.     fluidName = "",
  124. }
  125.  
  126. -- Fluid tank load
  127. function fluidTank:load()
  128.     self.tankCapacity = tankController.getTankCapacity(1)
  129.     local fluidInTank = tankController.getFluidInTank(1)
  130.     if fluidInTank[1] then
  131.         self.fluidAmount = fluidInTank[1].amount
  132.         self.fluidName = fluidInTank[1].name
  133.     else
  134.         self.fluidAmount = 0
  135.         self.fluidName = "Empty"
  136.     end
  137. end
  138.  
  139.  
  140. -- Fluid tank update
  141. function fluidTank:update()
  142.     self.fluidAmount = tankController.getTankLevel(1)
  143.     local fluidInTank = tankController.getFluidInTank(1)
  144.     if fluidInTank[1] then
  145.         self.fluidName = fluidInTank[1].name
  146.     else
  147.         self.fluidName = "Empty"
  148.     end
  149. end
  150.  
  151. -- Fluid tank draw
  152. function fluidTank:draw()
  153.     -- Calculate fluid level height
  154.     local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
  155.     if fluidLevelHeight > self.height - 2 then
  156.         fluidLevelHeight = self.height - 2
  157.     end
  158.     -- Draw fluid tank background
  159.     gpu.setBackground(0x808080)
  160.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  161.    
  162.     -- Draw fluid level if tank is not empty
  163.     if self.fluidAmount > 1 then
  164.         gpu.setBackground(0xFFFF00)
  165.         gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
  166.         gpu.setBackground(0x000000)
  167.        
  168.     end
  169.    
  170.     -- Draw unfilled part of the tank
  171.     gpu.setBackground(0x000000)
  172.     gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
  173.    
  174.     -- Draw fluid name and amount
  175.    
  176.     gpu.setForeground(0xFFFFFF)
  177.     gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
  178.     gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
  179. end
  180.  
  181. --================
  182. --  PART 1  END
  183. --================
  184.  
  185. --================
  186. --  PART 2  START
  187. --================
  188.  
  189.  
  190.  
  191.  
  192.  
  193. -- Engine object
  194. local engine = {
  195.    
  196.     body = {x = 105, y = 19, width = 1, height = 3, color = 0xFFFFFF},
  197.     head = {x = 105+1, y = 19, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
  198.     core = {x = 105+1, y = 19+1, width = 4, height = 1, color = 0x8B4513},
  199.    }
  200.  
  201. -- Engine load
  202. function engine:load()
  203.     self.core.x = engine.core.x
  204.     self.core.y = engine.core.y
  205.     self.body.x = engine.body.x
  206.     self.body.y = engine.body.y
  207.     self.head.x = engine.head.x
  208.     self.head.y = engine.head.y
  209. end
  210.  
  211. function resetCycle()
  212.     totalDischarge = 0
  213.     totalCharge = 0
  214.     dischargeCount = 0
  215.     chargeCount = 0
  216. end
  217.  
  218.  
  219. -- Engine update
  220. function engine:update()
  221.     if self.movement == nil then
  222.         self.movement = 0
  223.         self.direction = true
  224.     end
  225.    
  226.     if self.direction then
  227.         self.head.x = self.head.x + 1
  228.     else
  229.         self.head.x = self.head.x - 1
  230.     end
  231.    
  232.     self.movement = self.movement + 1
  233.    
  234.     if self.movement >= 3 then
  235.         self.movement = 0
  236.         self.direction = not self.direction
  237.         resetCycle() -- Reset the cycle when the engine completes a cycle
  238.     end
  239.  
  240.     --draw engine background
  241.     gpu.setBackground(0x000000)
  242.     gpu.fill(self.core.x, self.core.y-1, self.core.width, self.core.height+2, ' ')
  243.     -- Draw core
  244.     gpu.setBackground(self.core.color)
  245.     gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  246.     -- Draw head
  247.     gpu.setBackground(self.head.color)
  248.     gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')  
  249. end
  250.  
  251. --================
  252. --  PART 2  END
  253. --================
  254.  
  255.  
  256. --================
  257. --  PART 3  START
  258. --================
  259.  
  260.  
  261. -- Engine draw
  262. function engine:draw()
  263.  
  264.     gpu.setBackground(0x000000)
  265.     gpu.fill(self.core.x, self.core.y-1, self.core.width, self.core.height+2, ' ')
  266.  
  267.     -- Draw core
  268.     gpu.setBackground(self.core.color)
  269.     gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
  270.     -- Draw body
  271.     gpu.setBackground(self.body.color)
  272.     gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
  273.     -- Draw head
  274.     gpu.setBackground(self.head.color)
  275.     gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')  
  276.     -- Reset color to white
  277.     gpu.setBackground(0xFFFFFF)
  278. end
  279.  
  280.  
  281. function loadEnginPanel()
  282.     engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  283.     engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  284.     engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  285.     engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  286.     engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  287.     engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  288.     engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  289.     engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  290.     engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  291.     engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  292.     engine_4_bank_1_fuel =  engine_4_bank_1_temp[1]
  293.     engine_4_bank_1_coolant =  engine_4_bank_1_temp[2]
  294.  
  295.  
  296.     engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  297.     engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  298.     engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  299.     engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  300.     engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  301.     engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  302.     engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  303.     engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  304.     engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  305.     engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  306.     engine_4_bank_2_fuel =  engine_4_bank_2_temp[1]
  307.     engine_4_bank_2_coolant =  engine_4_bank_2_temp[2]
  308.  
  309.  
  310.    
  311. end
  312.  
  313. function drawEnginePanel()
  314.     gpu.setBackground(infoPanel.color)
  315.     gpu.fill(infoPanel.x, infoPanel.y, infoPanel.width, infoPanel.height, ' ')
  316.     gpu.setForeground(0x228B22)
  317.    
  318.     --FFA500
  319.     term.setCursor(infoPanel.x+(infoPanel.width/2)-string.len("engine bank 1")/2, infoPanel.y)
  320.     term.write("engine bank 1")
  321.  
  322.  
  323.     gpu.setForeground(0xCCCC00)
  324.     term.setCursor(infoPanel.x+1, infoPanel.y+1)
  325.     term.write("engine 1 fuel type:"..engine_1_bank_1_fuel.name)
  326.    
  327.     gpu.setForeground(0x000000)
  328.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2, infoPanel.y + 2)
  329.     term.write("engine 1 fuel:")
  330.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
  331.     term.write(engine_1_bank_1_fuel.amount)
  332.  
  333.    
  334.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2, infoPanel.y + 3)
  335.     term.write("engine 1 coolant:")
  336.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
  337.     term.write(engine_1_bank_1_coolant.amount)
  338.  
  339.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2, infoPanel.y + 4)
  340.     term.write("engine 2 fuel:")
  341.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
  342.     term.write(engine_2_bank_1_fuel.amount)
  343.  
  344.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2, infoPanel.y + 5)
  345.     term.write("engine 2 coolant:")
  346.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
  347.     term.write(engine_2_bank_1_coolant.amount)
  348.  
  349.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2, infoPanel.y + 6)
  350.     term.write("engine 3 fuel:")
  351.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
  352.     term.write(engine_3_bank_1_fuel.amount)
  353.  
  354.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2, infoPanel.y + 7)
  355.     term.write("engine 3 coolant:")
  356.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
  357.     term.write(engine_3_bank_1_coolant.amount)
  358.  
  359.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2, infoPanel.y + 8)
  360.     term.write("engine 4 fuel:")
  361.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
  362.     term.write(engine_4_bank_1_fuel.amount)
  363.  
  364.    
  365.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2, infoPanel.y + 9)
  366.     term.write("engine 4 coolant:")
  367.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
  368.     term.write(engine_4_bank_1_coolant.amount)
  369.  
  370.     gpu.setBackground(infoPanel.color)
  371.     gpu.fill(infoPanel.x, infoPanel.y+infoPanel.height+1, infoPanel.width, infoPanel.height, ' ')
  372.  
  373.     gpu.setForeground(0x228B22)
  374.     term.setCursor(infoPanel.x+(infoPanel.width/2)-string.len("engine bank 2")/2, infoPanel.y+infoPanel.height+1)
  375.     term.write("engine bank 2")
  376.  
  377.     gpu.setForeground(0xCCCC00)
  378.     term.setCursor(infoPanel.x+1, infoPanel.y+1+infoPanel.height+1)
  379.     term.write("engine 1 fuel type:"..engine_1_bank_2_fuel.name)
  380.  
  381.     gpu.setForeground(0x000000)
  382.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2, infoPanel.y + 2+infoPanel.height+1)
  383.     term.write("engine 1 fuel:")
  384.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
  385.     term.write(engine_1_bank_2_fuel.amount)
  386.    
  387.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2, infoPanel.y + 3+infoPanel.height+1)
  388.     term.write("engine 1 coolant:")
  389.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
  390.     term.write(engine_1_bank_2_coolant.amount)
  391.  
  392.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2, infoPanel.y + 4+infoPanel.height+1)
  393.     term.write("engine 2 fuel:")
  394.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
  395.     term.write(engine_2_bank_2_fuel.amount)
  396.  
  397.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2, infoPanel.y + 5+infoPanel.height+1)
  398.     term.write("engine 2 coolant:")
  399.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
  400.     term.write(engine_2_bank_2_coolant.amount)
  401.  
  402.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2, infoPanel.y + 6+infoPanel.height+1)
  403.     term.write("engine 3 fuel:")
  404.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
  405.     term.write(engine_3_bank_2_fuel.amount)
  406.  
  407.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2, infoPanel.y + 7+infoPanel.height+1)
  408.     term.write("engine 3 coolant:")
  409.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
  410.     term.write(engine_3_bank_2_coolant.amount)
  411.  
  412.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2, infoPanel.y + 8+infoPanel.height+1)
  413.     term.write("engine 4 fuel:")
  414.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
  415.     term.write(engine_4_bank_2_fuel.amount)
  416.    
  417.    
  418.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2, infoPanel.y + 9+infoPanel.height+1)
  419.     term.write("engine 4 coolant:")
  420.  
  421.    
  422.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
  423.     term.write(engine_4_bank_2_coolant.amount)
  424.  
  425.  
  426. end
  427.  
  428. function updateEnginePanel()
  429.     engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
  430.     engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
  431.     engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
  432.     engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
  433.     engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
  434.     engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
  435.     engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
  436.     engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
  437.     engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
  438.     engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
  439.     engine_4_bank_1_fuel =  engine_4_bank_1_temp[1]
  440.     engine_4_bank_1_coolant =  engine_4_bank_1_temp[2]
  441.  
  442.  
  443.     engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
  444.     engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
  445.     engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
  446.     engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
  447.     engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
  448.     engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
  449.     engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
  450.     engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
  451.     engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
  452.     engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
  453.     engine_4_bank_2_fuel =  engine_4_bank_2_temp[1]
  454.     engine_4_bank_2_coolant =  engine_4_bank_2_temp[2]
  455.  
  456.     gpu.setBackground(infoPanel.color)
  457.    
  458.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
  459.     gpu.setForeground(0xCCCC00)
  460.     term.write(engine_1_bank_1_fuel.amount)
  461.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
  462.     gpu.setForeground(0x000080)
  463.     term.write(engine_1_bank_1_coolant.amount)
  464.  
  465.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
  466.     gpu.setForeground(0xCCCC00)
  467.     term.write(engine_2_bank_1_fuel.amount)
  468.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
  469.     gpu.setForeground(0x000080)
  470.     term.write(engine_2_bank_1_coolant.amount)
  471.  
  472.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
  473.     gpu.setForeground(0xCCCC00)
  474.     term.write(engine_3_bank_1_fuel.amount)
  475.  
  476.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
  477.     gpu.setForeground(0x000080)
  478.     term.write(engine_3_bank_1_coolant.amount)
  479.  
  480.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
  481.     gpu.setForeground(0xCCCC00)
  482.     term.write(engine_4_bank_1_fuel.amount)
  483.  
  484.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
  485.     gpu.setForeground(0x000080)
  486.     term.write(engine_4_bank_1_coolant.amount)
  487.  
  488.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 17)
  489.     gpu.setForeground(0xCCCC00)
  490.     term.write(engine_1_bank_2_fuel.amount)
  491.  
  492.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 18)
  493.     gpu.setForeground(0x000080)
  494.     term.write(engine_1_bank_2_coolant.amount)
  495.  
  496.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 19)
  497.     gpu.setForeground(0xCCCC00)
  498.     term.write(engine_2_bank_2_fuel.amount)
  499.  
  500.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 20)
  501.     gpu.setForeground(0x000080)
  502.     term.write(engine_2_bank_2_coolant.amount)
  503.  
  504.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 21)
  505.     gpu.setForeground(0xCCCC00)
  506.     term.write(engine_3_bank_2_fuel.amount)
  507.  
  508.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 22)
  509.     gpu.setForeground(0x000080)
  510.     term.write(engine_3_bank_2_coolant.amount)
  511.  
  512.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 23)
  513.     gpu.setForeground(0xCCCC00)
  514.     term.write(engine_4_bank_2_fuel.amount)
  515.    
  516.     term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 24)
  517.     gpu.setForeground(0x000080)
  518.     term.write(engine_4_bank_2_coolant.amount)
  519.  
  520.     if engine_4_bank_2_fuel.amount <=1000 or engine_4_bank_1_fuel.amount <=1000 then
  521.         enableFuelPump(4)
  522.         enableFuelPump(5)
  523.     elseif engine_4_bank_2_fuel.amount >=9900 or engine_4_bank_1_fuel.amount >=9900 then
  524.         disableFuelPump(4)
  525.         disableFuelPump(5)
  526.     end
  527.  
  528.  
  529. end
  530.  
  531.  
  532. function loadEnergyPanel()
  533.    
  534.     totalCharge = 0
  535.     dischargeCount = 0
  536.     chargeCount = 0
  537.     totalDischarge = 0
  538.     energySamples = {} -- Table to store energy samples
  539.     sampleRate = 10 -- Number of ticks between energy samples
  540.     maxSamples = 10 -- Maximum number of energy samples to keep
  541.     dischargeRate = 0 -- Energy discharge rate
  542.     chargeRate = 0 -- Energy charge rate
  543.     sampleSize = 10 -- Number of samples to use when calculating average rates
  544.     chargeRateSamples = {} -- Table to store charge rate samples
  545.     dischargeRateSamples = {} -- Table to store discharge rate samples
  546.     infoPanel = {x = 115, y = 19, width = 33, height = 14, color = 0x229B22}
  547.  
  548.     boxX = progressBar.x
  549.     boxY = progressBar.y + progressBar.height + 1
  550.     boxWidth = 60
  551.     boxHeight = 6
  552.     averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
  553.     averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
  554.  
  555.    
  556.     --
  557. end
  558.  
  559.  
  560.  
  561. function updateEnergyPanel()
  562.  
  563.  
  564.         -- Calculate discharge and charge rates
  565.         local currentTick = computer.uptime()
  566.         local lastSample = energySamples[#energySamples]
  567.         if lastSample then
  568.             local deltaTime = currentTick - lastSample.tick
  569.             local deltaEnergy = energy - lastSample.energy
  570.    
  571.             if deltaTime > 0 then
  572.                 if deltaEnergy > 0 then
  573.                     chargeRate = deltaEnergy / deltaTime
  574.                     dischargeRate = 0
  575.                 elseif deltaEnergy < 0 then
  576.                     dischargeRate = -deltaEnergy / deltaTime
  577.                     chargeRate = 0
  578.                 end
  579.             end
  580.             if deltaEnergy > 0 then
  581.                 chargeRate = deltaEnergy / deltaTime
  582.                 totalCharge = totalCharge + chargeRate
  583.                 chargeCount = chargeCount + 1
  584.                 dischargeRate = 0
  585.             elseif deltaEnergy < 0 then
  586.                 dischargeRate = -deltaEnergy / deltaTime
  587.                 totalDischarge = totalDischarge + dischargeRate
  588.                 dischargeCount = dischargeCount + 1
  589.                 chargeRate = 0
  590.             end
  591.         end
  592.    
  593.         -- Store energy sample
  594.         table.insert(energySamples, 1, { tick = currentTick, energy = energy })
  595.         if #energySamples > maxSamples then
  596.             table.remove(energySamples)
  597.         end
  598.    
  599.     if shouldAnimate then
  600.         gpu.setBackground(0x000000)
  601.         gpu.setForeground(0x00FF00)
  602.         gpu.fill(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, 9, 1, ' ')
  603.         gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, tostring(energy))
  604.     else
  605.         gpu.setBackground(0x000000)
  606.         gpu.setForeground(0xFF0000)
  607.         gpu.fill(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, 9, 1, ' ')
  608.         gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, tostring(energy))
  609.     end
  610.  
  611.     -- Render discharge rate
  612.     local dischargeText = string.format("Discharge Rate:%.2f RF/t", dischargeRate)
  613.     gpu.setBackground(0x808080)
  614.     gpu.setForeground(0xFF0000)
  615.     gpu.fill(boxX + 2+string.len(dischargeText)-string.len(dischargeRate), boxY + 1, string.len(dischargeRate)+5, 1, " ")
  616.     gpu.set(boxX + 2, boxY + 1, dischargeText)
  617.  
  618.     -- Render charge rate
  619.     local chargeText = string.format("Charge Rate:%.2f RF/t", chargeRate)
  620.     gpu.setBackground(0x808080)
  621.     gpu.setForeground(0x00FF00)
  622.     gpu.fill(boxX + 2+string.len(chargeText)-string.len(chargeRate), boxY + 2, string.len(chargeRate)+5, 1, " ")
  623.     gpu.set(boxX + 2, boxY + 2, chargeText)
  624.  
  625.  
  626.     local averageDischargeText = string.format("Average Discharge Rate:%.2f RF/t", averageDischarge)
  627.     gpu.setBackground(0x808080)
  628.     gpu.setForeground(0xFF0000)
  629.     gpu.fill(boxX + 2+string.len(averageDischargeText)-string.len(averageDischarge), boxY + 3, string.len(averageDischarge)+5, 1, " ")
  630.     gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  631.    
  632.     local averageChargeText = string.format("Average Charge Rate:%.2f RF/t", averageCharge)
  633.     gpu.setBackground(0x808080)
  634.     gpu.setForeground(0x00FF00)
  635.     gpu.fill(boxX + 2+string.len(averageChargeText)-string.len(averageCharge), boxY + 4, string.len(averageCharge)+5, 1, " ")
  636.     gpu.set(boxX + 2, boxY + 4, averageChargeText)
  637.  
  638.  
  639.  
  640.     -- Update energy and progress bar
  641.     energy = energyCube.getEnergyStored()
  642.     progressBar:update(energy)
  643.  
  644.  
  645.    
  646.  
  647. end
  648.  
  649. function drawEnergyPanel()
  650.     -- Render discharge and charge rates
  651.  
  652.    
  653.     gpu.setBackground(0x000000)
  654.     gpu.setForeground(0xFFFFFF)
  655.     gpu.fill(1, 1, 160, 50, ' ')
  656.    
  657.     gpu.setBackground(0x000000)
  658.     gpu.setForeground(0xFFFFFF)
  659.     gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2, progressBar.y + progressBar.height + 1, "Current Energy: " .. tostring(energy))
  660.     gpu.set(progressBar.x+progressBar.width/2-string.len("Max Energy: ")+8/2, progressBar.y + progressBar.height + 2, "Max Energy: " .. tostring(maxEnergy))
  661.         -- Draw gray box
  662.         gpu.setBackground(0x808080)
  663.         gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
  664.         local averageDischargeText = string.format("Average Discharge Rate:%.2f RF/t", averageDischarge)
  665.         gpu.setBackground(0x808080)
  666.         gpu.setForeground(0xFFFFFF)
  667.         gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  668.        
  669.         local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  670.         gpu.setBackground(0x808080)
  671.         gpu.setForeground(0xFFFFFF)
  672.         gpu.set(boxX + 2, boxY + 4, averageChargeText)
  673.    
  674.    
  675.         -- Render discharge rate
  676.         local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
  677.         gpu.setBackground(0x808080)
  678.         gpu.setForeground(0xFFFFFF)
  679.         gpu.set(boxX + 2, boxY + 1, dischargeText)
  680.    
  681.         -- Render charge rate
  682.         local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
  683.         gpu.setBackground(0x808080)
  684.         gpu.setForeground(0xFFFFFF)
  685.         gpu.set(boxX + 2, boxY + 2, chargeText)
  686.         local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
  687.         gpu.setBackground(0x808080)
  688.         gpu.setForeground(0xFFFFFF)
  689.         gpu.set(boxX + 2, boxY + 3, averageDischargeText)
  690.        
  691.         local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
  692.         gpu.setBackground(0x808080)
  693.         gpu.setForeground(0xFFFFFF)
  694.         gpu.set(boxX + 2, boxY + 4, averageChargeText)
  695.    
  696. end
  697.  
  698.  
  699. --================
  700. --  PART 3  END
  701. --================
  702.  
  703. --================
  704. --  PART 4 START
  705. --================
  706.  
  707.  
  708. --[[
  709. local graph = {
  710.     x = progressBar.x,
  711.     y = progressBar.y + progressBar.height + 10,
  712.     width = progressBar.width,
  713.     height = 10,
  714.     data = {},
  715.     maxDataPoints = 100,
  716. }
  717.  
  718. -- Graph add data
  719. function graph:addData(value)
  720.     table.insert(self.data, 1, value)
  721.     if #self.data > self.maxDataPoints then
  722.         table.remove(self.data)
  723.     end
  724. end
  725.  
  726. -- Graph draw
  727. function graph:draw()
  728.     -- Draw graph background
  729.     gpu.setBackground(0x808080)
  730.     gpu.fill(self.x, self.y, self.width, self.height, ' ')
  731.  
  732.     -- Calculate scale and offset for mapping data to graph coordinates
  733.     local minData = math.min(table.unpack(self.data))
  734.     local maxData = math.max(table.unpack(self.data))
  735.     local scale = (maxData - minData) / self.height
  736.     local xOffset = self.width / (#self.data - 1)
  737.  
  738.     -- Draw data points
  739.     gpu.setBackground(0x00BFFF)
  740.     for i = 2, #self.data do
  741.         local x1 = self.x + (i - 2) * xOffset
  742.         local x2 = self.x + (i - 1) * xOffset
  743.         local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
  744.         local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
  745.         gpu.fill(x1, y1, 1, 1, ' ')
  746.         gpu.fill(x2, y2, 1, 1, ' ')
  747.         gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
  748.     end
  749.  
  750.     -- Reset color to white
  751.     gpu.setBackground(0xFFFFFF)
  752. end
  753.  
  754. --]]
  755.  
  756.  
  757.  
  758. --[[
  759.     ╔════════════════════════════╗
  760.     ║ MAIN PROGRAM INITIALIZATION║
  761.     ╚════════════════════════════╝
  762. --]]
  763. function load()
  764.     maxEnergy = energyCube.getMaxEnergyStored()
  765.     gpu.setResolution(160, 50) -- Set screen resolution
  766.     progressBar:load(2, 2, 158, 15, maxEnergy) -- Initialize progress bar
  767.     loadEnergyPanel()
  768.     engine:load() -- Initialize engine
  769.     loadEnginPanel()
  770.     --fluidTank:load()
  771. end
  772.  
  773. --================
  774. --  PART 4 END
  775. --================
  776.  
  777. --================
  778. --  PART 5 START
  779. --================
  780.  
  781.  
  782. --[[
  783.     ╔═══════════════════════╗
  784.     ║ MAIN PROGRAM LOOP     ║
  785.     ╚═══════════════════════╝
  786. --]]
  787.  
  788.  
  789. function update()
  790.     -- Check bundled inputs
  791.     local orangeInput = component.redstone.getBundledInput(3, 1) or 0
  792.     local whiteInput = component.redstone.getBundledInput(3, 0) or 0
  793.  
  794.     -- Check if animation should run
  795.      shouldAnimate = orangeInput > 1 or whiteInput > 1
  796.  
  797.    
  798.    
  799.     if shouldAnimate then
  800.         engine:update()
  801.     end
  802.  
  803.     -- Check thresholds and set bundled wire outputs
  804.     if energy <= onThreshold then
  805.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  806.         enableWireBank(0)
  807.         enableWireBank(1) -- Disable orange wire output
  808.     elseif energy >= offThreshold  then
  809.         -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
  810.         disableWireBank(0) -- Disable orange wire output
  811.         disableWireBank(1) -- Disable white wire output
  812.    
  813.     end
  814.     --fluidTank:update()
  815.     updateEnergyPanel()
  816.     updateEnginePanel()
  817.     --engine:draw()
  818.  
  819. end
  820.  
  821. --================
  822. --  PART 5 END
  823. --================
  824.  
  825.  
  826. --================
  827. --FINAL PART START
  828. --================
  829.  
  830.  
  831.  
  832.  
  833. function draw()
  834.     -- Clear screen
  835.  
  836.     drawEnergyPanel()
  837.     engine:draw()
  838.     drawEnginePanel()
  839.     progressBar:draw()
  840.    
  841.     -- Reset color to white
  842.     gpu.setBackground(0xFFFFFF)
  843.     --fluidTank:draw()
  844. end
  845.  
  846. --[[
  847.     ╔═══════════════════════════╗
  848.     ║MAIN PROGRAM INITIALIZATION║
  849.     ╚═══════════════════════════╝
  850. --]]
  851. function main()
  852.     load()
  853.     draw()
  854.     while true do
  855.         update()
  856.        
  857.         os.sleep(0.0) -- Wait for 0.1 seconds before updating again
  858.     end
  859. end
  860.  
  861. -- Run the program
  862. main()
  863.  
  864. --================
  865. --FINAL PART END
  866. --================
  867.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement