tMon = "1" rMon = "0" function clean() term.setBackgroundColor(colors.black) term.clear() term.setCursorPos(1,1) end function cleanMon() m.setBackgroundColor(colors.black) m.clear() m.setCursorPos(1,1) end function center(text,index,y) if index == m then screen = m elseif index == m2 then screen = m2 else screen = tWindow[index].window end w,h = screen.getSize() _text = tostring(text) sl = string.len(_text) screen.setCursorPos(math.floor(w/2 +.5)-math.floor(sl/2 +.5),y) screen.write(_text) end function displayReactor() if r.connected() then -- Show Reactor Stats m2.clear() center("| Reactor Monitor |",m2,1) center("-------------------",m2,2) if r.active() then m2.setBackgroundColor(colors.green) else m2.setBackgroundColor(colors.red) end center("POWER",m2,4) m2.setBackgroundColor(colors.black) center("Fuel Temp: " .. math.floor(r.fuelTemperature()),m2,6) center("Case Temp: " .. math.floor(r.casingTemperature()),m2,7) center("Fuel Amount: ".. math.floor(r.fuelTank().fuel()).."/"..math.floor(r.fuelTank().capacity()),m2,8) center("Steam Created: " .. r.coolantTank().transitionedLastTick().." mB/t",m2,9) center("Fuel Rate: ".. r.fuelTank().burnedLastTick() .. " mB/t",m2,10) center("Fuel Reactivity: ".. math.floor(r.fuelTank().fuelReactivity()).. "%",m2,11) center("Total Power Gen: " .. math.floor(totalPowerGen).. " RF/t",m2,12) sw,sh = m2.getSize() loc = 15 height = 10 fbl = sw-8 water = r.coolantTank().coldFluidAmount() waterMax = r.coolantTank().capacity() waterBlock = waterMax/height numWaterBlocks = math.floor(water/waterBlock) steamBroke = r.coolantTank().hotFluidAmount() steamMax = waterMax steam = steamMax - steamBroke steamBlock = steamMax/height numSteamBlocks = math.floor(steam/steamBlock) fuel = r.fuelTank().fuel() fuelMax = r.fuelTank().capacity() fuelBlock = fuelMax/(fbl-3) numFuelBlocks = math.floor(fuel/fuelBlock) -- Draw Boxes around Water and Steam Bar m2.setBackgroundColor(colors.lightGray) for l=1,height do m2.setCursorPos(5,loc-l) m2.write(" ") m2.setCursorPos(8,loc-l) m2.write(" ") m2.setCursorPos(sw-5,loc-l) m2.write(" ") m2.setCursorPos(sw-8,loc-l) m2.write(" ") end m2.setCursorPos(5,loc - height - 1) m2.write(" ") m2.setCursorPos(sw-8,loc - height - 1) m2.write(" ") m2.setCursorPos(5,loc) m2.write(" ") m2.setCursorPos(sw-8,loc) m2.write(" ") --Fill in water level m2.setBackgroundColor(colors.blue) for l=1,numWaterBlocks do m2.setCursorPos(6,loc-l) m2.write(" ") end -- Fill in Steam Level m2.setBackgroundColor(colors.gray) for l=1,numSteamBlocks do m2.setCursorPos(sw-7,loc-l) m2.write(" ") end -- Create Box around Fuel Bar -- top outline m2.setBackgroundColor(colors.lightGray) m2.setCursorPos(5,loc+2) for l=1,fbl-1 do m2.write(" ") end -- bottom outline m2.setCursorPos(5,loc + 5) for l=1,fbl-1 do m2.write(" ") end -- end caps for l=1,2 do m2.setCursorPos(5,loc+l+2) m2.write(" ") m2.setCursorPos(sw-5,loc+l+2) m2.write(" ") end -- Fill in Fuel Bars m2.setBackgroundColor(colors.yellow) for l=1,numFuelBlocks do m2.setCursorPos(5+l,loc+3) m2.write(" ") m2.setCursorPos(5+l,loc+4) m2.write(" ") end m2.setBackgroundColor(colors.black) -- Draw Control Rod Buttons center("Control Rod Level = " .. controlLevel,m2,sh-1) m2.setBackgroundColor(colors.red) m2.setCursorPos(sw/2-15,sh) m2.write(" -1 ") m2.setCursorPos(sw/2-8,sh) m2.write(" -10 ") m2.setCursorPos((sw/2-1),sh) if r.active() then m2.setBackgroundColor(colors.green) else m2.setBackgroundColor(colors.red) end m2.write("POWER") m2.setBackgroundColor(colors.green) m2.setCursorPos(sw/2+6,sh) m2.write(" +10 ") m2.setCursorPos(sw/2+13,sh) m2.write(" +1 ") m2.setBackgroundColor(colors.black) end end function checkValue() if controlLevel > 100 then controlLevel = 100 elseif controlLevel < 0 then controlLevel = 0 end end clean() peripherals = peripheral.getNames() t = {} print("Loading Peripherals..") for i=1,#peripherals do --print(peripherals[i]) type = peripheral.getType(peripherals[i]) if type == "BiggerReactors_Turbine" then table.insert(t,peripheral.wrap(peripherals[i])) print("Adding new turbine to index " .. tostring(#t)) elseif type == "BiggerReactors_Reactor" then if not r then r = peripheral.wrap(peripherals[i]) print("Reactor Has Been Connected") if r.active() then rs.setBundledOutput("bottom",colors.white) else rs.setBundledOutput("bottom",0) end end end end print("Defining Monitors") -- Turbine Monitor m = peripheral.wrap("monitor_"..tMon) -- Reactor Monitor m2 = peripheral.wrap("monitor_" .. rMon) m.setTextScale(.5) m2.setTextScale(.5) if not r then error("No Reactor Found") end if not m then error("No Monitor Found") end if not m2 then error("No Secondary Monitor Found") end cleanMon() --cpu = term.redirect(m) -- Prepare Windows for Turbines tWindow = {} width = 14 height = 5 print("Creating Turbine Windows") for i=1,#t do if i <= 5 then y = 4 xsub = 0 elseif i <= 10 then y = 4 + (1 + height) xsub = 5 elseif i <= 15 then y = 4 + (1 + height) * 2 xsub = 10 elseif i <= 20 then y = 4 + (1 + height) * 3 xsub = 15 elseif i <= 25 then y = 4 + (1 + height) * 4 xsub = 20 else y = 4 + (1 + height) * 5 xsub = 25 end x = 5 + (width * ((i-1) - xsub) ) + ((i-1)-xsub) --if i > 4 and i < 9 then -- x = x - i --end -- New Method tWindow[i] = { window = window.create(m,x,y,width,height,true), xPos = x, yPos = y, } --Old Method -- table.insert(tWindow,window.create(m,x,y,17,height,true)) end totalPowerGen = 0 controlLevel = r.getControlRod(0).level() -- Show Turbine Stats print("Loading Complete.") while true do center("| Turbine Monitor |",m,1) center("-------------------",m,2) x,y = 1,4 totalPowerGen = 0 for i=1,#t do if t[i].connected() then tWindow[i].window.clear() center(i,i,1) if t[i].active() then tWindow[i].window.setBackgroundColor(colors.green) else tWindow[i].window.setBackgroundColor(colors.red) end center("POWER",i,2) tWindow[i].window.setBackgroundColor(colors.gray) center(math.floor(t[i].battery().stored()).. "RF",i,3) center(math.floor(t[i].rotor().RPM()).." RPM",i,4) center(math.floor(t[i].battery().producedLastTick()) .. "RF/T",i,5) tWindow[i].window.setBackgroundColor(colors.black) totalPowerGen = totalPowerGen + t[i].battery().producedLastTick() end end displayReactor() timer = os.startTimer(.5) while true do event,side,x,y = os.pullEvent() if event == "timer" then break elseif event == "monitor_touch" then -- check coords for button push if side == "monitor_" .. rMon then local w,h = m2.getSize() powerX = (w/2)-(5/2) if x >= powerX and x <= powerX + 5 and y == 4 then if r.active() then -- disable input of yellorium rs.setBundledOutput("bottom",0) -- disable reactor r.setActive(false) -- dump fuel repeat r.doEjectFuel() sleep(1) displayReactor() until r.fuelTank().fuel() < 1000 else -- enable input of yellorium rs.setBundledOutput("bottom",colors.white) -- enable reactor r.setActive(true) end elseif y == h then if x >= w/2-15 and x <= w/2-12 then controlLevel = controlLevel - 1 checkValue() r.setAllControlRodLevels(controlLevel) elseif x >= w/2-8 and x <= w/2-4 then controlLevel = controlLevel - 10 checkValue() r.setAllControlRodLevels(controlLevel) elseif x >= w/2+6 and x <= w/2+10 then controlLevel = controlLevel + 10 checkValue() r.setAllControlRodLevels(controlLevel) elseif x >= w/2+13 and x <= w/2+16 then controlLevel = controlLevel + 1 checkValue() r.setAllControlRodLevels(controlLevel) elseif x >= w/2-1 and x <= w/2+3 then if r.active() then r.setActive(false) else r.setActive(true) end end end break elseif side == "monitor_" .. tMon then print("Got Turbine Screen Click at x:" .. x .. " y: " .. y) for i=1,#tWindow do local ww,_ = tWindow[i].window.getSize() local cOffset = math.floor(ww/2 + .5) - 5 local winX = tWindow[i].xPos local winY = tWindow[i].yPos print("Window " .. i .. " x:" .. winX + cOffset .. " y: " .. winY + 1 .. " Click x:" .. x .. " y: " .. y .. " Width:" .. ww .. " Offset:" .. cOffset) if x >= winX + cOffset and x <= winX + cOffset + 5 and y == winY + 1 then if t[i].getActive() then t[i].setActive(false) else t[i].setActive(true) end break end end end end end end