Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reactorSearch()
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == "BiggerReactors_Reactor" then
- return peripheral.wrap(name)
- else
- --return null
- end
- end
- end
- function monitorSearch()
- local names = peripheral.getNames()
- local i, name
- for i, name in pairs(names) do
- if peripheral.getType(name) == "monitor" then
- test = name
- return peripheral.wrap(name)
- else
- --return null
- end
- end
- end
- m=monitorSearch()
- reactor=reactorSearch()
- function clear()
- m.setBackgroundColor(colors.black)
- m.clear()
- m.setCursorPos(1,1)
- end
- --display text on computer's terminal screen
- function draw_text_term(x, y, text, text_color, bg_color)
- term.setTextColor(text_color)
- term.setBackgroundColor(bg_color)
- term.setCursorPos(x,y)
- write(text)
- end
- --display text text on monitor, "mon" peripheral
- function draw_text(x, y, text, text_color, bg_color)
- m.setBackgroundColor(bg_color)
- m.setTextColor(text_color)
- m.setCursorPos(x,y)
- m.write(text)
- end
- --draw line on computer terminal
- function draw_line(x, y, length, color)
- m.setBackgroundColor(color)
- m.setCursorPos(x,y)
- m.write(string.rep(" ", length))
- end
- --draw line on computer terminal
- function draw_line_term(x, y, length, color)
- term.setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(string.rep(" ", length))
- end
- --create progress bar
- --draws two overlapping lines
- --background line of bg_color
- --main line of bar_color as a percentage of minVal/maxVal
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- --same as above but on the computer terminal
- function progress_bar_term(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line_term(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line_term(x, y, barSize, bar_color) --progress so far
- end
- --create button on monitor
- function button(x, y, length, text, txt_color, bg_color)
- draw_line(x, y, length, bg_color)
- draw_text((x+2), y, text, txt_color, bg_color)
- if clicked and mx>=x-1 and mx<=x+length+1 and my>=y-1 and my<=y+1 then
- return true
- end
- return false
- end
- function getEnergy()
- if reactor.battery() ~= null then
- return reactor.battery().stored()/reactor.battery().capacity()
- end
- return 0
- end
- function setControlrod(p)
- reactor.setAllControlRodLevels(p)
- end
- function getControlrod()
- return reactor.getControlRod(0).level()
- end
- function producing()
- if reactor.battery() ~= null then
- return reactor.battery().producedLastTick()/1000;
- end
- return 0
- end
- function fuel()
- if reactor.fuelTank() ~= null then
- return reactor.fuelTank().burnedLastTick()
- end
- return 0
- end
- function round(num,s)
- return math.floor((num*(10^s))+0.5)/(10^s)
- end
- clicked=false
- mx=0
- my=0
- function handletouch()
- clicked=false
- mx=0
- my=0
- local event, button, x, y = os.pullEvent("monitor_touch")
- clicked=true
- mx=x
- my=y
- end
- function timeout()
- sleep(1)
- end
- function update()
- clear()
- local autocolor=colors.black
- local overdrivecolor=colors.black
- if mode=="AUTO" then
- autocolor=colors.green
- local reactoron=getEnergy()*getEnergy()
- setControlrod(reactoron*100)
- elseif mode=="OVERDRIVE" then
- overdrivecolor=colors.green
- setControlrod(0)
- end
- draw_text(3,2,"Reactor Control",colors.yellow,colors.black)
- draw_text(3,3,mode.." Mode",colors.white,colors.black)
- if reactor.active() then
- draw_text(3,4,"Status: ONLINE",colors.green, colors.black)
- else
- draw_text(3,4,"Status: OFFLINE",colors.red, colors.black)
- end
- local energy=round(getEnergy()*100,2)
- draw_text(3,5,"Current Energy:",colors.white, colors.black)
- progress_bar(3,6,20,energy,100,colors.green, colors.white)
- draw_text(24,6,energy.."",colors.white, colors.black)
- local rod=round(getControlrod(),2)
- draw_text(3,7,"ControlRods:",colors.white, colors.black)
- progress_bar(3,8,20,rod,100,colors.yellow, colors.white)
- draw_text(24,8,rod.."",colors.white, colors.black)
- draw_text(3,10,"Energy: "..round(producing(),2).." KRF/T",colors.white, colors.black)
- draw_text(3,11,"Fuel Consumption: "..round(fuel(),2).." MB/T",colors.white, colors.black)
- draw_text(3,12,"Efficienty: "..math.floor(producing()/fuel()).." KRF/MB",colors.white, colors.black)
- if button(3,15,6,"AUTO",autocolor,colors.lightGray) then
- mode="AUTO"
- clicked=false
- update()
- end
- if button(25,15,6,"OVERDRIVE",overdrivecolor,colors.lightGray) then
- mode="OVERDRIVE"
- clicked=false
- update()
- end
- end
- clear()
- mode="AUTO"
- while true do
- parallel.waitForAny(timeout,handletouch)
- clear()
- update()
- --sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement