Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This is Windows™ For Fusion Reactors.
- I am not responsible for the following misfortunes that may come as a result of using this program:
- -Loss of life
- -Bone loss
- -Accidental fusion of body parts
- -Vaporised teeth
- -Incineration by plasma
- and others.
- ]]--
- local UI = require "opus.ui"
- local Event = require "opus.event"
- local Util = require "opus.util"
- local combos = {
- ["hydrogen-hydrogen"] = 4430000000,
- ["hydrogen-deuterium"] = 1245000000,
- ["hydrogen-tritium"] = 6049000000,
- ["hydrogen-helium3"] = 3339000000,
- ["hydrogen-lithium6"] = 7278000000,
- ["hydrogen-lithium7"] = 5071000000,
- ["hydrogen-boron11"] = 16370000000,
- ["deuterium-deuterium"] = 1156000000,
- ["deuterium-tritium"] = 816000000,
- ["deuterium-helium3"] = 2632000000,
- ["deuterium-lithium6"] = 4818000000,
- ["deuterium-lithium7"] = 5034000000,
- ["deuterium-boron11"] = 16883000000,
- ["tritium-tritium"] = 897000000,
- ["tritium-helium3"] = 2604000000,
- ["tritium-lithium6"] = 4971000000,
- ["tritium-lithium7"] = 5511000000,
- ["tritium-boron11"] = 33215000000,
- ["helium3-helium3"] = 6605000000,
- ["helium3-lithium6"] = 9506000000,
- ["helium3-lithium7"] = 9673000000,
- ["helium3-boron11"] = 29574000000,
- ["lithium6-lithium6"] = 13732000000,
- ["lithium6-lithium7"] = 14536000000,
- ["lithium6-boron11"] = 37048000000,
- ["lithium7-lithium7"] = 16611000000,
- ["lithium7-boron11"] = 202000000000,
- ["boron11-boron11"] = 358000000000,
- ["Out of fuel"] = math.huge
- }
- local fuels = {
- ["hydrogen"] = "1H",
- ["deuterium"] = "2H",
- ["tritium"] = "3H",
- ["helium3"] = "3He",
- ["lithium6"] = "6Li",
- ["lithium7"] = "7Li",
- ["boron11"] = "11B",
- ["none"] = "none"
- }
- local termSize = { term.getSize() }
- local controllers = { peripheral.find "computer" }
- local modem = peripheral.find "modem"
- modem.open(1)
- for i,v in pairs(controllers) do
- v.turnOn()
- end
- local reactors = {}
- local reactorsLifetime = {}
- for i,v in ipairs(controllers) do
- modem.transmit(i, 1, "data")
- local e = { os.pullEvent "modem_message" }
- local data = e[5]
- local currData = {
- id = i,
- efficiency = data.efficiency > 100 and 100 or data.efficiency,
- temperature = data.temperature,
- power = data.power,
- fuelOne = data.fuelOne,
- fuelTwo = data.fuelTwo,
- problem = data.problem
- }
- local lifetimeData = {
- efficiency = { data.efficiency > 100 and 100 or data.efficiency },
- temperature = { data.temperature },
- power = { data.power },
- fuelOne = { data.fuelOne },
- fuelTwo = { data.fuelTwo },
- problem = { data.problem }
- }
- table.insert(reactors, currData)
- table.insert(reactorsLifetime, lifetimeData)
- end
- local function average(t)
- local total = 0
- for i, v in ipairs(t) do
- total = total + v
- end
- return total / #t
- end
- local function sum(t)
- local total = 0
- for i,v in ipairs(t) do
- total = total + v
- end
- return total
- end
- local function round(n, place)
- if place then return round(n / place) * place end
- return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
- end
- local function prettyTemp(t, place)
- local roundedTemp = round(t, place)
- if roundedTemp < 1000 then return roundedTemp.."K"
- elseif roundedTemp / 1000 < 1000 then return round(roundedTemp / 1000, 0.001).."kK"
- elseif roundedTemp / 1000000 < 1000 then return round(roundedTemp / 1000000, 0.001).."MK"
- elseif roundedTemp / 1000000000 < 1000 then return round(roundedTemp / 1000000000, 0.001).."GK"
- elseif roundedTemp / 1000000000000 < 1000 then return round(roundedTemp / 1000000000000, 0.001).."TK" end
- end
- local function prettyPow(t, place)
- local roundedPow = place ~= 0 and round(t, place) or t
- if roundedPow < 1000 then return roundedPow.."RF/t"
- elseif roundedPow / 1000 < 1000 then return round(roundedPow / 1000, 0.001).."kRF/t"
- elseif roundedPow / 1000000 < 1000 then return round(roundedPow / 1000000, 0.001).."MRF/t"
- elseif roundedPow / 1000000000 < 1000 then return round(roundedPow / 1000000000, 0.001).."GRF/t"
- elseif roundedPow / 1000000000000 < 1000 then return round(roundedPow / 1000000000000, 0.001).."TRF/t" end
- end
- local page = UI.Page {
- paused = false,
- index = 1,
- notification = UI.Notification { },
- menuBar = UI.MenuBar {
- buttons = menuButtons
- },
- reactorGrid = UI.ScrollingGrid {
- y = 1,
- reactorCount = #controllers,
- sortColumn = "id",
- values = reactors,
- columns = {
- { heading = "ID", key = "id", width = 2, align = "left" },
- { heading = "Temp", key = "temperature", width = 10, align = "left" },
- { heading = "Power", key = "power", width = 15, align = "left" },
- { heading = "Efficiency", key = "efficiency", width = 10, align = "left" }
- },
- autospace = true,
- getDisplayValues = function(_, row)
- row = Util.shallowCopy(row)
- if row.temperature then
- row.temperature = prettyTemp(row.temperature, 0.001)
- end
- if row.power then
- row.power = prettyPow(row.power, 0.001)
- end
- if row.efficiency then
- row.efficiency = round(row.efficiency, 0.001).."%"
- end
- return row
- end
- },
- reactorSlide = UI.SlideOut {
- titleBar = UI.TitleBar {
- title = "Reactor Stats",
- event = "reactor_close"
- },
- accelerators = {
- ["backspace"] = "reactor_close"
- },
- reactorMeta = UI.Grid {
- x = 1, y = 1, ex = termSize[1], height = termSize[2]-2,
- inactive = true,
- columns = {
- { key = "text", width = 12 },
- { key = "value", align = "left", textColor = colors.yellow }
- },
- values = {
- temperature = { text = "Temperature" },
- efficiency = { text = "Efficiency" },
- power = { text = "Power" },
- fuel = { text = "Fuel" },
- problem = { text = "Problem" }
- }
- }
- }
- }
- function page.reactorSlide:setReactor(reactor)
- self.currReactor = reactor
- local thisLifetimeData = reactorsLifetime[page.reactorSlide.currReactor.id]
- self.reactorMeta.values.temperature.value = round(page.reactorSlide.currReactor.temperature, 1).."K ("..round(average(thisLifetimeData.temperature), 1).."K avg)"
- self.reactorMeta.values.efficiency.value = round(page.reactorSlide.currReactor.efficiency, 0.000001).."% ("..round(average(thisLifetimeData.efficiency), 0.000001).."% avg)"
- self.reactorMeta.values.power.value = round(page.reactorSlide.currReactor.power, 0.001).."RF/t ("..round(average(thisLifetimeData.power), 0.001).."RF/t avg)"
- self.reactorMeta.values.fuel.value = fuels[page.reactorSlide.currReactor.fuelOne].."-"..fuels[page.reactorSlide.currReactor.fuelTwo]
- self.reactorMeta.values.problem.value = page.reactorSlide.currReactor.problem or "none"
- end
- function page.reactorSlide:show(reactor)
- self:setReactor(reactor)
- UI.SlideOut.show(self)
- end
- function page.reactorSlide:eventHandler(event)
- if event.type == "reactor_close" then
- self:hide()
- page:setFocus(page.reactorGrid)
- else return UI.SlideOut.eventHandler(self, event) end
- return true
- end
- function page:eventHandler(event)
- if event.type == "grid_select" then
- self.reactorSlide:show(event.selected)
- else return UI.Page.eventHandler(self, event) end
- return true
- end
- Event.onInterval(5, function()
- for i,v in ipairs(controllers) do
- modem.transmit(i, 1, "data")
- local e = { os.pullEvent "modem_message" }
- local data = e[5]
- local combo = { "Out of fuel" }
- if data.fuelOne and data.fuelTwo then
- combo = { data.fuelOne.."-"..data.fuelTwo, data.fuelTwo.."-"..data.fuelOne }
- end
- local currTemp = data.temperature
- local optimalTemp = combos[combo[1]] or combos[combo[2]]
- local isAboveTemp = (currTemp and optimalTemp) and currTemp - optimalTemp > 0 or false
- if isAboveTemp then
- modem.transmit(i, 1, "on")
- else
- modem.transmit(i, 1, "off")
- end
- local currData = {
- id = i,
- efficiency = data.efficiency > 100 and 100 or data.efficiency,
- temperature = data.temperature,
- power = data.power,
- fuelOne = data.fuelOne,
- fuelTwo = data.fuelTwo,
- problem = data.problem
- }
- reactors[i] = currData
- for k, v in pairs(currData) do
- if reactorsLifetime[i][k] then
- table.insert(reactorsLifetime[i][k], v)
- end
- end
- end
- page.reactorGrid:update()
- page.reactorGrid:draw()
- page:sync()
- end)
- UI:setPage(page)
- UI:start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement