Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Optimised Adaptive Turbine Controller with Feedback Rods
- --------------------------------------------------------
- * Layout, colours, button coordinates, labels and overall behaviour are **identical** to the original program supplied in your first message.
- * The **only** changes are internal optimisations (no blocking sleeps inside the main loop, nil‑safety, double‑buffered drawing) so the UI feels instantaneous.
- Version: 2025‑06‑14
- ]]--
- ---------------------------------------------------------------------
- -- 1. CONFIGURATION --------------------------------------------------
- ---------------------------------------------------------------------
- local reactorName = "BigReactors-Reactor_0"
- local turbineName = "BigReactors-Turbine_0"
- local monitorName = "monitor_0"
- local FLOW_PERSIST_FILE = "nominal_flow.txt"
- local RPM_TARGET, RPM_TOLERANCE = 1800, 5
- local COIL_ON_RPM = RPM_TARGET -- engage inductor when at or above
- local COIL_OFF_RPM = RPM_TARGET -- RPM_TOLERANCE -- disengage when below
- local FLOW_TUNE_LOWER, FLOW_TUNE_UPPER = 100, 2000 -- hard bounds
- local MAX_TUNE_ITER = 7 -- binary-search passes
- -- Fuel/control bar geometry (unchanged)
- local CTRLBAR_X, CTRLBAR_Y, CTRLBAR_WD, CTRLBAR_HT, CTRLBAR_SPC = 76, 6, 3, 30, 3
- local TURBAR_X, TURBAR_Y, TURBAR_WD, TURBAR_HT, TURBAR_SPC = 88, 6, 3, 30, 3
- -- RPM progress bar geometry
- local RPMBAR_X, RPMBAR_Y, RPMBAR_H, RPMBAR_W = 3, 21, 3, 70
- -- Dynamics
- local FLOW_BUFFER = 0.10 -- % extra flow when we are too slow
- local DECEL_FRACTION = 0.25 -- fraction of flow to keep when too fast
- local FLOW_LEARN_STEP = 2 -- learning granularity (mB/t per loop)
- -- UI refresh cadence (seconds). 0.25 s ⇒ 4 FPS; change if needed.
- local UPDATE_PERIOD = 0.25
- ---------------------------------------------------------------------
- -- 2. UTILITY HELPERS ------------------------------------------------
- ---------------------------------------------------------------------
- --- Return numeric `v` or fallback `d` if v is nil.
- local function num(v, d) if v == nil then return d end; return v end
- --- Pad a string on the right so residual characters are overwritten.
- local function pad(str, width)
- if #str < width then str = str .. string.rep(" ", width-#str) end
- return str
- end
- ---------------------------------------------------------------------
- -- 3. UI PRIMITIVES (unchanged API) ---------------------------------
- ---------------------------------------------------------------------
- UI = {}
- function UI.rectangle(wd,x,y,w,h,color)
- local win = window.create(wd,x,y,w,h,true)
- win.setBackgroundColor(color); win.clear(); return win
- end
- function UI.bar(wd,x,y,w,h,bg,segments,max)
- local bar = UI.rectangle(wd,x,y,w,h,bg)
- local total = max or 100
- if h < w then -- horizontal
- local px = 1
- for _,s in ipairs(segments) do
- local segW = math.floor((s.p/total)*w + 0.5)
- UI.rectangle(bar,px,1,segW,h,s.color); px = px+segW
- end
- else -- vertical (bottom‑up fill)
- local py = h
- for _,s in ipairs(segments) do
- local segH = math.floor((s.p/total)*h + 0.5)
- UI.rectangle(bar,1,py-segH+1,w,segH,s.color); py = py-segH
- end
- end
- end
- function UI.progress_bar(wd,x,y,w,h,p,bg,fg)
- UI.bar(wd,x,y,w,h,bg,{{p=p,color=fg}},100)
- end
- function UI.drawRect(wd,x,y,w,h,color)
- wd.setTextColor(color or colors.white)
- wd.setCursorPos(x,y); wd.write("+" .. string.rep("-",w-2) .. "+")
- for i=1,h-2 do wd.setCursorPos(x,y+i); wd.write("|" .. string.rep(" ",w-2) .. "|") end
- wd.setCursorPos(x,y+h-1); wd.write("+" .. string.rep("-",w-2) .. "+")
- end
- function UI.drawTable(wd,x,y,cols,rows,cellW,cellH,color)
- wd.setTextColor(color or colors.white)
- local tW,tH=cols*cellW+1,rows*cellH+1
- for dy=0,tH-1 do
- for dx=0,tW-1 do
- local cx,cy=x+dx,y+dy
- local rowLine=(dy%cellH==0); local colLine=(dx%cellW==0)
- local ch = (rowLine and colLine) and "+" or rowLine and "-" or colLine and "|" or " "
- wd.setCursorPos(cx,cy); wd.write(ch)
- end
- end
- end
- local function UIHeader(wd,x,y,w,h,text,bg,fg)
- local hdr=UI.rectangle(wd,x,y,w,h,bg)
- wd.setTextColor(fg)
- wd.setCursorPos(x+math.floor(w/2-#text/2),y+math.floor(h/2))
- wd.write(text)
- end
- ---------------------------------------------------------------------
- -- 4. PERIPHERAL SET‑UP ---------------------------------------------
- ---------------------------------------------------------------------
- local reactor = peripheral.wrap(reactorName) or error("Reactor not found")
- local turbine = peripheral.wrap(turbineName) or error("Turbine not found")
- local monitor = peripheral.wrap(monitorName) or peripheral.find("monitor") or error("Monitor not found")
- monitor.setTextScale(0.5)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- ---------------------------------------------------------------------
- -- 5. FLOW AUTOTUNE (runs once) -------------------------------------
- ---------------------------------------------------------------------
- local function readFlow()
- if fs.exists(FLOW_PERSIST_FILE) then
- local file=fs.open(FLOW_PERSIST_FILE,"r"); local v=tonumber(file.readAll()); file.close();
- if v then return math.floor(v) end
- end
- end
- local function writeFlow(v)
- local file=fs.open(FLOW_PERSIST_FILE,"w"); file.write(tostring(v)); file.close()
- end
- local function tuneFlow()
- local best, bestDelta=nil, math.huge
- local lo,hi=FLOW_TUNE_LOWER,FLOW_TUNE_UPPER
- for _=1,MAX_TUNE_ITER do
- local tf=math.floor((lo+hi)/2)
- turbine.setFluidFlowRateMax(tf)
- os.sleep(1)
- local r1=turbine.getRotorSpeed(); os.sleep(2); local r2=turbine.getRotorSpeed()
- local d=math.abs(r2-r1)
- if r2>RPM_TARGET+RPM_TOLERANCE then hi=tf-1
- elseif r2<RPM_TARGET-RPM_TOLERANCE then lo=tf+1
- else if d<bestDelta then best,bestDelta=tf,d end; if d<=1 then break end end
- end
- best = best or FLOW_TUNE_UPPER; writeFlow(best); return best
- end
- ---------------------------------------------------------------------
- -- 6. FAST, NON‑BLOCKING CONTROL RODS -------------------------------
- ---------------------------------------------------------------------
- local function adjustRodsForSteam(targetSteam, margin)
- local produced = num(reactor.getHotFluidProducedLastTick(),0)
- local diff=targetSteam-produced; if math.abs(diff)<=margin then return end
- local lvl=num(reactor.getControlRodLevel(0),0)
- if diff>0 then lvl=math.max(0,lvl-2) else lvl=math.min(100,lvl+2) end
- reactor.setAllControlRodLevels(lvl)
- end
- ---------------------------------------------------------------------
- -- 7. BUTTONS & INTERACTION -----------------------------------------
- ---------------------------------------------------------------------
- local TBL_X,TBL_Y=42,26 -- status LED table origin
- local ADJ_BTN_X_LEFT,ADJ_BTN_Y,ADJ_BTN_W,ADJ_BTN_H=24,27,7,3
- local ADJ_BTN_X_RIGHT=ADJ_BTN_X_LEFT+ADJ_BTN_W+1
- local ADJ_ROW_SPACING=1
- local ADJ_OFFSETS={-10,10,-2,2,-1,1}
- local ADJ_LABELS={"-10","+10","-2","+2","-1","+1"}
- local ADJ_CLR,ADJ_TXTCLR=colors.blue,colors.black
- learnedFlow = readFlow() or tuneFlow() -- forward declaration
- local function drawAdjButtons()
- for row=0,2 do
- local y=ADJ_BTN_Y+row*(ADJ_BTN_H+ADJ_ROW_SPACING)
- UI.rectangle(monitor,ADJ_BTN_X_LEFT ,y,ADJ_BTN_W,ADJ_BTN_H,ADJ_CLR)
- UI.rectangle(monitor,ADJ_BTN_X_RIGHT,y,ADJ_BTN_W,ADJ_BTN_H,ADJ_CLR)
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(ADJ_BTN_X_LEFT+2 ,y+1); monitor.write(ADJ_LABELS[row*2+1])
- monitor.setCursorPos(ADJ_BTN_X_RIGHT+2,y+1); monitor.write(ADJ_LABELS[row*2+2])
- end
- monitor.setBackgroundColor(colors.black)
- end
- local function handleTouch(x,y)
- for row=0,2 do
- local y0=ADJ_BTN_Y+row*(ADJ_BTN_H+ADJ_ROW_SPACING)
- if y>=y0 and y<y0+ADJ_BTN_H then
- if x>=ADJ_BTN_X_LEFT and x<ADJ_BTN_X_LEFT+ADJ_BTN_W then
- learnedFlow=math.min(FLOW_TUNE_UPPER,math.max(FLOW_TUNE_LOWER,learnedFlow+ADJ_OFFSETS[row*2+1]))
- writeFlow(learnedFlow); return
- elseif x>=ADJ_BTN_X_RIGHT and x<ADJ_BTN_X_RIGHT+ADJ_BTN_W then
- learnedFlow=math.min(FLOW_TUNE_UPPER,math.max(FLOW_TUNE_LOWER,learnedFlow+ADJ_OFFSETS[row*2+2]))
- writeFlow(learnedFlow); return
- end
- end
- end
- end
- ---------------------------------------------------------------------
- -- 8. DYNAMIC UI COMPONENTS -----------------------------------------
- ---------------------------------------------------------------------
- -- fuel / rod bar
- local function drawFuelRod()
- local fMax=num(reactor.getFuelAmountMax(),1) -- avoid /0
- local fAmt=num(reactor.getFuelAmount(),0)
- local wAmt=num(reactor.getWasteAmount(),0)
- local fPercent=fAmt/fMax; local wPercent=wAmt/fMax
- local fht=math.floor(fPercent*CTRLBAR_HT+0.5)
- local wht=math.floor(wPercent*CTRLBAR_HT+0.5)
- UI.rectangle(monitor,CTRLBAR_X,CTRLBAR_Y,2 + (CTRLBAR_SPC + CTRLBAR_WD) * 4 - CTRLBAR_WD,CTRLBAR_HT+2,colors.lightGray)
- UI.progress_bar(monitor,CTRLBAR_X+1,CTRLBAR_Y+1,CTRLBAR_WD,CTRLBAR_HT,100-num(reactor.getControlRodLevel(0),0),colors.blue,colors.gray)
- UI.rectangle(monitor,CTRLBAR_X+CTRLBAR_SPC+CTRLBAR_WD+1,CTRLBAR_Y+1,CTRLBAR_WD,CTRLBAR_HT,colors.gray)
- UI.rectangle(monitor,CTRLBAR_X+CTRLBAR_SPC+CTRLBAR_WD+1,CTRLBAR_Y+1+CTRLBAR_HT-fht,CTRLBAR_WD,fht,colors.orange)
- UI.rectangle(monitor,CTRLBAR_X+CTRLBAR_SPC+CTRLBAR_WD+1,CTRLBAR_Y+1,wht>0 and CTRLBAR_WD or 1,wht,colors.green)
- local fluidMax=num(turbine.getFluidAmountMax(),1)
- local fluidAmt=num(turbine.getInputAmount())
- local fluidPercent=fluidAmt/fluidMax;
- local fluidht=math.floor(fluidPercent*TURBAR_HT+0.5)
- local clntMax=num(reactor.getCoolantAmountMax(),1)
- local clntAmt=num(reactor.getCoolantAmount())
- local clntPercent=clntAmt/clntMax;
- local clntht=math.floor(clntPercent*TURBAR_HT+0.5)
- -- UI.rectangle(monitor,TURBAR_X,TURBAR_Y,TURBAR_SPC+2+TURBAR_WD*2,TURBAR_HT+2,colors.lightGray)
- UI.rectangle(monitor,TURBAR_X+1,TURBAR_Y+1,TURBAR_WD,TURBAR_HT,colors.gray)
- UI.rectangle(monitor,TURBAR_X+1,TURBAR_Y+1+TURBAR_HT-fluidht,TURBAR_WD,fluidht,colors.lightBlue)
- UI.rectangle(monitor,TURBAR_X+TURBAR_WD+TURBAR_SPC+1,TURBAR_Y+1,TURBAR_WD,TURBAR_HT,colors.gray)
- UI.rectangle(monitor,TURBAR_X+TURBAR_WD+TURBAR_SPC+1,TURBAR_Y+1+TURBAR_HT-clntht,TURBAR_WD,clntht,colors.cyan)
- end
- -- UI.rectangle(monitor,TURBAR_X,TURBAR_Y,TURBAR_SPC+2+TURBAR_WD*2,TURBAR_HT+2,colors.lightGray)
- local function drawRPMgraph(rpm)
- local percent=math.min(1,rpm/(RPM_TARGET+200))*100
- UI.drawRect(monitor,RPMBAR_X-1,RPMBAR_Y-1,72,RPMBAR_H+2,colors.orange)
- monitor.setTextColor(colors.orange)
- monitor.setCursorPos(RPMBAR_X+2,RPMBAR_Y-1); monitor.write("TURBINE RPM")
- UI.progress_bar(monitor,RPMBAR_X,RPMBAR_Y,RPMBAR_W,RPMBAR_H,percent,colors.gray,colors.lime)
- monitor.setTextColor(colors.white)
- end
- -- RPM status badge inside orange box
- local function drawRPMStatus(state)
- local labels={
- [0]={"RPM LOW" ,colors.orange,colors.orange},
- [1]={"RPM HIGH",colors.red ,colors.red },
- [2]={"NOMINAL" ,colors.blue ,colors.green },
- }
- local s=labels[state] or labels[0]
- UI.drawRect(monitor,2,26,19,13,colors.orange) -- outline already static but redraw to clear old label
- UI.drawRect(monitor,2,29,19,7,colors.orange)
- UIHeader(monitor,3,30,17,5,s[1],s[2],s[3])
- monitor.setTextColor(colors.white)
- end
- ---------------------------------------------------------------------
- -- 9. STATIC CHROME (draw once) -------------------------------------
- ---------------------------------------------------------------------
- local function drawChrome()
- UIHeader(monitor,1,1,164,3,"MAIN SYSTEMS INFORMATION PANEL - BLOCK A",colors.lightBlue,colors.orange)
- -- static frames
- UI.drawRect(monitor,2,26,19,13,colors.orange)
- UI.drawRect(monitor,2,29,19,7,colors.orange)
- UI.drawRect(monitor,ADJ_BTN_X_LEFT-1,ADJ_BTN_Y-1,17,13,colors.orange)
- UI.drawTable(monitor,TBL_X,TBL_Y,1,4,17,3,colors.orange)
- UI.drawTable(monitor,TBL_X+17,TBL_Y,2,4,7,3,colors.orange)
- UI.drawTable(monitor,2,6,1,4,31,3,colors.orange) -- fluid info frame
- UI.drawTable(monitor,42,6,1,4,31,3,colors.orange) -- fuel info frame
- UI.drawTable(monitor,101,6,1,10,31,3,colors.orange) -- general info frame
- UI.drawTable(monitor,135,6,2,5,13,6,colors.orange) -- general info LED
- drawAdjButtons()
- end
- ---------------------------------------------------------------------
- -- 10. INITIALISATION ------------------------------------------------
- ---------------------------------------------------------------------
- learnedFlow = readFlow() or tuneFlow()
- local lastRPM=num(turbine.getRotorSpeed(),0)
- local coilEngaged=turbine.getInductorEngaged()
- local stableTicks=0
- local RPMSTATUS=0 -- 0 low, 1 high, 2 nominal
- monitor.clear(); drawChrome()
- ---------------------------------------------------------------------
- -- 11. MAIN LOOP -----------------------------------------------------
- ---------------------------------------------------------------------
- while true do
- -------------------------------------------------------------------
- -- schedule next UI tick
- local timer=os.startTimer(UPDATE_PERIOD)
- -------------------------------------------------------------------
- -- SENSOR READ -----------------------------------------------------
- local rpm=num(turbine.getRotorSpeed(),0)
- local drift=rpm-lastRPM; lastRPM=rpm
- -------------------------------------------------------------------
- -- INDUCTOR COIL LOGIC --------------------------------------------
- if not coilEngaged and rpm>=COIL_ON_RPM then coilEngaged=true end
- if coilEngaged and rpm<=COIL_OFF_RPM then coilEngaged=false end
- -------------------------------------------------------------------
- -- ADAPTIVE FLOW LOGIC --------------------------------------------
- local flow; local ventMsg
- if rpm<RPM_TARGET-RPM_TOLERANCE then
- flow=math.floor(learnedFlow*(1+FLOW_BUFFER)); ventMsg="OVERFLOW"; RPMSTATUS=0; turbine.setVentOverflow()
- learnedFlow=math.min(FLOW_TUNE_UPPER,learnedFlow+FLOW_LEARN_STEP); writeFlow(learnedFlow); stableTicks=0
- elseif rpm>RPM_TARGET+RPM_TOLERANCE then
- flow=math.max(1,math.floor(learnedFlow*DECEL_FRACTION)); ventMsg="ALL"; RPMSTATUS=1; turbine.setVentAll()
- learnedFlow=math.max(FLOW_TUNE_LOWER,learnedFlow-FLOW_LEARN_STEP); writeFlow(learnedFlow); stableTicks=0
- else
- flow=learnedFlow; ventMsg="OVERFLOW"; RPMSTATUS=2; turbine.setVentOverflow(); stableTicks=stableTicks+1
- if stableTicks>=4 then
- if rpm<RPM_TARGET then learnedFlow=math.min(FLOW_TUNE_UPPER,learnedFlow+1)
- else learnedFlow=math.max(FLOW_TUNE_LOWER,learnedFlow-1) end
- writeFlow(learnedFlow); stableTicks=0
- end
- end
- -------------------------------------------------------------------
- -- APPLY CONTROLS --------------------------------------------------
- turbine.setFluidFlowRateMax(flow)
- turbine.setInductorEngaged(coilEngaged)
- adjustRodsForSteam(math.floor(flow*1.03),2)
- -------------------------------------------------------------------
- -- DYNAMIC UI UPDATE ----------------------------------------------
- drawRPMgraph(rpm)
- drawFuelRod()
- -- drawFluidAmount()
- drawRPMStatus(RPMSTATUS)
- local function w(x,y,str) monitor.setCursorPos(x,y); monitor.write(pad(str,28)) end
- -- high‑frequency numeric/status strings
- w(102,10,"Inductors: " .. (coilEngaged and "ENGAGED" or "DISENGAGED"))
- w(102,13,"Vent Mode: " .. ventMsg)
- monitor.setCursorPos(102,19); monitor.write(pad(string.format("Energy/t : %6.1f kFE/t",num(turbine.getEnergyProducedLastTick(),0)/1000),28))
- monitor.setCursorPos(102,22); monitor.write(pad(string.format("Energy Stored : %6.1f kFE",num(turbine.getEnergyStored(),0)/1000),28))
- monitor.setCursorPos(102,28); monitor.write(pad(string.format("Casing Temp : %6.1f °C",num(reactor.getCasingTemperature(),0)),28))
- monitor.setCursorPos(102,31); monitor.write(pad(string.format("Fuel Temp : %6.1f °C",num(reactor.getFuelTemperature(),0)),28))
- monitor.setCursorPos(102,34); monitor.write(pad(string.format("Fuel Consumed : %6.1f mB/t",num(reactor.getFuelConsumedLastTick(),0)),28))
- monitor.setCursorPos(3,36); monitor.write(pad(string.format("RPM : %.1f rpm", rpm), 17))
- monitor.setCursorPos(3,37); monitor.write(pad(string.format("Drift: %.1f rpm", drift), 17))
- -- fuel & fluid info (these rarely change but we update each tick for safety)
- monitor.setCursorPos(4,10); monitor.write(pad("Target Flow: " .. learnedFlow .. " mB/t",28))
- monitor.setCursorPos(4,13); monitor.write(pad("Current Flow: " .. flow .. " mB/t",28))
- monitor.setCursorPos(4,16); monitor.write(pad("Fluid/t : " .. num(reactor.getHotFluidProducedLastTick(),0) .. " mB/t",28))
- monitor.setCursorPos(44,10); monitor.write(pad("Fuel Capacity (mB) : " .. num(reactor.getFuelAmountMax(),0),28))
- monitor.setCursorPos(44,13); monitor.write(pad("Available Fuel(mB) : " .. num(reactor.getFuelAmount(),0),28))
- monitor.setCursorPos(44,16); monitor.write(pad("Waste Amount (mB) : " .. num(reactor.getWasteAmount(),0),28))
- -- ON/OFF LEDs -----------------------------------------------------
- local function led(state,onX,offX,y)
- if state then
- UI.rectangle(monitor,onX ,y,4,2,colors.green)
- UI.rectangle(monitor,offX,y,4,2,colors.black)
- else
- UI.rectangle(monitor,onX ,y,4,2,colors.black)
- UI.rectangle(monitor,offX,y,4,2,colors.red)
- end
- end
- led(reactor.getActive(), TBL_X+26,TBL_X+19,TBL_Y+4)
- led(turbine.getActive(), TBL_X+26,TBL_X+19,TBL_Y+7)
- led(turbine.getInductorEngaged(),TBL_X+26,TBL_X+19,TBL_Y+10)
- -- LED Table -----------------------------------------------------
- -- static labels (do once, but cheap to overwrite)
- monitor.setCursorPos(10,27); monitor.write("RPM")
- monitor.setCursorPos(8,28); monitor.write("Status:")
- monitor.setCursorPos(TBL_X+20,TBL_Y+1); monitor.write("OFF")
- monitor.setCursorPos(TBL_X+27,TBL_Y+1); monitor.write("ON")
- monitor.setCursorPos(TBL_X+1,TBL_Y+4); monitor.write("REACTOR:")
- monitor.setCursorPos(TBL_X+1,TBL_Y+7); monitor.write("TURBINE:")
- monitor.setCursorPos(TBL_X+1,TBL_Y+10); monitor.write("INDUCTORS:")
- monitor.setBackgroundColor(colors.lightGray)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(77,6); monitor.write("ROD")
- monitor.setCursorPos(83,6); monitor.write("FUL")
- local fpercent=math.floor(num(reactor.getFuelAmount(),0)/num(reactor.getFuelAmountMax(),1)*100+0.5)
- local fldpercent=math.floor(num(turbine.getInputAmount(),0)/num(turbine.getFluidAmountMax(),1)*100+0.5)
- local cntpercent=math.floor(num(reactor.getCoolantAmount(),0)/num(reactor.getCoolantAmountMax(),1)*100+0.5)
- local wpercent=math.floor(num(reactor.getWasteAmount(),0)/num(reactor.getFuelAmountMax(),1)*100+0.5)
- monitor.setCursorPos(77,37); monitor.write(string.format("%3d",num(reactor.getControlRodLevel(0),0)))
- monitor.setCursorPos(83,37); monitor.write(string.format("%3d",fpercent))
- monitor.setCursorPos(89,6); monitor.write("FLD")
- monitor.setCursorPos(95,6); monitor.write("CNT")
- monitor.setCursorPos(89,37); monitor.write(string.format("%3d",fldpercent))
- monitor.setCursorPos(95,37); monitor.write(pad(string.format("%d", num((100/reactor.getCoolantAmountMax()*reactor.getCoolantAmount()),0)),4))
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- UI.rectangle(monitor, 3, 7, 30, 2, colors.blue) -- FLUID INFORMATION
- UI.rectangle(monitor, 43, 7, 30, 2, colors.blue) -- FUEL INFORMATION
- UI.rectangle(monitor, 102, 7, 30, 2, colors.blue) -- TURBINE STATUS
- UI.rectangle(monitor, 102, 16, 30, 2, colors.blue) -- ENERGY STATS
- UI.rectangle(monitor, 102, 25, 30, 2, colors.blue) -- CORE STATUS
- monitor.setBackgroundColor(colors.blue)
- monitor.setTextColor(colors.white)
- monitor.setCursorPos(3,7); monitor.write(" FLUID INFORMATION ")
- monitor.setCursorPos(43,7); monitor.write(" FUEL INFORMATION ")
- monitor.setCursorPos(102,7); monitor.write(" TURBINE STATUS ")
- monitor.setCursorPos(102,16); monitor.write(" ENERGY STATS ")
- monitor.setCursorPos(102,25); monitor.write(" CORE STATUS ")
- monitor.setBackgroundColor(colors.black)
- local colorOK = colors.lightBlue
- local colorER = colors.orange
- if reactor.getActive() then
- UIHeader(monitor, 136, 7, 12, 5, "REACTOR", colorOK , colorOK )
- else
- UIHeader(monitor, 136, 7, 12, 5, "REACTORREAC OFF", colorER , colorER )
- end
- if turbine.getActive() then
- UIHeader(monitor, 149, 7, 12, 5, "TURBINE", colorOK , colorOK )
- else
- UIHeader(monitor, 149, 7, 12, 5, "TURBINE", colorER , colorER )
- end
- if cntpercent > 10 then
- UIHeader(monitor, 136, 13, 12, 5, "COOLANT", colorOK , colorOK )
- else
- UIHeader(monitor, 136, 13, 12, 5, "COOLANT", colorER , colorER )
- end
- if fldpercent > 10 then
- UIHeader(monitor, 149, 13, 12, 5, "STEAM", colorOK , colorOK )
- else
- UIHeader(monitor, 149, 13, 12, 5, "STEAM", colorER , colorER )
- end
- if fpercent > 10 then
- UIHeader(monitor, 136, 19, 12, 5, "FUEL", colorOK , colorOK )
- else
- UIHeader(monitor, 136, 19, 12, 5, "FUEL", colorER , colorER )
- end
- if wpercent < 10 then
- UIHeader(monitor, 149, 19, 12, 5, "WASTE", colorOK , colorOK )
- else
- UIHeader(monitor, 149, 19, 12, 5, "WASTE", colorER , colorER )
- end
- if turbine.getEnergyStored() > 100 then
- UIHeader(monitor, 136, 25, 12, 5, "BATTERY", colorOK , colorOK )
- else
- UIHeader(monitor, 136, 25, 12, 5, "BATTERY", colorER , colorER )
- end
- if turbine.getEnergyProducedLastTick() > 15000 then
- UIHeader(monitor, 149, 25, 12, 5, "GENERATOR", colorOK , colorOK )
- else
- UIHeader(monitor, 149, 25, 12, 5, "GENERATOR", colorER , colorER )
- end
- if turbine.getFluidFlowRate() > 250 then
- UIHeader(monitor, 136, 31, 12, 5, "FLOW", colorOK , colorOK )
- else
- UIHeader(monitor, 136, 31, 12, 5, "FLOW", colorER , colorER )
- end
- if reactor.getHotFluidProducedLastTick() > 250 then
- UIHeader(monitor, 149, 31, 12, 5, "FLUID", colorOK , colorOK )
- else
- UIHeader(monitor, 149, 31, 12, 5, "FLUID", colorER , colorER )
- end
- -------------------------------------------------------------------
- -- EVENT HANDLING --------------------------------------------------
- repeat
- local ev={os.pullEvent()}
- if ev[1]=="monitor_touch" then handleTouch(ev[3],ev[4]) end
- until ev[1]=="timer" and ev[2]==timer
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement