Advertisement
MaximumFrank

ReactOS

Sep 19th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.21 KB | None | 0 0
  1. ---start vbuffer functions
  2.     function new(_w, _h)
  3.         --just in case, declare these guys locally
  4.         local i;
  5.         local j;
  6.  
  7.         --initialize the template buffer
  8.         local buffer = {};
  9.  
  10.         --loop through one iteration of _w, and catch all elements on the way
  11.         for i = 1, _w do
  12.             --create the three parts of the array: bgCol, txCol, and tx
  13.             buffer[i] = {};
  14.             buffer[i + _w] = {};
  15.             buffer[i + (2 * _w)] = {};
  16.             for j = 1, _h do
  17.                 buffer[i][j] = colors.black;
  18.                 buffer[i + _w][j] = colors.white;
  19.                 buffer[i + (2 * _w)][j] = "";
  20.             end
  21.         end
  22.  
  23.         return buffer;
  24.     end
  25.  
  26.     function init()
  27.         --get terminal width and height
  28.         local _w;
  29.         local _h;
  30.         _w, _h = term.getSize();
  31.  
  32.         --call the new() function to generate the template buffer
  33.         local buffer = new(_w, _h);
  34.         buffer = textutils.serialize(buffer);
  35.  
  36.         --set the video and frame buffer to equal the template buffer
  37.         _G.vBuffer = textutils.unserialize(buffer);
  38.         _G.fBuffer = textutils.unserialize(buffer);
  39.  
  40.         --set the application buffer to equal the template buffer
  41.         _G.aBuffer = textutils.unserialize(buffer);
  42.  
  43.         --set the error buffer to equal the template buffer
  44.         _G.eBuffer = textutils.unserialize(buffer);
  45.     end
  46.  
  47.     function add(buffer, x, y, bgCol, txcol, tx)
  48.         --make sure that everything is not out of bounds
  49.         if x <= #buffer / 3 and y <= #buffer[1] then
  50.             --make sure they want to change bgCol
  51.             if bgCol ~= nil then
  52.                 buffer[x][y] = bgCol;
  53.             end
  54.  
  55.             --make sure they want to change txCol
  56.             if txcol ~= nil then
  57.                 buffer[x + (#buffer / 3)][y] = txcol;
  58.             end
  59.  
  60.             --make sure they want to change tx
  61.             if tx ~= nil then
  62.                 buffer[x + ( 2 * #buffer / 3)][y] = tx;
  63.             end
  64.         end
  65.  
  66.         --return the buffer
  67.         return buffer;
  68.     end
  69.  
  70.     function write(buffer, x, y, bgCol, txcol, tx)
  71.         --declare this locally just in case
  72.         local i;
  73.  
  74.         for i = 1, string.len(tx) do
  75.             --they obviously want to change the text
  76.             buffer = add(buffer, x + i - 1, y, bgCol, txcol, string.sub(tx, i, i));
  77.         end
  78.  
  79.         --return the new buffer
  80.         return buffer;
  81.     end
  82.  
  83.     function rect(buffer, x1, y1, x2, y2, bgCol, txcol, tx)
  84.         --declare these locally just in case
  85.         local i;
  86.         local j;
  87.  
  88.         if tx == nil then
  89.             tx = " ";
  90.         end
  91.  
  92.         --loop through the all of the elements needed
  93.         for i = x1, x2 do
  94.             for j = y1, y2 do
  95.                 buffer = add(buffer, i, j, bgCol, txcol, tx);
  96.             end
  97.         end
  98.  
  99.         --return the buffer
  100.         return buffer;
  101.     end
  102.  
  103.     function fill(buffer, bgCol, txcol, tx)
  104.         --declare these locally just in case
  105.         local i;
  106.         local j;
  107.         local _w;
  108.         local _h;
  109.  
  110.         --get the terminal size
  111.         _w, _h = term.getSize();
  112.  
  113.         --fill the screen
  114.         buffer = rect(buffer, 1, 1, _w, _h, bgCol, txcol, tx);
  115.  
  116.         --return the buffer
  117.         return buffer;
  118.     end
  119.  
  120.     function renderto(buffer, renderBuffer)
  121.         --declare these locally just in case
  122.         local i;
  123.         local j;
  124.  
  125.         for i = 1, #buffer / 3 do
  126.             for j = 1, #buffer[1] do
  127.                 if buffer[i + (2 * #buffer / 3)][j] ~= "" and buffer[i + (2 * #buffer / 3)][j] ~= nil then
  128.                     renderBuffer = add(renderBuffer, i, j, buffer[i][j], buffer[i + (#buffer / 3)][j], buffer[i + (2 * #buffer / 3)][j]);
  129.                 end
  130.             end
  131.         end
  132.     end
  133.  
  134.     function drawScreen()
  135.         --render the current desktop and application buffers to the frame buffer
  136.         renderto(aBuffer, fBuffer);
  137.         renderto(eBuffer, fBuffer);
  138.  
  139.         --declare these locally just in case
  140.         local i;
  141.         local j;
  142.  
  143.         for i = 1, #fBuffer / 3 do
  144.             for j = 1, #fBuffer[1] do
  145.                 --set the cursor position to the current pixel
  146.                 term.setCursorPos(i, j);
  147.                 --make sure that the current frame's bgCol is not nil
  148.                 if fBuffer[i][j] ~= nil then
  149.                     term.setBackgroundColor(fBuffer[i][j]);
  150.                 else
  151.                     --otherwise set the background color to black
  152.                     term.setBackgroundColor(vBuffer[i][j]);
  153.                 end
  154.  
  155.                 --make sure that the current frame's txCol is not nil
  156.                 if fBuffer[i + (#fBuffer / 3)][j] ~= nil then
  157.                     term.setTextColor(fBuffer[i + (#fBuffer / 3)][j]);
  158.                 else
  159.                     --otherwise set the text color to white
  160.                     term.setTextColor(vBuffer[i + (#vBuffer / 3)][j]);
  161.                 end
  162.  
  163.                 --make sure that the current frame's tx is not nil or ""
  164.                 if fBuffer[i + (2 * #fBuffer / 3)][j] ~= nil and fBuffer[i + (2 * #fBuffer / 3)][j] ~= "" then
  165.                     term.write(fBuffer[i + (2 * #fBuffer / 3)][j]);
  166.                 end
  167.             end
  168.         end
  169.  
  170.         --render the current frame to vBuffer
  171.         renderto(fBuffer, vBuffer);
  172.     end
  173.  
  174. ---load settings api
  175.     local s;
  176.     if fs.exists("/Settings") then
  177.         os.loadAPI("/Settings");
  178.     --if it doesn't exist, make the default settings
  179.     else
  180.         local file = fs.open("/Settings", "w");
  181.         file.writeLine("--reactor optimization");
  182.         file.writeLine("--NOTE: this will adjust control rods to keep reactor at");
  183.         file.writeLine("--      an optimal temperature to conserve fuel");
  184.         file.writeLine("--      activated at the fuel percentage specified below (0 for off)");
  185.         file.writeLine("--WARNING: this can limit power output by as much as half");
  186.         file.writeLine("optimizeLevel = 50;");
  187.         file.writeLine("");
  188.  
  189.         file.writeLine("--reactor automation");
  190.         file.writeLine("--NOTE: this will enable and disable the reactor to keep");
  191.         file.writeLine("--      stored power in specified range (in millions)")
  192.         file.writeLine("deactivateLevel = 9");
  193.         file.writeLine("activateLevel = 7.5");
  194.         file.writeLine("");
  195.  
  196.         file.writeLine("--set reactor warmup before OS starts (in seconds)");
  197.         file.writeLine("--NOTE: warmup is disabled if reactor is already on");
  198.         file.writeLine("--NOTE: disabling warmup completely can cause issues with graphing");
  199.         file.writeLine("warmup = 5;")
  200.         file.writeLine("");
  201.  
  202.         file.writeLine("--set update frequencies (in seconds; minimum of 0.05)");
  203.         file.writeLine("powerUpdate = 0.5;");
  204.         file.writeLine("graphUpdate = 3;");
  205.         file.writeLine("fuelUpdate = 0.5;");
  206.         file.writeLine("tempUpdate = 1;");
  207.         file.writeLine("");
  208.  
  209.         file.writeLine("--set graph type (0 is power usage graph, 1 is power production graph)")
  210.         file.writeLine("--NOTE: graph type 0 can get buggy when reactor is on...");
  211.         file.writeLine("graphType = 0;");
  212.         file.writeLine("");
  213.  
  214.         file.writeLine("--set colors");
  215.         file.writeLine("--NOTE: only use colors API color definitions");
  216.         file.writeLine("backgroundColor = colors.black;");
  217.         file.writeLine("textColor = colors.white;");
  218.         file.writeLine("borderColor = colors.lightGray;");
  219.         file.writeLine("labelColor = colors.lightBlue;");
  220.         file.writeLine("graphColor = colors.blue;");
  221.         file.writeLine("freeSpaceColor = colors.yellow;");
  222.         file.writeLine("fuelColor = colors.lightBlue;");
  223.         file.writeLine("wasteColor = colors.blue;");
  224.         file.writeLine("positiveColor = colors.green;");
  225.         file.writeLine("negativeColor = colors.red;");
  226.         file.writeLine("");
  227.  
  228.         file.writeLine("--enable terminal glasses HUD");
  229.         file.writeLine("--NOTE: this will draw over current HUD");
  230.         file.writeLine("enableGlasses = false;");
  231.         file.writeLine("--quadrant to display the HUD in the corner of");
  232.         file.writeLine("quadrant = 3;");
  233.         file.writeLine("opacity = 0.2");
  234.  
  235.         file.close();
  236.  
  237.         os.loadAPI("/Settings");
  238.     end
  239.  
  240. --redirect to monitor
  241.     local mon = peripheral.find("monitor");
  242.     term.redirect(mon);
  243.     mon.setTextScale(0.5);
  244.  
  245. --get terminal width and height
  246.     local _w, _h = mon.getSize();
  247.  
  248. --attach reactor
  249.     local r = peripheral.find("BigReactors-Reactor");
  250.  
  251. ---load necessary vbuffers
  252.     init();
  253.  
  254. ---initialize necessary graphing array
  255.     local graphArray = {};
  256.     local lastPower = r.getEnergyStored();
  257.     local highest = 0;
  258.  
  259.     for i = 0, _w - 16 do
  260.         graphArray[i] = 0;
  261.     end
  262.  
  263. ---import variables from settings file
  264.     --reactor optimization
  265.     local oLevel = Settings.optimizeLevel;
  266.  
  267.     --reactor automation
  268.     local hBound = Settings.deactivateLevel * 1000000;
  269.     local lBound = Settings.activateLevel * 1000000;
  270.  
  271.     --warmup period
  272.     local warm = Settings.warmup;
  273.  
  274.     --update frequencies
  275.     local pTick = Settings.powerUpdate;
  276.     local gTick = Settings.graphUpdate;
  277.     local fTick = Settings.fuelUpdate;
  278.     local tTick = Settings.tempUpdate;
  279.  
  280.     --graph type
  281.     local gType = Settings.graphType;
  282.  
  283.     --colors
  284.     local bgCol = Settings.backgroundColor;
  285.     local tCol = Settings.textColor;
  286.     local bCol = Settings.borderColor;
  287.     local lCol = Settings.labelColor;
  288.     local gCol = Settings.graphColor;
  289.     local sCol = Settings.freeSpaceColor;
  290.     local fCol = Settings.fuelColor;
  291.     local wCol = Settings.wasteColor;
  292.     local pCol = Settings.positiveColor;
  293.     local nCol = Settings.negativeColor;
  294.  
  295.     --terminal glasses
  296.     local gEnabled = Settings.enableGlasses;
  297.     local q = Settings.quadrant;
  298.     local o = Settings.opacity;
  299.  
  300. ---reactor main functions
  301.     function drawStatus()
  302.         --turn on if power is below low bound
  303.         if r.getEnergyStored() <= lBound and r.getActive() == false then
  304.             r.setActive(true);
  305.         elseif r.getEnergyStored() >= hBound and r.getActive() then
  306.             r.setActive(false);
  307.         end
  308.  
  309.  
  310.         --draw border
  311.         aBuffer = rect(aBuffer, 2, 2, _w * 0.5 - 1, 9, bCol, tCol, ' ');
  312.         aBuffer = rect(aBuffer, 3, 3, _w * 0.5 - 2, 8, bgCol, tCol, ' ');
  313.  
  314.         aBuffer = write(aBuffer, math.ceil(((_w * 0.5) - 1 - string.len(" Status ")) / 2), 2, bgCol, tCol, " Status ");
  315.  
  316.         --reactor activity
  317.         aBuffer = write(aBuffer, 4, 4, bgCol, tCol, "Reactor is ");
  318.         if r.getActive() then
  319.             aBuffer = write(aBuffer, 4 + string.len("Reactor is "), 4, bgCol, pCol, "Active");
  320.         else
  321.             aBuffer = write(aBuffer, 4 + string.len("Reactor is "), 4, bgCol, nCol, "Inactive");
  322.         end
  323.  
  324.         --reactor temps
  325.  
  326.         --fuel temp
  327.         aBuffer = write(aBuffer, 4, 6, bgCol, tCol, "Core Temp: ");
  328.         if (r.getFuelTemperature() > 1000 or r.getFuelTemperature() < 800) and r.getActive() then
  329.             aBuffer = write(aBuffer, 4 + string.len("Core Temp: "), 6, bgCol, nCol, math.ceil(r.getFuelTemperature()));
  330.         else
  331.             aBuffer = write(aBuffer, 4 + string.len("Core Temp: "), 6, bgCol, pCol, math.ceil(r.getFuelTemperature()));
  332.         end
  333.         aBuffer = write(aBuffer, 4 + string.len("Core Temp: ") + #tostring(math.ceil(r.getFuelTemperature())) + 1, 6, bgCol, tCol, "C");
  334.  
  335.         --case temp
  336.         aBuffer = write(aBuffer, 4, 7, bgCol, tCol, "Case Temp: ");
  337.         if r.getCasingTemperature() > 1000 then
  338.             aBuffer = write(aBuffer, 4 + string.len("Case Temp: "), 7, bgCol, nCol, math.floor(r.getCasingTemperature()));
  339.         else
  340.             aBuffer = write(aBuffer, 4 + string.len("Case Temp: "), 7, bgCol, pCol, math.floor(r.getCasingTemperature()));
  341.         end
  342.         aBuffer = write(aBuffer, 4 + string.len("Case Temp: ") + #tostring(math.floor(r.getCasingTemperature())) + 1, 7, bgCol, tCol, "C");
  343.     end
  344.  
  345.     function drawFuel()
  346.         --draw border
  347.         aBuffer = rect(aBuffer, math.ceil(_w * 0.5), 2, _w - 1, 9, bCol, tCol, ' ');
  348.         aBuffer = rect(aBuffer, math.ceil(_w * 0.5) + 1, 3, _w - 2, 8, bgCol, tCol, ' ');
  349.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + math.ceil(((_w - 1) - math.ceil(_w * 0.5) - string.len(" Fuel ")) / 2), 2, bgCol, tCol, " Fuel ");
  350.  
  351.         --draw mB/t display
  352.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2, 4, bgCol, tCol, "Fuel Usage: " .. tostring(math.ceil(r.getFuelConsumedLastTick() * 100) / 100) .. " mB/t");
  353.  
  354.         --draw free space bar
  355.         aBuffer = rect(aBuffer, math.ceil(_w * 0.5) + 2, 7, _w - 3, 7, sCol, tCol, ' ');
  356.  
  357.         --draw fuel bar
  358.         local wastePercent = r.getWasteAmount() / r.getFuelAmountMax();
  359.         local fuelPercent = r.getFuelAmount() / r.getFuelAmountMax();
  360.  
  361.         local byAmount = (_w - 3) - math.floor(((_w - 3) - ((_w * 0.5) + 2)) * (fuelPercent + wastePercent));
  362.         aBuffer = rect(aBuffer, byAmount, 7, _w - 3, 7, fCol, tCol, ' ');
  363.  
  364.         --draw waste bar
  365.         byAmount = (_w - 3) - math.floor(((_w - 3) - ((_w * 0.5) + 2)) * wastePercent);
  366.         aBuffer = rect(aBuffer, byAmount, 7, _w - 3, 7, wCol, tCol, ' ');
  367.  
  368.         --draw percentages
  369.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2, 6, bgCol, sCol, math.ceil(100 - ((fuelPercent + wastePercent) * 100)));
  370.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2 + string.len(tostring(math.ceil(100 - ((fuelPercent + wastePercent) * 100)))), 6, bgCol, tCol, "% | ");
  371.  
  372.  
  373.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2 + string.len(tostring(math.ceil(100 - ((fuelPercent + wastePercent) * 100)))) + #"% | ", 6, bgCol, fCol, 100 - (math.ceil(100 - ((fuelPercent + wastePercent) * 100)) + math.ceil(wastePercent * 100)));
  374.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2 + string.len(tostring(math.ceil(100 - ((fuelPercent + wastePercent) * 100)))) + #"% | " + #tostring(100 - (math.ceil(100 - ((fuelPercent + wastePercent) * 100)) + math.ceil(wastePercent * 100))), 6, bgCol, tCol, "% | ");
  375.  
  376.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2 + string.len(tostring(math.ceil(100 - ((fuelPercent + wastePercent) * 100)))) + (2 * #"% | ") + #tostring(100 - (math.ceil(100 - ((fuelPercent + wastePercent) * 100)) + math.ceil(wastePercent * 100))), 6, bgCol, wCol, math.ceil(wastePercent * 100));
  377.         aBuffer = write(aBuffer, math.ceil(_w * 0.5) + 2 + string.len(tostring(math.ceil(100 - ((fuelPercent + wastePercent) * 100)))) + (2 * #"% | ") + #tostring(100 - (math.ceil(100 - ((fuelPercent + wastePercent) * 100)) + math.ceil(wastePercent * 100))) + #tostring(math.floor(wastePercent * 100)), 6, bgCol, tCol, "%");
  378.     end
  379.  
  380.     function drawRod()
  381.         --draw border
  382.         aBuffer = rect(aBuffer, _w - 10, 11, _w - 1, _h - 1, bCol, tCol, ' ');
  383.         aBuffer = rect(aBuffer, _w - 9, 12, _w - 2, _h - 2, bgCol, tCol, ' ');
  384.         aBuffer = write(aBuffer, _w - 10 + math.ceil(((_w - 1) - (_w - 10) - #" Rods ") / 2), 11, bgCol, tCol, " Rods ");
  385.  
  386.         --draw control rod level
  387.         aBuffer = write(aBuffer, _w - 8 + math.ceil(((_w - 3) - (_w - 8) - #(tostring(r.getControlRodLevel(0)).. "%")) / 2), 13, bgCol, tCol, tostring(r.getControlRodLevel(0)) .. "%");
  388.  
  389.         --draw rod visual indicator
  390.         aBuffer = rect(aBuffer, _w - 7, 15, _w - 4, _h - 3, fCol, tCol, ' ');
  391.         aBuffer = rect(aBuffer, _w - 6, 15, _w - 5, 15 + math.floor((_h - 18) * ((r.getControlRodLevel(0) - 1) / 100)), wCol, tCol, ' ');
  392.     end
  393.  
  394.     function drawPower()
  395.         --draw border
  396.         aBuffer = rect(aBuffer, 2, 11, _w - 12, _h - 9, bCol, tCol, ' ');
  397.         aBuffer = rect(aBuffer, 3, 12, _w - 13, _h - 9, bgCol, tCol, ' ');
  398.         aBuffer = write(aBuffer, math.ceil(((_w - 9) - #" Energy ") / 2), 11, bgCol, tCol, " Energy ");
  399.  
  400.         --draw production
  401.         aBuffer = write(aBuffer, 4, 13, bgCol, tCol, "Energy Produced: ");
  402.         aBuffer = write(aBuffer, 4 + #"Energy Produced: ", 13, bgCol, pCol, math.floor(r.getEnergyProducedLastTick()));
  403.         aBuffer = write(aBuffer, 4 + #"Energy Produced: " + #tostring(math.floor(r.getEnergyProducedLastTick())), 13, bgCol, tCol, " RF/t");
  404.  
  405.         --draw stored
  406.         aBuffer = write(aBuffer, 4, 14, bgCol, tCol, "Energy Stored: ");
  407.         aBuffer = write(aBuffer, 4 + #"Energy Stored: ", 14, bgCol, pCol, r.getEnergyStored());
  408.         aBuffer = write(aBuffer, 4 + #"Energy Stored: " + #tostring(r.getEnergyStored()), 14, bgCol, tCol, " RF");
  409.     end
  410.  
  411.     function drawGraph()
  412.         aBuffer = rect(aBuffer, 2, _h - 9, _w - 12, _h - 1, bCol, tCol, ' ');
  413.         aBuffer = rect(aBuffer, 3, _h - 9, _w - 13, _h - 2, bgCol, tCol, ' ');
  414.  
  415.         for i = 0, _w - 16 do
  416.             if i == 0 and graphArray[i] == highest then
  417.                 highest = 0;
  418.                 for j = 1, _w - 16 do
  419.                     highest = math.max(graphArray[j], highest);
  420.                 end
  421.             end
  422.  
  423.             if i < _w - 16 then
  424.                 graphArray[i] = graphArray[i + 1];
  425.             else
  426.                 if gType == 1 then
  427.                     graphArray[i] = r.getEnergyProducedLastTick();
  428.                 else
  429.                     graphArray[i] = math.max((lastPower - r.getEnergyStored()) / (20 * gTick), 0);
  430.                 end
  431.             end
  432.  
  433.             highest = math.max(graphArray[i], highest);
  434.  
  435.             if highest ~= 0 then
  436.                 aBuffer = rect(aBuffer, 3 + i, math.floor(_h - 2 - ((_h - 18) * (graphArray[i] / highest))), 3 + i, _h - 2, gCol, tCol, ' ');
  437.             end
  438.         end
  439.  
  440.         lastPower = r.getEnergyStored();
  441.     end
  442.  
  443.     function calibrate()
  444.         if r.getFuelAmount() * 100 / r.getFuelAmountMax() <= oLevel  and r.getActive() == true then
  445.             if r.getFuelTemperature() > 1000 then
  446.                 r.setAllControlRodLevels(r.getControlRodLevel(0) + (100 - r.getControlRodLevel(0)) / 8)
  447.             elseif r.getFuelTemperature() < 800 then
  448.                 r.setAllControlRodLevels(r.getControlRodLevel(0)/8);
  449.             end
  450.         elseif r.getActive() == true then
  451.             r.setAllControlRodLevels(0);
  452.         end
  453.     end
  454.  
  455.     function drawGlasses()
  456.         g.clear();
  457.         stText = g.addText(5, -15, "Reactor Status: ");
  458.         if r.getActive() then
  459.             active = g.addText(5 + 5 * #"Reactor Status: ", -15, "Active", 0x00FF00);
  460.         else
  461.             active = g.addText(5 + 5 * #"Reactor Status: ", -15, "Inactive", 0xFF0000);
  462.         end
  463.  
  464.         fText = g.addText(5, -5, "Reactor Fuel: ");
  465.  
  466.         local col = 0x000000;
  467.  
  468.         if math.floor((r.getFuelAmount() * 100) / r.getFuelAmountMax()) >= 75 then
  469.             col = 0x00FF00;
  470.         elseif math.floor((r.getFuelAmount() * 100) / r.getFuelAmountMax()) < 75 and math.floor((r.getFuelAmount() * 100) / r.getFuelAmountMax()) >= 50 then
  471.             col = 0xFFFF00;
  472.         else
  473.             col = 0xFF0000;
  474.         end
  475.  
  476.         fuel = g.addText(5 + 5 * #"Reactur Fuel: ", -5, tostring(math.floor(r.getFuelAmount() * 100/ r.getFuelAmountMax())) .. "%", col)
  477.  
  478.         if q == 1 then
  479.             stText.setAlignment("right", "top");
  480.             active.setAlignment("right", "top");
  481.             fText.setAlignment("right", "top");
  482.             fuel("right", "top");
  483.         elseif q == 2 then
  484.             stText.setAlignment("left", "top");
  485.             active.setAlignment("left", "top");
  486.             fText.setAlignment("left", "top");
  487.             fuel.setAlignment("left", "top");
  488.         elseif q == 3 then
  489.             stText.setAlignment("left", "bottom");
  490.             active.setAlignment("left", "bottom");
  491.             fText.setAlignment("left", "bottom");
  492.             fuel.setAlignment("left", "bottom");
  493.         elseif q == 4 then
  494.             stText.setAlignment("right", "bottom");
  495.             active.setAlignment("right", "bottom");
  496.             fText.setAlignment("right", "bottom");
  497.             fuel.setAlignment("right", "bottom");
  498.         end
  499.  
  500.         g.sync()
  501.     end
  502.  
  503. --attach glasses bridge
  504.     if gEnabled == true then
  505.         g = peripheral.find("openperipheral_bridge");
  506.     end
  507.  
  508. ---start warmup
  509.     if warm > 0  and not r.getActive() then
  510.         local w = 0;
  511.         while w < warm do
  512.             r.setActive(true);
  513.             local percent = math.ceil((_w - 3) * (w / warm));
  514.  
  515.             aBuffer = fill(aBuffer, bgCol, tCol, ' ');
  516.  
  517.             aBuffer = rect(aBuffer, 1, 1, _w, 1, bCol, nil, nil, nil)
  518.             aBuffer = write(aBuffer, math.ceil((_w - string.len("Reactor warmup in progress...")) / 2), 1, bCol, tCol, "Reactor warmup in progress...")
  519.  
  520.             aBuffer = rect(aBuffer, 5, math.ceil(_h / 2) + 1, _w - 3, math.ceil(_h / 2) + 1, fCol, tCol, ' ');
  521.             aBuffer = rect(aBuffer, 5, math.ceil(_h / 2) + 1, percent, math.ceil(_h / 2) + 1, wCol, nil, ' ');
  522.  
  523.             drawScreen();
  524.  
  525.             sleep(1);
  526.  
  527.             w = w + 1;
  528.         end
  529.     end
  530.  
  531. --initialize screen
  532.     aBuffer = fill(aBuffer, bgCol, tCol, nil);
  533.  
  534. --pre-render the screen
  535.     drawStatus();
  536.     drawFuel();
  537.     drawRod();
  538.     drawPower();
  539.     drawGraph();
  540.  
  541.     drawScreen();
  542.  
  543. --schedule events
  544.     local status = os.startTimer(tTick);
  545.     local fuel = os.startTimer(fTick);
  546.     local rod = os.startTimer(fTick);
  547.     local power = os.startTimer(pTick);
  548.     local graph = os.startTimer(gTick);
  549.     local getStore = os.startTimer(pTick - 0.05);
  550.     local glasses;
  551.     local optimum = os.startTimer(10);
  552.  
  553.     local dstat, dfuel, drod, dpower, dgraph, dglass;
  554.  
  555. --start glasses timer
  556.     if gEnabled == true then
  557.         glasses = os.startTimer(0.05);
  558.     end
  559.  
  560.     local stored = 0;
  561.  
  562. --run main loop
  563. while true do
  564.     local event, timerID = os.pullEvent("timer");
  565.  
  566.     if timerID == status then
  567.         dstat = coroutine.create(drawStatus);
  568.         ok, err = coroutine.resume(dstat);
  569.         if not ok then
  570.             error(err);
  571.         end
  572.         status = os.startTimer(tTick);
  573.     elseif timerID == fuel then
  574.         dfuel = coroutine.create(drawFuel);
  575.         ok, err = coroutine.resume(dfuel);
  576.         if not ok then
  577.             error(err);
  578.         end
  579.         fuel = os.startTimer(fTick);
  580.     elseif timerID == rod then
  581.         drod = coroutine.create(drawRod);
  582.         ok, err = coroutine.resume(drod);
  583.         if not ok then
  584.             error(err);
  585.         end
  586.         rod = os.startTimer(fTick);
  587.     elseif timerID == graph then
  588.         dgraph = coroutine.create(drawGraph);
  589.         ok, err = coroutine.resume(dgraph);
  590.         if not ok then
  591.             error(err);
  592.         end
  593.         graph = os.startTimer(gTick);
  594.     elseif timerID == glasses then
  595.         dglass = coroutine.create(drawGlasses);
  596.         ok, err = coroutine.resume(dglass);
  597.         if not ok then
  598.             error(err);
  599.         end
  600.         glasses = os.startTimer(0.05);
  601.     elseif timerID == power then
  602.         dpower = coroutine.create(drawPower);
  603.         ok, err = coroutine.resume(dpower);
  604.         if not ok then
  605.             error(err);
  606.         end
  607.         power = os.startTimer(pTick);
  608.     elseif timerID == optimum then
  609.         dcalibrate = coroutine.create(calibrate);
  610.         ok, err = coroutine.resume(dcalibrate);
  611.         if not ok then
  612.             error(err);
  613.         end
  614.         optimum = os.startTimer(10);
  615.     end
  616.  
  617.     --draw the screen
  618.     drawScreen();
  619. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement