Advertisement
fusty

BigReactor Turbine Control

Nov 25th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 97.88 KB | None | 0 0
  1. --[[
  2. Program name: Lolmer's EZ-NUKE reactor control system
  3. Version: v0.3.14
  4. Programmer: Lolmer
  5. Great assistance by Mechaet
  6. Last update: 2014-09-30
  7. Pastebin: http://pastebin.com/fguScPBQ
  8.  
  9. Description:
  10. This program controls a Big Reactors nuclear reactor in Minecraft with a Computercraft computer, using Computercraft's own wired modem connected to the reactors computer control port.
  11.  
  12. This program was designed to work with the mods and versions installed on Never Stop Toasting (NST) Diet http://www.technicpack.net/modpack/details/never-stop-toasting-diet.254882 Endeavour: Never Stop Toasting: Diet official Minecraft server http://forums.somethingawful.com/showthread.php?threadid=3603757
  13.  
  14. To simplify the code and guesswork, I assume the following monitor layout, where each "monitor" listed below is a collection of 3 wide by two high Advanced Monitors:
  15. 1) One Advanced Monitor for overall status display plus
  16. one or more Reactors plus
  17. none or more Turbines.
  18. 2) One Advanced Monitor for overall status display plus (furthest monitor from computer by cable length)
  19. one Advanced Monitor for each connected Reactor plus (subsequent found monitors)
  20. one Advanced Monitor for each connected Turbine (last group of monitors found).
  21. If you enable debug mode, add one additional Advanced Monitor for #1 or #2.
  22.  
  23. Notes:
  24. Only one reactor and one, two, and three turbines have been tested with the above, but IN THEORY any number is supported.
  25. Devices are found in the reverse order they are plugged in, so monitor_10 will be found before monitor_9.
  26. Two 15x15x14 Turbines can output 260K RF/t by just one 7^3 (four rods) reactor putting out 4k mB steam.
  27.  
  28. When using actively cooled reactors with turbines, keep the following in mind:
  29. - 1 mB steam carries up to 10RF of potential energy to extract in a turbine.
  30. - Actively cooled reactors produce steam, not power.
  31. - You will need about 10 mB of water for each 1 mB of steam that you want to create in a 7^3 reactor.
  32.  
  33. Features:
  34. Configurable min/max energy buffer and min/max temperature via ReactorOptions file.
  35. ReactorOptions is read on start and then current values are saved every program cycle.
  36. Rod Control value in ReactorOptions is only useful for initial start, after that the program saves the current Rod Control average over all Fuel Rods for next boot.
  37. Auto-adjusts control rods per reactor to maintain temperature.
  38. Will display reactor data to all attached monitors of correct dimensions.
  39. For multiple monitors, the first monitor (often last plugged in) is the overall status monitor.
  40. For multiple monitors, the first monitor (often last plugged in) is the overall status monitor.
  41. A new cruise mode from mechaet, ONLINE will be "blue" when active, to keep your actively cooled reactors running smoothly.
  42.  
  43. GUI Usage:
  44. The "<" and ">" buttons, when right-clicked with the mouse, will decrease and increase, respectively, the values assigned to the monitor:
  45. "Rod (%)" will lower/raise the Reactor Control Rods for that Reactor
  46. "mB/t" will lower/raise the Turbine Flow Rate maximum for that Turbine
  47. "RPM" will lower/raise the target Turbine RPM for that Turbine
  48. Right-clicking between the "<" and ">" (not on them) will disable auto-adjust of that value for attached device.
  49. Right-clicking on the "Enabled" or "Disabled" text for auto-adjust will do the same.
  50. Right-clicking on "ONLINE" or "OFFLINE" at the top-right will toggle the state of attached device.
  51.  
  52. Default values:
  53. Rod Control: 90% (Let's start off safe and then power up as we can)
  54. Minimum Energy Buffer: 15% (will power on below this value)
  55. Maximum Energy Buffer: 85% (will power off above this value)
  56. Minimum Passive Cooling Temperature: 950^C (will raise control rods below this value)
  57. Maximum Passive Cooling Temperature: 1,400^C (will lower control rods above this value)
  58. Minimum Active Cooling Temperature: 300^C (will raise the control rods below this value)
  59. Maximum Active Cooling Temperature: 420^C (will lower control rods above this value)
  60. Optimal Turbine RPM: 900, 1,800, or 2,700 (divisible by 900)
  61. New user-controlled option for target speed of turbines, defaults to 2726RPM, which is high-optimal.
  62.  
  63. Requirements:
  64. Advanced Monitor size is X: 29, Y: 12 with a 3x2 size
  65. Computer or Advanced Computer
  66. Modems (not wireless) connecting each of the Computer to both the Advanced Monitor and Reactor Computer Port.
  67. Big Reactors (http://www.big-reactors.com/) 0.3.2A+
  68. Computercraft (http://computercraft.info/) 1.63+
  69. Reset the computer any time number of connected devices change.
  70.  
  71. Resources:
  72. This script is available from:
  73. http://pastebin.com/fguScPBQ
  74. https://github.com/sandalle/minecraft_bigreactor_control
  75. Start-up script is available from:
  76. http://pastebin.com/ZTMzRLez
  77. https://github.com/sandalle/minecraft_bigreactor_control
  78. Other reactor control program which I based my program on:
  79. http://pastebin.com/aMAu4X5J (ScatmanJohn)
  80. http://pastebin.com/HjUVNDau (version ScatmanJohn based his on)
  81. A simpler Big Reactor control program is available from:
  82. http://pastebin.com/7S5xCvgL (IronClaymore only for passively cooled reactors)
  83.  
  84. Reactor Computer Port API: http://wiki.technicpack.net/Reactor_Computer_Port
  85. Computercraft API: http://computercraft.info/wiki/Category:APIs
  86. Big Reactors Efficiency, Speculation and Questions! http://www.reddit.com/r/feedthebeast/comments/1vzds0/big_reactors_efficiency_speculation_and_questions/
  87. Big Reactors API code: https://github.com/erogenousbeef/BigReactors/blob/master/erogenousbeef/bigreactors/common/multiblock/tileentity/TileEntityReactorComputerPort.java
  88. Big Reactors API: http://big-reactors.com/cc_api.html
  89.  
  90. ChangeLog:
  91. - 0.3.14
  92. - Fix Issue #5. EZ-Nuke should now work with ComputerCraft 1.58 or 1.63.
  93.  
  94. - 0.3.13
  95. - Fix one reactor and one monitor incorrectly using status display instead of control display (Issue #35)
  96. - Fix concatenating a string and boolean, see http://stackoverflow.com/questions/6615572/how-to-format-a-lua-string-with-a-boolean-variable
  97. - Hopefully fix concatenating string and nul in printLog (Issue #3)
  98.  
  99. - 0.3.12
  100. - Mechaet's changes:
  101. - Redid some typing to correct a bug where the reactors always started with rod control disabled.
  102.  
  103. - 0.3.11
  104. - Mechaet's changes:
  105. - Cleaned up global variables list
  106. - Added in per-device naming (displays a friendly name on the bottom of the monitor if configured in the device options file)
  107. - Bigger bypasses of control routines when the control has been overridden
  108. - Individual config files for turbines and reactors. Persistent between reboots, remembers your last saved settings.
  109. - Cruise mode override bypass
  110. - Changing flow rate no longer toggles flow rate override on and off. Changing the flow rate clearly indicates intent, so we put the override flag on and leave it there.
  111. - Changed the rate at which the regular algorithm adjusts reactor rod control rates. Instead of being 1:1 we now move at 1:5 speed because there is a wide loophole where big adjustments can cause a swinging pendulum effect continually missing the target.
  112.  
  113. - 0.3.10
  114. - Turbine algorithm pass by Mechaet.
  115. - Updated turbine GUI.
  116. - Fix single monitor (again) for Issue #22.
  117.  
  118. - 0.3.9
  119. - Reactor algorithm pass by Mechaet.
  120. - Additional user config options by Mechaet.
  121. - Fix multiple reactors and none or more turbines with only one status monitor.
  122. - Fix monitor scaling after one was used as debug (or in case of other modifications).
  123. - Cruise mode implemented, defaults off but is saved between boots.
  124. - Fix energy/% displays to match Big Reactors' GUI (Issue #9).
  125. - Always write out found devices on computer terminal.
  126. - Much improved round() function from mechaet (Issue #14).
  127. - Refactoring pass/algorithm change on the reactor temperature control. Should now adjust in increments to achieve the desired temperature range quicker and more accurately.
  128. - Optimal passive-cooled reactor temperature range changed from 850-900 to 950-1400.
  129. - Fix display Issue #15.
  130.  
  131. - 0.3.8
  132. - Update to ComputerCraft 1.6 API (only term.restore() -> term.native() required :)).
  133.  
  134. - 0.3.7
  135. - Fix typo when initializing TurbineNames array.
  136. - Fix Issue #1, turbine display is using the Reactor buffer size (10M RF) instead of the Turbine buffer size (1M RF).
  137.  
  138. - 0.3.6
  139. - Fix multi-reactors displaying on the correct monitors (thanks HybridFusion).
  140. - Fix rod auto-adjust text position.
  141. - Reactors store 10M RF and Turbines store 1M RF in their buffer.
  142. - Add more colour to displayAllStatus().
  143. - Sleep for only two seconds instead of five.
  144. - Fix getDeviceStoredEnergyBufferPercent() for Reactors storing 10M RF in buffer.
  145. - Keep actively cooled reactors between 0-300^C (non-configurable for now).
  146.  
  147. - 0.3.5
  148. - Do not discover connected devices every loop - nicer on servers. Reset computer anytime number of connected devices change.
  149. - Fix multi-reactor setups to display the additional reactors on monitors, rather than the last one found.
  150. - Fix passive reactor display having auto-adjust and energy buffer overwrite each other (removes rod count).
  151.  
  152. - 0.3.4
  153. - Fix arithmetic for checking if we have enough monitors for the number of reactors.
  154. - Turbines are optimal at 900, 1800, *and* 2700 RPM
  155. - Increase loop timer from 1 to 5 to be nicer to servers
  156.  
  157. - 0.3.3
  158. - Add Big Reactors Turbine support.
  159. - First found monitor (appears to be last connected monitor) is used to display status of all found devices (if more than one valid monitor is found)
  160. - Display monitor number on top left of each monitor as "M#" to help find which monitor is which.
  161. - Enabling debug will use the last monitor found, if more than one, to print out debug info (also written to file)
  162. - Only clear monitors when we're about to use them (e.g. turbine monitors no longer clear, then wait for all reactors to update)
  163. - Fix getDeviceStoredEnergyBufferPercent(), was off by a decimal place
  164. - Just use first Control Rod level for entire reactor, they are no longer treated individually in BR 0.3
  165. - Allow for one monitor for n number of reactors and m number of turbines
  166. - Auto-adjust turbine flow rate by 25 mB to keep rotor speed at 900 or 1,800 RPM.
  167. - Clicks on monitors relate to what the monitor is showing (e.g. clicking on reactor 1's display won't modify turbine 1's nor reactor 2's values)
  168. - Print monitor name and device (reactor|turbine) name in blue to monitor associated for easier design by users.
  169. - Remove version number from monitors to free up space for monitor names.
  170. - Add option of right-clicking on "Enabled"/"Disabled" of auto-adjust to toggle it.
  171.  
  172. - 0.3.2
  173. - Allow for rod control to override (disable) auto-adjust via UI (Rhonyn)
  174.  
  175. - 0.3.1
  176. - Add fuel consumption per tick to display
  177.  
  178. - 0.3.0
  179. - Add multi-monitor support! Sends one reactor's data to all monitors.
  180. - print function now takes table to support optional specified monitor
  181. - Set "numRods" every cycle for some people (mechaet)
  182. - Don't redirect terminal output with multiple monitor support
  183. - Log troubleshooting data to reactorcontrol.log
  184. - FC_API no longer used (copied and modified what I needed)
  185. - Multi-reactor support is theoretically implemented, but it is UNTESTED!
  186. - Updated for Big Reactor 0.3 (no longer works with 0.2)
  187. - BR getFuelTemperature() now returns many significant digits, just use math.ceil()
  188. - BR 0.3 removed individual rod temperatures, now it's only reactor-level temperature
  189.  
  190. - 0.2.4
  191. - Simplify math, don't divide by a simple large number and then multiply by 100 (#/10000000*100)
  192. - Fix direct-connected (no modem) devices. getDeviceSide -> FC_API.getDeviceSide (simple as that :))
  193.  
  194. - 0.2.3
  195. - Check bounds on reactor.setRodControlLevel(#,#), Big Reactor doesn't check for us.
  196.  
  197. - 0.2.2
  198. - Do not auto-start the reactor if it was manually powered off (autoStart=false)
  199.  
  200. - 0.2.1
  201. - Lower/raise only the hottest/coldest Control Rod while trying to control the reactor temperature.
  202. - "<" Rod Control buttons was off by one (to the left)
  203.  
  204. - 0.2.0 - Lolmer Edition :)
  205. - Add min/max stored energy percentage (default is 15%/85%), configurable via ReactorOptions file.
  206. - No reason to keep burning fuel if our power output is going nowhere. :)
  207. - Use variables variable for the title and version.
  208. - Try to keep the temperature between configured values (default is 850^C-950^C)
  209. - Add Waste and number of Control/Fuel Rods to displayBards()
  210.  
  211. TODO:
  212. - Save parameters per reactor instead of one global set for all reactors.
  213. - Add min/max RF/t output and have it override temperature concerns (maybe?).
  214. - Add support for wireless modems, see http://computercraft.info/wiki/Modem_%28API%29, will not be secure (anyone can send/listen to your channels)!
  215. - Add support for any sized monitor (minimum 3x3), dynamic allocation/alignment.
  216. - Lookup using pcall for better error handling http://www.computercraft.info/forums2/index.php?/topic/10992-using-pcall/ .
  217. - Update cruise mode to work independently for each actively-cooled reactor.
  218.  
  219. ]]--
  220.  
  221.  
  222. -- Some global variables
  223. local progVer = "0.3.14"
  224. local progName = "EZ-NUKE"
  225. local sideClick, xClick, yClick = nil, 0, 0
  226. local loopTime = 1
  227. local controlRodAdjustAmount = 1 -- Default Reactor Rod Control % adjustment amount
  228. local flowRateAdjustAmount = 25 -- Default Turbine Flow Rate in mB adjustment amount
  229. local debugMode = false
  230. -- End multi-reactor cleanup section
  231. local minStoredEnergyPercent = nil -- Max energy % to store before activate
  232. local maxStoredEnergyPercent = nil -- Max energy % to store before shutdown
  233. local monitorList = {} -- Empty monitor array
  234. local monitorNames = {} -- Empty array of monitor names
  235. local reactorList = {} -- Empty reactor array
  236. local reactorNames = {} -- Empty array of reactor names
  237. local turbineList = {} -- Empty turbine array
  238. local turbineNames = {} -- Empty array of turbine names
  239. local turbineMonitorOffset = 0 -- Turbines are assigned monitors after reactors
  240.  
  241.  
  242. term.clear()
  243. term.setCursorPos(2,1)
  244. write("Initializing program...\n")
  245.  
  246.  
  247. -- File needs to exist for append "a" later and zero it out if it already exists
  248. -- Always initalize this file to avoid confusion with old files and the latest run
  249. local logFile = fs.open("reactorcontrol.log", "w")
  250. if logFile then
  251. logFile.writeLine("Minecraft time: Day "..os.day().." at "..textutils.formatTime(os.time(),true))
  252. logFile.close()
  253. else
  254. error("Could not open file reactorcontrol.log for writing.")
  255. end
  256.  
  257.  
  258. -- Helper functions
  259.  
  260. local function termRestore()
  261. local ccVersion = nil
  262. ccVersion = os.version()
  263.  
  264. if ccVersion == "CraftOS 1.6" then
  265. term.native()
  266. elseif ccVersion == "CraftOS 1.5" then
  267. term.restore()
  268. else -- Default to older term.restore
  269. printLog("Unsupported CraftOS found. Reported version is \""..ccVersion.."\".")
  270. term.restore()
  271. end -- if ccVersion
  272. end -- function termRestore()
  273.  
  274. local function printLog(printStr)
  275. -- if debugMode then
  276. -- -- If multiple monitors, use the last monitor for debugging if debug is enabled
  277. -- if #monitorList > 1 then
  278. -- --term.redirect(monitorList[#monitorList]) -- Redirect to last monitor for debugging
  279. -- monitorList[#monitorList].setTextScale(0.5) -- Fit more logs on screen
  280. -- write(printStr.."\n") -- May need to use term.scroll(x) if we output too much, not sure
  281. -- termRestore()
  282. -- end -- if #monitorList > 1 then
  283.  
  284. -- local logFile = fs.open("reactorcontrol.log", "a") -- See http://computercraft.info/wiki/Fs.open
  285. -- if logFile then
  286. -- logFile.writeLine(printStr)
  287. -- logFile.close()
  288. -- else
  289. -- error("Cannot open file reactorcontrol.log for appending!")
  290. -- end -- if logFile then
  291. -- end -- if debugMode then
  292. end -- function printLog(printStr)
  293.  
  294. -- Trim a string
  295. function stringTrim(s)
  296. assert(s ~= nil, "String can't be nil")
  297. return(string.gsub(s, "^%s*(.-)%s*$", "%1"))
  298. end
  299.  
  300. config = {}
  301.  
  302. -- Save a table into a config file
  303. -- path: path of the file to write
  304. -- tab: table to save
  305. config.save = function(path, tab)
  306. printLog("Save function called for config for "..path.." EOL")
  307. assert(path ~= nil, "Path can't be nil")
  308. assert(type(tab) == "table", "Second parameter must be a table")
  309. local f = io.open(path, "w")
  310. local i = 0
  311. for key, value in pairs(tab) do
  312. if i ~= 0 then
  313. f:write("\n")
  314. end
  315. f:write("["..key.."]".."\n")
  316. for key2, value2 in pairs(tab[key]) do
  317. key2 = stringTrim(key2)
  318. --doesn't like boolean values
  319. if (type(value2) ~= "boolean") then
  320. value2 = stringTrim(value2)
  321. else
  322. value2 = tostring(value2)
  323. end
  324. key2 = key2:gsub(";", "\\;")
  325. key2 = key2:gsub("=", "\\=")
  326. value2 = value2:gsub(";", "\\;")
  327. value2 = value2:gsub("=", "\\=")
  328. f:write(key2.."="..value2.."\n")
  329. end
  330. i = i + 1
  331. end
  332. f:close()
  333. end --config.save = function(path, tab)
  334.  
  335. -- Load a config file
  336. -- path: path of the file to read
  337. config.load = function(path)
  338. printLog("Load function called for config for "..path.." EOL")
  339. assert(path ~= nil, "Path can't be nil")
  340. local f = fs.open(path, "r")
  341. if f ~= nil then
  342. local tab = {}
  343. local line = ""
  344. local newLine
  345. local i
  346. local currentTag = nil
  347. local found = false
  348. local pos = 0
  349. while line ~= nil do
  350. found = false
  351. line = line:gsub("\\;", "#_!36!_#") -- to keep \;
  352. line = line:gsub("\\=", "#_!71!_#") -- to keep \=
  353. if line ~= "" then
  354. -- Delete comments
  355. newLine = line
  356. line = ""
  357. for i=1, string.len(newLine) do
  358. if string.sub(newLine, i, i) ~= ";" then
  359. line = line..newLine:sub(i, i)
  360. else
  361. break
  362. end
  363. end
  364. line = stringTrim(line)
  365. -- Find tag
  366. if line:sub(1, 1) == "[" and line:sub(line:len(), line:len()) == "]" then
  367. currentTag = stringTrim(line:sub(2, line:len()-1))
  368. tab[currentTag] = {}
  369. found = true
  370. end
  371. -- Find key and values
  372. if not found and line ~= "" then
  373. pos = line:find("=")
  374. if pos == nil then
  375. error("Bad INI file structure")
  376. end
  377. line = line:gsub("#_!36!_#", ";")
  378. line = line:gsub("#_!71!_#", "=")
  379. tab[currentTag][stringTrim(line:sub(1, pos-1))] = stringTrim(line:sub(pos+1, line:len()))
  380. found = true
  381. end
  382. end
  383. line = f.readLine()
  384. end
  385.  
  386. f:close()
  387.  
  388. return tab
  389. else
  390. return nil
  391. end
  392. end --config.load = function(path)
  393.  
  394.  
  395.  
  396. -- round() function from mechaet
  397. local function round(num, places)
  398. local mult = 10^places
  399. local addon = nil
  400. if ((num * mult) < 0) then
  401. addon = -.5
  402. else
  403. addon = .5
  404. end
  405.  
  406. local integer, decimal = math.modf(num*mult+addon)
  407. newNum = integer/mult
  408. printLog("Called round(num="..num..",places="..places..") returns \""..newNum.."\".")
  409. return newNum
  410. end -- function round(num, places)
  411.  
  412.  
  413. local function print(printParams)
  414. -- Default to xPos=1, yPos=1, and first monitor
  415. setmetatable(printParams,{__index={xPos=1, yPos=1, monitorIndex=1}})
  416. local printString, xPos, yPos, monitorIndex =
  417. printParams[1], -- Required parameter
  418. printParams[2] or printParams.xPos,
  419. printParams[3] or printParams.yPos,
  420. printParams[4] or printParams.monitorIndex
  421.  
  422. local monitor = nil
  423. monitor = monitorList[monitorIndex]
  424.  
  425. if not monitor then
  426. printLog("monitor["..monitorIndex.."] in print() is NOT a valid monitor.")
  427. return -- Invalid monitorIndex
  428. end
  429.  
  430. monitor.setCursorPos(xPos, yPos)
  431. monitor.write(printString)
  432. end -- function print(printParams)
  433.  
  434.  
  435. -- Replaces the one from FC_API (http://pastebin.com/A9hcbZWe) and adding multi-monitor support
  436. local function printCentered(printString, yPos, monitorIndex)
  437. local monitor = nil
  438. monitor = monitorList[monitorIndex]
  439.  
  440. if not monitor then
  441. printLog("monitor["..monitorIndex.."] in printCentered() is NOT a valid monitor.")
  442. return -- Invalid monitorIndex
  443. end
  444.  
  445. local width, height = monitor.getSize()
  446. local monitorNameLength = 0
  447.  
  448. -- Special changes for title bar
  449. if yPos == 1 then
  450. -- Add monitor name to first line
  451. monitorNameLength = monitorNames[monitorIndex]:len()
  452.  
  453. -- Leave room for "offline" and "online" on the right except for overall status display
  454. if (#monitorList ~= 1) and (monitorIndex ~= 1) then
  455. width = width - 7
  456. end
  457. end
  458.  
  459. monitor.setCursorPos(math.floor(width/2) - math.ceil(printString:len()/2) + monitorNameLength/2, yPos)
  460. monitor.clearLine()
  461. monitor.write(printString)
  462.  
  463. monitor.setTextColor(colors.blue)
  464. print{monitorNames[monitorIndex], 1, 1, monitorIndex}
  465. monitor.setTextColor(colors.white)
  466. end -- function printCentered(printString, yPos, monitorIndex)
  467.  
  468.  
  469. -- Print text padded from the left side
  470. -- Clear the left side of the screen
  471. local function printLeft(printString, yPos, monitorIndex)
  472. local monitor = nil
  473. monitor = monitorList[monitorIndex]
  474.  
  475. if not monitor then
  476. printLog("monitor["..monitorIndex.."] in printLeft() is NOT a valid monitor.")
  477. return -- Invalid monitorIndex
  478. end
  479.  
  480. local gap = 1
  481. local width = monitor.getSize()
  482.  
  483. -- Clear left-half of the monitor
  484.  
  485. for curXPos = 1, (width / 2) do
  486. monitor.setCursorPos(curXPos, yPos)
  487. monitor.write(" ")
  488. end
  489.  
  490. -- Write our string left-aligned
  491. monitor.setCursorPos(1+gap, yPos)
  492. monitor.write(printString)
  493. end
  494.  
  495.  
  496. -- Print text padded from the right side
  497. -- Clear the right side of the screen
  498. local function printRight(printString, yPos, monitorIndex)
  499. local monitor = nil
  500. monitor = monitorList[monitorIndex]
  501.  
  502. if not monitor then
  503. printLog("monitor["..monitorIndex.."] in printRight() is NOT a valid monitor.")
  504. return -- Invalid monitorIndex
  505. end
  506.  
  507. -- Make sure printString is a string
  508. printString = tostring(printString)
  509.  
  510. local gap = 1
  511. local width = monitor.getSize()
  512.  
  513. -- Clear right-half of the monitor
  514. for curXPos = (width/2), width do
  515. monitor.setCursorPos(curXPos, yPos)
  516. monitor.write(" ")
  517. end
  518.  
  519. -- Write our string right-aligned
  520. monitor.setCursorPos(math.floor(width) - math.ceil(printString:len()+gap), yPos)
  521. monitor.write(printString)
  522. end
  523.  
  524.  
  525. -- Replaces the one from FC_API (http://pastebin.com/A9hcbZWe) and adding multi-monitor support
  526. local function clearMonitor(printString, monitorIndex)
  527. local monitor = nil
  528. monitor = monitorList[monitorIndex]
  529.  
  530. printLog("Called as clearMonitor(printString="..printString..",monitorIndex="..monitorIndex..").")
  531.  
  532. if not monitor then
  533. printLog("monitor["..monitorIndex.."] in clearMonitor(printString="..printString..",monitorIndex="..monitorIndex..") is NOT a valid monitor.")
  534. return -- Invalid monitorIndex
  535. end
  536.  
  537. local gap = 2
  538. monitor.clear()
  539. local width, height = monitor.getSize()
  540. monitor.setTextScale(1.0) -- Make sure scale is correct
  541.  
  542. printCentered(printString, 1, monitorIndex)
  543. monitor.setTextColor(colors.blue)
  544. print{monitorNames[monitorIndex], 1, 1, monitorIndex}
  545. monitor.setTextColor(colors.white)
  546.  
  547. for i=1, width do
  548. monitor.setCursorPos(i, gap)
  549. monitor.write("-")
  550. end
  551.  
  552. monitor.setCursorPos(1, gap+1)
  553. end -- function clearMonitor(printString, monitorIndex)
  554.  
  555.  
  556. -- Return a list of all connected (including via wired modems) devices of "deviceType"
  557. local function getDevices(deviceType)
  558. printLog("Called as getDevices(deviceType="..deviceType..")")
  559.  
  560. local deviceName = nil
  561. local deviceIndex = 1
  562. local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
  563. local peripheralList = peripheral.getNames() -- Get table of connected peripherals
  564.  
  565. deviceType = deviceType:lower() -- Make sure we're matching case here
  566.  
  567. for peripheralIndex = 1, #peripheralList do
  568. -- Log every device found
  569. -- printLog("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] attached as \""..peripheralList[peripheralIndex].."\".")
  570. if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then
  571. -- Log devices found which match deviceType and which device index we give them
  572. printLog("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] as index \"["..deviceIndex.."]\" attached as \""..peripheralList[peripheralIndex].."\".")
  573. --write("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] as index \"["..deviceIndex.."]\" attached as \""..peripheralList[peripheralIndex].."\".\n")
  574. deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  575. deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  576. deviceIndex = deviceIndex + 1
  577. end
  578. end -- for peripheralIndex = 1, #peripheralList do
  579.  
  580. return deviceList, deviceNames
  581. end -- function getDevices(deviceType)
  582.  
  583. -- Draw a line across the entire x-axis
  584. local function drawLine(yPos, monitorIndex)
  585. local monitor = nil
  586. monitor = monitorList[monitorIndex]
  587.  
  588. if not monitor then
  589. printLog("monitor["..monitorIndex.."] in drawLine() is NOT a valid monitor.")
  590. return -- Invalid monitorIndex
  591. end
  592.  
  593. local width, height = monitor.getSize()
  594.  
  595. for i=1, width do
  596. monitor.setCursorPos(i, yPos)
  597. monitor.write("-")
  598. end
  599. end -- function drawLine(yPos,monitorIndex)
  600.  
  601.  
  602. -- Display a solid bar of specified color
  603. local function drawBar(startXPos, startYPos, endXPos, endYPos, color, monitorIndex)
  604. local monitor = nil
  605. monitor = monitorList[monitorIndex]
  606.  
  607. if not monitor then
  608. printLog("monitor["..monitorIndex.."] in drawBar() is NOT a valid monitor.")
  609. return -- Invalid monitorIndex
  610. end
  611.  
  612. -- PaintUtils only outputs to term., not monitor.
  613. -- See http://www.computercraft.info/forums2/index.php?/topic/15540-paintutils-on-a-monitor/
  614. term.redirect(monitor)
  615. paintutils.drawLine(startXPos, startYPos, endXPos, endYPos, color)
  616. monitor.setBackgroundColor(colors.black) -- PaintUtils doesn't restore the color
  617. termRestore()
  618. end -- function drawBar(startXPos, startYPos,endXPos,endYPos,color,monitorIndex)
  619.  
  620.  
  621. -- Display single pixel color
  622. local function drawPixel(xPos, yPos, color, monitorIndex)
  623. local monitor = nil
  624. monitor = monitorList[monitorIndex]
  625.  
  626. if not monitor then
  627. printLog("monitor["..monitorIndex.."] in drawPixel() is NOT a valid monitor.")
  628. return -- Invalid monitorIndex
  629. end
  630.  
  631. -- PaintUtils only outputs to term., not monitor.
  632. -- See http://www.computercraft.info/forums2/index.php?/topic/15540-paintutils-on-a-monitor/
  633. term.redirect(monitor)
  634. paintutils.drawPixel(xPos, yPos, color)
  635. monitor.setBackgroundColor(colors.black) -- PaintUtils doesn't restore the color
  636. termRestore()
  637. end -- function drawPixel(xPos, yPos, color, monitorIndex)
  638.  
  639.  
  640. -- End helper functions
  641.  
  642.  
  643. -- Then initialize the monitors
  644. local function findMonitors()
  645. -- Empty out old list of monitors
  646. monitorList = {}
  647.  
  648. printLog("Finding monitors...")
  649. monitorList, monitorNames = getDevices("monitor")
  650.  
  651. if #monitorList == 0 then
  652. printLog("No monitors found!")
  653. error("Can't find any monitors!")
  654. else
  655. for monitorIndex = 1, #monitorList do
  656. local monitor, monitorX, monitorY = nil, nil, nil
  657. monitor = monitorList[monitorIndex]
  658.  
  659. if not monitor then
  660. printLog("monitorList["..monitorIndex.."] in findMonitors() is NOT a valid monitor.")
  661.  
  662. table.remove(monitorList, monitorIndex) -- Remove invalid monitor from list
  663. if monitorIndex ~= #monitorList then -- If we're not at the end, clean up
  664. monitorIndex = monitorIndex - 1 -- We just removed an element
  665. end -- if monitorIndex == #monitorList then
  666. break -- Invalid monitorIndex
  667. else -- valid monitor
  668. monitorX, monitorY = monitor.getSize()
  669. if (monitorX == nil) or (monitorY == nil) then -- somehow a valid monitor, but non-existent sizes? Maybe fixes Issue #3
  670. printLog("monitorList["..monitorIndex.."] in findMonitors() is NOT a valid sized monitor.")
  671.  
  672. table.remove(monitorList, monitorIndex) -- Remove invalid monitor from list
  673. if monitorIndex ~= #monitorList then -- If we're not at the end, clean up
  674. monitorIndex = monitorIndex - 1 -- We just removed an element
  675. end -- if monitorIndex == #monitorList then
  676. break -- Invalid monitorIndex
  677.  
  678. -- Check for minimum size to allow for monitor.setTextScale(0.5) to work for 3x2 debugging monitor, changes getSize()
  679. elseif monitorX < 29 or monitorY < 12 then
  680. term.redirect(monitor)
  681. monitor.clear()
  682. printLog("Removing monitor "..monitorIndex.." for being too small.")
  683. monitor.setCursorPos(1,2)
  684. write("Monitor is the wrong size!\n")
  685. write("Needs to be at least 3x2.")
  686. termRestore()
  687.  
  688. table.remove(monitorList, monitorIndex) -- Remove invalid monitor from list
  689. if monitorIndex == #monitorList then -- If we're at the end already, break from loop
  690. break
  691. else
  692. monitorIndex = monitorIndex - 1 -- We just removed an element
  693. end -- if monitorIndex == #monitorList then
  694.  
  695. end -- if monitorX < 29 or monitorY < 12 then
  696. end -- if not monitor then
  697.  
  698. printLog("Monitor["..monitorIndex.."] named \""..monitorNames[monitorIndex].."\" is a valid monitor of size x:"..monitorX.." by y:"..monitorY..".")
  699. end -- for monitorIndex = 1, #monitorList do
  700. end -- if #monitorList == 0 then
  701.  
  702. printLog("Found "..#monitorList.." monitor(s) in findMonitors().")
  703. end -- local function findMonitors()
  704.  
  705.  
  706. -- Initialize all Big Reactors - Reactors
  707. local function findReactors()
  708. -- Empty out old list of reactors
  709. newReactorList = {}
  710. printLog("Finding reactors...")
  711. newReactorList, reactorNames = getDevices("BigReactors-Reactor")
  712.  
  713. if #newReactorList == 0 then
  714. printLog("No reactors found!")
  715. error("Can't find any reactors!")
  716. else -- Placeholder
  717. for reactorIndex = 1, #newReactorList do
  718. local reactor = nil
  719. reactor = newReactorList[reactorIndex]
  720.  
  721. if not reactor then
  722. printLog("reactorList["..reactorIndex.."] in findReactors() is NOT a valid Big Reactor.")
  723.  
  724. table.remove(newReactorList, reactorIndex) -- Remove invalid reactor from list
  725. if reactorIndex ~= #newReactorList then -- If we're not at the end, clean up
  726. reactorIndex = reactorIndex - 1 -- We just removed an element
  727. end -- reactorIndex ~= #newReactorList then
  728. return -- Invalid reactorIndex
  729. else
  730. printLog("reactor["..reactorIndex.."] in findReactors() is a valid Big Reactor.")
  731. --initialize the default table
  732. _G[reactorNames[reactorIndex]] = {}
  733. _G[reactorNames[reactorIndex]]["ReactorOptions"] = {}
  734. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = 80
  735. _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"] = 0
  736. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = true
  737. _G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"] = true
  738. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"] = 1400 --set for passive-cooled, the active-cooled subroutine will correct it
  739. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"] = 1000
  740. _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] = false
  741. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorName"] = reactorNames[reactorIndex]
  742. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = false
  743. if reactor.getConnected() then
  744. printLog("reactor["..reactorIndex.."] in findReactors() is connected.")
  745. else
  746. printLog("reactor["..reactorIndex.."] in findReactors() is NOT connected.")
  747. return -- Disconnected reactor
  748. end
  749. end
  750.  
  751. --failsafe
  752. local tempTable = _G[reactorNames[reactorIndex]]
  753.  
  754. --check to make sure we get a valid config
  755. if (config.load(reactorNames[reactorIndex]..".options")) ~= nil then
  756. tempTable = config.load(reactorNames[reactorIndex]..".options")
  757. else
  758. --if we don't have a valid config from disk, make a valid config
  759. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  760. end
  761.  
  762. --load values from tempTable, checking for nil values along the way
  763. if tempTable["ReactorOptions"]["baseControlRodLevel"] ~= nil then
  764. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = tempTable["ReactorOptions"]["baseControlRodLevel"]
  765. end
  766.  
  767. if tempTable["ReactorOptions"]["lastTempPoll"] ~= nil then
  768. _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"] = tempTable["ReactorOptions"]["lastTempPoll"]
  769. end
  770.  
  771. if tempTable["ReactorOptions"]["autoStart"] ~= nil then
  772. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = tempTable["ReactorOptions"]["autoStart"]
  773. end
  774.  
  775. if tempTable["ReactorOptions"]["activeCooled"] ~= nil then
  776. _G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"] = tempTable["ReactorOptions"]["activeCooled"]
  777. end
  778.  
  779. if tempTable["ReactorOptions"]["reactorMaxTemp"] ~= nil then
  780. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"] = tempTable["ReactorOptions"]["reactorMaxTemp"]
  781. end
  782.  
  783. if tempTable["ReactorOptions"]["reactorMinTemp"] ~= nil then
  784. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"] = tempTable["ReactorOptions"]["reactorMinTemp"]
  785. end
  786.  
  787. if tempTable["ReactorOptions"]["rodOverride"] ~= nil then
  788. printLog("Got value from config file for Rod Override, the value is: "..tostring(tempTable["ReactorOptions"]["rodOverride"]).." EOL")
  789. _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] = tempTable["ReactorOptions"]["rodOverride"]
  790. end
  791.  
  792. if tempTable["ReactorOptions"]["reactorName"] ~= nil then
  793. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorName"] = tempTable["ReactorOptions"]["reactorName"]
  794. end
  795.  
  796. if tempTable["ReactorOptions"]["reactorCruising"] ~= nil then
  797. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = tempTable["ReactorOptions"]["reactorCruising"]
  798. end
  799.  
  800. --stricter typing, let's set these puppies up with the right type of value.
  801. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = tonumber(_G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"])
  802.  
  803. _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"] = tonumber(_G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"])
  804.  
  805. if (tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"]) == "true") then
  806. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = true
  807. else
  808. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = false
  809. end
  810.  
  811. if (tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"]) == "true") then
  812. _G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"] = true
  813. else
  814. _G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"] = false
  815. end
  816.  
  817. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"] = tonumber(_G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"])
  818.  
  819. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"] = tonumber(_G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"])
  820.  
  821. if (tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]) == "true") then
  822. printLog("Setting Rod Override for "..reactorNames[reactorIndex].." to true because value was "..tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]).." EOL")
  823. _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] = true
  824. else
  825. printLog("Setting Rod Override for "..reactorNames[reactorIndex].." to false because value was "..tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]).." EOL")
  826. _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] = false
  827. end
  828.  
  829. if (tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"]) == "true") then
  830. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = true
  831. else
  832. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = false
  833. end
  834.  
  835. --save one more time, in case we didn't have a complete config file before
  836. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  837. end -- for reactorIndex = 1, #newReactorList do
  838. end -- if #newReactorList == 0 then
  839.  
  840. -- Overwrite old reactor list with the now updated list
  841. reactorList = newReactorList
  842.  
  843. -- Start turbine monitor offset after reactors get monitors
  844. -- This assumes that there is a monitor for each turbine and reactor, plus the overall monitor display
  845. turbineMonitorOffset = #reactorList + 1 -- #turbineList will start at "1" if turbines found and move us just beyond #reactorList and status monitor range
  846.  
  847. printLog("Found "..#reactorList.." reactor(s) in findReactors().")
  848. printLog("Set turbineMonitorOffset to "..turbineMonitorOffset.." in findReactors().")
  849. end -- function findReactors()
  850.  
  851.  
  852. -- Initialize all Big Reactors - Turbines
  853. local function findTurbines()
  854. -- Empty out old list of turbines
  855. newTurbineList = {}
  856.  
  857. printLog("Finding turbines...")
  858. newTurbineList, turbineNames = getDevices("BigReactors-Turbine")
  859.  
  860. if #newTurbineList == 0 then
  861. printLog("No turbines found") -- Not an error
  862. else
  863. for turbineIndex = 1, #newTurbineList do
  864. local turbine = nil
  865. turbine = newTurbineList[turbineIndex]
  866.  
  867. if not turbine then
  868. printLog("turbineList["..turbineIndex.."] in findTurbines() is NOT a valid Big Reactors Turbine.")
  869.  
  870. table.remove(newTurbineList, turbineIndex) -- Remove invalid turbine from list
  871. if turbineIndex ~= #newTurbineList then -- If we're not at the end, clean up
  872. turbineIndex = turbineIndex - 1 -- We just removed an element
  873. end -- turbineIndex ~= #newTurbineList then
  874.  
  875. return -- Invalid turbineIndex
  876. else
  877.  
  878. _G[turbineNames[turbineIndex]] = {}
  879. _G[turbineNames[turbineIndex]]["TurbineOptions"] = {}
  880. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"] = 0
  881. _G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"] = 1840
  882. _G[turbineNames[turbineIndex]]["TurbineOptions"]["autoStart"] = true
  883. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"] = 2000 --open up with all the steam wide open
  884. _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] = false
  885. _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] = 0
  886. _G[turbineNames[turbineIndex]]["TurbineOptions"]["turbineName"] = turbineNames[turbineIndex]
  887. printLog("turbineList["..turbineIndex.."] in findTurbines() is a valid Big Reactors Turbine.")
  888. if turbine.getConnected() then
  889. printLog("turbine["..turbineIndex.."] in findTurbines() is connected.")
  890. else
  891. printLog("turbine["..turbineIndex.."] in findTurbines() is NOT connected.")
  892. return -- Disconnected turbine
  893. end
  894. end
  895.  
  896. --failsafe
  897. local tempTable = _G[turbineNames[turbineIndex]]
  898.  
  899. --check to make sure we get a valid config
  900. if (config.load(turbineNames[turbineIndex]..".options")) ~= nil then
  901. tempTable = config.load(turbineNames[turbineIndex]..".options")
  902. else
  903. --if we don't have a valid config from disk, make a valid config
  904. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  905. end
  906.  
  907. --load values from tempTable, checking for nil values along the way
  908. if tempTable["TurbineOptions"]["LastSpeed"] ~= nil then
  909. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"] = tempTable["TurbineOptions"]["LastSpeed"]
  910. end
  911.  
  912. if tempTable["TurbineOptions"]["BaseSpeed"] ~= nil then
  913. _G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"] = tempTable["TurbineOptions"]["BaseSpeed"]
  914. end
  915.  
  916. if tempTable["TurbineOptions"]["autoStart"] ~= nil then
  917. _G[turbineNames[turbineIndex]]["TurbineOptions"]["autoStart"] = tempTable["TurbineOptions"]["autoStart"]
  918. end
  919.  
  920. if tempTable["TurbineOptions"]["LastFlow"] ~= nil then
  921. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"] = tempTable["TurbineOptions"]["LastFlow"]
  922. end
  923.  
  924. if tempTable["TurbineOptions"]["flowOverride"] ~= nil then
  925. _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] = tempTable["TurbineOptions"]["flowOverride"]
  926. end
  927.  
  928. if tempTable["TurbineOptions"]["turbineName"] ~= nil then
  929. _G[turbineNames[turbineIndex]]["TurbineOptions"]["turbineName"] = tempTable["TurbineOptions"]["turbineName"]
  930. end
  931.  
  932. --save once more just to make sure we got it
  933. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  934. end -- for turbineIndex = 1, #newTurbineList do
  935.  
  936. -- Overwrite old turbine list with the now updated list
  937. turbineList = newTurbineList
  938. end -- if #newTurbineList == 0 then
  939.  
  940. printLog("Found "..#turbineList.." turbine(s) in findTurbines().")
  941. end -- function findTurbines()
  942.  
  943.  
  944. -- Return current energy buffer in a specific reactor by %
  945. local function getReactorStoredEnergyBufferPercent(reactor)
  946. printLog("Called as getReactorStoredEnergyBufferPercent(reactor).")
  947.  
  948. if not reactor then
  949. printLog("getReactorStoredEnergyBufferPercent() did NOT receive a valid Big Reactor Reactor.")
  950. return -- Invalid reactorIndex
  951. else
  952. printLog("getReactorStoredEnergyBufferPercent() did receive a valid Big Reactor Reactor.")
  953. end
  954.  
  955. local energyBufferStorage = reactor.getEnergyStored()
  956. return round(energyBufferStorage/100000, 1) -- (buffer/10000000 RF)*100%
  957. end -- function getReactorStoredEnergyBufferPercent(reactor)
  958.  
  959.  
  960. -- Return current energy buffer in a specific Turbine by %
  961. local function getTurbineStoredEnergyBufferPercent(turbine)
  962. printLog("Called as getTurbineStoredEnergyBufferPercent(turbine)")
  963.  
  964. if not turbine then
  965. printLog("getTurbineStoredEnergyBufferPercent() did NOT receive a valid Big Reactor Turbine.")
  966. return -- Invalid reactorIndex
  967. else
  968. printLog("getTurbineStoredEnergyBufferPercent() did receive a valid Big Reactor Turbine.")
  969. end
  970.  
  971. local energyBufferStorage = turbine.getEnergyStored()
  972. if energyBufferStorage == nil then
  973. return 0
  974. else
  975. return round(energyBufferStorage/10000, 1) -- (buffer/1000000 RF)*100%
  976. end
  977. end -- function getTurbineStoredEnergyBufferPercent(turbine)
  978.  
  979. local function reactorCruise(cruiseMaxTemp, cruiseMinTemp, reactorIndex)
  980. printLog("Called as reactorCruise(cruiseMaxTemp="..cruiseMaxTemp..",cruiseMinTemp="..cruiseMinTemp..",lastPolledTemp=".._G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"]..",reactorIndex="..reactorIndex..").")
  981.  
  982. --sanitization
  983. local lastPolledTemp = tonumber(_G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"])
  984. cruiseMaxTemp = tonumber(cruiseMaxTemp)
  985. cruiseMinTemp = tonumber(cruiseMinTemp)
  986.  
  987. if ((lastPolledTemp < cruiseMaxTemp) and (lastPolledTemp > cruiseMinTemp)) then
  988. local reactor = nil
  989. reactor = reactorList[reactorIndex]
  990. if not reactor then
  991. printLog("reactor["..reactorIndex.."] in reactorCruise(cruiseMaxTemp="..cruiseMaxTemp..",cruiseMinTemp="..cruiseMinTemp..",lastPolledTemp="..lastPolledTemp..",reactorIndex="..reactorIndex..") is NOT a valid Big Reactor.")
  992. return -- Invalid reactorIndex
  993. else
  994. printLog("reactor["..reactorIndex.."] in reactorCruise(cruiseMaxTemp="..cruiseMaxTemp..",cruiseMinTemp="..cruiseMinTemp..",lastPolledTemp="..lastPolledTemp..",reactorIndex="..reactorIndex..") is a valid Big Reactor.")
  995. if reactor.getConnected() then
  996. printLog("reactor["..reactorIndex.."] in reactorCruise(cruiseMaxTemp="..cruiseMaxTemp..",cruiseMinTemp="..cruiseMinTemp..",lastPolledTemp="..lastPolledTemp..",reactorIndex="..reactorIndex..") is connected.")
  997. else
  998. printLog("reactor["..reactorIndex.."] in reactorCruise(cruiseMaxTemp="..cruiseMaxTemp..",cruiseMinTemp="..cruiseMinTemp..",lastPolledTemp="..lastPolledTemp..",reactorIndex="..reactorIndex..") is NOT connected.")
  999. return -- Disconnected reactor
  1000. end -- if reactor.getConnected() then
  1001. end -- if not reactor then
  1002.  
  1003. local rodPercentage = math.ceil(reactor.getControlRodLevel(0))
  1004. local reactorTemp = math.ceil(reactor.getFuelTemperature())
  1005. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = rodPercentage
  1006.  
  1007. if ((reactorTemp < cruiseMaxTemp) and (reactorTemp > cruiseMinTemp)) then
  1008. if (reactorTemp < lastPolledTemp) then
  1009. rodPercentage = (rodPercentage - 1)
  1010. --Boundary check
  1011. if rodPercentage < 0 then
  1012. reactor.setAllControlRodLevels(0)
  1013. else
  1014. reactor.setAllControlRodLevels(rodPercentage)
  1015. end
  1016. else
  1017. rodPercentage = (rodPercentage + 1)
  1018. --Boundary check
  1019. if rodPercentage > 99 then
  1020. reactor.setAllControlRodLevels(99)
  1021. else
  1022. reactor.setAllControlRodLevels(rodPercentage)
  1023. end
  1024. end -- if (reactorTemp > lastPolledTemp) then
  1025. else
  1026. --disengage cruise, we've fallen out of the ideal temperature range
  1027. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = false
  1028. end -- if ((reactorTemp < cruiseMaxTemp) and (reactorTemp > cruiseMinTemp)) then
  1029. else
  1030. --I don't know how we'd get here, but let's turn the cruise mode off
  1031. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = false
  1032. end -- if ((lastPolledTemp < cruiseMaxTemp) and (lastPolledTemp > cruiseMinTemp)) then
  1033. _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"] = reactorTemp
  1034. _G[reactorNames[reactorIndex]]["ReactorOptions"]["activeCooled"] = true
  1035. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"] = cruiseMaxTemp
  1036. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"] = cruiseMinTemp
  1037. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1038. end -- function reactorCruise(cruiseMaxTemp, cruiseMinTemp, lastPolledTemp, reactorIndex)
  1039.  
  1040. -- Modify reactor control rod levels to keep temperature with defined parameters, but
  1041. -- wait an in-game half-hour for the temperature to stabalize before modifying again
  1042. local function temperatureControl(reactorIndex)
  1043. printLog("Called as temperatureControl(reactorIndex="..reactorIndex..")")
  1044.  
  1045. local reactor = nil
  1046. reactor = reactorList[reactorIndex]
  1047. if not reactor then
  1048. printLog("reactor["..reactorIndex.."] in temperatureControl(reactorIndex="..reactorIndex..") is NOT a valid Big Reactor.")
  1049. return -- Invalid reactorIndex
  1050. else
  1051. printLog("reactor["..reactorIndex.."] in temperatureControl(reactorIndex="..reactorIndex..") is a valid Big Reactor.")
  1052.  
  1053. if reactor.getConnected() then
  1054. printLog("reactor["..reactorIndex.."] in temperatureControl(reactorIndex="..reactorIndex..") is connected.")
  1055. else
  1056. printLog("reactor["..reactorIndex.."] in temperatureControl(reactorIndex="..reactorIndex..") is NOT connected.")
  1057. return -- Disconnected reactor
  1058. end -- if reactor.getConnected() then
  1059. end
  1060.  
  1061. local reactorNum = reactorIndex
  1062. local rodPercentage = math.ceil(reactor.getControlRodLevel(0))
  1063. local reactorTemp = math.ceil(reactor.getFuelTemperature())
  1064. local localMinReactorTemp, localMaxReactorTemp = _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"], _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"]
  1065.  
  1066. --bypass if the reactor itself is set to not be auto-controlled
  1067. if ((not _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]) or (_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] == "false")) then
  1068. -- No point modifying control rod levels for temperature if the reactor is offline
  1069. if reactor.getActive() then
  1070. -- Actively cooled reactors should range between 0^C-300^C
  1071. -- Actually, active-cooled reactors should range between 300 and 420C (Mechaet)
  1072. -- Accordingly I changed the below lines
  1073. if reactor.isActivelyCooled() then
  1074. localMinReactorTemp = 420
  1075. localMaxReactorTemp = 800
  1076. else
  1077. localMinReactorTemp = _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMinTemp"]
  1078. localMaxReactorTemp = _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorMaxTemp"]
  1079. end
  1080. local lastTempPoll = _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"]
  1081. if _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] then
  1082. --let's bypass all this math and hit the much-more-subtle cruise feature
  1083. --printLog("min: "..localMinReactorTemp..", max: "..localMaxReactorTemp..", lasttemp: "..lastTempPoll..", ri: "..reactorIndex.." EOL")
  1084. reactorCruise(localMaxReactorTemp, localMinReactorTemp, reactorIndex)
  1085. else
  1086. -- Don't bring us to 100, that's effectively a shutdown
  1087. if (reactorTemp > localMaxReactorTemp) and (rodPercentage ~= 99) then
  1088. --increase the rods, but by how much?
  1089. if (reactorTemp > lastTempPoll) then
  1090. --we're climbing, we need to get this to decrease
  1091. if ((reactorTemp - lastTempPoll) > 100) then
  1092. --we're climbing really fast, arrest it
  1093. if (rodPercentage + (10 * controlRodAdjustAmount)) > 99 then
  1094. reactor.setAllControlRodLevels(99)
  1095. else
  1096. reactor.setAllControlRodLevels(rodPercentage + (10 * controlRodAdjustAmount))
  1097. end
  1098. else
  1099. --we're not climbing by leaps and bounds, let's give it a rod adjustment based on temperature increase
  1100. local diffAmount = reactorTemp - lastTempPoll
  1101. diffAmount = (round(diffAmount/10, 0))/5
  1102. controlRodAdjustAmount = diffAmount
  1103. if (rodPercentage + controlRodAdjustAmount) > 99 then
  1104. reactor.setAllControlRodLevels(99)
  1105. else
  1106. reactor.setAllControlRodLevels(rodPercentage + controlRodAdjustAmount)
  1107. end
  1108. end --if ((reactorTemp - lastTempPoll) > 100) then
  1109. elseif (reactorTemp == lastTempPoll) then
  1110. --temperature has stagnated, kick it very lightly
  1111. local controlRodAdjustment = 1
  1112. if (rodPercentage + controlRodAdjustment) > 99 then
  1113. reactor.setAllControlRodLevels(99)
  1114. else
  1115. reactor.setAllControlRodLevels(rodPercentage + controlRodAdjustment)
  1116. end
  1117. end --if (reactorTemp > lastTempPoll) then
  1118. --worth noting that if we're above temp but decreasing, we do nothing. let it continue decreasing.
  1119.  
  1120. elseif (reactorTemp < localMinReactorTemp) and (rodPercentage ~=0) then
  1121. --we're too cold. time to warm up, but by how much?
  1122. if (reactorTemp < lastTempPoll) then
  1123. --we're descending, let's stop that.
  1124. if ((lastTempPoll - reactorTemp) > 100) then
  1125. --we're headed for a new ice age, bring the heat
  1126. if (rodPercentage - (10 * controlRodAdjustAmount)) < 0 then
  1127. reactor.setAllControlRodLevels(0)
  1128. else
  1129. reactor.setAllControlRodLevels(rodPercentage - (10 * controlRodAdjustAmount))
  1130. end
  1131. else
  1132. --we're not descending quickly, let's bump it based on descent rate
  1133. local diffAmount = lastTempPoll - reactorTemp
  1134. diffAmount = (round(diffAmount/10, 0))/5
  1135. controlRodAdjustAmount = diffAmount
  1136. if (rodPercentage - controlRodAdjustAmount) < 0 then
  1137. reactor.setAllControlRodLevels(0)
  1138. else
  1139. reactor.setAllControlRodLevels(rodPercentage - controlRodAdjustAmount)
  1140. end
  1141. end --if ((lastTempPoll - reactorTemp) > 100) then
  1142. elseif (reactorTemp == lastTempPoll) then
  1143. --temperature has stagnated, kick it very lightly
  1144. local controlRodAdjustment = 1
  1145. if (rodPercentage - controlRodAdjustment) < 0 then
  1146. reactor.setAllControlRodLevels(0)
  1147. else
  1148. reactor.setAllControlRodLevels(rodPercentage - controlRodAdjustment)
  1149. end --if (rodPercentage - controlRodAdjustment) < 0 then
  1150.  
  1151. end --if (reactorTemp < lastTempPoll) then
  1152. --if we're below temp but increasing, do nothing and let it continue to rise.
  1153. end --if (reactorTemp > localMaxReactorTemp) and (rodPercentage ~= 99) then
  1154.  
  1155. if ((reactorTemp > localMinReactorTemp) and (reactorTemp < localMaxReactorTemp)) then
  1156. --engage cruise mode
  1157. _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] = true
  1158. end -- if ((reactorTemp > localMinReactorTemp) and (reactorTemp < localMaxReactorTemp)) then
  1159. end -- if reactorCruising then
  1160. --always set this number
  1161. _G[reactorNames[reactorIndex]]["ReactorOptions"]["lastTempPoll"] = reactorTemp
  1162. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1163. end -- if reactor.getActive() then
  1164. else
  1165. printLog("Bypassed temperature control due to rodOverride being "..tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]).." EOL")
  1166. end -- if not _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] then
  1167. end -- function temperatureControl(reactorIndex)
  1168.  
  1169. -- Load saved reactor parameters if ReactorOptions file exists
  1170. local function loadReactorOptions()
  1171. local reactorOptions = fs.open("ReactorOptions", "r") -- See http://computercraft.info/wiki/Fs.open
  1172.  
  1173. if reactorOptions then
  1174. -- The following values were added by Lolmer
  1175. minStoredEnergyPercent = reactorOptions.readLine()
  1176. maxStoredEnergyPercent = reactorOptions.readLine()
  1177. --added by Mechaet
  1178. -- If we succeeded in reading a string, convert it to a number
  1179.  
  1180. if minStoredEnergyPercent ~= nil then
  1181. minStoredEnergyPercent = tonumber(minStoredEnergyPercent)
  1182. end
  1183.  
  1184. if maxStoredEnergyPercent ~= nil then
  1185. maxStoredEnergyPercent = tonumber(maxStoredEnergyPercent)
  1186. end
  1187.  
  1188. reactorOptions.close()
  1189. end -- if reactorOptions then
  1190.  
  1191. -- Set default values if we failed to read any of the above
  1192. if minStoredEnergyPercent == nil then
  1193. minStoredEnergyPercent = 15
  1194. end
  1195.  
  1196. if maxStoredEnergyPercent == nil then
  1197. maxStoredEnergyPercent = 85
  1198. end
  1199.  
  1200. end -- function loadReactorOptions()
  1201.  
  1202.  
  1203. -- Save our reactor parameters
  1204. local function saveReactorOptions()
  1205. local reactorOptions = fs.open("ReactorOptions", "w") -- See http://computercraft.info/wiki/Fs.open
  1206.  
  1207. -- If we can save the files, save them
  1208. if reactorOptions then
  1209. local reactorIndex = 1
  1210. -- The following values were added by Lolmer
  1211. reactorOptions.writeLine(minStoredEnergyPercent)
  1212. reactorOptions.writeLine(maxStoredEnergyPercent)
  1213. reactorOptions.close()
  1214. else
  1215. printLog("Failed to open file ReactorOptions for writing!")
  1216. end -- if reactorOptions then
  1217. end -- function saveReactorOptions()
  1218.  
  1219.  
  1220. local function displayReactorBars(barParams)
  1221. -- Default to first reactor and first monitor
  1222. setmetatable(barParams,{__index={reactorIndex=1, monitorIndex=1}})
  1223. local reactorIndex, monitorIndex =
  1224. barParams[1] or barParams.reactorIndex,
  1225. barParams[2] or barParams.monitorIndex
  1226.  
  1227. printLog("Called as displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1228.  
  1229. -- Grab current monitor
  1230. local monitor = nil
  1231. monitor = monitorList[monitorIndex]
  1232. if not monitor then
  1233. printLog("monitor["..monitorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT a valid monitor.")
  1234. return -- Invalid monitorIndex
  1235. end
  1236.  
  1237. -- Grab current reactor
  1238. local reactor = nil
  1239. reactor = reactorList[reactorIndex]
  1240. if not reactor then
  1241. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT a valid Big Reactor.")
  1242. return -- Invalid reactorIndex
  1243. else
  1244. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is a valid Big Reactor.")
  1245. if reactor.getConnected() then
  1246. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is connected.")
  1247. else
  1248. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT connected.")
  1249. return -- Disconnected reactor
  1250. end -- if reactor.getConnected() then
  1251. end -- if not reactor then
  1252.  
  1253. -- Draw border lines
  1254. local width, height = monitor.getSize()
  1255. printLog("Size of monitor is "..width.."w x"..height.."h in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..")")
  1256.  
  1257. for i=3, 5 do
  1258. monitor.setCursorPos(22, i)
  1259. monitor.write("|")
  1260. end
  1261.  
  1262. drawLine(2, monitorIndex)
  1263. drawLine(6, monitorIndex)
  1264.  
  1265. -- Draw some text
  1266. local fuelString = "Fuel: "
  1267. local tempString = "Temp: "
  1268. local energyBufferString = ""
  1269.  
  1270. if reactor.isActivelyCooled() then
  1271. energyBufferString = "Steam: "
  1272. else
  1273. energyBufferString = "Energy: "
  1274. end
  1275.  
  1276. local padding = math.max(string.len(fuelString), string.len(tempString), string.len(energyBufferString))
  1277.  
  1278. local fuelPercentage = round(reactor.getFuelAmount()/reactor.getFuelAmountMax()*100,1)
  1279. print{fuelString,2,3,monitorIndex}
  1280. print{fuelPercentage.." %",padding+2,3,monitorIndex}
  1281.  
  1282. local reactorTemp = math.ceil(reactor.getFuelTemperature())
  1283. print{tempString,2,5,monitorIndex}
  1284. print{reactorTemp.." C",padding+2,5,monitorIndex}
  1285.  
  1286. local rodPercentage = math.ceil(reactor.getControlRodLevel(0))
  1287. printLog("Current Rod Percentage for reactor["..reactorIndex.."] is "..rodPercentage.."% in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1288. -- Allow controlling Reactor Control Rod Level from GUI
  1289. -- Decrease rod button: 23X, 4Y
  1290. -- Increase rod button: 28X, 4Y
  1291. if (xClick == 23) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1292. printLog("Decreasing Rod Levels in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1293. --Decrease rod level by amount
  1294. newRodPercentage = rodPercentage - (5 * controlRodAdjustAmount)
  1295. if newRodPercentage < 0 then
  1296. newRodPercentage = 0
  1297. end
  1298. sideClick, xClick, yClick = 0, 0, 0
  1299.  
  1300. printLog("Setting reactor["..reactorIndex.."] Rod Levels to "..newRodPercentage.."% in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1301. reactor.setAllControlRodLevels(newRodPercentage)
  1302. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = newRodPercentage
  1303.  
  1304. -- Save updated rod percentage
  1305. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1306. rodPercentage = newRodPercentage
  1307. elseif (xClick == 29) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1308. printLog("Increasing Rod Levels in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1309. --Increase rod level by amount
  1310. newRodPercentage = rodPercentage + (5 * controlRodAdjustAmount)
  1311. if newRodPercentage > 100 then
  1312. newRodPercentage = 100
  1313. end
  1314. sideClick, xClick, yClick = 0, 0, 0
  1315.  
  1316. printLog("Setting reactor["..reactorIndex.."] Rod Levels to "..newRodPercentage.."% in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1317. reactor.setAllControlRodLevels(newRodPercentage)
  1318. _G[reactorNames[reactorIndex]]["ReactorOptions"]["baseControlRodLevel"] = newRodPercentage
  1319.  
  1320. -- Save updated rod percentage
  1321. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1322. rodPercentage = round(newRodPercentage,0)
  1323. else
  1324. printLog("No change to Rod Levels requested by "..progName.." GUI in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1325. end -- if (xClick == 29) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1326.  
  1327. print{"Rod (%)",23,3,monitorIndex}
  1328. print{"< >",23,4,monitorIndex}
  1329. print{stringTrim(rodPercentage),25,4,monitorIndex}
  1330.  
  1331.  
  1332. -- getEnergyProducedLastTick() is used for both RF/t (passively cooled) and mB/t (actively cooled)
  1333. local energyBuffer = reactor.getEnergyProducedLastTick()
  1334. if reactor.isActivelyCooled() then
  1335. printLog("reactor["..reactorIndex.."] produced "..energyBuffer.." mB last tick in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1336. else
  1337. printLog("reactor["..reactorIndex.."] produced "..energyBuffer.." RF last tick in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1338. end
  1339.  
  1340. print{energyBufferString,2,4,monitorIndex}
  1341.  
  1342. -- Actively cooled reactors do not produce energy, only hot fluid mB/t to be used in a turbine
  1343. -- still uses getEnergyProducedLastTick for mB/t of hot fluid generated
  1344. if not reactor.isActivelyCooled() then
  1345. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT an actively cooled reactor.")
  1346.  
  1347. -- Draw stored energy buffer bar
  1348. drawBar(2,8,28,8,colors.gray,monitorIndex)
  1349.  
  1350. local curStoredEnergyPercent = getReactorStoredEnergyBufferPercent(reactor)
  1351. if curStoredEnergyPercent > 4 then
  1352. drawBar(2, 8, math.floor(26*curStoredEnergyPercent/100)+2, 8, colors.yellow, monitorIndex)
  1353. elseif curStoredEnergyPercent > 0 then
  1354. drawPixel(2, 8, colors.yellow, monitorIndex)
  1355. end -- if curStoredEnergyPercent > 4 then
  1356.  
  1357. print{"Energy Buffer",2,7,monitorIndex}
  1358. print{curStoredEnergyPercent, width-(string.len(curStoredEnergyPercent)+2),7,monitorIndex}
  1359. print{"%",28,7,monitorIndex}
  1360.  
  1361. print{math.ceil(energyBuffer).." RF/t",padding+2,4,monitorIndex}
  1362. else
  1363. printLog("reactor["..reactorIndex.."] in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is an actively cooled reactor.")
  1364. print{math.ceil(energyBuffer).." mB/t",padding+2,4,monitorIndex}
  1365. end -- if not reactor.isActivelyCooled() then
  1366.  
  1367. -- Print rod override status
  1368. local reactorRodOverrideStatus = ""
  1369.  
  1370. print{"Rod Auto-adjust:",2,9,monitorIndex}
  1371.  
  1372. if not _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] then
  1373. printLog("Reactor Rod Override status is: "..tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]).." EOL")
  1374. reactorRodOverrideStatus = "Enabled"
  1375. monitor.setTextColor(colors.green)
  1376. else
  1377. printLog("Reactor Rod Override status is: "..tostring(_G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]).." EOL")
  1378. reactorRodOverrideStatus = "Disabled"
  1379. monitor.setTextColor(colors.red)
  1380. end -- if not reactorRodOverride then
  1381. printLog("reactorRodOverrideStatus is \""..reactorRodOverrideStatus.."\" in displayReactorBars(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..").")
  1382.  
  1383. print{reactorRodOverrideStatus, width - string.len(reactorRodOverrideStatus) - 1, 9, monitorIndex}
  1384. monitor.setTextColor(colors.white)
  1385.  
  1386. print{"Reactivity: "..math.ceil(reactor.getFuelReactivity()).." %", 2, 10, monitorIndex}
  1387. print{"Fuel: "..round(reactor.getFuelConsumedLastTick(),3).." mB/t", 2, 11, monitorIndex}
  1388. print{"Waste: "..reactor.getWasteAmount().." mB", width-(string.len(reactor.getWasteAmount())+10), 11, monitorIndex}
  1389.  
  1390. monitor.setTextColor(colors.blue)
  1391. printCentered(_G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorName"],12,monitorIndex)
  1392. monitor.setTextColor(colors.white)
  1393. end -- function displayReactorBars(barParams)
  1394.  
  1395.  
  1396. local function reactorStatus(statusParams)
  1397. -- Default to first reactor and first monitor
  1398. setmetatable(statusParams,{__index={reactorIndex=1, monitorIndex=1}})
  1399. local reactorIndex, monitorIndex =
  1400. statusParams[1] or statusParams.reactorIndex,
  1401. statusParams[2] or statusParams.monitorIndex
  1402. printLog("Called as reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..")")
  1403.  
  1404. -- Grab current monitor
  1405. local monitor = nil
  1406. monitor = monitorList[monitorIndex]
  1407. if not monitor then
  1408. printLog("monitor["..monitorIndex.."] in reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT a valid monitor.")
  1409. return -- Invalid monitorIndex
  1410. end
  1411.  
  1412. -- Grab current reactor
  1413. local reactor = nil
  1414. reactor = reactorList[reactorIndex]
  1415. if not reactor then
  1416. printLog("reactor["..reactorIndex.."] in reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT a valid Big Reactor.")
  1417. return -- Invalid reactorIndex
  1418. else
  1419. printLog("reactor["..reactorIndex.."] in reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is a valid Big Reactor.")
  1420. end
  1421.  
  1422. local width, height = monitor.getSize()
  1423. local reactorStatus = ""
  1424.  
  1425. if reactor.getConnected() then
  1426. printLog("reactor["..reactorIndex.."] in reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is connected.")
  1427.  
  1428. if reactor.getActive() then
  1429. reactorStatus = "ONLINE"
  1430.  
  1431. -- Set "ONLINE" to blue if the actively cooled reactor is both in cruise mode and online
  1432. if _G[reactorNames[reactorIndex]]["ReactorOptions"]["reactorCruising"] and reactor.isActivelyCooled() then
  1433. monitor.setTextColor(colors.blue)
  1434. else
  1435. monitor.setTextColor(colors.green)
  1436. end -- if reactorCruising and reactor.isActivelyCooled() then
  1437. else
  1438. reactorStatus = "OFFLINE"
  1439. monitor.setTextColor(colors.red)
  1440. end -- if reactor.getActive() then
  1441.  
  1442. if xClick >= (width - string.len(reactorStatus) - 1) and xClick <= (width-1) and (sideClick == monitorNames[monitorIndex]) then
  1443. if yClick == 1 then
  1444. reactor.setActive(not reactor.getActive()) -- Toggle reactor status
  1445. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = reactor.getActive()
  1446. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1447. sideClick, xClick, yClick = 0, 0, 0 -- Reset click after we register it
  1448.  
  1449. -- If someone offlines the reactor (offline after a status click was detected), then disable autoStart
  1450. if not reactor.getActive() then
  1451. _G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] = false
  1452. end
  1453. end -- if yClick == 1 then
  1454. end -- if (xClick >= (width - string.len(reactorStatus) - 1) and xClick <= (width-1)) and (sideClick == monitorNames[monitorIndex]) then
  1455.  
  1456. -- Allow disabling rod level auto-adjust and only manual rod level control
  1457. if ((xClick > 23 and xClick < 28 and yClick == 4)
  1458. or (xClick > 20 and xClick < 27 and yClick == 9))
  1459. and (sideClick == monitorNames[monitorIndex]) then
  1460. _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] = not _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"]
  1461. config.save(reactorNames[reactorIndex]..".options", _G[reactorNames[reactorIndex]])
  1462. sideClick, xClick, yClick = 0, 0, 0 -- Reset click after we register it
  1463. end -- if (xClick > 23) and (xClick < 28) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1464.  
  1465. else
  1466. printLog("reactor["..reactorIndex.."] in reactorStatus(reactorIndex="..reactorIndex..",monitorIndex="..monitorIndex..") is NOT connected.")
  1467. reactorStatus = "DISCONNECTED"
  1468. monitor.setTextColor(colors.red)
  1469. end -- if reactor.getConnected() then
  1470.  
  1471. print{reactorStatus, width - string.len(reactorStatus) - 1, 1, monitorIndex}
  1472. monitor.setTextColor(colors.white)
  1473. end -- function reactorStatus(statusParams)
  1474.  
  1475.  
  1476. -- Display all found reactors' status to monitor 1
  1477. -- This is only called if multiple reactors and/or a reactor plus at least one turbine are found
  1478. local function displayAllStatus()
  1479. local reactor, turbine = nil, nil
  1480. local onlineReactor, onlineTurbine = 0, 0
  1481. local totalReactorRF, totalReactorSteam, totalTurbineRF = 0, 0, 0
  1482. local totalReactorFuelConsumed = 0
  1483. local totalCoolantStored, totalSteamStored, totalEnergy, totalMaxEnergyStored = 0, 0, 0, 0 -- Total turbine and reactor energy buffer and overall capacity
  1484. local maxSteamStored = (2000*#turbineList)+(5000*#reactorList)
  1485. local maxCoolantStored = (2000*#turbineList)+(5000*#reactorList)
  1486.  
  1487. local monitor, monitorIndex = nil, 1
  1488. monitor = monitorList[monitorIndex]
  1489. if not monitor then
  1490. printLog("monitor["..monitorIndex.."] in displayAllStatus() is NOT a valid monitor.")
  1491. return -- Invalid monitorIndex
  1492. end
  1493.  
  1494. for reactorIndex = 1, #reactorList do
  1495. reactor = reactorList[reactorIndex]
  1496. if not reactor then
  1497. printLog("reactor["..reactorIndex.."] in displayAllStatus() is NOT a valid Big Reactor.")
  1498. break -- Invalid reactorIndex
  1499. else
  1500. printLog("reactor["..reactorIndex.."] in displayAllStatus() is a valid Big Reactor.")
  1501. end -- if not reactor then
  1502.  
  1503. if reactor.getConnected() then
  1504. printLog("reactor["..reactorIndex.."] in displayAllStatus() is connected.")
  1505. if reactor.getActive() then
  1506. onlineReactor = onlineReactor + 1
  1507. totalReactorFuelConsumed = totalReactorFuelConsumed + reactor.getFuelConsumedLastTick()
  1508. end -- reactor.getActive() then
  1509.  
  1510. -- Actively cooled reactors do not produce or store energy
  1511. if not reactor.isActivelyCooled() then
  1512. totalMaxEnergyStored = totalMaxEnergyStored + 10000000 -- Reactors store 10M RF
  1513. totalEnergy = totalEnergy + reactor.getEnergyStored()
  1514. totalReactorRF = totalReactorRF + reactor.getEnergyProducedLastTick()
  1515. else
  1516. totalReactorSteam = totalReactorSteam + reactor.getEnergyProducedLastTick()
  1517. totalSteamStored = totalSteamStored + reactor.getHotFluidAmount()
  1518. totalCoolantStored = totalCoolantStored + reactor.getCoolantAmount()
  1519. end -- if not reactor.isActivelyCooled() then
  1520. else
  1521. printLog("reactor["..reactorIndex.."] in displayAllStatus() is NOT connected.")
  1522. end -- if reactor.getConnected() then
  1523. end -- for reactorIndex = 1, #reactorList do
  1524.  
  1525. for turbineIndex = 1, #turbineList do
  1526. turbine = turbineList[turbineIndex]
  1527. if not turbine then
  1528. printLog("turbine["..turbineIndex.."] in displayAllStatus() is NOT a valid Turbine.")
  1529. break -- Invalid turbineIndex
  1530. else
  1531. printLog("turbine["..turbineIndex.."] in displayAllStatus() is a valid Turbine.")
  1532. end -- if not turbine then
  1533.  
  1534. if turbine.getConnected() then
  1535. printLog("turbine["..turbineIndex.."] in displayAllStatus() is connected.")
  1536. if turbine.getActive() then
  1537. onlineTurbine = onlineTurbine + 1
  1538. end
  1539.  
  1540. totalMaxEnergyStored = totalMaxEnergyStored + 1000000 -- Turbines store 1M RF
  1541. totalEnergy = totalEnergy + turbine.getEnergyStored()
  1542. totalTurbineRF = totalTurbineRF + turbine.getEnergyProducedLastTick()
  1543. totalSteamStored = totalSteamStored + turbine.getInputAmount()
  1544. totalCoolantStored = totalCoolantStored + turbine.getOutputAmount()
  1545. else
  1546. printLog("turbine["..turbineIndex.."] in displayAllStatus() is NOT connected.")
  1547. end -- if turbine.getConnected() then
  1548. end -- for turbineIndex = 1, #turbineList do
  1549.  
  1550. print{"Reactors online/found: "..onlineReactor.."/"..#reactorList, 2, 3, monitorIndex}
  1551. print{"Turbines online/found: "..onlineTurbine.."/"..#turbineList, 2, 4, monitorIndex}
  1552.  
  1553. if totalReactorRF ~= 0 then
  1554. monitor.setTextColor(colors.blue)
  1555. printRight("Reactor", 9, monitorIndex)
  1556. monitor.setTextColor(colors.white)
  1557. printRight(math.ceil(totalReactorRF).." (RF/t)", 10, monitorIndex)
  1558. end
  1559.  
  1560. if #turbineList then
  1561. -- Display liquids
  1562. monitor.setTextColor(colors.blue)
  1563. printLeft("Steam (mB)", 6, monitorIndex)
  1564. monitor.setTextColor(colors.white)
  1565. printLeft(math.ceil(totalSteamStored).."/"..maxSteamStored, 7, monitorIndex)
  1566. printLeft(math.ceil(totalReactorSteam).." mB/t", 8, monitorIndex)
  1567. monitor.setTextColor(colors.blue)
  1568. printRight("Coolant (mB)", 6, monitorIndex)
  1569. monitor.setTextColor(colors.white)
  1570. printRight(math.ceil(totalCoolantStored).."/"..maxCoolantStored, 7, monitorIndex)
  1571.  
  1572. monitor.setTextColor(colors.blue)
  1573. printLeft("Turbine", 9, monitorIndex)
  1574. monitor.setTextColor(colors.white)
  1575. printLeft(math.ceil(totalTurbineRF).." RF/t", 10, monitorIndex)
  1576. end -- if #turbineList then
  1577.  
  1578. printCentered("Fuel: "..round(totalReactorFuelConsumed,3).." mB/t", 11, monitorIndex)
  1579. print{"Buffer: "..math.ceil(totalEnergy,3).."/"..totalMaxEnergyStored.." RF", 2, 12, monitorIndex}
  1580. end -- function displayAllStatus()
  1581.  
  1582.  
  1583. -- Get turbine status
  1584. local function displayTurbineBars(turbineIndex, monitorIndex)
  1585. printLog("Called as displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1586.  
  1587. -- Grab current monitor
  1588. local monitor = nil
  1589. monitor = monitorList[monitorIndex]
  1590. if not monitor then
  1591. printLog("monitor["..monitorIndex.."] in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT a valid monitor.")
  1592. return -- Invalid monitorIndex
  1593. end
  1594.  
  1595. -- Grab current turbine
  1596. local turbine = nil
  1597. turbine = turbineList[turbineIndex]
  1598. if not turbine then
  1599. printLog("turbine["..turbineIndex.."] in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT a valid Big Turbine.")
  1600. return -- Invalid turbineIndex
  1601. else
  1602. printLog("turbine["..turbineIndex.."] in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is a valid Big Turbine.")
  1603. if turbine.getConnected() then
  1604. printLog("turbine["..turbineIndex.."] in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is connected.")
  1605. else
  1606. printLog("turbine["..turbineIndex.."] in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT connected.")
  1607. return -- Disconnected turbine
  1608. end -- if turbine.getConnected() then
  1609. end -- if not turbine then
  1610.  
  1611. --local variable to match the view on the monitor
  1612. local turbineBaseSpeed = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"])
  1613.  
  1614. -- Draw border lines
  1615. local width, height = monitor.getSize()
  1616.  
  1617. for i=3, 6 do
  1618. monitor.setCursorPos(21, i)
  1619. monitor.write("|")
  1620. end
  1621.  
  1622. drawLine(2,monitorIndex)
  1623. drawLine(7,monitorIndex)
  1624.  
  1625. -- Allow controlling Turbine Flow Rate from GUI
  1626. -- Decrease flow rate button: 22X, 4Y
  1627. -- Increase flow rate button: 28X, 4Y
  1628. local turbineFlowRate = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"])
  1629. if (xClick == 22) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1630. printLog("Decrease to Flow Rate requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1631. --Decrease rod level by amount
  1632. newTurbineFlowRate = turbineFlowRate - flowRateAdjustAmount
  1633. if newTurbineFlowRate < 0 then
  1634. newTurbineFlowRate = 0
  1635. end
  1636. sideClick, xClick, yClick = 0, 0, 0
  1637.  
  1638. -- Check bounds [0,2000]
  1639. if newTurbineFlowRate > 2000 then
  1640. newTurbineFlowRate = 2000
  1641. elseif newTurbineFlowRate < 0 then
  1642. newTurbineFlowRate = 1 -- Don't go to zero, might as well power off
  1643. end
  1644.  
  1645. turbine.setFluidFlowRateMax(newTurbineFlowRate)
  1646. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"] = newTurbineFlowRate
  1647. -- Save updated Turbine Flow Rate
  1648. turbineFlowRate = newTurbineFlowRate
  1649. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1650. elseif (xClick == 29) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1651. printLog("Increase to Flow Rate requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1652. --Increase rod level by amount
  1653. newTurbineFlowRate = turbineFlowRate + flowRateAdjustAmount
  1654. if newTurbineFlowRate > 2000 then
  1655. newTurbineFlowRate = 2000
  1656. end
  1657. sideClick, xClick, yClick = 0, 0, 0
  1658.  
  1659. -- Check bounds [0,2000]
  1660. if newTurbineFlowRate > 2000 then
  1661. newTurbineFlowRate = 2000
  1662. elseif newTurbineFlowRate < 0 then
  1663. newTurbineFlowRate = 1 -- Don't go to zero, might as well power off
  1664. end
  1665.  
  1666. turbine.setFluidFlowRateMax(newTurbineFlowRate)
  1667.  
  1668. -- Save updated Turbine Flow Rate
  1669. turbineFlowRate = math.ceil(newTurbineFlowRate)
  1670. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"] = turbineFlowRate
  1671. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1672. else
  1673. printLog("No change to Flow Rate requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1674. end -- if (xClick == 29) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1675.  
  1676. if (xClick == 22) and (yClick == 6) and (sideClick == monitorNames[monitorIndex]) then
  1677. printLog("Decrease to Turbine RPM requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1678. rpmRateAdjustment = 909
  1679. newTurbineBaseSpeed = turbineBaseSpeed - rpmRateAdjustment
  1680. if newTurbineBaseSpeed < 908 then
  1681. newTurbineBaseSpeed = 908
  1682. end
  1683. sideClick, xClick, yClick = 0, 0, 0
  1684. _G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"] = newTurbineBaseSpeed
  1685. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1686. elseif (xClick == 29) and (yClick == 6) and (sideClick == monitorNames[monitorIndex]) then
  1687. printLog("Increase to Turbine RPM requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1688. rpmRateAdjustment = 909
  1689. newTurbineBaseSpeed = turbineBaseSpeed + rpmRateAdjustment
  1690. if newTurbineBaseSpeed > 1840 then
  1691. newTurbineBaseSpeed = 1840
  1692. end
  1693. sideClick, xClick, yClick = 0, 0, 0
  1694. _G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"] = newTurbineBaseSpeed
  1695. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1696. else
  1697. printLog("No change to Turbine RPM requested by "..progName.." GUI in displayTurbineBars(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1698. end -- if (xClick == 29) and (yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1699. print{" mB/t",22,3,monitorIndex}
  1700. print{"< >",22,4,monitorIndex}
  1701. print{stringTrim(turbineFlowRate),24,4,monitorIndex}
  1702. print{" RPM",22,5,monitorIndex}
  1703. print{"< >",22,6,monitorIndex}
  1704. print{stringTrim(tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"])),24,6,monitorIndex}
  1705. local rotorSpeedString = "Speed: "
  1706. local energyBufferString = "Energy: "
  1707. local padding = math.max(string.len(rotorSpeedString), string.len(energyBufferString))
  1708.  
  1709. local energyBuffer = turbine.getEnergyProducedLastTick()
  1710. print{energyBufferString,1,4,monitorIndex}
  1711. print{math.ceil(energyBuffer).." RF/t",padding+1,4,monitorIndex}
  1712.  
  1713. local rotorSpeed = math.ceil(turbine.getRotorSpeed())
  1714. print{rotorSpeedString,1,5,monitorIndex}
  1715. print{rotorSpeed.." RPM",padding+1,5,monitorIndex}
  1716.  
  1717. -- PaintUtils only outputs to term., not monitor.
  1718. -- See http://www.computercraft.info/forums2/index.php?/topic/15540-paintutils-on-a-monitor/
  1719.  
  1720. -- Draw stored energy buffer bar
  1721. drawBar(1,9,28,9,colors.gray,monitorIndex)
  1722.  
  1723. local curStoredEnergyPercent = getTurbineStoredEnergyBufferPercent(turbine)
  1724. if curStoredEnergyPercent > 4 then
  1725. drawBar(1, 9, math.floor(26*curStoredEnergyPercent/100)+2, 9, colors.yellow,monitorIndex)
  1726. elseif curStoredEnergyPercent > 0 then
  1727. drawPixel(1, 9, colors.yellow, monitorIndex)
  1728. end -- if curStoredEnergyPercent > 4 then
  1729.  
  1730. print{"Energy Buffer",1,8,monitorIndex}
  1731. print{curStoredEnergyPercent, width-(string.len(curStoredEnergyPercent)+2),8,monitorIndex}
  1732. print{"%",28,8,monitorIndex}
  1733.  
  1734. -- Print rod override status
  1735. local turbineFlowRateOverrideStatus = ""
  1736.  
  1737. print{"Flow Auto-adjust:",2,10,monitorIndex}
  1738.  
  1739. if ((not _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"]) or (_G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] == "false")) then
  1740. turbineFlowRateOverrideStatus = "Enabled"
  1741. monitor.setTextColor(colors.green)
  1742. else
  1743. turbineFlowRateOverrideStatus = "Disabled"
  1744. monitor.setTextColor(colors.red)
  1745. end -- if not reactorRodOverride then
  1746.  
  1747. print{turbineFlowRateOverrideStatus, width - string.len(turbineFlowRateOverrideStatus) - 1, 10, monitorIndex}
  1748. monitor.setTextColor(colors.white)
  1749.  
  1750. print{"Coils Engaged:",2,11,monitorIndex}
  1751.  
  1752. if turbine.getInductorEngaged() then
  1753. turbineInductorStatus = "Engaged"
  1754. monitor.setTextColor(colors.green)
  1755. else
  1756. turbineInductorStatus = "Disengaged"
  1757. monitor.setTextColor(colors.red)
  1758. end -- if not reactorRodOverride then
  1759.  
  1760. print{turbineInductorStatus, width - string.len(turbineInductorStatus) - 1, 11, monitorIndex}
  1761. monitor.setTextColor(colors.white)
  1762.  
  1763.  
  1764. monitor.setTextColor(colors.blue)
  1765. printCentered(_G[turbineNames[turbineIndex]]["TurbineOptions"]["turbineName"],12,monitorIndex)
  1766. monitor.setTextColor(colors.white)
  1767.  
  1768. -- Need equation to figure out rotor efficiency and display
  1769. end -- function displayTurbineBars(statusParams)
  1770.  
  1771.  
  1772. -- Display turbine status
  1773. local function turbineStatus(turbineIndex, monitorIndex)
  1774. -- Grab current monitor
  1775. local monitor = nil
  1776.  
  1777. printLog("Called as turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..").")
  1778.  
  1779. monitor = monitorList[monitorIndex]
  1780. if not monitor then
  1781. printLog("monitor["..monitorIndex.."] in turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT a valid monitor.")
  1782. return -- Invalid monitorIndex
  1783. end
  1784.  
  1785. -- Grab current turbine
  1786. local turbine = nil
  1787. turbine = turbineList[turbineIndex]
  1788. if not turbine then
  1789. printLog("turbine["..turbineIndex.."] in turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT a valid Big Turbine.")
  1790. return -- Invalid turbineIndex
  1791. else
  1792. printLog("turbine["..turbineIndex.."] in turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is a valid Big Turbine.")
  1793. end
  1794.  
  1795. local width, height = monitor.getSize()
  1796. local turbineStatus = ""
  1797.  
  1798. if turbine.getConnected() then
  1799. printLog("turbine["..turbineIndex.."] in turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is connected.")
  1800. if turbine.getActive() then
  1801. turbineStatus = "ONLINE"
  1802. monitor.setTextColor(colors.green)
  1803. else
  1804. turbineStatus = "OFFLINE"
  1805. monitor.setTextColor(colors.red)
  1806. end -- if turbine.getActive() then
  1807.  
  1808. if (xClick >= (width - string.len(turbineStatus) - 1)) and (xClick <= (width-1)) and (sideClick == monitorNames[monitorIndex]) then
  1809. if yClick == 1 then
  1810. turbine.setActive(not turbine.getActive()) -- Toggle turbine status
  1811. _G[turbineNames[turbineIndex]]["TurbineOptions"]["autoStart"] = turbine.getActive()
  1812. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1813. sideClick, xClick, yClick = 0, 0, 0 -- Reset click after we register it
  1814. end -- if yClick == 1 then
  1815. end -- if (xClick >= (width - string.len(turbineStatus) - 1)) and (xClick <= (width-1)) and (sideClick == monitorNames[monitorIndex]) then
  1816.  
  1817. -- Allow disabling/enabling flow rate auto-adjust
  1818. if (xClick > 23 and xClick < 28 and yClick == 4) and (sideClick == monitorNames[monitorIndex]) then
  1819. _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] = true
  1820. sideClick, xClick, yClick = 0, 0, 0 -- Reset click after we register it
  1821. elseif (xClick > 20 and xClick < 27 and yClick == 10) and (sideClick == monitorNames[monitorIndex]) then
  1822.  
  1823. if ((_G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"]) or (_G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] == "true")) then
  1824. _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] = false
  1825. else
  1826. _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] = true
  1827. end
  1828. sideClick, xClick, yClick = 0, 0, 0 -- Reset click after we register it
  1829. end
  1830. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1831.  
  1832. else
  1833. printLog("turbine["..turbineIndex.."] in turbineStatus(turbineIndex="..turbineIndex..",monitorIndex="..monitorIndex..") is NOT connected.")
  1834. turbineStatus = "DISCONNECTED"
  1835. monitor.setTextColor(colors.red)
  1836. end -- if turbine.getConnected() then
  1837.  
  1838. print{turbineStatus, width - string.len(turbineStatus) - 1, 1, monitorIndex}
  1839. monitor.setTextColor(colors.white)
  1840. end -- function function turbineStatus(turbineIndex, monitorIndex)
  1841.  
  1842.  
  1843. -- Maintain Turbine flow rate at 900 or 1,800 RPM
  1844. local function flowRateControl(turbineIndex)
  1845. if ((not _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"]) or (_G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] == "false")) then
  1846.  
  1847. printLog("Called as flowRateControl(turbineIndex="..turbineIndex..").")
  1848.  
  1849. -- Grab current turbine
  1850. local turbine = nil
  1851. turbine = turbineList[turbineIndex]
  1852.  
  1853. -- assign for the duration of this run
  1854. local lastTurbineSpeed = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"])
  1855. local turbineBaseSpeed = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["BaseSpeed"])
  1856.  
  1857. if not turbine then
  1858. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is NOT a valid Big Turbine.")
  1859. return -- Invalid turbineIndex
  1860. else
  1861. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is a valid Big Turbine.")
  1862.  
  1863. if turbine.getConnected() then
  1864. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is connected.")
  1865. else
  1866. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is NOT connected.")
  1867. end -- if turbine.getConnected() then
  1868. end -- if not turbine then
  1869.  
  1870. -- No point modifying control rod levels for temperature if the turbine is offline
  1871. if turbine.getActive() then
  1872. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is active.")
  1873.  
  1874. local flowRate = tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"])
  1875. local flowRateUserMax = math.ceil(turbine.getFluidFlowRateMax())
  1876. local rotorSpeed = math.ceil(turbine.getRotorSpeed())
  1877. local newFlowRate = 0
  1878.  
  1879. -- Going to control the turbine based on target RPM since changing the target flow rate bypasses this function
  1880. if (rotorSpeed < turbineBaseSpeed) then
  1881. printLog("BELOW COMMANDED SPEED")
  1882. if (rotorSpeed > lastTurbineSpeed) then
  1883. --we're still increasing, let's let it level off
  1884. --also lets the first control pass go by on startup
  1885. elseif (rotorSpeed < lastTurbineSpeed) then
  1886. --we're decreasing where we should be increasing, do something
  1887. if ((lastTurbineSpeed - rotorSpeed) > 100) then
  1888. --kick it harder
  1889. newFlowRate = 2000
  1890. printLog("HARD KICK")
  1891. else
  1892. --let's adjust based on proximity
  1893. flowAdjustment = (turbineBaseSpeed - rotorSpeed)/5
  1894. newFlowRate = flowRate + flowAdjustment
  1895. printLog("Light Kick: new flow rate is "..newFlowRate.." mB/t and flowAdjustment was "..flowAdjustment.." EOL")
  1896. end
  1897. else
  1898. --we've stagnated, kick it.
  1899. flowAdjustment = (turbineBaseSpeed - lastTurbineSpeed)
  1900. newFlowRate = flowRate + flowAdjustment
  1901. printLog("Stagnated: new flow rate is "..newFlowRate.." mB/t and flowAdjustment was "..flowAdjustment.." EOL")
  1902. end --if (rotorSpeed > lastTurbineSpeed) then
  1903. else
  1904. --we're above commanded turbine speed
  1905. printLog("ABOVE COMMANDED SPEED")
  1906. if (rotorSpeed < lastTurbineSpeed) then
  1907. --we're decreasing, let it level off
  1908. --also bypasses first control pass on startup
  1909. elseif (rotorSpeed > lastTurbineSpeed) then
  1910. --we're above and ascending.
  1911. if ((rotorSpeed - lastTurbineSpeed) > 100) then
  1912. --halt
  1913. newFlowRate = 1
  1914. else
  1915. --let's adjust based on proximity
  1916. flowAdjustment = (rotorSpeed - turbineBaseSpeed)/5
  1917. newFlowRate = flowRate - flowAdjustment
  1918. printLog("Light Kick: new flow rate is "..newFlowRate.." mB/t and flowAdjustment was "..flowAdjustment.." EOL")
  1919. end
  1920. else
  1921. --we've stagnated, kick it.
  1922. flowAdjustment = (lastTurbineSpeed - turbineBaseSpeed)
  1923. newFlowRate = flowRate - flowAdjustment
  1924. printLog("Stagnated: new flow rate is "..newFlowRate.." mB/t and flowAdjustment was "..flowAdjustment.." EOL")
  1925. end --if (rotorSpeed < lastTurbineSpeed) then
  1926. end --if (rotorSpeed < turbineBaseSpeed)
  1927.  
  1928. --check to make sure an adjustment was made
  1929. if (newFlowRate == 0) then
  1930. --do nothing, we didn't ask for anything this pass
  1931. else
  1932. --boundary check
  1933. if newFlowRate > 2000 then
  1934. newFlowRate = 2000
  1935. elseif newFlowRate < 1 then
  1936. newFlowRate = 1 -- Don't go to zero, might as well power off
  1937. end -- if newFlowRate > 2000 then
  1938.  
  1939. --no sense running an adjustment if it's not necessary
  1940. if ((newFlowRate < flowRate) or (newFlowRate > flowRate)) then
  1941. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is being commanded to "..newFlowRate.." mB/t flow")
  1942. newFlowRate = round(newFlowRate, 0)
  1943. turbine.setFluidFlowRateMax(newFlowRate)
  1944. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastFlow"] = newFlowRate
  1945. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1946. end
  1947. end
  1948. --always set this
  1949. _G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"] = rotorSpeed
  1950. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  1951. else
  1952. printLog("turbine["..turbineIndex.."] in flowRateControl(turbineIndex="..turbineIndex..") is NOT active.")
  1953. end -- if turbine.getActive() then
  1954. else
  1955. printLog("turbine["..turbineIndex.."] has flow override set to "..tostring(_G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"])..", bypassing flow control.")
  1956. end -- if not _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] then
  1957. end -- function flowRateControl(turbineIndex)
  1958.  
  1959.  
  1960. function main()
  1961. -- Load reactor parameters and initialize systems
  1962. loadReactorOptions()
  1963.  
  1964. -- Get our initial list of connected monitors and reactors
  1965. -- and initialize every cycle in case the connected devices change
  1966. findMonitors()
  1967. findReactors()
  1968. findTurbines()
  1969.  
  1970. while not finished do
  1971. local reactor = nil
  1972. local monitorIndex = 1
  1973.  
  1974. -- For multiple reactors/monitors, monitor #1 is reserved for overall status
  1975. -- or for multiple reactors/turbines and only one monitor
  1976. if ( ( ((#reactorList + #turbineList) > 1) and (#monitorList >= 1) ) or
  1977. ( ((#reactorList + #turbineList) >=1) and (#monitorList > 1) ) ) then
  1978. local monitor = nil
  1979. monitor = monitorList[monitorIndex]
  1980. if not monitor then
  1981. printLog("monitor["..monitorIndex.."] in main() is NOT a valid monitor.")
  1982. return -- Invalid monitorIndex
  1983. end
  1984.  
  1985. clearMonitor(progName.." "..progVer, monitorIndex) -- Clear monitor and draw borders
  1986. printCentered(progName.." "..progVer, 1, monitorIndex)
  1987. displayAllStatus()
  1988. monitorIndex = 2 -- Next monitor, #1 is reserved for overall status
  1989. end
  1990.  
  1991. -- Iterate through reactors, continue to run even if not enough monitors are connected
  1992. for reactorIndex = 1, #reactorList do
  1993. local monitor = nil
  1994. local reactorMonitorIndex = monitorIndex + reactorIndex - 1 -- reactorIndex starts at 1
  1995.  
  1996. printLog("Attempting to display reactor["..reactorIndex.."] on monitor["..reactorMonitorIndex.."]...")
  1997.  
  1998. reactor = reactorList[reactorIndex]
  1999. if not reactor then
  2000. printLog("reactor["..reactorIndex.."] in main() is NOT a valid Big Reactor.")
  2001. break -- Invalid reactorIndex
  2002. else
  2003. printLog("reactor["..reactorIndex.."] in main() is a valid Big Reactor.")
  2004. end -- if not reactor then
  2005.  
  2006. -- Only attempt to assign a monitor if we have a monitor for this reactor
  2007. if (reactorMonitorIndex <= #monitorList) then
  2008. printLog("Displaying reactor["..reactorIndex.."] on monitor["..reactorMonitorIndex.."].")
  2009. monitor = monitorList[reactorMonitorIndex]
  2010.  
  2011. if not monitor then
  2012. printLog("monitor["..reactorMonitorIndex.."] in main() is NOT a valid monitor.")
  2013. else
  2014. clearMonitor(progName, reactorMonitorIndex) -- Clear monitor and draw borders
  2015. printCentered(progName, 1, reactorMonitorIndex)
  2016.  
  2017. -- Display reactor status, includes "Disconnected" but found reactors
  2018. reactorStatus{reactorIndex, reactorMonitorIndex}
  2019.  
  2020. -- Draw the borders and bars for the current reactor on the current monitor
  2021. displayReactorBars{reactorIndex, reactorMonitorIndex}
  2022. end -- if not monitor
  2023. else
  2024. printLog("You may want "..(#reactorList + #turbineList + 1).." monitors for your "..#reactorList.." connected reactors and "..#turbineList.." connected turbines.")
  2025. end -- if (#monitorList ~= 1) and (reactorMonitorIndex < #monitorList) then
  2026.  
  2027. if reactor.getConnected() then
  2028. printLog("reactor["..reactorIndex.."] is connected.")
  2029. local curStoredEnergyPercent = getReactorStoredEnergyBufferPercent(reactor)
  2030.  
  2031. -- Shutdown reactor if current stored energy % is >= desired level, otherwise activate
  2032. -- First pass will have curStoredEnergyPercent=0 until displayBars() is run once
  2033. if curStoredEnergyPercent >= maxStoredEnergyPercent then
  2034. reactor.setActive(false)
  2035. -- Do not auto-start the reactor if it was manually powered off (autoStart=false)
  2036. elseif (curStoredEnergyPercent <= minStoredEnergyPercent) and (_G[reactorNames[reactorIndex]]["ReactorOptions"]["autoStart"] == true) then
  2037. reactor.setActive(true)
  2038. end -- if curStoredEnergyPercent >= maxStoredEnergyPercent then
  2039.  
  2040. -- Don't try to auto-adjust control rods if manual control is requested
  2041. if not _G[reactorNames[reactorIndex]]["ReactorOptions"]["rodOverride"] then
  2042. temperatureControl(reactorIndex)
  2043. end -- if not reactorRodOverride then
  2044. else
  2045. printLog("reactor["..reactorIndex.."] is NOT connected.")
  2046. end -- if reactor.getConnected() then
  2047. end -- for reactorIndex = 1, #reactorList do
  2048.  
  2049. -- Monitors for turbines start after turbineMonitorOffset
  2050. for turbineIndex = 1, #turbineList do
  2051. local monitor = nil
  2052. local turbineMonitorIndex = turbineIndex + turbineMonitorOffset
  2053.  
  2054. printLog("Attempting to display turbine["..turbineIndex.."] on monitor["..turbineMonitorIndex.."]...")
  2055.  
  2056. -- Only attempt to assign a monitor if we found a monitor for this turbine
  2057. if (turbineMonitorIndex <= #monitorList) then
  2058. printLog("Displaying turbine["..turbineIndex.."] on monitor["..turbineMonitorIndex.."].")
  2059. monitor = monitorList[turbineMonitorIndex]
  2060. if not monitor then
  2061. printLog("monitor["..turbineMonitorIndex.."] in main() is NOT a valid monitor.")
  2062. else
  2063. clearMonitor(progName, turbineMonitorIndex) -- Clear monitor and draw borders
  2064. printCentered(progName, 1, turbineMonitorIndex)
  2065.  
  2066. -- Display turbine status, includes "Disconnected" but found turbines
  2067. turbineStatus(turbineIndex, turbineMonitorIndex)
  2068.  
  2069. -- Draw the borders and bars for the current turbine on the current monitor
  2070. displayTurbineBars(turbineIndex, turbineMonitorIndex)
  2071. end -- if not monitor
  2072. else
  2073. printLog("You may want "..(#reactorList + #turbineList + 1).." monitors for your "..#reactorList.." connected reactors and "..#turbineList.." connected turbines.")
  2074. end -- if (#monitorList ~= 1) and (turbineMonitorIndex < #monitorList) then
  2075.  
  2076. turbine = turbineList[turbineIndex]
  2077. if not turbine then
  2078. printLog("turbine["..turbineIndex.."] in main() is NOT a valid Big Turbine.")
  2079. break -- Invalid turbineIndex
  2080. else
  2081. printLog("turbine["..turbineIndex.."] in main() is a valid Big Turbine.")
  2082. end -- if not turbine then
  2083.  
  2084. if turbine.getConnected() then
  2085. printLog("turbine["..turbineIndex.."] is connected.")
  2086.  
  2087. if not _G[turbineNames[turbineIndex]]["TurbineOptions"]["flowOverride"] then
  2088. flowRateControl(turbineIndex)
  2089. end -- if not turbineFlowRateOverride[turbineIndex] then
  2090. else
  2091. printLog("turbine["..turbineIndex.."] is NOT connected.")
  2092. end -- if turbine.getConnected() then
  2093. end -- for reactorIndex = 1, #reactorList do
  2094.  
  2095. sleep(loopTime) -- Sleep
  2096. saveReactorOptions()
  2097. end -- while not finished do
  2098. end -- main()
  2099.  
  2100. local function powerHandler()
  2101. for reactorIndex = 1, #reactorList do
  2102. reactor = reactorList[reactorIndex]
  2103. --Ignore Actively Cooled Reactors
  2104. if reactor.getCoolantType() == nil then
  2105. if getReactorStoredEnergyBufferPercent(reactor) > 90 then
  2106. reactor.setActive(false)
  2107. elseif getReactorStoredEnergyBufferPercent(reactor) < 40 then
  2108. reactor.setActive(true)
  2109. end
  2110. end
  2111. end
  2112.  
  2113. -- _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] = 0
  2114.  
  2115. for turbineIndex = 1, #turbineList do
  2116. turbine = turbineList[turbineIndex]
  2117.  
  2118. flowRateControl(turbineIndex)
  2119.  
  2120. if tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"]) > 2000 then
  2121. --We're going WAY to fast, slow it down
  2122. turbine.setActive(false)
  2123. turbine.setInductorEngaged(true)
  2124. --sleep(0.1)
  2125. --_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"] = turbine.getRotorSpeed()
  2126. elseif tonumber(_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"]) > 1900 then
  2127. --We're almost way too fast, cut the fluidFlowRate first
  2128. turbine.setActive(true)
  2129. turbine.setInductorEngaged(true)
  2130. turbine.setFluidFlowRateMax(25)
  2131. --sleep(0.1)
  2132. --_G[turbineNames[turbineIndex]]["TurbineOptions"]["LastSpeed"] = turbine.getRotorSpeed()
  2133. elseif getTurbineStoredEnergyBufferPercent(turbine) < 10 then
  2134. --We need to kickstart this turbine
  2135. turbine.setInductorEngaged(true)
  2136. turbine.setActive(true)
  2137. turbine.setFluidFlowRateMax(2000)
  2138. elseif _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] > 300 then
  2139. --Put this turbine to sleep
  2140. turbine.setActive(false)
  2141. turbine.setInductorEngaged(false)
  2142. elseif getTurbineStoredEnergyBufferPercent(turbine) > 90 then
  2143. --Too much Power, disengage
  2144. turbine.setInductorEngaged(false)
  2145. turbine.setFluidFlowRateMax(1)
  2146. elseif getTurbineStoredEnergyBufferPercent(turbine) < 40 then
  2147. --Re-engage
  2148. turbine.setInductorEngaged(true)
  2149. end
  2150.  
  2151. --Time how long we've let the coils go idle
  2152. if turbine.getInductorEngaged() then
  2153. _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] = 0
  2154. else
  2155. _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] = _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] + 1
  2156. end
  2157. config.save(turbineNames[turbineIndex]..".options", _G[turbineNames[turbineIndex]])
  2158.  
  2159. -- --Kickstart
  2160. -- if not turbine.getActive() and getTurbineStoredEnergyBufferPercent(turbine) < 10 then
  2161. -- turbine.setInductorEngaged(true)
  2162. -- turbine.setActive(true)
  2163. -- end
  2164.  
  2165. -- --Shut down turbine if we've been idle for a bit now
  2166. -- if _G[turbineNames[turbineIndex]]["TurbineOptions"]["idleTime"] > 300 then
  2167. -- turbine.setActive(false)
  2168. -- turbine.setInductorEngaged(false)
  2169. -- end
  2170.  
  2171. -- --Disengage the coils if we're full
  2172. -- if getTurbineStoredEnergyBufferPercent(turbine) > 90 then
  2173. -- --Disengage
  2174. -- turbine.setInductorEngaged(false)
  2175. -- elseif getTurbineStoredEnergyBufferPercent(turbine) < 40 then
  2176. -- --Re-engage
  2177. -- turbine.setInductorEngaged(true)
  2178. -- end
  2179.  
  2180.  
  2181. --Old method
  2182. -- if getTurbineStoredEnergyBufferPercent(turbine) > 90 then
  2183. -- turbine.setActive(false)
  2184. -- elseif getTurbineStoredEnergyBufferPercent(turbine) < 40 then
  2185. -- turbine.setActive(true)
  2186. -- end
  2187. end
  2188. end
  2189.  
  2190. local function eventHandler()
  2191. while not finished do
  2192. -- http://computercraft.info/wiki/Os.pullEvent
  2193. -- http://www.computercraft.info/forums2/index.php?/topic/1516-ospullevent-what-is-it-and-how-is-it-useful/
  2194. event, arg1, arg2, arg3 = os.pullEvent()
  2195.  
  2196. if event == "monitor_touch" then
  2197. sideClick, xClick, yClick = arg1, math.floor(arg2), math.floor(arg3)
  2198. printLog("Side: "..arg1.." Monitor touch X: "..xClick.." Y: "..yClick)
  2199. elseif event == "char" and not inManualMode then
  2200. local ch = string.lower(arg1)
  2201. if ch == "q" then
  2202. finished = true
  2203. elseif ch == "r" then
  2204. finished = true
  2205. os.reboot()
  2206. end -- if ch == "q" then
  2207. end -- if event == "monitor_touch" then
  2208. end -- while not finished do
  2209. end -- function eventHandler()
  2210.  
  2211.  
  2212. local times = 0
  2213. while not finished and times < 1000 do
  2214. parallel.waitForAny(eventHandler, main, powerHandler)
  2215. sleep(loopTime)
  2216. times = times + 1
  2217. end -- while not finished do
  2218.  
  2219.  
  2220. -- Clear up after an exit
  2221. term.clear()
  2222. term.setCursorPos(1,1)
  2223.  
  2224. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement