Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --================
- -- PART 1 START
- --================
- -- Load the components
- local component = require("component")
- local gpu = component.gpu
- local sides = require("sides")
- local computer = require("computer")
- local term = require("term")
- -- Load the energy cube
- local energyCube = component.elite_energy_cube
- local engine_4_bank_2 = "14470fcc-cb6d-4acd-90c1-4975ed9ce48f"
- local engine_3_bank_2 = "fcd32370-6b57-4c50-b224-97afb2598de6"
- local engine_2_bank_2 = "f04fbbe0-fd11-4748-9eaf-a95d7a1409ec"
- local engine_1_bank_2 = "fa76b96e-5c83-4944-be81-4d2ceb3dbb61"
- local engine_1_bank_1 = "08a57843-b7b5-4a5f-be68-6693ede070ef"
- local engine_2_bank_1 = "a72b707d-9902-4b4e-b33d-c59c91057cd4"
- local engine_3_bank_1 = "9ad89be2-98f6-488f-b07c-e6438f3a639e"
- local engine_4_bank_1 = "bebbcce8-435f-448c-a6bd-5b5e8566c39c"
- -- Variables
- local energy = 0
- local maxEnergy = 0
- local fluidLevel = 0
- local maxFluidLevel = 0
- -- Thresholds for bundled wire outputs
- local offThreshold = 11000000 -- Energy threshold to turn the engine off
- local onThreshold = 9298000 -- Energy threshold to turn the engine on
- -- Function to enable a specific bank of bundled wire outputs connected to engines
- local function enableWireBank(bank)
- component.redstone.setBundledOutput(3, bank, 255)
- end
- -- Function to disable a specific bank of bundled wire outputs connected to engines
- local function disableWireBank(bank)
- component.redstone.setBundledOutput(3, bank, 0)
- end
- -- Function to enable a specific bank of bundled wire outputs connected to fuel tank
- local function enableFuelPump(bank)
- component.redstone.setBundledOutput(1, bank, 255)
- end
- -- Function to disable a specific bank of bundled wire outputs connected to engines
- local function disableFuelPump(bank)
- component.redstone.setBundledOutput(1, bank, 0)
- end
- -- Progress bar object
- local progressBar = {
- x = 25,
- y = 6,
- width = 120,
- height = 10,
- progress = 0,
- maxProgress = 100,
- backgroundColor = 0x808080,
- filledColor = 0x00BFFF,
- shadowColor = 0x404040,
- highlightColor = 0xFFFFFF,
- orientation = "horizontal" -- Default orientation is horizontal
- }
- function progressBar:load(x, y, width, height, maxProgress)
- self.x = x or self.x
- self.y = y or self.y
- self.width = width or self.width
- self.height = height or self.height
- self.maxProgress = maxProgress or self.maxProgress
- self.orientation = orientation or self.orientation
- end
- -- Progress bar draw
- function progressBar:draw()
- local filledWidth = math.floor((self.progress / self.maxProgress) * self.width)
- -- Set color for filled part
- gpu.setBackground(0x00BFFF)
- gpu.fill(self.x, self.y, filledWidth, self.height, ' ')
- -- Set color for unfilled part
- gpu.setBackground(0x808080)
- gpu.fill(self.x + filledWidth, self.y, self.width - filledWidth, self.height, ' ')
- -- Draw threshold line
- local offThresholdX = math.floor((offThreshold / self.maxProgress) * self.width) + self.x+1
- local onThresholdX = math.floor((onThreshold / self.maxProgress) * self.width) + self.x+1
- gpu.setBackground(0xFF0000) -- Red color for off threshold
- gpu.fill(offThresholdX, self.y , 1, self.height, ' ')
- gpu.setBackground(0x00FF00) -- Green color for on threshold
- gpu.fill(onThresholdX, self.y, 1, self.height, ' ')
- -- Reset color to white
- gpu.setBackground(0xFFFFFF)
- end
- -- Progress bar update
- function progressBar:update(progress)
- self.progress = progress
- progressBar:draw()
- end
- -- Fluid tank object
- local fluidTank = {
- x = 120,
- y = 5,
- width = 15,
- height = 8,
- tankCapacity = 0,
- fluidAmount = 0,
- fluidName = "",
- }
- -- Fluid tank load
- function fluidTank:load()
- self.tankCapacity = tankController.getTankCapacity(1)
- local fluidInTank = tankController.getFluidInTank(1)
- if fluidInTank[1] then
- self.fluidAmount = fluidInTank[1].amount
- self.fluidName = fluidInTank[1].name
- else
- self.fluidAmount = 0
- self.fluidName = "Empty"
- end
- end
- -- Fluid tank update
- function fluidTank:update()
- self.fluidAmount = tankController.getTankLevel(1)
- local fluidInTank = tankController.getFluidInTank(1)
- if fluidInTank[1] then
- self.fluidName = fluidInTank[1].name
- else
- self.fluidName = "Empty"
- end
- end
- -- Fluid tank draw
- function fluidTank:draw()
- -- Calculate fluid level height
- local fluidLevelHeight = math.floor((self.fluidAmount / self.tankCapacity) * (self.height - 2))
- if fluidLevelHeight > self.height - 2 then
- fluidLevelHeight = self.height - 2
- end
- -- Draw fluid tank background
- gpu.setBackground(0x808080)
- gpu.fill(self.x, self.y, self.width, self.height, ' ')
- -- Draw fluid level if tank is not empty
- if self.fluidAmount > 1 then
- gpu.setBackground(0xFFFF00)
- gpu.fill(self.x + 1, self.y + self.height - fluidLevelHeight - 1, self.width - 2, fluidLevelHeight, ' ')
- gpu.setBackground(0x000000)
- end
- -- Draw unfilled part of the tank
- gpu.setBackground(0x000000)
- gpu.fill(self.x + 1, self.y + 1, self.width - 2, self.height - fluidLevelHeight - 2, ' ')
- -- Draw fluid name and amount
- gpu.setForeground(0xFFFFFF)
- gpu.set(self.x-2, self.y - 1, "Fluid: " .. self.fluidName)
- gpu.set(self.x, self.y + self.height, "Amount: " .. self.fluidAmount .. " mB")
- end
- --================
- -- PART 1 END
- --================
- --================
- -- PART 2 START
- --================
- -- Engine object
- local engine = {
- body = {x = 105, y = 19, width = 1, height = 3, color = 0xFFFFFF},
- head = {x = 105+1, y = 19, width = 1, height = 3, color = 0xC0C0C0}, -- Silver (0xC0C0C0) or White (0xFFFFFF)
- core = {x = 105+1, y = 19+1, width = 4, height = 1, color = 0x8B4513},
- }
- -- Engine load
- function engine:load()
- self.core.x = engine.core.x
- self.core.y = engine.core.y
- self.body.x = engine.body.x
- self.body.y = engine.body.y
- self.head.x = engine.head.x
- self.head.y = engine.head.y
- end
- function resetCycle()
- totalDischarge = 0
- totalCharge = 0
- dischargeCount = 0
- chargeCount = 0
- end
- -- Engine update
- function engine:update()
- if self.movement == nil then
- self.movement = 0
- self.direction = true
- end
- if self.direction then
- self.head.x = self.head.x + 1
- else
- self.head.x = self.head.x - 1
- end
- self.movement = self.movement + 1
- if self.movement >= 3 then
- self.movement = 0
- self.direction = not self.direction
- resetCycle() -- Reset the cycle when the engine completes a cycle
- end
- --draw engine background
- gpu.setBackground(0x000000)
- gpu.fill(self.core.x, self.core.y-1, self.core.width, self.core.height+2, ' ')
- -- Draw core
- gpu.setBackground(self.core.color)
- gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
- -- Draw head
- gpu.setBackground(self.head.color)
- gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
- end
- --================
- -- PART 2 END
- --================
- --================
- -- PART 3 START
- --================
- -- Engine draw
- function engine:draw()
- gpu.setBackground(0x000000)
- gpu.fill(self.core.x, self.core.y-1, self.core.width, self.core.height+2, ' ')
- -- Draw core
- gpu.setBackground(self.core.color)
- gpu.fill(self.core.x, self.core.y, self.core.width, self.core.height, ' ')
- -- Draw body
- gpu.setBackground(self.body.color)
- gpu.fill(self.body.x, self.body.y, self.body.width, self.body.height, ' ')
- -- Draw head
- gpu.setBackground(self.head.color)
- gpu.fill(self.head.x, self.head.y, self.head.width, self.head.height, ' ')
- -- Reset color to white
- gpu.setBackground(0xFFFFFF)
- end
- function loadEnginPanel()
- engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
- engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
- engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
- engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
- engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
- engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
- engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
- engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
- engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
- engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
- engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
- engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
- engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
- engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
- engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
- engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
- engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
- engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
- engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
- engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
- engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
- engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
- engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
- engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
- end
- function drawEnginePanel()
- gpu.setBackground(infoPanel.color)
- gpu.fill(infoPanel.x, infoPanel.y, infoPanel.width, infoPanel.height, ' ')
- gpu.setForeground(0x228B22)
- --FFA500
- term.setCursor(infoPanel.x+(infoPanel.width/2)-string.len("engine bank 1")/2, infoPanel.y)
- term.write("engine bank 1")
- gpu.setForeground(0xCCCC00)
- term.setCursor(infoPanel.x+1, infoPanel.y+1)
- term.write("engine 1 fuel type:"..engine_1_bank_1_fuel.name)
- gpu.setForeground(0x000000)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2, infoPanel.y + 2)
- term.write("engine 1 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
- term.write(engine_1_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2, infoPanel.y + 3)
- term.write("engine 1 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
- term.write(engine_1_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2, infoPanel.y + 4)
- term.write("engine 2 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
- term.write(engine_2_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2, infoPanel.y + 5)
- term.write("engine 2 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
- term.write(engine_2_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2, infoPanel.y + 6)
- term.write("engine 3 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
- term.write(engine_3_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2, infoPanel.y + 7)
- term.write("engine 3 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
- term.write(engine_3_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2, infoPanel.y + 8)
- term.write("engine 4 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
- term.write(engine_4_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2, infoPanel.y + 9)
- term.write("engine 4 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
- term.write(engine_4_bank_1_coolant.amount)
- gpu.setBackground(infoPanel.color)
- gpu.fill(infoPanel.x, infoPanel.y+infoPanel.height+1, infoPanel.width, infoPanel.height, ' ')
- gpu.setForeground(0x228B22)
- term.setCursor(infoPanel.x+(infoPanel.width/2)-string.len("engine bank 2")/2, infoPanel.y+infoPanel.height+1)
- term.write("engine bank 2")
- gpu.setForeground(0xCCCC00)
- term.setCursor(infoPanel.x+1, infoPanel.y+1+infoPanel.height+1)
- term.write("engine 1 fuel type:"..engine_1_bank_2_fuel.name)
- gpu.setForeground(0x000000)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2, infoPanel.y + 2+infoPanel.height+1)
- term.write("engine 1 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
- term.write(engine_1_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2, infoPanel.y + 3+infoPanel.height+1)
- term.write("engine 1 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
- term.write(engine_1_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2, infoPanel.y + 4+infoPanel.height+1)
- term.write("engine 2 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
- term.write(engine_2_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2, infoPanel.y + 5+infoPanel.height+1)
- term.write("engine 2 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
- term.write(engine_2_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2, infoPanel.y + 6+infoPanel.height+1)
- term.write("engine 3 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
- term.write(engine_3_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2, infoPanel.y + 7+infoPanel.height+1)
- term.write("engine 3 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
- term.write(engine_3_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2, infoPanel.y + 8+infoPanel.height+1)
- term.write("engine 4 fuel:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
- term.write(engine_4_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2, infoPanel.y + 9+infoPanel.height+1)
- term.write("engine 4 coolant:")
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
- term.write(engine_4_bank_2_coolant.amount)
- end
- function updateEnginePanel()
- engine_1_bank_1_temp = component.proxy(engine_1_bank_1).getFluidInTank(1)
- engine_1_bank_1_fuel = engine_1_bank_1_temp[1]
- engine_1_bank_1_coolant = engine_1_bank_1_temp[2]
- engine_2_bank_1_temp = component.proxy(engine_2_bank_1).getFluidInTank(1)
- engine_2_bank_1_fuel = engine_2_bank_1_temp[1]
- engine_2_bank_1_coolant = engine_2_bank_1_temp[2]
- engine_3_bank_1_temp = component.proxy(engine_3_bank_1).getFluidInTank(1)
- engine_3_bank_1_fuel = engine_3_bank_1_temp[1]
- engine_3_bank_1_coolant = engine_3_bank_1_temp[2]
- engine_4_bank_1_temp = component.proxy(engine_4_bank_1).getFluidInTank(1)
- engine_4_bank_1_fuel = engine_4_bank_1_temp[1]
- engine_4_bank_1_coolant = engine_4_bank_1_temp[2]
- engine_1_bank_2_temp = component.proxy(engine_1_bank_2).getFluidInTank(1)
- engine_1_bank_2_fuel = engine_1_bank_2_temp[1]
- engine_1_bank_2_coolant = engine_1_bank_2_temp[2]
- engine_2_bank_2_temp = component.proxy(engine_2_bank_2).getFluidInTank(1)
- engine_2_bank_2_fuel = engine_2_bank_2_temp[1]
- engine_2_bank_2_coolant = engine_2_bank_2_temp[2]
- engine_3_bank_2_temp = component.proxy(engine_3_bank_2).getFluidInTank(1)
- engine_3_bank_2_fuel = engine_3_bank_2_temp[1]
- engine_3_bank_2_coolant = engine_3_bank_2_temp[2]
- engine_4_bank_2_temp = component.proxy(engine_4_bank_2).getFluidInTank(1)
- engine_4_bank_2_fuel = engine_4_bank_2_temp[1]
- engine_4_bank_2_coolant = engine_4_bank_2_temp[2]
- gpu.setBackground(infoPanel.color)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 2)
- gpu.setForeground(0xCCCC00)
- term.write(engine_1_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 3)
- gpu.setForeground(0x000080)
- term.write(engine_1_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 4)
- gpu.setForeground(0xCCCC00)
- term.write(engine_2_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 coolant:") + 5) / 2 + (string.len("engine 2 coolant:")), infoPanel.y + 5)
- gpu.setForeground(0x000080)
- term.write(engine_2_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 6)
- gpu.setForeground(0xCCCC00)
- term.write(engine_3_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 7)
- gpu.setForeground(0x000080)
- term.write(engine_3_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 8)
- gpu.setForeground(0xCCCC00)
- term.write(engine_4_bank_1_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 9)
- gpu.setForeground(0x000080)
- term.write(engine_4_bank_1_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 fuel:") + 5) / 2 + (string.len("engine 1 fuel:")), infoPanel.y + 17)
- gpu.setForeground(0xCCCC00)
- term.write(engine_1_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 1 coolant:") + 5) / 2 + (string.len("engine 1 coolant:")), infoPanel.y + 18)
- gpu.setForeground(0x000080)
- term.write(engine_1_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 19)
- gpu.setForeground(0xCCCC00)
- term.write(engine_2_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 2 fuel:") + 5) / 2 + (string.len("engine 2 fuel:")), infoPanel.y + 20)
- gpu.setForeground(0x000080)
- term.write(engine_2_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 fuel:") + 5) / 2 + (string.len("engine 3 fuel:")), infoPanel.y + 21)
- gpu.setForeground(0xCCCC00)
- term.write(engine_3_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 3 coolant:") + 5) / 2 + (string.len("engine 3 coolant:")), infoPanel.y + 22)
- gpu.setForeground(0x000080)
- term.write(engine_3_bank_2_coolant.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 fuel:") + 5) / 2 + (string.len("engine 4 fuel:")), infoPanel.y + 23)
- gpu.setForeground(0xCCCC00)
- term.write(engine_4_bank_2_fuel.amount)
- term.setCursor(infoPanel.x + infoPanel.width / 2 - (string.len("engine 4 coolant:") + 5) / 2 + (string.len("engine 4 coolant:")), infoPanel.y + 24)
- gpu.setForeground(0x000080)
- term.write(engine_4_bank_2_coolant.amount)
- if engine_4_bank_2_fuel.amount <=1000 or engine_4_bank_1_fuel.amount <=1000 then
- enableFuelPump(4)
- enableFuelPump(5)
- elseif engine_4_bank_2_fuel.amount >=9900 or engine_4_bank_1_fuel.amount >=9900 then
- disableFuelPump(4)
- disableFuelPump(5)
- end
- end
- function loadEnergyPanel()
- totalCharge = 0
- dischargeCount = 0
- chargeCount = 0
- totalDischarge = 0
- energySamples = {} -- Table to store energy samples
- sampleRate = 10 -- Number of ticks between energy samples
- maxSamples = 10 -- Maximum number of energy samples to keep
- dischargeRate = 0 -- Energy discharge rate
- chargeRate = 0 -- Energy charge rate
- sampleSize = 10 -- Number of samples to use when calculating average rates
- chargeRateSamples = {} -- Table to store charge rate samples
- dischargeRateSamples = {} -- Table to store discharge rate samples
- infoPanel = {x = 115, y = 19, width = 33, height = 14, color = 0x229B22}
- boxX = progressBar.x
- boxY = progressBar.y + progressBar.height + 1
- boxWidth = 60
- boxHeight = 6
- averageDischarge = totalDischarge / (dischargeCount > 0 and dischargeCount or 1)
- averageCharge = totalCharge / (chargeCount > 0 and chargeCount or 1)
- --
- end
- function updateEnergyPanel()
- -- Calculate discharge and charge rates
- local currentTick = computer.uptime()
- local lastSample = energySamples[#energySamples]
- if lastSample then
- local deltaTime = currentTick - lastSample.tick
- local deltaEnergy = energy - lastSample.energy
- if deltaTime > 0 then
- if deltaEnergy > 0 then
- chargeRate = deltaEnergy / deltaTime
- dischargeRate = 0
- elseif deltaEnergy < 0 then
- dischargeRate = -deltaEnergy / deltaTime
- chargeRate = 0
- end
- end
- if deltaEnergy > 0 then
- chargeRate = deltaEnergy / deltaTime
- totalCharge = totalCharge + chargeRate
- chargeCount = chargeCount + 1
- dischargeRate = 0
- elseif deltaEnergy < 0 then
- dischargeRate = -deltaEnergy / deltaTime
- totalDischarge = totalDischarge + dischargeRate
- dischargeCount = dischargeCount + 1
- chargeRate = 0
- end
- end
- -- Store energy sample
- table.insert(energySamples, 1, { tick = currentTick, energy = energy })
- if #energySamples > maxSamples then
- table.remove(energySamples)
- end
- if shouldAnimate then
- gpu.setBackground(0x000000)
- gpu.setForeground(0x00FF00)
- gpu.fill(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, 9, 1, ' ')
- gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, tostring(energy))
- else
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFF0000)
- gpu.fill(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, 9, 1, ' ')
- gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2+string.len("Current Energy: "), progressBar.y + progressBar.height + 1, tostring(energy))
- end
- -- Render discharge rate
- local dischargeText = string.format("Discharge Rate:%.2f RF/t", dischargeRate)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFF0000)
- gpu.fill(boxX + 2+string.len(dischargeText)-string.len(dischargeRate), boxY + 1, string.len(dischargeRate)+5, 1, " ")
- gpu.set(boxX + 2, boxY + 1, dischargeText)
- -- Render charge rate
- local chargeText = string.format("Charge Rate:%.2f RF/t", chargeRate)
- gpu.setBackground(0x808080)
- gpu.setForeground(0x00FF00)
- gpu.fill(boxX + 2+string.len(chargeText)-string.len(chargeRate), boxY + 2, string.len(chargeRate)+5, 1, " ")
- gpu.set(boxX + 2, boxY + 2, chargeText)
- local averageDischargeText = string.format("Average Discharge Rate:%.2f RF/t", averageDischarge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFF0000)
- gpu.fill(boxX + 2+string.len(averageDischargeText)-string.len(averageDischarge), boxY + 3, string.len(averageDischarge)+5, 1, " ")
- gpu.set(boxX + 2, boxY + 3, averageDischargeText)
- local averageChargeText = string.format("Average Charge Rate:%.2f RF/t", averageCharge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0x00FF00)
- gpu.fill(boxX + 2+string.len(averageChargeText)-string.len(averageCharge), boxY + 4, string.len(averageCharge)+5, 1, " ")
- gpu.set(boxX + 2, boxY + 4, averageChargeText)
- -- Update energy and progress bar
- energy = energyCube.getEnergyStored()
- progressBar:update(energy)
- end
- function drawEnergyPanel()
- -- Render discharge and charge rates
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- gpu.fill(1, 1, 160, 50, ' ')
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- gpu.set(progressBar.x+progressBar.width/2-string.len("Current Energy: ")+8/2, progressBar.y + progressBar.height + 1, "Current Energy: " .. tostring(energy))
- gpu.set(progressBar.x+progressBar.width/2-string.len("Max Energy: ")+8/2, progressBar.y + progressBar.height + 2, "Max Energy: " .. tostring(maxEnergy))
- -- Draw gray box
- gpu.setBackground(0x808080)
- gpu.fill(boxX, boxY, boxWidth, boxHeight, ' ')
- local averageDischargeText = string.format("Average Discharge Rate:%.2f RF/t", averageDischarge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 3, averageDischargeText)
- local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 4, averageChargeText)
- -- Render discharge rate
- local dischargeText = string.format("Discharge Rate: %.2f RF/t", dischargeRate)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 1, dischargeText)
- -- Render charge rate
- local chargeText = string.format("Charge Rate: %.2f RF/t", chargeRate)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 2, chargeText)
- local averageDischargeText = string.format("Average Discharge Rate: %.2f RF/t", averageDischarge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 3, averageDischargeText)
- local averageChargeText = string.format("Average Charge Rate: %.2f RF/t", averageCharge)
- gpu.setBackground(0x808080)
- gpu.setForeground(0xFFFFFF)
- gpu.set(boxX + 2, boxY + 4, averageChargeText)
- end
- --================
- -- PART 3 END
- --================
- --================
- -- PART 4 START
- --================
- --[[
- local graph = {
- x = progressBar.x,
- y = progressBar.y + progressBar.height + 10,
- width = progressBar.width,
- height = 10,
- data = {},
- maxDataPoints = 100,
- }
- -- Graph add data
- function graph:addData(value)
- table.insert(self.data, 1, value)
- if #self.data > self.maxDataPoints then
- table.remove(self.data)
- end
- end
- -- Graph draw
- function graph:draw()
- -- Draw graph background
- gpu.setBackground(0x808080)
- gpu.fill(self.x, self.y, self.width, self.height, ' ')
- -- Calculate scale and offset for mapping data to graph coordinates
- local minData = math.min(table.unpack(self.data))
- local maxData = math.max(table.unpack(self.data))
- local scale = (maxData - minData) / self.height
- local xOffset = self.width / (#self.data - 1)
- -- Draw data points
- gpu.setBackground(0x00BFFF)
- for i = 2, #self.data do
- local x1 = self.x + (i - 2) * xOffset
- local x2 = self.x + (i - 1) * xOffset
- local y1 = self.y + self.height - math.floor((self.data[i - 1] - minData) / scale)
- local y2 = self.y + self.height - math.floor((self.data[i] - minData) / scale)
- gpu.fill(x1, y1, 1, 1, ' ')
- gpu.fill(x2, y2, 1, 1, ' ')
- gpu.fill(x1, y1, math.abs(x2 - x1) + 1, math.abs(y2 - y1) + 1, ' ')
- end
- -- Reset color to white
- gpu.setBackground(0xFFFFFF)
- end
- --]]
- --[[
- ╔════════════════════════════╗
- ║ MAIN PROGRAM INITIALIZATION║
- ╚════════════════════════════╝
- --]]
- function load()
- maxEnergy = energyCube.getMaxEnergyStored()
- gpu.setResolution(160, 50) -- Set screen resolution
- progressBar:load(2, 2, 158, 15, maxEnergy) -- Initialize progress bar
- loadEnergyPanel()
- engine:load() -- Initialize engine
- loadEnginPanel()
- --fluidTank:load()
- end
- --================
- -- PART 4 END
- --================
- --================
- -- PART 5 START
- --================
- --[[
- ╔═══════════════════════╗
- ║ MAIN PROGRAM LOOP ║
- ╚═══════════════════════╝
- --]]
- function update()
- -- Check bundled inputs
- local orangeInput = component.redstone.getBundledInput(3, 1) or 0
- local whiteInput = component.redstone.getBundledInput(3, 0) or 0
- -- Check if animation should run
- shouldAnimate = orangeInput > 1 or whiteInput > 1
- if shouldAnimate then
- engine:update()
- end
- -- Check thresholds and set bundled wire outputs
- if energy <= onThreshold then
- -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
- enableWireBank(0)
- enableWireBank(1) -- Disable orange wire output
- elseif energy >= offThreshold then
- -- Set bundled wire outputs to white (bit 0) and orange (bit 1)
- disableWireBank(0) -- Disable orange wire output
- disableWireBank(1) -- Disable white wire output
- end
- --fluidTank:update()
- updateEnergyPanel()
- updateEnginePanel()
- --engine:draw()
- end
- --================
- -- PART 5 END
- --================
- --================
- --FINAL PART START
- --================
- function draw()
- -- Clear screen
- drawEnergyPanel()
- engine:draw()
- drawEnginePanel()
- progressBar:draw()
- -- Reset color to white
- gpu.setBackground(0xFFFFFF)
- --fluidTank:draw()
- end
- --[[
- ╔═══════════════════════════╗
- ║MAIN PROGRAM INITIALIZATION║
- ╚═══════════════════════════╝
- --]]
- function main()
- load()
- draw()
- while true do
- update()
- os.sleep(0.0) -- Wait for 0.1 seconds before updating again
- end
- end
- -- Run the program
- main()
- --================
- --FINAL PART END
- --================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement