Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---first thing to do is to schedule events
- local array = {};
- local max = 0;
- for i = 0, 40 do
- array[i] = 0;
- end
- --set the task frequencies
- local tempTick = 2;
- local powerTick = 2;
- local energyTick = 3;
- local fuelTick = 2;
- local powerGraphTick = 5;
- --energy bounds
- local lowBound = 7500000;
- local highBound = 9500000;
- local targOut = 600;
- --set limits
- local tempLimit = 3000;
- --find the reactor
- local r = peripheral.find("BigReactors-Reactor")
- --redirect to monitor
- local mon = peripheral.find("monitor");
- term.redirect(mon);
- mon.setTextScale(0.5);
- --get terminal width and height
- local width, height = mon.getSize();
- ---define functions
- --draw rectangle
- function rect(x1, y1, x2, y2, col)
- local i, ii;
- term.setBackgroundColor(col);
- for i = x1, x2 do
- for ii = y1, y2 do
- term.setCursorPos(i, ii);
- term.write(' ');
- end
- end
- end
- --clear the terminal
- function clear()
- term.setBackgroundColor(colors.black);
- term.clear();
- end
- --reset colors
- function resetCols()
- term.setBackgroundColor(colors.black);
- term.setTextColor(colors.lightGray);
- end
- function drawTemps()
- local temp = math.ceil(r.getFuelTemperature());
- --core temperature
- resetCols();
- term.setTextColor(colors.white);
- term.setCursorPos(4, 6);
- term.write("Core Temp: ")
- if temp > tempLimit then
- term.setTextColor(colors.red);
- elseif temp > tempLimit * 0.75 then
- term.setTextColor(colors.orange);
- else
- term.setTextColor(colors.green);
- end
- term.write(temp);
- term.setTextColor(colors.white);
- term.write(" C ");
- resetCols();
- term.setTextColor(colors.white);
- term.setCursorPos(4, 7);
- term.write("Case Temp: ")
- temp = math.ceil(r.getCasingTemperature());
- if temp > tempLimit then
- term.setTextColor(colors.red);
- elseif temp > tempLimit * 0.75 then
- term.setTextColor(colors.yellow);
- else
- term.setTextColor(colors.green);
- end
- term.write(temp);
- term.setTextColor(colors.white);
- term.write(" C ");
- end
- function drawStatus()
- resetCols();
- term.setCursorPos(4, 4);
- --reactor status
- term.setTextColor(colors.white);
- term.write("Reactor is ");
- if r.getActive() then
- term.setTextColor(colors.green);
- term.write("Active ");
- else
- term.setTextColor(colors.red);
- term.write("Inactive");
- end
- ---draw boxes
- --upper left top
- rect(2, 2, (width * 0.5) - 1, 2, colors.lightGray);
- --upper left bottom
- rect(2, 9, (width * 0.5) - 1, 9, colors.lightGray);
- --upper left left
- rect(2, 2, 2, 8, colors.lightGray);
- --upper left right
- rect((width * 0.5) - 1, 2, (width * 0.5) - 1, 9, colors.lightGray);
- resetCols();
- term.setTextColor(colors.lightBlue);
- term.setCursorPos(((width * 0.5) - string.len(" STATUS ")) / 2, 2);
- term.write(" Status ");
- drawTemps();
- end
- function drawFuel()
- --upper right top
- rect((width * 0.5) + 1, 2, width - 1, 2, colors.lightGray);
- --upper right bottom
- rect((width * 0.5) + 1, 9, width - 1, 9, colors.lightGray);
- --upper right left
- rect((width * 0.5) + 1, 2, (width * 0.5) + 1, 9, colors.lightGray);
- --upper right right
- rect(width - 1, 2, width - 1, 9, colors.lightGray);
- local fuelPercent = math.floor((r.getFuelAmount() / r.getFuelAmountMax()) * 100);
- local wastePercent = math.ceil((r.getWasteAmount() / r.getFuelAmountMax()) * 100);
- resetCols();
- term.setTextColor(colors.lightBlue);
- term.setCursorPos((width * 0.5) + (((width * 0.5) - string.len(" Fuel "))) / 2, 2);
- term.write(" Fuel ");
- resetCols();
- term.setTextColor(colors.white);
- term.setCursorPos((width * 0.5) + 3, 4);
- term.write("Fuel Usage: ");
- term.write(math.ceil(r.getFuelConsumedLastTick() * 100) / 100);
- term.write(" mB/t ")
- term.setCursorPos((width * 0.5) + 3, 6);
- term.setTextColor(colors.yellow)
- term.write(math.ceil((r.getFuelAmountMax() - (r.getFuelAmount() + r.getWasteAmount())) / r.getFuelAmountMax() * 100));
- resetCols();
- term.write("% | ");
- term.setTextColor(colors.lightBlue);
- term.write(fuelPercent);
- resetCols();
- term.write("% | ");
- term.setTextColor(colors.blue);
- term.write(wastePercent);
- resetCols();
- term.write("% ");
- local percent = (((width - 2) - ((width * 0.5) + 3)) / 100)
- --draw free space bar
- rect((width * 0.5) + 3, 7, width - 2, 7, colors.yellow);
- --draw fuel bar
- rect((width * 0.5) + 3 + math.ceil(percent * (100 - (fuelPercent + wastePercent))), 7, width - 2, 7, colors.lightBlue);
- --draw waste bar
- rect((width * 0.5) + 3 + math.ceil(percent * (100 - wastePercent)), 7, width - 2, 7, colors.blue);
- end
- function drawRod()
- rect(width - 9, 12, width - 2, height - 2, colors.black)
- --percent
- local percent = ((height - 4) - 15) / 100;
- --lower right top
- rect(width - 10, 11, width - 1, 11, colors.lightGray);
- --lower right bottom
- rect(width - 10, height - 1, width - 1, height - 1, colors.lightGray);
- --lower right left
- rect(width - 10, 11, width - 10, height - 1, colors.lightGray);
- --lower right right
- rect(width - 1, 11, width - 1, height - 1, colors.lightGray);
- resetCols();
- term.setTextColor(colors.lightBlue);
- term.setCursorPos(width - 10 + math.ceil(((width - 1) - (width - 10) - (string.len(" Rods "))) / 2), 11);
- term.write(" Rods ");
- resetCols();
- --draw bar
- rect(width - 6, 15, width - 4, height - 3, colors.lightBlue);
- if r.getControlRodLevel(0) > 0 then
- rect(width - 5, 15, width - 5 , height - (4 + ((percent * 100) - (percent * r.getControlRodLevel(0)))), colors.blue);
- end
- resetCols();
- term.setTextColor(colors.white);
- term.setCursorPos(width - 8, 13);
- term.write(r.getControlRodLevel(0));
- term.write("% ");
- end
- function drawPower()
- rect(3, 12, width - 13, 14, colors.black);
- --reset the max if applicable
- if r.getEnergyProducedLastTick() > max then
- max = r.getEnergyProducedLastTick();
- end
- --bottom left top
- rect(2, 11, width - 12, 11, colors.lightGray);
- --bottom left bottom
- rect(2, height - 1, width - 12, height - 1, colors.lightGray);
- --bottom left left
- rect(2, 11, 2, height - 1, colors.lightGray);
- --bottom left right
- rect(width - 12, 11, width - 12, height - 1, colors.lightGray);
- resetCols();
- term.setTextColor(colors.lightBlue);
- term.setCursorPos((((width - 14) - string.len(" Power ")) / 2), 11);
- term.write(" Power ");
- resetCols();
- term.setTextColor(colors.white);
- term.setCursorPos(4, 13);
- term.write("Power Produced: ");
- term.setTextColor(colors.green);
- term.write(math.ceil(r.getEnergyProducedLastTick() * 100) / 100);
- term.setTextColor(colors.white);
- term.write(" RF/t ");
- term.setTextColor(colors.white);
- term.setCursorPos(4, 14);
- term.write("Stored Energy: ");
- term.setTextColor(colors.green);
- term.write(tostring(r.getEnergyStored()));
- term.setTextColor(colors.white);
- term.write(" RF ");
- end
- function drawGraph()
- rect(3, 15, width - 13, height - 2, colors.black)
- local percent = ((height - 3) - 17) / 100
- for i = 0, 39 do
- if i < 39 then
- array[i] = array[i + 1];
- rect(4 + i, 18 + ((percent * 100) - (percent * math.ceil((array[i] / max) * 100))), 4 + i, height - 2, colors.blue);
- else
- array[i] = math.ceil(r.getEnergyProducedLastTick() * 100) / 100;
- rect(4 + i, 18 + ((percent * 100) - (percent * math.ceil((array[i] / max) * 100))), 4 + i, height - 2, colors.blue);
- end
- end
- rect(3, height - 2, 44, height - 2, colors.black);
- end
- calTick = 0;
- function calibrate(case)
- if targOut > 0 then
- if case == 0 then
- r.setAllControlRodLevels(50)
- calTick = os.startTimer(12)
- elseif case == 1 and r.getActive() == true then
- if r.getEnergyProducedLastTick() > targOut + 10 then
- r.setAllControlRodLevels(r.getControlRodLevel(0) + 1);
- calTick = os.startTimer(3);
- elseif r.getEnergyProducedLastTick() < targOut - 10 then
- r.setAllControlRodLevels(r.getControlRodLevel(0) - 1);
- calTick = os.startTimer(3);
- else
- calTick = os.startTimer(60);
- end
- end
- else
- r.setAllControlRodLevels(0);
- end
- end
- local loading = 0;
- clear();
- --turn it on
- if r.getActive() ~= true then
- r.setActive(true);
- while loading < 100 do
- rect(1, 1, width, 1, colors.gray);
- term.setCursorPos((width - string.len(" Reactor Warmup in Progress... ")) / 2, 1);
- term.write(" Reactor Warmup in Progress... ")
- local percent = (width - 3) / 100;
- rect(2, height / 2, width - 1, height / 2, colors.lightBlue);
- rect(2, height / 2, 2 + (loading * percent), height / 2, colors.blue);
- loading = loading + 2;
- os.sleep(0.5);
- end
- end
- clear();
- drawStatus();
- drawFuel();
- drawRod();
- drawPower();
- calibrate(0);
- --set the timers
- temp = os.startTimer(tempTick);
- power = os.startTimer(powerTick);
- energy = os.startTimer(energyTick);
- fuel = os.startTimer(fuelTick);
- pgraph = os.startTimer(powerGraphTick);
- while(true) do
- if r.getEnergyStored() < lowBound and r.getActive() == false then
- r.setActive(true);
- calibrate(0);
- elseif r.getEnergyStored() > highBound then
- r.setActive(false);
- end
- ---start the program
- local event, timerID = os.pullEvent("timer");
- if timerID == temp then
- drawStatus();
- temp = os.startTimer(tempTick);
- elseif timerID == fuel then
- drawFuel();
- fuel = os.startTimer(fuelTick);
- elseif timerID == energy then
- drawRod();
- energy = os.startTimer(energyTick);
- elseif timerID == power then
- drawPower();
- power = os.startTimer(powerTick);
- elseif timerID == pgraph then
- drawGraph();
- pgraph = os.startTimer(powerGraphTick);
- elseif timerID == calTick then
- calibrate(1);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement