Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("bottom")
- local mon = peripheral.wrap("left")
- local cap = peripheral.wrap("right")
- capNum = 3
- --UTILITIES
- function contact(message)
- modem.transmit(621, 622, message)
- modem.open(622)
- timerID = os.startTimer(.5)
- local event, modemSide, senderChannel, replyChannel, m, senderDistance = os.pullEvent("modem_message")
- if event == "modem_message" then
- os.cancelTimer(timerID)
- modem.close(622)
- return m
- elseif event == "timer" then
- print("A timeout has occured, will skip this request")
- else
- print("An unknown event occured")
- os.cancelTimer(timerID)
- end
- modem.close(622)
- end
- maximumFuel = contact("getFuelAmountMax")
- function writeLine(x,y,label,content,colorvar,optional)
- mon.setCursorPos(x,y)
- mon.clearLine()
- mon.setTextColor(colors.white)
- mon.write(label..": ")
- mon.setTextColor(colorvar)
- if optional == nil then
- mon.write(tostring(contact(content)))
- else
- mon.write(tostring(optional))
- end
- end
- function percent(part,whole)
- --print("Part: "..tostring(part).." Whole: "..tostring(whole))
- local per = part/whole*100
- local color
- if per < 20 then color = colors.red
- elseif per < 40 then color = colors.orange
- elseif per < 60 then color = colors.yellow
- elseif per < 80 then color = colors.lime
- elseif per < 100 then color = colors.green
- elseif per == 100 then color = colors.cyan
- end
- return color
- end
- --WRITING
- function active(x,y)
- temp = contact("getActive")
- if temp then colorvar = colors.green
- else colorvar = colors.red
- end
- writeLine(x,y,"Active", _,colorvar, temp)
- end
- function displayPer(x,y,label,cont,max,append,invert,literal)
- if literal == nil then temp = contact(cont)
- else temp = cont end
- if invert then colorvar = percent(max-temp,max)
- else colorvar = percent(temp, max)
- end
- writeLine(x,y,label, _,colorvar, math.floor(temp))
- mon.setTextColor(colors.cyan)
- mon.write(" "..append.." ("..tostring(math.floor(temp/max*100)).."%)")
- end
- function colorWrite(color, text, x, y)
- if x ~= nil then
- mon.setCursorPos(x,y)
- mon.clearLine()
- end
- mon.setTextColor(color)
- mon.write(text)
- end
- function energyStored(x,y)
- displayPer(x,y,"RF in Reactor","getEnergyStored",10000000, "RF")
- end
- function fuelTemp(x,y)
- displayPer(x,y,"Fuel Temp", "getFuelTemperature",2000, "C", true)
- end
- function caseTemp(x,y)
- displayPer(x,y,"Casing Temp", "getCasingTemperature",2000,"C", true)
- end
- function efficiency(x,y)
- proE = contact("getEnergyProducedLastTick")
- cosF = contact("getFuelConsumedLastTick")
- colorWrite(colors.white, "Efficiency: ",x,y)
- colorWrite(colors.cyan, tostring(math.floor(proE/cosF)).." RF/mB")
- end
- function capEnergy(x,y)
- displayPer(x,y,"RF in Capacitor", capNum*cap.getEnergyStored(), capNum*cap.getMaxEnergyStored(), "RF", false, true)
- end
- function fuelWaste(x,y)
- colorWrite(colors.white,"Fuel: ", x, y)
- fuel = contact("getFuelAmount")
- colorWrite(percent(fuel,maximumFuel), tostring(math.floor(fuel)))
- colorWrite(colors.cyan, " mB ")
- colorWrite(colors.white, "Waste: ")
- waste = contact("getWasteAmount")
- colorWrite(percent(maximumFuel-waste,maximumFuel),tostring(waste))
- colorWrite(colors.cyan, " mB ("..tostring(math.floor(fuel/waste*100)).."%)")
- colorWrite(colors.white, "Ratio: ", x,y+1)
- colorWrite(colors.cyan, tostring(fuel/waste))
- colorWrite(colors.white, " to 1")
- end
- --MAIN LOOP
- --The monitor is 36 across
- while true do
- --mon.clear()
- mon.setTextScale(0.5)
- active(1,1)
- sleep(.1)
- energyStored(1,2)
- sleep(.1)
- capEnergy(1,3)
- sleep(.1)
- fuelTemp(1,4)
- sleep(.1)
- caseTemp(1,5)
- sleep(.1)
- fuelWaste(1,6)
- sleep(.1)
- efficiency(1,8)
- if cap.getEnergyStored()/cap.getMaxEnergyStored() > .9 then contact("setActiveFalse")
- elseif cap.getEnergyStored()/cap.getMaxEnergyStored() <.75 then contact("setActiveTrue")
- end
- if contact("getFuelAmount")<2000 then contact("setActiveFalse"); colorWrite(colors.red, "Warning! Fuel monitor tripped!", 1,9)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement