Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reactor = peripheral.wrap("BigReactors-Reactor_0")
- turbine1 = peripheral.wrap("BigReactors-Turbine_0")
- turbine2 = peripheral.wrap("BigReactors-Turbine_1")
- monitor = peripheral.wrap("top")
- mon = true
- watch = true
- times = {}
- times.monitor = {}
- times.watch = {}
- times.monitor.monitor = 0.4
- times.monitor.sync = 2
- times.watch.sync = 2
- times.watch.watch = 0.4
- buttons = {}
- buttons[1] = {}
- buttons[2] = {}
- buttons[3] = {}
- buttons[4] = {}
- buttons[5] = {}
- buttons[6] = {}
- buttons[1].label = "1 only "
- buttons[2].label = "2 only "
- buttons[3].label = "all on "
- buttons[4].label = "all off"
- buttons[5].label = " auto "
- buttons[6].label = "monitor"
- buttons[1].sx = 20
- buttons[3].sx = 20
- buttons[5].sx = 20
- buttons[1].sy = 2
- buttons[2].sx = 30
- buttons[4].sx = 30
- buttons[6].sx = 30
- buttons[1].sy = 2
- buttons[2].sy = 2
- buttons[3].sy = 7
- buttons[4].sy = 7
- buttons[5].sy = 12
- buttons[6].sy = 12
- for sdfg = 1,6 do
- buttons[sdfg].x = 9
- buttons[sdfg].y = 3
- end
- function singleTurbine(turb)
- reactor.setAllControlRodLevels(86)
- if turb == turbine1 then
- turb1Enable()
- turb2Disable()
- elseif turb == turbine2 then
- turb1Disable()
- turb2Enable()
- end
- end
- function actives()
- if turbine1.getActive() and turbine2.getActive() then
- return 2
- elseif turbine1.getActive() and not turbine2.getActive() then
- return 1
- elseif turbine2.getActive() and not turbine1.getActive() then
- return 1
- elseif not (turbine1.getActive() and turbine2.getActive()) then
- return 0
- end
- end
- function createButtons()
- for bts = 1,#buttons do
- makeButton(buttons[bts].label,buttons[bts].x,buttons[bts].y,buttons[bts].sx,buttons[bts].sy)
- end
- end
- function allTurbines()
- reactor.setAllControlRodLevels(73)
- turb1Enable()
- turb2Enable()
- end
- function allOff()
- reactor.setActive(false)
- turbine1.setActive(false)
- turbine2.setActive(false)
- end
- function turb1Enable()
- turbine1.setActive(true)
- end
- function turb2Enable()
- turbine2.setActive(true)
- end
- function setupMon()
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- function monClear()
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- function monit()
- while true do
- while mon do
- monitorer()
- sleep(times.monitor.monitor)
- end
- sleep(times.monitor.sync)
- end
- end
- function makeButton(label,x,y,xs,ys)
- xf = xs + x-1
- yf = ys + y-1
- monitor.setBackgroundColor(colors.red)
- for i = xs,xf do
- for k = ys,yf do
- monitor.setCursorPos(i,k)
- monitor.write(" ")
- end
- end
- monitor.setCursorPos(xs+1, math.floor((yf+ys)/2))
- monitor.setTextColor(colors.blue)
- monitor.write(label)
- monitor.setBackgroundColor(colors.black)
- end
- function pullTouch()
- while true do
- event, per, tx, ty = os.pullEvent("monitor_touch")
- if event == "monitor_touch" then
- for aa = 1,#buttons do
- for ax = buttons[aa].sx,(buttons[aa].sx+buttons[aa].x) do
- for ay = buttons[aa].sy, (buttons[aa].sy+buttons[aa].y) do
- if tx == ax and ty == ay then
- if buttons[aa].label == "1 only " then
- singleTurbine(turbine1)
- elseif buttons[aa].label == "2 only " then
- singleTurbine(turbine2)
- elseif buttons[aa].label == "all on " then
- allTurbines()
- elseif buttons[aa].label == "all off" then
- allOff()
- elseif buttons[aa].label == " auto " then
- changeAuto()
- elseif buttons[aa].label == "monitor" then
- changeMonitor()
- end
- end
- end
- end
- end
- end
- end
- end
- function turbWatch()
- while true do
- while watch do
- onChange()
- if turbine1.getActive() then
- if turbine1.getRotorSpeed() < 1600 then
- turbine1.setInductorEngaged(false)
- else
- turbine1.setInductorEngaged(true)
- end
- else
- turbine1.setInductorEngaged(false)
- end
- if turbine2.getActive() then
- if turbine2.getRotorSpeed() < 1600 then
- turbine2.setInductorEngaged(false)
- else
- turbine2.setInductorEngaged(true)
- end
- else
- turbine2.setInductorEngaged(false)
- end
- sleep(times.watch.watch)
- end
- sleep(times.watch.sync)
- end
- end
- function termClear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function changeMonitor()
- mon = not mon
- termClear()
- print("Monitor: "..tostring(mon))
- print("Auto: "..tostring(watch))
- end
- function changeAuto()
- watch = not watch
- termClear()
- print("Monitor: "..tostring(mon))
- print("Auto: "..tostring(watch))
- end
- function onChange()
- if actives() == 0 then
- reactor.setActive(false)
- elseif actives() == 1 then
- reactor.setActive(true)
- reactor.setAllControlRodLevels(86)
- elseif actives() == 2 then
- reactor.setActive(true)
- reactor.setAllControlRodLevels(73)
- end
- end
- function turb1Disable()
- turbine1.setActive(false)
- end
- function turb2Disable()
- turbine2.setActive(false)
- end
- function monitorer()
- monClear()
- -- reactor monitor --
- monitor.setTextColor(colors.blue)
- monitor.write("Reactor")
- monitor.setCursorPos(1,2)
- if reactor.getActive() then
- monitor.setTextColor(colors.lime)
- monitor.write("Active")
- else
- monitor.setTextColor(colors.red)
- monitor.write("Not Active")
- end
- monitor.setTextColor(colors.lightBlue)
- monitor.setCursorPos(1,3)
- monitor.write("Rods: ".. tostring(reactor.getControlRodLevel(1)).."%")
- monitor.setCursorPos(1,4)
- fuel = math.floor(reactor.getFuelAmount() / reactor.getFuelAmountMax() * 100)
- monitor.write("Fuel: ".. tostring(fuel).."%")
- energy = turbine1.getEnergyProducedLastTick() + turbine2.getEnergyProducedLastTick()
- monitor.setCursorPos(1,5)
- monitor.write("Power: ")
- if actives() == 0 then
- monitor.setTextColor(colors.red)
- monitor.write(tostring(math.floor(energy)).."rf/t")
- elseif actives() == 1 then
- monitor.setTextColor(colors.blue)
- monitor.write(tostring(math.floor(energy)).."rf/t")
- elseif actives() == 2 then
- monitor.setTextColor(colors.lime)
- monitor.write(tostring(math.floor(energy)).."rf/t")
- end
- -- turbine 1 monitor --
- monitor.setCursorPos(1,7)
- monitor.setTextColor(colors.blue)
- monitor.write("Turbine 1")
- monitor.setCursorPos(1,8)
- if turbine1.getActive() then
- monitor.setTextColor(colors.lime)
- monitor.write("Active")
- else
- monitor.setTextColor(colors.red)
- monitor.write("Not Active")
- end
- monitor.setTextColor(colors.lightBlue)
- monitor.setCursorPos(1,9)
- monitor.write("Energy: ")
- if turbine1.getActive() then
- monitor.setTextColor(colors.lime)
- monitor.write(tostring(math.floor(turbine1.getEnergyProducedLastTick())).."rf/t")
- else
- monitor.setTextColor(colors.red)
- monitor.write(tostring(math.floor(turbine1.getEnergyProducedLastTick())).."rf/t")
- end
- monitor.setCursorPos(1,10)
- monitor.setTextColor(colors.lightBlue)
- monitor.write("Speed: ")
- if turbine1.getActive() then
- monitor.setTextColor(colors.lime)
- else
- monitor.setTextColor(colors.red)
- end
- monitor.write(tostring(math.floor(turbine1.getRotorSpeed())).." RPM")
- monitor.setCursorPos(1,11)
- if turbine1.getInductorEngaged() then
- monitor.setTextColor(colors.lime)
- monitor.write("Coils Engaged")
- else
- monitor.setTextColor(colors.red)
- monitor.write("Coils Disengaged")
- end
- -- turbine 2 monitor --
- monitor.setCursorPos(1,13)
- monitor.setTextColor(colors.blue)
- monitor.write("Turbine 2")
- monitor.setCursorPos(1,14)
- if turbine2.getActive() then
- monitor.setTextColor(colors.lime)
- monitor.write("Active")
- else
- monitor.setTextColor(colors.red)
- monitor.write("Not Active")
- end
- monitor.setTextColor(colors.lightBlue)
- monitor.setCursorPos(1,15)
- monitor.write("Energy: ")
- if turbine2.getActive() then
- monitor.setTextColor(colors.lime)
- monitor.write(tostring(math.floor(turbine2.getEnergyProducedLastTick())).."rf/t")
- else
- monitor.setTextColor(colors.red)
- monitor.write(tostring(math.floor(turbine2.getEnergyProducedLastTick())).."rf/t")
- end
- monitor.setCursorPos(1,16)
- monitor.setTextColor(colors.lightBlue)
- monitor.write("Speed: ")
- if turbine2.getActive() then
- monitor.setTextColor(colors.lime)
- else
- monitor.setTextColor(colors.red)
- end
- monitor.write(tostring(math.floor(turbine2.getRotorSpeed())).." RPM")
- monitor.setCursorPos(1,17)
- if turbine2.getInductorEngaged() then
- monitor.setTextColor(colors.lime)
- monitor.write("Coils Engaged")
- else
- monitor.setTextColor(colors.red)
- monitor.write("Coils Disengaged")
- end
- createButtons()
- end
- parallel.waitForAll(monit,turbWatch,pullTouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement