Advertisement
Guest User

startup

a guest
Feb 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.71 KB | None | 0 0
  1. os.sleep(10)
  2. --[[
  3.        
  4.     V0.3
  5.         Changed displayroutine for Turbines and Reactor
  6.         added return value to calcultaeFuelTime
  7.         added runtime to Reactoroverview
  8.         changed update routine to be event based
  9.         improved calibrateRpm() function to check faster for right RPM
  10.         added infotext to the computer terminal
  11.         added eventhandling for keypresses
  12.         added graphical visualization for rod insertion
  13.         added function getTotalEnergy()
  14.         added total RF/t to Monitor
  15.         added wireless script for energycore monitoring
  16.         added rednet message handling
  17.         added displayEnergyCore() to show a panel with information of the energycore
  18.         changed drawProg(), added an option to show text under the bar
  19.         added RF/t calculation to wirelessscript
  20.         added RF changerate to wirelessscript
  21.         added RF changerate to the monitor
  22.        
  23.        
  24.            
  25.     V0.2
  26.         file in filename umbenannt
  27.         color_bg in color_background umbenannt
  28.         comments leicht geåA4ndert
  29.         drawProg umgeschrieben
  30.         displayTurbine_header hinzugefåBCgt
  31.         displayTurbine veråA4ndert (Funktionsaufrufe nur an einer Stelle, local variablen auå9Ferhalb der schleife)
  32.         displayReactor (Funktionsaufrufe nur an einer Stelle)
  33.         displayReactor_bottom hinzugefåBCgt (bessere Lesbarkeit)
  34.         file_exists f in file umbenannt
  35.         calculateFuelTime String fåBCr åBCbrige Zeit angefertigt
  36.  
  37.  
  38.  
  39.         Wireless Energy monitoring script: http://pastebin.com/iv6S2Ef7
  40.  
  41.         Peripherals needed: Atleast 1 Reactor, Turbine; Monitor; Diamondchest
  42.  --]]
  43.  
  44.  
  45. modem = peripheral.wrap("back")
  46. rednet.open("right")
  47.  
  48.  
  49. --
  50. -- settings
  51. -- filename: name of the file where the settings will be saved
  52. -- color_background: color of the background of the monitor
  53. -- color_txt: font color
  54. -- color_border: color of the border of the whole monitor
  55. -- color_panel: color of the panels where the text will be
  56. -- color_header: color of the header line of panels
  57. -- targetSpeed: RPM that the reactor should aim for
  58. -- rodLevel: insertionlevel of fuelrods
  59. -- updateTime: time in Sec, how fast to update the GUI
  60. settings = {
  61.     filename = "settings.dat";
  62.     color_background = colors.blue;
  63.     color_txt = colors.white;
  64.     color_border = colors.black;
  65.     color_panel = colors.lightBlue;
  66.     color_header = colors.gray;
  67.     targetSpeed = 1820;
  68.     rodLevel = 999;
  69.     updateTime = 2;
  70.     senderId = 999;
  71. }
  72.  
  73.  
  74. -- table of tables of (list-matrix) monitors, turbines, reactors and chests
  75. local p = {
  76.     mon = { };
  77.     turb = { };
  78.     reactor = { };
  79.     chest = { };
  80. }
  81.  
  82.  
  83. -- gets all peripherals that the modem receives
  84. local peripherals = modem.getNamesRemote()
  85.  
  86.  
  87.  
  88. local statusCalibrateRpm -- boolean; variable to getRPM calibration status
  89. local energyTable = {} -- table to save data from energy core, [0]= maxEnergy [1]= energyStored
  90. local firstRun-- boolean; get first run to prevent nil Table from energycore
  91.  
  92. --
  93. -- go through all
  94. -- monitors, BigReactors-Turbines,
  95. -- BigReactors-Reactors, diamond-chests REVIEW COMMENT
  96. -- and put them in the according list in the next available slot
  97. -- @param peripherals table of peripherals available
  98. --
  99. for index, connection in pairs(peripherals) do
  100.     if peripheral.getType(connection) == "monitor" then
  101.         p.mon[#p.mon + 1] = peripheral.wrap(connection)
  102.     elseif peripheral.getType(connection) == "BigReactors-Turbine" then
  103.         p.turb[#p.turb + 1] = peripheral.wrap(connection)
  104.     elseif peripheral.getType(connection) == "BigReactors-Reactor" then
  105.         p.reactor[#p.reactor + 1] = peripheral.wrap(connection)
  106.     elseif peripheral.getType(connection) == "diamond" then
  107.         p.chest[#p.chest + 1] = peripheral.wrap(connection)
  108.     else
  109.         print(peripheral.getType(connection))
  110.         print("Was not added!")
  111.     end
  112. end
  113.  
  114.  
  115. --
  116. -- print out number of
  117. -- monitors, turbines, reactors and chests
  118. --
  119. print("New connections:")
  120. print("Monitors:        " .. #p.mon)
  121. print("Turbines:        " .. #p.turb)
  122. print("Reactors:        " .. #p.reactor)
  123. print("Chests:          " .. #p.chest)
  124.  
  125.  
  126. --
  127. -- save a table under a given name
  128. -- @param table table of parameters
  129. -- @param name name of the file
  130. --
  131. function save(table, name)
  132.     local file = fs.open(name, "w")
  133.     file.write(textutils.serialize(table))
  134.     file.close()
  135. end
  136.  
  137.  
  138. --
  139. -- load a table with a given name
  140. -- @param name name of the file that will be loaded
  141. --
  142. function load(name)
  143.     local file = fs.open(name, "r")
  144.     local data = file.readAll()
  145.     file.close()
  146.     return textutils.unserialize(data)
  147. end
  148.  
  149.  
  150. ------------------------------------------------------------------------------------------------------------
  151. ----------------------------Style functions-----------------------------------------------------------------
  152. ------------------------------------------------------------------------------------------------------------
  153.  
  154.  
  155. -- max x, y coordinate of Mon[1]
  156. monX, monY = p.mon[1].getSize()
  157.  
  158.  
  159. --
  160. -- clear monitor and reset cursorPosition
  161. --
  162. function clear()
  163.     p.mon[1].setBackgroundColor(settings.color_background)
  164.     p.mon[1].clear()
  165.     p.mon[1].setCursorPos(1, 1)
  166. end
  167.  
  168.  
  169. --
  170. -- get Text onto the screen
  171. -- @param x x-Position
  172. -- @param y y-Position
  173. -- @param text text that will be put onto the screen
  174. -- @param color_txt font color
  175. -- @param color_background background color
  176. --
  177. function drawText(x, y, text, color_txt, color_background)
  178.     p.mon[1].setBackgroundColor(color_background)
  179.     p.mon[1].setTextColor(color_txt)
  180.     p.mon[1].setCursorPos(x, y)
  181.     p.mon[1].write(text)
  182. end
  183.  
  184.  
  185. --
  186. -- draws a line out of char or spaces if !char (rectangle)
  187. -- @param x x-Position
  188. -- @param y y-Position
  189. -- @param length length in x-axis
  190. -- @param size size of the line (y-axis)
  191. -- @param color_bar background color
  192. -- @param char line made of specific char
  193. --
  194. function drawLine(x, y, length, size, color_bar, char)
  195.     for yPos = y, y + size - 1 do
  196.         p.mon[1].setBackgroundColor(color_bar)
  197.         p.mon[1].setCursorPos(x, yPos)
  198.         if char then
  199.             p.mon[1].write(string.rep(char, length))
  200.         else
  201.             p.mon[1].write(string.rep(" ", length))
  202.         end
  203.     end
  204. end
  205.  
  206.  
  207. --
  208. -- draws a progressbar
  209. -- @param x x-Position
  210. -- @param y y-Position
  211. -- @param name
  212. -- @param length length in x-axis
  213. -- @param size size in y-axis
  214. -- @param minVal min Value
  215. -- @param maxVal max Value
  216. -- @param color_bar color of the actual bar
  217. -- @param color_background background color
  218. --
  219. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_background, textUnderBar)
  220.    
  221.     drawLine(x, y, length, size, color_background)
  222.     local barSize = math.floor((minVal / maxVal) * length)
  223.     drawLine(x, y, barSize, size, color_bar)
  224.     local text = name .. " " .. math.floor((minVal / maxVal) * 100) .. "%"
  225.     local backgroundcolor = color_bar
  226.     local x_Position, y_Position
  227.     if(textUnderBar) then
  228.         x_Position = x + ((length/2)-#text/2+2)
  229.         y_Position = y + 2;
  230.         backgroundcolor = settings.color_panel
  231.     else
  232.         if barSize > monX / 2 + #text / 2 then
  233.             -- drawText(monX / 2 - #text / 2 + 2, y + size / 2, text, settings.color_txt, color_bar)
  234.             x_Position = monX / 2 - #text / 2 + 2
  235.             y_Position = y + size / 2
  236.         elseif barSize > #text then
  237.             -- drawText((x + barSize) - #text, y + size / 2, text, settings.color_txt, color_bar)
  238.             x_Position =(x + barSize) - #text
  239.             y_Position = y + size / 2
  240.         else
  241.             -- drawText(monX / 2 - #text / 2 + 2, y + size / 2, text, settings.color_txt, color_background)
  242.             backgroundcolor = color_background
  243.             x_Position = monX / 2 - #text / 2 + 2
  244.             y_Position = y + size / 2
  245.         end
  246.     end
  247.     drawText(x_Position, y_Position, text, settings.color_txt, backgroundcolor)
  248. end
  249.  
  250.  
  251. --
  252. -- draws text in the center (y-axis)
  253. -- @param y y-Position
  254. -- @param text text that will be centered
  255. -- @param color_txt font color
  256. -- @param color_background background color
  257. --
  258. function centerText(y, text, color_txt, color_background)
  259.     drawText(monX / 2 - #text / 2 + 2, y, text, color_txt, color_background)
  260. end
  261.  
  262.  
  263. --
  264. -- draws turbine panel with information of all trubines:
  265. -- number, Active, RPM, RF/t, Engaged
  266. -- @param x x-Position
  267. -- @param y y-Position
  268. --
  269. function displayTurbine_bottom(x, y)
  270.     local turbActive, coilsEngaged, font_color
  271.  
  272.     for i = 1, #p.turb do
  273.         drawText(x, y + i, "#" .. i, settings.color_txt, settings.color_panel)
  274.         if (p.turb[i].getActive()) then
  275.             turbActive = "True"
  276.             font_color = colors.green
  277.         else
  278.             turbActive = "False"
  279.             font_color = colors.red
  280.         end
  281.         drawText(10 + x, y + i, turbActive, font_color, settings.color_panel)
  282.  
  283.         drawText(18 + x, y + i, tostring(math.floor(p.turb[i].getRotorSpeed())), settings.color_txt, settings.color_panel)
  284.         drawText(24 + x, y + i, tostring(math.floor(p.turb[i].getEnergyProducedLastTick())), settings.color_txt, settings.color_panel)
  285.  
  286.         if (p.turb[i].getInductorEngaged()) then
  287.             coilsEngaged = "True"
  288.             font_color = colors.green
  289.         else
  290.             coilsEngaged = "False"
  291.             font_color = colors.red
  292.         end
  293.         drawText(31 + x, y + i, coilsEngaged, font_color, settings.color_panel)
  294.        
  295.     end
  296. end
  297.  
  298.  
  299. --
  300. -- draw routine for displayTurbine
  301. --
  302. function displayTurbine(x, y)
  303.     drawPanel(x - 1, x + 38, y - 1, y + 1 + #p.turb, settings.color_panel)
  304.     drawText(x, y, "Turbine", settings.color_header, settings.color_panel)
  305.     drawText(x + 10, y, "Active", settings.color_header, settings.color_panel)
  306.     drawText(x + 18, y, "RPM", settings.color_header, settings.color_panel)
  307.     drawText(x + 24, y, "RF/t ", settings.color_header, settings.color_panel)
  308.     drawText(x + 31, y, "Engaged", settings.color_header, settings.color_panel)
  309.  
  310.     if (#p.turb ~= 0) then
  311.         displayTurbine_bottom(x,y)
  312.     end
  313.  
  314. end
  315.  
  316.  
  317. --
  318. -- draws Reactoroverview-panel which displays overall information:
  319. -- Active, Heat, Fuel, Cost, Steam, React, #Rods REVIEW, Rodlvl
  320. -- @param x x-Position
  321. -- @param y y-Position
  322. --
  323. function displayReactor(x, y)
  324.     drawPanel(x - 1, x + 18, y - 1, y + 13, settings.color_panel)
  325.    
  326.     drawText(x, y, "Reactoroverview", settings.color_header, settings.color_panel)
  327.     if (#p.reactor ~= 0) then
  328.         displayReactor_bottom(x, y)
  329.     end
  330. end
  331.  
  332.  
  333. --
  334. -- helper function for displayReactor
  335. -- displays everything below "Heat:"-line
  336. --
  337. function displayReactor_bottom(x, y)
  338.     drawText(x + 1, y + 3, "Fuel: ", settings.color_txt, settings.color_panel)
  339.     local fuelMax = p.reactor[1].getFuelAmountMax()
  340.     local fuelAmount = p.reactor[1].getFuelAmount()
  341.     local fuelPerc =(fuelAmount / fuelMax) * 100
  342.     local reactorActive, reactorheat, font_color
  343.  
  344.     drawText(x + 1, y + 1, "Active: ", settings.color_txt, settings.color_panel)
  345.  
  346.     if (p.reactor[1].getActive()) then
  347.         reactorActive = "True"
  348.         font_color = colors.green
  349.     else
  350.         reactorActive = "False"
  351.         font_color = colors.red
  352.     end
  353.     drawText(x + 9, y + 1, reactorActive, font_color, settings.color_panel)
  354.     drawText(x + 1, y + 2, "Heat: ", settings.color_txt, settings.color_panel)
  355.  
  356.     if (p.reactor[1].getFuelTemperature() > 2000) then
  357.         font_color = colors.red
  358.     elseif (p.reactor[1].getFuelTemperature() > 1000) then
  359.         font_color = colors.purple
  360.     else
  361.         font_color = colors.white
  362.     end
  363.     drawText(x + 9, y + 2, tostring(math.floor(p.reactor[1].getFuelTemperature())) .. " C", font_color, settings.color_panel)
  364.  
  365.     drawText(x + 9, y + 3, round(fuelPerc, 1) .. " %", settings.color_txt, settings.color_panel)
  366.     drawText(x + 1, y + 4, "Cost: ", settings.color_txt, settings.color_panel)
  367.     temp = round(p.reactor[1].getFuelConsumedLastTick(), 2)
  368.     drawText(x + 9, y + 4, temp .. " mb/t", settings.color_txt, settings.color_panel)
  369.     drawText(x + 1, y + 5, "Steam: ", settings.color_txt, settings.color_panel)
  370.     drawText(x + 9, y + 5, p.reactor[1].getHotFluidProducedLastTick() .. " mb/t", settings.color_txt, settings.color_panel)
  371.     drawText(x + 1, y + 6, "React: ", settings.color_txt, settings.color_panel)
  372.     drawText(x + 9, y + 6, tostring(math.floor(p.reactor[1].getFuelReactivity())) .. " %", settings.color_txt, settings.color_panel)
  373.     drawText(x + 1, y + 7, "Rods#: ", settings.color_txt, settings.color_panel)
  374.     drawText(x + 9, y + 7, tostring(math.floor(p.reactor[1].getNumberOfControlRods())), settings.color_txt, settings.color_panel)
  375.     drawText(x + 1, y + 8, "Rodlvl: ", settings.color_txt, settings.color_panel)
  376.     drawText(x + 9, y + 8, tostring(math.floor(p.reactor[1].getControlRodLevel(0))), settings.color_txt, settings.color_panel)
  377.     drawText(x , y + 9, "Estimated Runtime", settings.color_header, settings.color_panel)
  378.     drawText(x + 1, y + 10, calculateFuelTime(), settings.color_txt, settings.color_panel)
  379.     drawText(x , y + 11, "Total RF/t", settings.color_header, settings.color_panel)
  380.     drawText(x + 1, y + 12, tostring(math.floor(getTotalEnergy())), settings.color_txt, settings.color_panel)
  381. end
  382.  
  383.  
  384. --
  385. -- draw a panel
  386. -- @param xStart Starting point x-Position
  387. -- @param xEnd End point x-Position
  388. -- @param yStart Starting point y-Position
  389. -- @param yEnd End point y-Position
  390. -- @param color color of the panel
  391. --
  392. function drawPanel(xStart, xEnd, yStart, yEnd, color)
  393.     p.mon[1].setBackgroundColor(color)
  394.     for j = yStart, yEnd do
  395.         for i = xStart, xEnd do
  396.             p.mon[1].setCursorPos(i, j)
  397.             p.mon[1].write(" ")
  398.         end
  399.     end
  400. end
  401.  
  402.  
  403. --
  404. -- shows information in the terminal
  405. --
  406. function showInfo()
  407.     term.clear()
  408.     term.setCursorPos(1,1)
  409.     print("---Peripherals connected---")
  410.     print("Monitors:        " .. #p.mon)
  411.     print("Turbines:        " .. #p.turb)
  412.     print("Reactors:        " .. #p.reactor)
  413.     print("Chests:          " .. #p.chest)
  414.     print("---------------------------")
  415.     print("press R for reboot")
  416.     print("press D to delete settings")
  417.     print("press i to reset Sender ID")
  418.     print("---------------------------")
  419. end
  420.  
  421. --
  422. -- shows a Panel with information of the draconic energy core
  423. -- @param x x-Position
  424. -- @param y y-Position
  425. --
  426. function displayEnergyCore(x,y)
  427.     local amount = energyTable[1]
  428.     local max = energyTable[0]
  429.     local rate = energyTable[2]
  430.     drawPanel(x-1, x+36, y-1, y+4, settings.color_panel)
  431.     drawText(x, y,"Energy Core", settings.color_header, settings.color_panel)
  432.     drawProg(x+1, y+1, "Energy", 34, 2, amount, max, colors.cyan, colors.lightGray, true)
  433.     drawText(x, y+3,"Changerate", settings.color_header, settings.color_panel)
  434.     if(rate > 1) then
  435.         drawText(x+1, y+4,"+"..tostring(rate).." RF/t", colors.green, settings.color_panel)
  436.     elseif(rate < 1) then
  437.         drawText(x+1, y+4,tostring(rate).." RF/t", colors.red, settings.color_panel)
  438.     end
  439.    
  440. end
  441.  
  442. ------------------------------------------------------------------------------------------------------------
  443. ----------------------------Functionality-------------------------------------------------------------------
  444. ------------------------------------------------------------------------------------------------------------
  445.  
  446.  
  447. --
  448. -- rounds the given number
  449. -- @param number given number to be rounded
  450. -- @param decimal rounding accuracy
  451. --
  452. function round(number, decimal)
  453.     local multiplier = 10 ^(decimal or 0)
  454.     return math.floor(number * multiplier + 0.5) / multiplier
  455. end
  456.  
  457.  
  458. --
  459. -- test if a file exists
  460. -- @param name name of the file
  461. --
  462. function file_exists(name)
  463.     local file = io.open(name, "r")
  464.     if file ~= nil then io.close(file) return true else return false end
  465. end
  466.  
  467. --
  468. --calculates the total RF/t produced of all turbines connected
  469. --
  470. function getTotalEnergy()
  471.     local totalEnergy = 0  
  472.  
  473.     if (#p.turb ~= 0) then
  474.         for i = 1, #p.turb do
  475.             totalEnergy = totalEnergy + p.turb[i].getEnergyProducedLastTick()
  476.         end
  477.     end
  478.     return totalEnergy
  479. end
  480.  
  481. --
  482. -- calibrates RPM of all turbines by disengaging if speed is to low
  483. -- and engaging if speed is less or equal than targeted speed
  484. --
  485. function calibrateRpm()
  486.     if oldUpdateTime == 0 then
  487.         oldUpdateTime = settings.updateTime -- save the Actual update time
  488.     end
  489.  
  490.     for i = 1, #p.turb do
  491.         if (p.turb[i].getRotorSpeed() < settings.targetSpeed - 10) then
  492.             if (p.turb[i].getInductorEngaged() == true) then
  493.                 p.turb[i].setInductorEngaged(false)
  494.                 statusCalibrateRpm = true
  495.             end
  496.         elseif(p.turb[i].getRotorSpeed() >= settings.targetSpeed) then
  497.             p.turb[i].setInductorEngaged(true)
  498.             statusCalibrateRpm = false
  499.         end
  500.     end
  501. end
  502.  
  503.  
  504. --
  505. -- calculates the remaining time the reactor could run
  506. -- based on the remaining fuel
  507. --
  508. function calculateFuelTime()
  509.     if (#p.reactor ~= 0) then
  510.         local cost = p.reactor[1].getFuelConsumedLastTick()
  511.         local fuelAmount = 0
  512.         local runtimeHrs, runtimeMin, runtimeSec, time
  513.  
  514.         for i = 1, p.chest[1].getInventorySize() do
  515.             if (p.chest[1].getStackInSlot(i)) ~= nil then
  516.                 item_name = p.chest[1].getStackInSlot(i)
  517.                 if (item_name.display_name == "Yellorium Ingot" or item_name.display_name == "Blutonium Ingot") then
  518.                     fuelAmount = fuelAmount + item_name.qty
  519.                 end
  520.             end
  521.         end
  522.         fuelAmount =(fuelAmount * 1000) + p.reactor[1].getFuelAmount()
  523.  
  524.         runtimeSec = fuelAmount / cost / 20
  525.         runtimeMin = runtimeSec / 60
  526.         runtimeHrs = runtimeMin / 60
  527.  
  528.         time = tostring(math.floor(runtimeHrs)) .. "h" .. tostring(math.floor(runtimeMin % 60)) .. "m" .. tostring(math.floor(runtimeSec % 60)).."s"
  529.         return time
  530.     else
  531.         return "no Reactor"
  532.     end
  533. end
  534.  
  535.  
  536. --
  537. -- sets the most efficient Rodlevel inside of the reactor
  538. -- could be inaccurate if the fuel level is below 100%
  539. --
  540. function setRodLevelForSteam()
  541.     if (#p.turb ~= 0) and (#p.reactor ~= 0) then
  542.         if (settings.rodLevel == 999) then
  543.             centerText(monY/2, "Setting up fuelrods, please wait...", settings.color_txt, settings.color_background)
  544.             while (p.reactor[1].getFuelTemperature() > 100) do
  545.                 p.reactor[1].setAllControlRodLevels(100)
  546.                 p.reactor[1].setActive(false)
  547.                 print("Temperatur is to high to messure. Please Wait till " .. math.floor(p.reactor[1].getFuelTemperature()) .. "<100 C")
  548.                 sleep(2)
  549.             end
  550.             --
  551.             print("Setting up the Rodlevel for the amount of Turbines connected...")
  552.             sleep(1)
  553.             local turbs = #p.turb
  554.             local steamNeeded = turbs * 2000
  555.             local actualSteam = 0
  556.             settings.rodLevel = 100
  557.             --
  558.             if (p.reactor[1].getFuelAmount() <(p.reactor[1].getFuelAmountMax() -1000)) then
  559.                 term.setTextColor(colors.red)
  560.                 print("Fuel Level below 100%, calculation of Rodlevel may be wrong")
  561.                 term.setTextColor(colors.white)
  562.                 sleep(0.5)
  563.             end
  564.             --
  565.             p.reactor[1].setActive(true)
  566.             while (steamNeeded > actualSteam) do
  567.                 print("Steam needed: " .. steamNeeded .. " Output: " .. p.reactor[1].getHotFluidProducedLastTick() .. " Rodlevel: " .. p.reactor[1].getControlRodLevel(0))
  568.                 settings.rodLevel = settings.rodLevel - 1
  569.                 p.reactor[1].setAllControlRodLevels(settings.rodLevel)
  570.             -- Visualize Rodlevel on screen
  571.                 drawLine(20, (monY/2)+3, monX-35, 1, colors.black, " ")
  572.                 drawLine(20, (monY/2)+4, monX-35, 1, colors.yellow, " ")
  573.                 drawProg(20, (monY/2)+5, "Rodlevel", monX-35, 3, settings.rodLevel, 100, colors.yellow, colors.black, false)
  574.                 drawLine(20, (monY/2)+8, monX-35, 1, colors.yellow, " ")
  575.                 drawLine(20, (monY/2)+9, monX-35, 1, colors.black, " ")
  576.                 for i = 3, 9 do
  577.                     drawText(19, (monY/2)+i, " ", colors.black, colors.black)
  578.                 end
  579.             --
  580.                 sleep(3)
  581.                 actualSteam = p.reactor[1].getHotFluidProducedLastTick()
  582.             end
  583.             --
  584.             print("Perfect Rodlevel: " .. settings.rodLevel)
  585.             save(settings, settings.filename)
  586.             print("Settings saved")
  587.         end
  588.     print("Setting Rodlevels")
  589.     p.reactor[1].setAllControlRodLevels(settings.rodLevel)
  590.     else
  591.         print("GO CRAFT A FUCKING REACTOR YOU LAZY BASTERD, or a Turbine")
  592.     end
  593. end
  594.  
  595. --
  596. -- Get input from user, to set Sender ID
  597. --
  598. function getSenderID()
  599.     if (settings.senderId == 999) then
  600.         term.clear()
  601.          term.setCursorPos(1,1)
  602.         print("Please input the ID of the sending computer:")
  603.         print("You get this ID by typing 'id' in the console of a computer.")
  604.         local number
  605.         while true do
  606.           number=read()
  607.           number=tonumber(number)
  608.           if number then
  609.                 break --break out of while true loop
  610.           end
  611.           --complain
  612.  
  613.           term.setTextColor(colors.red)
  614.           print("Please provide a valid number!")
  615.           term.setTextColor(colors.white)
  616.         end
  617.         settings.senderId = number
  618.     end
  619.  
  620. end
  621.  
  622.  
  623.  
  624.  
  625. --
  626. -- updates the GUI
  627. --
  628. function update()
  629.     clear()
  630.     displayTurbine(3, 3)
  631.     displayReactor(63, 3)
  632.     if (firstRun == false) then
  633.         displayEnergyCore(45, 19)
  634.     end
  635.     calibrateRpm()
  636.     showInfo()
  637.    
  638. end
  639.  
  640.  
  641. --
  642. -- initializes the reactor setup
  643. --
  644. function init()
  645.     if (file_exists(settings.filename)) then
  646.         settings = load(settings.filename)
  647.     end
  648.     clear()
  649.     firstRun = true
  650.     getSenderID()
  651.     setRodLevelForSteam()
  652.    
  653.     sleep(0.5)
  654.     print("Activating Turbines")
  655.     sleep(0.5)
  656.     for i = 1, #p.turb do
  657.         p.turb[i].setActive(true)
  658.     end
  659.     print("Setup Ready and running!")
  660.  
  661. end
  662.  
  663.  
  664. init()
  665.  
  666. ------------------------------------------------------------------------------------------------------------
  667. ----------------------------Main loop-----------------------------------------------------------------------
  668. ------------------------------------------------------------------------------------------------------------
  669. while true do
  670.     update()
  671.     save(settings, settings.filename)
  672.     if(statusCalibrateRpm == false) then
  673.         tID = os.startTimer(settings.updateTime) --start updateTimer
  674.     else
  675.         tID = os.startTimer(0.5) --start calibrate timer
  676.     end
  677.  
  678.  
  679.  
  680. repeat
  681.     -- Event handling
  682.     local evt, p1, p2, p3 = os.pullEvent()
  683.     -- Keypress
  684.     if (evt == "char") then
  685.         if (p1 == "r") then
  686.             os.reboot()
  687.         elseif (p1 == "d") then
  688.             fs.delete (settings.filename)
  689.             os.reboot()
  690.         elseif (p1 == "i") then
  691.                 settings.senderId = 999
  692.                 getSenderID()
  693.                 save(settings, settings.filename)
  694.                 update()
  695.                 tID = os.startTimer(settings.updateTime)
  696.         end
  697.     -- Rednet Message
  698.     elseif(evt == "rednet_message") then
  699.             if(p1 == settings.senderId) then
  700.                 energyTable = textutils.unserialize(p2)
  701.                 if (firstRun == true) then
  702.                     displayEnergyCore(45, 19)
  703.                     firstRun = false
  704.                 end
  705.                
  706.             end    
  707.     end
  708.  
  709.     until (evt == "timer" and p1 == tID)
  710.  
  711. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement