Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables--
- local printer = peripheral.wrap("bottom")
- local modem = peripheral.wrap("right")
- local txChannel = 1400
- local rxChannel = 1410
- local rsOutSide = "left"
- local rsInfoSide = "top"
- local boilerFeeder = {colors.red,colors.orange,colors.gray}
- local boilerStock = {colors.blue,colors.lightBlue,colors.black}
- local coal = {false,false,false}
- local coalInfo = {"","",""}
- local boilerInfo ={"","",""}
- local alarm = colors.orange
- local signal = colors.red
- local modeSwitch = colors.white
- local mode = "local" -- local,offline
- local switch = ""
- local tankMax = {colors.purple,colors.green}
- local tankMin = {colors.cyan,colors.lime}
- local boilerOn = {false,false,false}
- local tankLevel = {111,222}
- local rsOut = 0
- local rsInfo = 0
- local devMode = false
- local dataEvent ={}
- x, y = term.getSize()
- --Network variables
- local production = "coal"
- local typeOf = "production"
- local boilerWork ={"","",""}
- local coalLevel ={"","",""}
- --Functions--
- function drawAcross(line, char)
- term.setCursorPos(1, line)
- for i = 1, x do
- term.write(char)
- end
- end
- function drawCentered(line, text)
- term.setCursorPos((x - string.len(text))/ 2, line)
- term.write(text)
- end
- function printReport ()
- printer.newPage()
- local time = os.time()
- local day = os.day()
- local formattedTime = textutils.formatTime(time, false)
- printer.setCursorPos(1, 1)
- printer.write("Report:")
- printer.setCursorPos(1, 2)
- printer.write("Day :"..day)
- printer.setCursorPos(1, 3)
- printer.write("Time :".. formattedTime)
- printer.setCursorPos(1, 4)
- printer.write(""..printerLine1)
- printer.setCursorPos(1, 5)
- printer.write(""..printerLine2)
- printer.setCursorPos(1, 6)
- printer.write(""..printerLine3)
- printer.setCursorPos(1, 7)
- printer.write(""..printerLine4)
- printer.setCursorPos(1, 8)
- printer.write(""..printerLine5)
- printer.setCursorPos(1, 9)
- printer.write(""..printerLine6)
- printer.setCursorPos(1, 10)
- printer.write(""..printerLine7)
- printer.setCursorPos(1, 11)
- printer.write(""..printerLine8)
- printer.setCursorPos(1, 12)
- printer.write(""..printerLine9)
- printer.setCursorPos(1, 13)
- printer.write(""..printerLine10)
- printer.endPage()
- end
- function cleanPrintReport ()
- printerLine1 = ""
- printerLine2 = ""
- printerLine3 = ""
- printerLine4 = ""
- printerLine5 = ""
- printerLine6 = ""
- printerLine7 = ""
- printerLine8 = ""
- printerLine9 = ""
- printerLine10 = ""
- end
- function checkTanks ()
- check = redstone.testBundledInput (rsOutSide, tankMax[1] )
- if check == true then
- tankLevel[1] = 100
- else
- check = redstone.testBundledInput (rsOutSide, tankMin[1] )
- if check == true then
- tankLevel[1] = 51
- else
- tankLevel[1] = 0
- end
- end
- check = redstone.testBundledInput (rsOutSide, tankMax[2] )
- if check == true then
- tankLevel[2] = 100
- else
- check = redstone.testBundledInput (rsOutSide, tankMin[2] )
- if check == true then
- tankLevel[2] = 51
- else
- tankLevel[2] = 0
- end
- end
- end
- function checkCoal ()
- for i = 1, 3 do
- check = redstone.testBundledInput (rsOutSide, boilerStock[i] )
- if check == true then
- coal[i] = true
- coalInfo[i] = "Yes"
- coalLevel[i] = 100
- else
- coal[i] = false
- coalInfo[i] = "No"
- coalLevel[i] = 0
- end
- end
- end
- function checkBoiler ()
- for i = 1, 3 do
- check = redstone.testBundledInput (rsOutSide, boilerFeeder[i] )
- if check == true then
- boilerOn[i] = false
- boilerInfo[i] = "Off"
- boilerWork[i] = "no"
- else
- boilerOn[i] = true
- boilerInfo[i] = "On"
- boilerWork[i] = "yes"
- end
- end
- end
- function termClearLines ()
- term.setCursorPos(1, 5)
- term.clearLine()
- term.setCursorPos(1, 6)
- term.clearLine()
- term.setCursorPos(1, 7)
- term.clearLine()
- term.setCursorPos(1, 8)
- term.clearLine()
- term.setCursorPos(1, 9)
- term.clearLine()
- term.setCursorPos(1, 10)
- term.clearLine()
- term.setCursorPos(1, 11)
- term.clearLine()
- term.setCursorPos(1, 12)
- term.clearLine()
- term.setCursorPos(1, 13)
- term.clearLine()
- end
- function termShowInfo ()
- --steam tanks levels--
- term.setCursorPos(1, 6)
- term.write("Steam tank 1 %:"..tankLevel[1])
- term.setCursorPos(1, 7)
- term.write("Steam tank 2 %:"..tankLevel[2])
- --coal chests level--
- term.setCursorPos(1, 9)
- term.write("Fuel boiler 1:"..coalInfo[1])
- term.setCursorPos(1, 10)
- term.write("Fuel boiler 2:"..coalInfo[2])
- term.setCursorPos(1, 11)
- term.write("Fuel boiler 3:"..coalInfo[3])
- --sytem mode--
- term.setCursorPos(1, 13)
- term.write("Mode:"..mode)
- --Boilers--
- term.setCursorPos(23, 6)
- term.write("Boiler 1:"..boilerInfo[1])
- term.setCursorPos(23, 7)
- term.write("Boiler 2:"..boilerInfo[2])
- term.setCursorPos(23, 8)
- term.write("Boiler 3:"..boilerInfo[3])
- end
- function OnOff ()
- check = redstone.testBundledInput (rsOutSide, modeSwitch )
- if check == true then
- switch = "On"
- else
- switch = "Off"
- end
- end
- function siren()
- rsInfo = colors.combine(rsInfo, alarm)
- redstone.setBundledOutput(rsInfoSide, rsInfo)
- sleep (4)
- rsInfo = colors.subtract(colors.combine(rsInfo), alarm)
- redstone.setBundledOutput(rsInfoSide, rsInfo)
- end
- function prepareDatas()
- data = {production,typeOf,0,0,switch,boilerWork,coalLevel,tankLevel}
- end
- --Init--
- rsOut = colors.combine(boilerFeeder[1], boilerFeeder[2], boilerFeeder[3] )
- redstone.setBundledOutput(rsOutSide, rsOut)
- sleep (3)
- OnOff ()
- if (devMode == true) then
- term.clear()
- drawAcross(1, "-")
- drawCentered(2, "DEV mode")
- drawCentered(4,"---")
- while (devMode == true) do
- term.setCursorPos(1, 17)
- term.write("press T to refresh, E to exit, C to continue")
- local event, key = os.pullEvent( "key" )
- if key == keys.t then -- if the key pressed was 't'
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- end
- if key == keys.e then -- if the key pressed was 'e'
- devMode = false
- os.reboot()
- end
- if key == keys.c then -- if the key pressed was 'c'
- devMode = false
- end
- end
- end
- term.clear()
- drawAcross(1, "-")
- drawCentered(2, "Init.")
- drawCentered(4,"---")
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- while true do
- OnOff ()
- if switch == "Off" then
- rsOut = colors.combine(boilerFeeder[1], boilerFeeder[2], boilerFeeder[3] )
- redstone.setBundledOutput(rsOutSide, rsOut )
- term.clear()
- drawAcross(1, "-")
- drawCentered(2, "Standby mode")
- drawCentered(4,"---")
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- event = os.pullEvent("redstone")
- OnOff ()
- if switch == "On" then
- siren ()
- end
- end
- if switch == "On" then
- term.clear()
- drawAcross(1, "-")
- drawCentered(2, "Operation mode")
- drawCentered(4,"---")
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- event, dataEvent[1], dataEvent[2],dataEvent[3],dataEvent[4],dataEvent[5]= os.pullEvent()
- if (event == "char") and (dataEvent[1] == "m") then
- if mode == "local" then
- mode = "offline"
- else
- mode = "local"
- end
- end
- if (event == "redstone") or ((event == "char") and (dataEvent[1] == "r")) then
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- --Boiler 1
- if tankLevel[1] < 99 then
- boilerOn[1] = true
- else
- boilerOn[1] = false
- end
- --Boiler 2
- if (tankLevel[1] < 50) or (tankLevel[2] < 99) then
- boilerOn[2] = true
- else
- boilerOn[2] = false
- end
- --Boiler 3
- if tankLevel[2] < 50 then
- boilerOn[3] = true
- else
- boilerOn[3] = false
- end
- --If fuel
- for i = 1,3 do
- if (coal[i] == false) and (boilerOn[i] == true) then
- boilerOn[i] = false
- end
- end
- --Turn boilers on needed boilers
- for i = 1,3 do
- if boilerOn[i] == true then
- check = redstone.testBundledInput (rsOutSide, boilerFeeder[i] )
- if check == true then
- rsOut = colors.subtract(colors.combine(rsOut), boilerFeeder[i])
- redstone.setBundledOutput(rsOutSide, rsOut)
- end
- end
- end
- --Turn off the others
- for i = 1,3 do
- if boilerOn[i] == false then
- check = redstone.testBundledInput (rsOutSide, boilerFeeder[i] )
- if check == false then
- rsOut = colors.combine(rsOut, boilerFeeder[i] )
- redstone.setBundledOutput(rsOutSide, rsOut)
- end
- end
- end
- checkTanks ()
- checkCoal ()
- checkBoiler ()
- termClearLines ()
- termShowInfo ()
- end
- end
- --Sending to control room
- if mode == "local" then
- prepareDatas()
- modem.transmit(txChannel,rxChannel,textutils.serialize(data))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement