Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("monitor_1")
- state_home_channel = 1
- state_fissionreactor_channel = 2
- control_channel = 3
- control_reactors = {
- ["BigReactor"] = false,
- ["FissionReactor"] = false
- }
- home_states = {
- ["BigReactor"] = {
- ["state"] = false
- },
- ["Capacitor"] = {
- ["charge"] = 0
- },
- }
- fissionreactor_states = {
- ["FissionReactor"] = {
- ["state"] = false,
- ["temperature"] = 0,
- ["damage"]= 0,
- ["coolant"]= 0,
- ["fuel"]= 0,
- ["waste"]= 0,
- },
- }
- modem_wireless = peripheral.wrap("top")
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.clearLine()
- monitor.setTextColour(colors.orange)
- monitor.write("Reactor Control Server")
- while true do
- -- Get Data from Network
- modem_wireless.open(state_home_channel)
- local event, side, channel, replyChannel, home_states, distance = os.pullEvent("modem_message")
- charge = home_states["Capacitor"]["charge"]
- print("Capacitor Charge: ", charge)
- BigReactor_state = home_states["BigReactor"]["state"]
- print("BigReactor state: ", BigReactor_state)
- modem_wireless.close(state_home_channel)
- modem_wireless.open(state_fissionreactor_channel)
- local event, side, channel, replyChannel, fissionreactor_states, distance = os.pullEvent("modem_message")
- FissionReactor_state = fissionreactor_states["FissionReactor"]["state"]
- modem_wireless.close(state_fissionreactor_channel)
- ----------------------------------------------
- -- Handle Reactors
- if charge <= 10 then
- if BigReactor_state == false then
- print("Turning on BigReactor")
- control_reactors["BigReactor"] = true
- end
- if FissionReactor_state == false then
- control_reactors["FissionReactor"] = true
- end
- elseif charge >= 95 then
- if BigReactor_state == true then
- print("Turning off BigReactor")
- control_reactors["BigReactor"] = false
- end
- if FissionReactor_state == true then
- control_reactors["FissionReactor"] = false
- end
- end
- modem_wireless.transmit(control_channel, 65534, control_reactors)
- ----------------------------------------------
- -- Handle Monitor
- monitor.setCursorPos(1, 2)
- monitor.clearLine()
- print(("Capacitor Charge: %d%%"):format(charge))
- if charge > 70 then
- monitor.setTextColour(colors.green)
- elseif charge < 25 then
- monitor.setTextColour(colors.red)
- else
- monitor.setTextColour(colors.yellow)
- end
- monitor.write(("Capacitor Charge: %d%%"):format(charge))
- monitor.setCursorPos(1, 3)
- monitor.clearLine()
- if BigReactor_state == true then
- monitor.setTextColour(colors.green)
- print("Big Reactor: ", BigReactor_state)
- monitor.write("Big Reactor running")
- monitor.setTextColour(colors.white)
- elseif BigReactor_state == false then
- monitor.setTextColour(colors.red)
- print("Big Reactor: ", BigReactor_state)
- monitor.write("Big Reactor not running")
- monitor.setTextColour(colors.white)
- end
- monitor.setCursorPos(1, 4)
- monitor.clearLine()
- if FissionReactor_state == true then
- monitor.setTextColour(colors.green)
- print("Fission Reactor: ", FissionReactor_state)
- monitor.write("Fission Reactor running")
- monitor.setTextColour(colors.white)
- elseif FissionReactor_state == false then
- monitor.setTextColour(colors.red)
- print("Fission Reactor: ", FissionReactor_state)
- monitor.write("Fission Reactor not running")
- monitor.setTextColour(colors.white)
- end
- --------------------------------------------
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement