Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --modpack configs
- reactorOutputMultiplier = 1.0
- reactorFuelUsageMultiplier = 1.0
- -- please report any bugs to @jona23 on discord
- ------------------------------------------------------------------------------------------------
- -- SETUP
- -- 1. Build a Draconic Reactor
- -- 2. Place a flux gate behind it's energy injector facing into it (this is the input gate).
- -- 3. Place one or more flux gates beind a stabilizer facing away from it (this is the output gate).
- -- 4. Connect the output gate(s) to the input of your energy storage (make sure it can handle 25m+rf/t).
- -- 5. Connect the input gate to the output of your energy storage, AVOID DISCONNECTING AT ALL COSTS!
- -- 6. Put a monitor somewhere, 3 tall and minimum 5 wide!
- -- 7. Place down a computer and using Wired Modems and Networking Cables, connect your flux
- -- gates, monitor, computer, and a reactor stabilizer to the network!
- -- 8. Now type "pastebin get KKpxW74v startup.lua" into your computer, then type in "startup"
- -- 9. Configure the script to your likings and press "initialize script"
- -- 10. Done! Fuel up your reactor and hit "start" on the monitor.
- ------------------------------------------------------------------------------------------------
- -- DO NOT:
- -- - Break flux gates, this will mess up the peripheral names!
- -- - Use between minecraft version updates, this will also mess up peripheral names!
- -- - Delete config.txt while the reactor is running, this will cause many problems.
- -- - Move the computer if a flux gate is next to it.
- -- - Install the script whilst the reactor is running, it knows which flux gate is the input/output by powering them and checking if the shield goes up or no.
- -- If your script is crashing, manually hit shutdown on the reactor and let it cool down,
- -- then and ONLY THEN type "delete config.txt" into the computer.
- -- Doing this will reset all your precious values you set!
- -- INFO
- -- This program calculates the reactor's input/output based only the amount
- -- of fuel it has, and on it's conversion level! No heat, no shield just conversion (aka passive)
- -- Therefore it dosent care about flux gates being disconnected nor server lag
- -- you can even shutdown and start the program while the reactor is running!
- -- TEST IN CREATIVE BEFORE USING IN SURVIVAL! I CAN'T ENSURE YOU'RE DOING EVERYTHING CORRECTLY!
- -- CONFIGS
- -- 1.12 mode: Makes the script work in 1.12.2 (and possibly 1.7.10) by changing the flux gate's names
- -- Fancy Startup: Makes the reactor start up slowly and smoothly, cinematic!
- -- Safety Systems: Disables limit on the sliders, if you like your base and it's sorroundings i dont recommend disabling
- -- Keepalive Signal: Outputs a blinking redstone signal on the computer's back, allowing redstone to detect if the script crashes (this gets disabled if the reactor goes overload!)
- -- Compact Mode: Disables the reactor visualization rendering, allowing for a smaller screen
- ------------------------------------------------------------------------------------------------
- -- !!!!!!! Do not change anything below !!!!!!!
- --warnings
- function energyCoreFullWarning()
- gWrite("! ATTENTION !", corePosX-5, corePosY-1, colors.black, coreColor)
- gWrite("ENERGY CORE FULL!", corePosX-7, corePosY, colors.black, coreColor)
- end
- function fuelConversionWarning()
- gWrite("! ATTENTION !", corePosX-5, corePosY-1, colors.black, coreColor)
- gWrite("FUEL CONVERSION", corePosX-7, corePosY, colors.black, coreColor)
- gWrite("ABOVE SET LIMITS!", corePosX-7, corePosY+1, colors.black, coreColor)
- gWrite("SHUTTING DOWN...", corePosX-7, corePosY+2, colors.black, coreColor)
- end
- function powerOutputWarning()
- gWrite("!! WARNING !!", corePosX-5, corePosY-1, colors.black, coreColor)
- gWrite("INSUFFICIENT", corePosX-7, corePosY, colors.black, coreColor)
- gWrite("OUTPUT FOR SELF-", corePosX-7, corePosY+1, colors.black, coreColor)
- gWrite("SUSTAINABILITY", corePosX-7, corePosY+2, colors.black, coreColor)
- end
- function reactorBoomWarning()
- gWrite("!! DANGER !!", corePosX-5, corePosY-1, colors.black, coreColor)
- gWrite("CORE DESTABILIZED", corePosX-7, corePosY, colors.black, coreColor)
- gWrite("!! EXPLOSION !!", corePosX-6, corePosY+1, colors.black, coreColor)
- gWrite("!! IMMINENT !!", corePosX-6, corePosY+2, colors.black, coreColor)
- end
- function noInputGatePower()
- gWrite("INPUT GATE IS", corePosX-6, corePosY, colors.black, coreColor)
- gWrite("NOT CONNECTED TO", corePosX-7, corePosY+1, colors.black, coreColor)
- gWrite("POWER!", corePosX-2, corePosY+2, colors.black, coreColor)
- end
- --save/load config functions
- function saveConfig()
- config = fs.open("config.txt", "w")
- config.writeLine(tempTarget)
- config.writeLine(fieldTarget)
- config.writeLine(saturationTarget)
- config.writeLine(fuelUseRateTarget)
- config.writeLine(conversionTarget)
- config.writeLine(powerOutputTarget)
- config.writeLine(fancyStartup)
- config.writeLine(safetySystems)
- config.writeLine(onePointTwelveMode)
- config.writeLine(controlSelected)
- config.writeLine(scriptInitialized)
- config.writeLine(controlsLocked)
- config.writeLine(targetPowerOutput)
- config.writeLine(targetPowerInput)
- config.writeLine(keepaliveSignal)
- config.writeLine(compactMode)
- if inputGate then
- config.writeLine(inputGate.name)
- end
- config.close()
- end
- function loadConfig()
- config = fs.open("config.txt", "r")
- tempTarget = tonumber(config.readLine())
- fieldTarget = tonumber(config.readLine())
- saturationTarget = tonumber(config.readLine())
- fuelUseRateTarget = tonumber(config.readLine())
- conversionTarget = tonumber(config.readLine())
- powerOutputTarget = tonumber(config.readLine())
- fancyStartup = tonumber(config.readLine())
- safetySystems = tonumber(config.readLine())
- onePointTwelveMode = tonumber(config.readLine())
- controlSelected = tonumber(config.readLine())
- scriptInitialized = tonumber(config.readLine())
- controlsLocked = tonumber(config.readLine())
- targetPowerOutput = tonumber(config.readLine())
- targetPowerInput = tonumber(config.readLine())
- keepaliveSignal = tonumber(config.readLine())
- compactMode = tonumber(config.readLine())
- local inputGateName = "flow_gate_0"
- local outputGateName = "flow_gate_2"
- if inputGateName then
- inputGate = nameWrap(inputGateName)
- inputGate.setOverrideEnabled(true)
- end
- if outputGateName then
- outputGate = nameWrap(outputGateName)
- outputGate.setOverrideEnabled(true)
- end
- config.close()
- end
- --periphSearch function by https:--github.com/acidjazz/drgfx/blob/master/drgfx.lua
- function periphSearch(type)
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == type then
- return peripheral.wrap(name)
- end
- end
- return null
- end
- function nameWrap(name)
- local table = peripheral.wrap(name)
- if not table then
- print('"' .. name .. '"')
- error("This flux gate was once connected to the computer, but now it cant be found! Check for disconneced modems or broken cables, if that dosent work type \"delete config.txt\"")
- end
- table.name = name
- return table
- end
- function secondsToTimeString(seconds)
- local days = math.floor(seconds / (24 * 3600))
- local hours = math.floor((seconds % (24 * 3600)) / 3600)
- local minutes = math.floor((seconds % 3600) / 60)
- local remainingSeconds = math.floor(seconds % 60)
- local formattedTime = string.format("%sd %sh %sm %ss", days, hours, minutes, remainingSeconds)
- return formattedTime
- end
- function secondsToTimeStringExtended(seconds)
- local years = math.floor(seconds / (365 * 24 * 3600))
- local days = math.floor((seconds % (365 * 24 * 3600)) / (24 * 3600))
- local hours = math.floor((seconds % (24 * 3600)) / 3600)
- local minutes = math.floor((seconds % 3600) / 60)
- local remainingSeconds = math.floor(seconds % 60)
- local formattedTime = string.format("%sy %sd %sh %sm %ss", years, days, hours, minutes, remainingSeconds)
- return formattedTime
- end
- function toggle(boolean)
- if boolean == 1 then
- return 0
- else
- return 1
- end
- end
- function gWrite(text, x, y, cl, clBg)
- gfx.setCursorPos(x, y)
- gfx.setTextColor(cl)
- gfx.setBackgroundColor(clBg)
- gfx.write(text)
- end
- function gWriteR(text, x, y, cl, clBg)
- gWrite(text, gfx.xRes - string.len(tostring(text)) - x, y, cl, clBg)
- end
- function gBlit(x,y,text,cl,clBg)
- gfx.setCursorPos(x, y)
- gfx.blit(text, cl, clBg)
- end
- function gBlitR(x,y,text,cl,clBg)
- gfx.setCursorPos(gfx.xRes - string.len(tostring(text)) - x + 1, y)
- gfx.blit(text, cl, clBg)
- end
- function gWriteTransparent(text, x, y, cl)
- gfx.setCursorPos(x, y)
- _, _, lineColors = gfx.getLine(y)
- length = string.len(text)
- lineColor = string.sub(lineColors, x, x + length - 1)
- gfx.blit(text, string.rep(colors.toBlit(cl), length), lineColor)
- end
- function gClear()
- gfx.setBackgroundColor(colors.black)
- gfx.clear()
- end
- function gDrawLine(x, y, length, cl)
- if length < 0 then
- return
- end
- gfx.setCursorPos(x, y)
- if cl ~= nil then
- gfx.setBackgroundColor(cl)
- end
- gfx.write(string.rep(" ", length))
- end
- function gDrawProgressBar(x, y, length, proportion, cl, clBg)
- if proportion < 0.0 or proportion > 1.0 then
- gDrawLine(x, y, length, cl)
- else
- gDrawLine(x, y, length, clBg)
- gDrawLine(x, y, math.floor(proportion*length), cl)
- end
- end
- function calculateTargetIO(targetShield, targetTemp, fuelConversion, maxFuelConversion)
- coreFuelMultiplier = maxFuelConversion / 10368
- maxEnergySaturation = coreFuelMultiplier * 1000000000
- targetTemp50 = math.min((targetTemp / 10000) * 50, 99)
- convLVL = ((fuelConversion - fuelUseRate/300000) / (maxFuelConversion + fuelUseRate/300000) * 1.3) - 0.3
- targetTempResist = ((targetTemp50^4) / (100 - targetTemp50))
- targetTempExpo = -(targetTempResist*convLVL) - 1000*convLVL + targetTempResist
- term1 = 1334.1-(3*targetTempExpo)
- term2 = (1200690-(2700*targetTempExpo))^2
- term3 = ((-1350*targetTempExpo)+(((-4*term1^3+term2)^(1/2))/2)+600345)^(1/3)
- targetNegCSat = -(term1/(3*term3))-(term3/3)
- targetCoreSat = 1 - (targetNegCSat/99)
- targetSat = targetCoreSat * maxEnergySaturation
- baseMaxRFt = ((maxEnergySaturation / 1000) * 1.5 * 10)
- maxRFt = (baseMaxRFt * (1 + (convLVL * 2)))
- targetPowerOutput = ((1 - targetCoreSat) * maxRFt)
- if targetTemp > 8000 then
- tempDrainFactor = 1 + ((targetTemp-8000)^2 * 0.0000025)
- elseif targetTemp > 2000 then
- tempDrainFactor = 1
- elseif targetTemp > 1000 then
- tempDrainFactor = (targetTemp-1000)/1000
- else
- tempDrainFactor = 0
- end
- fuelUseRate = (tempDrainFactor*(1-targetCoreSat)*(0.005)*1000000)*reactorFuelUsageMultiplier
- maxFieldStrength = maxEnergySaturation/10
- fieldDrain = math.min(tempDrainFactor * math.max(0.01, (1 - targetCoreSat)) * (baseMaxRFt / 10.923556), 2147483647)
- fieldNegPercent = 1 - targetShield/100
- targetPowerInput = fieldDrain / fieldNegPercent
- return targetPowerInput, targetPowerOutput
- end
- --Always runs every time when the script starts
- if fs.exists("config.txt") then
- print("Loading config...")
- loadConfig()
- else
- print("Creating config...")
- tempTarget = 8000
- fieldTarget = 20
- fancyStartup = 0
- safetySystems = 1
- keepaliveSignal = 0
- onePointTwelveMode = 0
- saturationTarget = 11.33
- fuelUseRateTarget = 4433
- conversionTarget = 85
- powerOutputTarget = 3797871
- controlSelected = 0
- scriptInitialized = 0
- controlsLocked = 0
- targetPowerOutput = 0
- targetPowerInput = 0
- compactMode = 0
- saveConfig()
- print("Done!")
- end
- if onePointTwelveMode == 1 then
- TotalReactorOutputMultiplier = reactorOutputMultiplier/10
- fluxGateName = "flux_gate"
- else
- TotalReactorOutputMultiplier = reactorOutputMultiplier
- fluxGateName = "flow_gate"
- end
- reactor = periphSearch("draconic_reactor")
- if reactor == nil then
- error("No connected reactor was found!")
- end
- if reactor.getReactorInfo().fieldStrength ~= 0 and scriptInitialized == 0 then
- error("Hi, Im Mr. Error and i just saved your reactor from a rapid unscheduled disassembly because you didnt think of fully shutting it down before initializing this script!")
- end
- mon = periphSearch("monitor")
- if mon == nil then
- error("No connected monitor was found!")
- end
- energy_core = periphSearch("draconic_rf_storage")
- if energy_core == nil then
- print("No connected energy core found, skipping.")
- end
- gfx = window.create(mon, 1, 1, mon.getSize())
- gfx.xRes, gfx.yRes = gfx.getSize()
- fpscooldown = 0
- prevTime = 0
- scriptFPS = 0
- messageCooldown = 0
- currentTableValue = 0
- powerInput = 0
- explosionTextState = 0
- fuelUseRate = 0
- targetSat = 0
- indexSwitch = 0
- globalAnimationTimer = 0
- prevEnergyStored = 0
- shieldCoords = {{1,-5},{2,-5},{3,-5},{4,-5},{5,-5},{6,-4},{7,-4},{8,-3},{9,-2},{10,-1},{10,0},{10,1},{10,2},{9,3},{8,4},{7,5},{6,5},{5,6},{4,6},{3,6},{2,6},{1,6},{0,6},{-1,6},{-2,6},{-3,6},{-4,5},{-5,5},{-6,4},{-7,3},{-8,2},{-8,1},{-8,0},{-8,-1},{-7,-2},{-6,-3},{-5,-4},{-4,-4},{-3,-5},{-2,-5},{-1,-5},{0,-5}}
- print("Script Loaded!")
- --Runs every tick no matter what
- function update()
- while true do
- gClear()
- globalAnimationTimer = globalAnimationTimer + 1
- --check the script's fps every 10 ticks
- fpscooldown = fpscooldown + 1
- if fpscooldown >= 10 then
- currentTime = os.epoch("utc")
- scriptFPS = 10000/(currentTime - prevTime)
- prevTime = currentTime
- fpscooldown = 0
- end
- --read energy core
- if energy_core then
- energyStored = energy_core.getEnergyStored()
- end
- if energyStored then
- energyThroughput = energyStored - prevEnergyStored
- prevEnergyStored = energyStored
- end
- --check if the script is initialized, otherwise display the config screen
- if scriptInitialized == 1 then
- info = reactor.getReactorInfo()
- if info then
- main()
- else
- gfx.setBackgroundColor(colors.blue)
- gfx.clear()
- gWrite("Reactor Disconnected", gfx.xRes/2 - 10, gfx.yRes/2, colors.white, colors.blue)
- end
- else
- configScreenSelected = true
- configScreen()
- gWrite("INITIALIZE SCRIPT", 8, 17, colors.white, colors.purple)
- end
- if scriptStatusDisplay ~= 0 then
- gWrite(" ", 1, gfx.yRes, colors.white, colors.green)
- scriptStatusDisplay = 0
- else
- gWrite(" ", 1, gfx.yRes, colors.white, colors.red)
- scriptStatusDisplay = 1
- end
- local barColor = colors.lightGray
- if controlsLocked == 1 then
- barColor = colors.gray
- end
- gDrawLine(2, gfx.yRes, gfx.xRes, barColor)
- gWrite("FPS: " .. math.floor(scriptFPS*10)/10, 2, gfx.yRes, colors.white, barColor)
- if energyStored then
- gWrite("E.S: " .. energyStored, 13, gfx.yRes, colors.white, barColor)
- end
- --update the display
- gfx.setVisible(true)
- gfx.setVisible(false)
- sleep()
- end
- end
- --the function that runs when the script is initialized
- function main()
- if keepaliveSignal == 1 and info.status ~= "beyond_hope" then
- if globalAnimationTimer % 10 >= 5 then
- redstone.setOutput("back", true)
- else
- redstone.setOutput("back", false)
- end
- end
- if not prevShield then
- prevShield = info.fieldStrength
- end
- fieldPercentage = info.fieldStrength / info.maxFieldStrength * 100
- fuelConversion = info.fuelConversion / info.maxFuelConversion * 100
- saturationPercentage = info.energySaturation / info.maxEnergySaturation * 100
- if info.status == "cold" then
- targetPowerInput = 0
- targetPowerOutput = 0
- else
- targetPowerInput, targetPowerOutput = calculateTargetIO(fieldTarget,tempTarget,info.fuelConversion,info.maxFuelConversion)
- end
- --startup logic
- if info.status == "warming_up" and not inputGate then
- targetPowerInput = 5
- targetPowerOutput = 0
- indexSwitch = indexSwitch + 1
- local gateNumber = math.floor(math.fmod(indexSwitch, 20)/10) + 1
- if fieldPercentage > 50 then
- reactor.stopReactor()
- error("Cannot index flux gates if shield is above 50%! Please wait for your reactor to fully shut down before initializing the script!")
- end
- print("Setting Override")
- inputGate.setFlowOverride(targetPowerInput)
- outputGate.setFlowOverride(0)
- end
- if info.status == "warming_up" and inputGate then
- targetPowerOutput = 0
- if fieldPercentage >= 10 or fancyStartup == 0 then
- if saturationPercentage >= 50 and fancyStartup ~= 0 then
- targetPowerInput = 500000*TotalReactorOutputMultiplier*coreFuelMultiplier
- else
- targetPowerInput = 100000000*TotalReactorOutputMultiplier*coreFuelMultiplier
- end
- else
- targetPowerInput = 10000*TotalReactorOutputMultiplier*coreFuelMultiplier
- end
- if info.temperature >= 2000 then
- reactor.activateReactor()
- end
- end
- --conversion rate shutdown
- if info.status == "running" and fuelConversion >= conversionTarget then
- reactor.stopReactor()
- print("Fuel conversion levels above set target. Stopping reactor!")
- end
- --do not update input unless its enough to sustain shield
- if info.temperature-10 <= tempTarget or targetPowerInput > powerInput or info.status ~= "running" then
- powerInput = targetPowerInput
- end
- if inputGate then
- inputGate.setFlowOverride(powerInput)
- outputGate.setFlowOverride(targetPowerOutput / 1)
- end
- if configScreenSelected == true then
- configScreen()
- else
- controlScreen()
- end
- prevShield = info.fieldStrength
- end
- --the screen where you control the reactor
- function controlScreen()
- corePosX = gfx.xRes/2
- corePosY = gfx.yRes/2-2
- coreColor = colors.gray
- if energyStored then
- if energyThroughput < 0 and info.status == "running" then
- local explosionETA = math.max(0,(energyStored / -energyThroughput)/20)
- gWrite("Explosion In: " .. secondsToTimeStringExtended(explosionETA), corePosX-13, 18, colors.yellow, colors.red)
- end
- end
- gWrite("CONFIG", 8, 17, colors.white, colors.purple)
- remainingFuel = (info.maxFuelConversion - info.fuelConversion) * 1000
- fuelTargetRemove = (info.maxFuelConversion * 1000 * ((100 - conversionTarget)/100))
- reactableFuel = remainingFuel - fuelTargetRemove
- fuelETA = (reactableFuel / fuelUseRate) * 1000 / 20
- if fuelETA < 0 then
- fuelETA = 0
- end
- if info.status == "stopping" or info.status == "cold" or info.status == "cooling" then
- if info.maxFuelConversion ~= 0 then
- gWrite("START", 2, 17, colors.white, colors.green)
- end
- elseif info.status ~= "beyond_hope" then
- gWrite("STOP", 2, 17, colors.white, colors.red)
- else
- gWrite("RUN!", 2, 17, colors.yellow, colors.red)
- end
- if info.status == "running" or info.status == "stopping" then
- if info.temperature > 10000 then
- coreColor = colors.white
- elseif info.temperature > 9000 then
- coreColor = colors.yellow
- elseif info.temperature > 5700 then
- coreColor = colors.orange
- else
- coreColor = colors.red
- end
- elseif info.status == "cold" then
- coreColor = colors.gray
- elseif info.status == "warming_up" then
- coreColor = colors.lightGray
- end
- shieldColorTMP = colors.gray
- shieldColorTMP2 = colors.gray
- if fieldPercentage > 50 then
- shieldColorTMP2 = colors.lightBlue
- elseif fieldPercentage > 25 then
- shieldColorTMP2 = colors.cyan
- else
- shieldColorTMP2 = colors.blue
- end
- if info.status == "beyond_hope" then
- shieldColorTMP = colors.magenta
- shieldColorTMP2 = colors.magenta
- coreColor = colors.pink
- if math.random(0,100) > 90 then
- coreColor = colors.white
- end
- end
- if compactMode == 0 then
- for k, v in pairs(shieldCoords) do
- if fieldPercentage > k/#shieldCoords*10 then
- shieldColor = shieldColorTMP2
- else
- shieldColor = shieldColorTMP
- end
- if info.status == "running" and (k == math.fmod(globalAnimationTimer,#shieldCoords)+1 or k == math.fmod(math.floor(globalAnimationTimer/2),#shieldCoords)+1 or k == math.fmod(math.floor(globalAnimationTimer/3),#shieldCoords)+1) then
- shieldColor = colors.cyan
- end
- gWrite(" ", corePosX+v[1], corePosY+v[2], colors.black, shieldColor)
- end
- gDrawLine(corePosX-3, corePosY-4, 9, coreColor)
- gDrawLine(corePosX-5, corePosY-3, 13, coreColor)
- gDrawLine(corePosX-6, corePosY-2, 15, coreColor)
- gDrawLine(corePosX-7, corePosY-1, 17, coreColor)
- gDrawLine(corePosX-7, corePosY, 17, coreColor)
- gDrawLine(corePosX-7, corePosY+1, 17, coreColor)
- gDrawLine(corePosX-7, corePosY+2, 17, coreColor)
- gDrawLine(corePosX-6, corePosY+3, 15, coreColor)
- gDrawLine(corePosX-5, corePosY+4, 13, coreColor)
- gDrawLine(corePosX-3, corePosY+5, 9, coreColor)
- end
- warnings = {}
- messageCooldown = messageCooldown + 1
- if energyStored and energyStored > energy_core.getMaxEnergyStored()-energyThroughput and energy_core.getMaxEnergyStored() ~= 2^64/2 then
- table.insert(warnings, energyCoreFullWarning)
- end
- if fuelConversion >= conversionTarget then
- table.insert(warnings, fuelConversionWarning)
- end
- if targetPowerOutput < targetPowerInput and inputGate then
- table.insert(warnings, powerOutputWarning)
- end
- if info.status == "beyond_hope" then
- table.insert(warnings, reactorBoomWarning)
- end
- if info.status == "warming_up" and indexSwitch > 40 and not inputGate then
- table.insert(warnings, noInputGatePower)
- end
- if messageCooldown > 20 then
- currentTableValue = currentTableValue + 1
- messageCooldown = 0
- end
- if currentTableValue > #warnings then
- currentTableValue = 1
- end
- if warnings[currentTableValue] then
- warnings[currentTableValue]()
- end
- if info.maxFuelConversion < 144 then
- gWrite("Not Enough Fuel!", corePosX-8, 1, colors.orange, colors.black)
- elseif info.status == "cold" then
- gWrite("Reactor Offline", corePosX-6, 1, colors.lightGray, colors.black)
- elseif info.status == "warming_up" then
- if inputGate then
- gWrite("Charging Reactor...", corePosX-8, 1, colors.blue, colors.black)
- else
- gWrite("Indexing Flux Gates...", corePosX-9, 1, colors.pink, colors.black)
- end
- elseif info.status == "running" then
- gWrite("Reactor Online", corePosX-6, 1, colors.lime, colors.black)
- elseif info.status == "stopping" then
- gWrite("Shutting Down...", corePosX-6, 1, colors.yellow, colors.black)
- elseif info.status == "cooling" then
- gWrite("Cooling Down...", corePosX-6, 1, colors.cyan, colors.black)
- elseif info.status == "beyond_hope" then
- explosionTextState = explosionTextState + 1
- if explosionTextState > 5 then
- if explosionTextState > 10 then
- explosionTextState = 0
- end
- gDrawLine(0,0,gfx.xRes,colors.red)
- gWrite("!!!EXPLOSION IMMINENT!!!", corePosX-12, 1, colors.orange, colors.red)
- else
- gDrawLine(0,0,gfx.xRes,colors.orange)
- gWrite("!!!EXPLOSION IMMINENT!!!", corePosX-12, 1, colors.red, colors.orange)
- end
- end
- --display core temp controls
- gWrite("Core Temp: " .. math.floor(info.temperature*(100-(compactMode*99)))/(100-(compactMode*99)) .. "\176C", 2, 2, colors.white, colors.black)
- gWrite("Target: " .. math.floor(tempTarget*1000.0)/1000.0 .. "\176C", 2, 3, colors.white, colors.black)
- gBlit(2, 4, "< << <<< >>> >> >","00000000000000000","bfbbfbbbfbbbfbbfb")
- if math.floor(info.temperature) > math.floor(tempTarget) then
- tempLineColor = colors.red
- elseif math.floor(info.temperature) < math.floor(tempTarget) then
- tempLineColor = colors.yellow
- else
- tempLineColor = colors.green
- end
- gDrawProgressBar(1, 5, 19, info.temperature/16000.0, tempLineColor, colors.gray)
- --display field controls
- gWrite("Field: " .. math.floor(fieldPercentage*100000000)/100000000 .. "%", 2, 7, colors.white, colors.black)
- gWrite("Target: " .. fieldTarget .. "%", 2, 8, colors.white, colors.black)
- gBlit(2, 9, "< << <<< >>> >> >","00000000000000000","bfbbfbbbfbbbfbbfb")
- if math.floor(info.fieldStrength/info.maxFieldStrength*1000.0)/10.0 > fieldTarget+0.1 then
- fieldLineColor = colors.yellow
- elseif math.floor((info.fieldStrength+1000)/info.maxFieldStrength*1000.0)/10.0 < fieldTarget-0.1 then
- fieldLineColor = colors.red
- else
- fieldLineColor = colors.green
- end
- if fieldStrength == 0 then
- fieldAdder = 0.1
- else
- fieldAdder = 0
- end
- gDrawProgressBar(1, 10, 19, (math.floor((info.fieldStrength+1000)/info.maxFieldStrength*10*10)/100) + fieldAdder, fieldLineColor, colors.gray)
- --display saturation controls
- gWrite("Saturation: " .. math.floor(saturationPercentage*(100-(compactMode*99)))/(100-(compactMode*99)) .. "%", 2, 12, colors.white, colors.black)
- gWrite("Target: " .. math.min(100,math.floor(targetSat/info.maxEnergySaturation*10000)/100) .. "%", 2, 13, colors.white, colors.black)
- --gBlit(2, 14, "< << <<< >>> >> >","00000000000000000","bfbbfbbbfbbbfbbfb")
- if math.floor(info.energySaturation/10000000*100.0)/100.0 < math.floor(targetSat/10000000*10.0*10)/100.0 then
- saturationLineColor = colors.red
- elseif math.floor(info.energySaturation/10000000*100.0)/100.0 > math.floor(targetSat/10000000*10.0*10)/100.0 then
- saturationLineColor = colors.yellow
- else
- saturationLineColor = colors.green
- end
- gDrawProgressBar(1, 15, 19, math.floor(info.energySaturation/info.maxEnergySaturation*1100.0*10)/10000.0, saturationLineColor, colors.gray)
- --display conversion rate controls
- gWriteR(math.floor(fuelUseRate*1)/1.0 .. "nb/t" .. " :Conv Rate", 0, 2, colors.white, colors.black)
- gWriteR(math.floor(10*1)/1.0 .. "nb/t " .. " :Target", 0, 3, colors.white, colors.black)
- if math.floor(fuelUseRate*1)/1.0 < math.floor(10*1)/1.0 then
- fuelUseRateLineColor = colors.yellow
- elseif math.floor(fuelUseRate*1)/1.0 > math.floor(10*1)/1.0 then
- fuelUseRateLineColor = colors.red
- else
- fuelUseRateLineColor = colors.green
- end
- gDrawProgressBar(gfx.xRes-18, 5, 19, fuelUseRate/20000, fuelUseRateLineColor, colors.gray)
- --display conversion level controls
- gWriteR(math.floor(fuelConversion*10)/10.0 .. "%" .. " :Conv Level", 0, 7, colors.white, colors.black)
- gWriteR(conversionTarget .. "%" .. " :Stop at", 0, 8, colors.white, colors.black)
- gBlitR(1, 9, "< << <<< >>> >> >","00000000000000000","bfbbfbbbfbbbfbbfb")
- if fuelConversion > conversionTarget then
- convLevelLineColor = colors.red
- elseif fuelConversion > conversionTarget/1.1 then
- convLevelLineColor = colors.orange
- elseif fuelConversion > conversionTarget/1.25 then
- convLevelLineColor = colors.yellow
- else
- convLevelLineColor = colors.green
- end
- local fuelBarFillage = fuelConversion / conversionTarget
- gDrawProgressBar(gfx.xRes-18, 10, 19, fuelBarFillage, convLevelLineColor, colors.gray)
- if fuelUseRate > 1 then
- gWriteTransparent(secondsToTimeString(fuelETA), gfx.xRes-18, 10, colors.white)
- else
- gWriteTransparent(("-:-d -:-h -:-m -:-s"), gfx.xRes-18, 10, colors.white)
- end
- --display generation rate controls
- gWriteR(math.floor(targetPowerOutput-targetPowerInput)/1.0 .. "RF/t" .. " :Total", 0, 12, colors.white, colors.black)
- gWriteR(math.floor(targetPowerOutput*1)/1.0 .. "RF/t" .. " :Target", 0, 13, colors.white, colors.black)
- if (targetPowerOutput-targetPowerInput)+1000*TotalReactorOutputMultiplier < math.floor(targetPowerOutput*1)/1.0 then
- outputLineColor = colors.red
- elseif (targetPowerOutput-targetPowerInput)-1000*TotalReactorOutputMultiplier > math.floor(targetPowerOutput*1)/1.0 then
- outputLineColor = colors.yellow
- else
- outputLineColor = colors.green
- end
- gDrawProgressBar(gfx.xRes-18, 15, 19, (info.generationRate-targetPowerInput*1)/25000000/TotalReactorOutputMultiplier, outputLineColor, colors.gray)
- gWrite("IN: " .. math.floor(powerInput) .. "RF/t", corePosX-6+compactMode*3, corePosY+8+compactMode, colors.green, colors.black)
- gWrite("OUT: " .. math.floor(targetPowerOutput) .. "RF/t", corePosX-7+compactMode*3, corePosY+9+compactMode, colors.red, colors.black)
- end
- --The function that detects if the monitor has been touched and then runs
- function monitorTouch()
- while true do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if configScreenSelected == true then
- --runs if config screen is selected and the monitor has been touched
- if yPos == 2 and xPos >= 15 and xPos <= 16 then
- onePointTwelveMode = toggle(onePointTwelveMode)
- elseif yPos == 3 and xPos >= 17 and xPos <= 18 then
- fancyStartup = toggle(fancyStartup)
- elseif yPos == 4 and xPos >= 18 and xPos <= 19 then
- safetySystems = toggle(safetySystems)
- elseif yPos == 5 and xPos >= 20 and xPos <= 21 then
- keepaliveSignal = toggle(keepaliveSignal)
- elseif yPos == 6 and xPos >= 16 and xPos <= 17 then
- compactMode = toggle(compactMode)
- end
- if scriptInitialized == 1 then
- if yPos == 17 and xPos >= 8 and xPos <= 13 then
- configScreenSelected = false
- end
- else
- if yPos == 17 and xPos >= 8 and xPos <= 24 then
- scriptInitialized = 1
- configScreenSelected = false
- gClear()
- gWrite('Your script has been initialized and configured.', 1,1,colors.white,colors.black)
- gWrite('Please restart it by typing "startup" into the computer', 1,2,colors.white,colors.black)
- gfx.setVisible(true)
- gfx.setVisible(false)
- print('Your script has been initialized and configured, please restart it by typing "startup"')
- saveConfig()
- error()
- end
- end
- else
- --runs if config screen is NOT selected and the monitor has been touched
- if yPos == 17 and xPos == 1 then
- controlsLocked = toggle(controlsLocked)
- end
- if controlsLocked ~= 1 then
- if yPos == 4 and xPos == 2 then
- tempTarget = tempTarget - 1.0
- controlSelected = 0
- elseif yPos == 4 and xPos >= 4 and xPos <= 5 then
- tempTarget = tempTarget - 10.0
- controlSelected = 0
- elseif yPos == 4 and xPos >= 7 and xPos <= 9 then
- tempTarget = tempTarget - 100.0
- controlSelected = 0
- elseif yPos == 4 and xPos >= 11 and xPos <= 13 then
- tempTarget = tempTarget + 100.0
- controlSelected = 0
- elseif yPos == 4 and xPos >= 15 and xPos <= 16 then
- tempTarget = tempTarget + 10.0
- controlSelected = 0
- elseif yPos == 4 and xPos == 18 then
- tempTarget = tempTarget + 1.0
- controlSelected = 0
- end
- if controlSelected == 0 then
- tempTarget = math.floor(tempTarget*1.0)/1.0
- if tempTarget < 2000 then
- tempTarget = 2000
- end
- end
- if fieldTarget <= 10 then
- fieldTargetSetDivider = 10
- else
- fieldTargetSetDivider = 1
- end
- if fieldTarget <= 9.999 then
- fieldTargetSetDivider2 = 10
- else
- fieldTargetSetDivider2 = 1
- end
- if yPos == 9 and xPos == 2 then
- fieldTarget = fieldTarget - 0.099/fieldTargetSetDivider
- elseif yPos == 9 and xPos >= 4 and xPos <= 5 then
- fieldTarget = fieldTarget - 0.999/fieldTargetSetDivider
- elseif yPos == 9 and xPos >= 7 and xPos <= 9 then
- fieldTarget = fieldTarget - 9.999/fieldTargetSetDivider
- elseif yPos == 9 and xPos >= 11 and xPos <= 13 then
- fieldTarget = fieldTarget + 10.001/fieldTargetSetDivider2
- elseif yPos == 9 and xPos >= 15 and xPos <= 16 then
- fieldTarget = fieldTarget + 1.001/fieldTargetSetDivider2
- elseif yPos == 9 and xPos == 18 then
- fieldTarget = fieldTarget + 0.101/fieldTargetSetDivider2
- end
- if fieldTarget <= 10 and fieldTargetSetDivider == 1 then
- fieldTarget = 10
- end
- if fieldTarget <= 10 then
- fieldTarget = math.floor(fieldTarget*10.0*10.0)/100.0
- else
- fieldTarget = math.floor(fieldTarget*10.0)/10.0
- end
- if fieldTarget < 0.00001 then
- fieldTarget = 0.00001
- elseif fieldTarget > 100 then
- fieldTarget = 100
- end
- --if yPos == 14 and xPos == 2 then
- -- saturationTarget = saturationTarget - 100000
- -- controlSelected = 2
- --elseif yPos == 14 and xPos >= 4 and xPos <= 5 then
- -- saturationTarget = saturationTarget - 1000000.0
- -- controlSelected = 2
- --elseif yPos == 14 and xPos >= 7 and xPos <= 9 then
- -- saturationTarget = saturationTarget - 10000000.0
- -- controlSelected = 2
- --elseif yPos == 14 and xPos >= 11 and xPos <= 13 then
- -- saturationTarget = saturationTarget + 10000000.0
- -- controlSelected = 2
- --elseif yPos == 14 and xPos >= 15 and xPos <= 16 then
- -- saturationTarget = saturationTarget + 1000000.0
- -- controlSelected = 2
- --elseif yPos == 14 and xPos == 18 then
- -- saturationTarget = saturationTarget + 100000
- -- controlSelected = 2
- --end
- --if controlSelected == 2 then
- -- if saturationTarget > 1000000000 then
- -- saturationTarget = 1000000000
- -- end
- -- if saturationTarget < 0 then
- -- saturationTarget = 0
- -- end
- --end
- --if fuelUseRateTarget >= 10000 then
- -- fuelUseRateTargetMultiplier = 10
- --else
- -- fuelUseRateTargetMultiplier = 1
- --end
- --if yPos == 4 and xPos == gfx.xRes-17 then
- -- fuelUseRateTarget = fuelUseRateTarget - 1*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 20000
- --elseif yPos == 4 and xPos >= gfx.xRes-15 and xPos <= gfx.xRes-14 then
- -- fuelUseRateTarget = fuelUseRateTarget - 10.0*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 200000
- --elseif yPos == 4 and xPos >= gfx.xRes-12 and xPos <= gfx.xRes-10 then
- -- fuelUseRateTarget = fuelUseRateTarget - 100.0*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 2000000
- --elseif yPos == 4 and xPos >= gfx.xRes-8 and xPos <= gfx.xRes-6 then
- -- fuelUseRateTarget = fuelUseRateTarget + 100.0*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 20000
- --elseif yPos == 4 and xPos >= gfx.xRes-4 and xPos <= gfx.xRes-3 then
- -- fuelUseRateTarget = fuelUseRateTarget + 10.0*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 20000
- --elseif yPos == 4 and xPos == gfx.xRes-1 then
- -- fuelUseRateTarget = fuelUseRateTarget + 1*fuelUseRateTargetMultiplier
- -- controlSelected = 3
- -- prevLowestSatSubtractor = 20000
- --end
- --if controlSelected == 3 then
- -- if fuelUseRateTarget < 500 then
- -- fuelUseRateTarget = 500.5
- -- end
- --end
- if yPos == 9 and xPos == gfx.xRes-17 then
- conversionTarget = conversionTarget - 0.1
- elseif yPos == 9 and xPos >= gfx.xRes-15 and xPos <= gfx.xRes-14 then
- conversionTarget = conversionTarget - 1.0
- elseif yPos == 9 and xPos >= gfx.xRes-12 and xPos <= gfx.xRes-10 then
- conversionTarget = conversionTarget - 10.0
- elseif yPos == 9 and xPos >= gfx.xRes-8 and xPos <= gfx.xRes-6 then
- conversionTarget = conversionTarget + 10.0
- elseif yPos == 9 and xPos >= gfx.xRes-4 and xPos <= gfx.xRes-3 then
- conversionTarget = conversionTarget + 1.0
- elseif yPos == 9 and xPos == gfx.xRes-1 then
- conversionTarget = conversionTarget + 0.1
- end
- if conversionTarget > 100 then
- conversionTarget = 100
- end
- if conversionTarget < 0 then
- conversionTarget = 0
- end
- --if yPos == 14 and xPos == gfx.xRes-17 then
- -- targetPowerOutput = targetPowerOutput - 1000.0
- -- controlSelected = 5
- --elseif yPos == 14 and xPos >= gfx.xRes-15 and xPos <= gfx.xRes-14 then
- -- targetPowerOutput = targetPowerOutput - 10000.0
- -- controlSelected = 5
- --elseif yPos == 14 and xPos >= gfx.xRes-12 and xPos <= gfx.xRes-10 then
- -- targetPowerOutput = targetPowerOutput - 100000.0
- -- controlSelected = 5
- --elseif yPos == 14 and xPos >= gfx.xRes-8 and xPos <= gfx.xRes-6 then
- -- targetPowerOutput = targetPowerOutput + 100000.0
- -- controlSelected = 5
- --elseif yPos == 14 and xPos >= gfx.xRes-4 and xPos <= gfx.xRes-3 then
- -- targetPowerOutput = targetPowerOutput + 10000.0
- -- controlSelected = 5
- --elseif yPos == 14 and xPos == gfx.xRes-1 then
- -- targetPowerOutput = targetPowerOutput + 1000.0
- -- controlSelected = 5
- --end
- --if targetPowerOutput < 0*TotalReactorOutputMultiplier then
- -- targetPowerOutput = 0*TotalReactorOutputMultiplier
- --end
- if safetySystems == 1 then
- if tempTarget > 10000 then
- tempTarget = 10000
- end
- if conversionTarget > 90 then
- conversionTarget = 90
- end
- --if fuelUseRateTarget > 51000.5 then
- -- fuelUseRateTarget = 51000.5
- --end
- --if saturationTarget < 85000000 then
- -- saturationTarget = 85000000
- --end
- if fieldTarget <= 5 and safetySystems == 1 then
- fieldTarget = 5
- end
- end
- if yPos == 17 and xPos >= 2 and xPos <= 5 then
- if info.status == "cold" or info.status == "cooling" or info.status == "stopping" then
- indexSwitch = 0
- reactor.chargeReactor()
- reactor.activateReactor()
- else
- reactor.stopReactor()
- end
- end
- if yPos == 17 and xPos >= 8 and xPos <= 13 then
- configScreenSelected = true
- end
- end
- end
- saveConfig()
- end
- end
- function configScreen()
- gWrite("1.12.2 Mode:", 2, 2, colors.white, colors.black)
- gWrite("Fancy Startup:", 2, 3, colors.white, colors.black)
- gWrite("Safety Systems:", 2, 4, colors.white, colors.black)
- gWrite("Keepalive Signal:", 2, 5, colors.white, colors.black)
- gWrite("Compact Mode:", 2, 6, colors.white, colors.black)
- if onePointTwelveMode == 1 then
- gWrite("ON", 15, 2, colors.white, colors.green)
- else
- gWrite("OF", 15, 2, colors.white, colors.red)
- end
- if fancyStartup == 1 then
- gWrite("ON", 17, 3, colors.white, colors.green)
- else
- gWrite("OF", 17, 3, colors.white, colors.red)
- end
- if safetySystems == 1 then
- gWrite("ON", 18, 4, colors.white, colors.green)
- else
- gWrite("OF", 18, 4, colors.white, colors.red)
- end
- if keepaliveSignal == 1 then
- gWrite("ON", 20, 5, colors.white, colors.green)
- else
- gWrite("OF", 20, 5, colors.white, colors.red)
- end
- if compactMode == 1 then
- gWrite("ON", 16, 6, colors.white, colors.green)
- else
- gWrite("OF", 16, 6, colors.white, colors.red)
- end
- gWrite("CONFIG", 8, 17, colors.white, colors.purple)
- end
- -- run the update function and the monitor function in parallel so the entire program dosent only tick when someone clicks the monitor
- parallel.waitForAny(update, monitorTouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement