Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.94 KB | None | 0 0
  1. os.loadAPI("button")
  2.  
  3. p = peripheral.find("tile_blockcapacitorbank_name")
  4. m = peripheral.find("monitor")
  5. r = peripheral.find("BigReactors-Reactor")
  6. t = peripheral.find("BigReactors-Turbine")
  7.  
  8. local steamReactor = r.isActivelyCooled()
  9. local menuType = "Reactor"
  10.  
  11. local numCapacitors = 3
  12. local turnOnAt = 50
  13. local turnOffAt = 90
  14.  
  15. local energy = 0
  16. local energyStored = 0
  17. local energyMax = 0
  18. local energyStoredPercent = 0
  19. local timerCode
  20. local mode = "Automatic"
  21. local RFProduction = 0
  22. local fuelUse = 0
  23. local coreTemp = 0
  24. local reactorOnline = false
  25. local rodLevel = 0
  26.  
  27. local turbineOnline = false
  28. local turbineRotorSpeed = 0
  29. local turbineRFGen = 0
  30. local turbineFluidRate = 0
  31. local turbineInductor = false
  32.  
  33. local OptFuelRodLevel = 0
  34.  
  35. function autoMenu()
  36. m.setTextScale(1)
  37. button.clearTable()
  38. button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  39. button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  40.  
  41. if steamReactor then
  42. button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  43. button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  44. end
  45. button.screen()
  46. checkMode()
  47. menuMode()
  48. end
  49.  
  50. function manualMenu()
  51. m.setTextScale(1)
  52. button.clearTable()
  53. button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  54. button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  55. button.setTable("Online", online, "", 3, 13, 8, 8)
  56. button.setTable("Offline", offline, "", 15, 25, 8, 8)
  57. button.setTable("0", setRods, 0, 11,14, 10, 10)
  58. button.setTable("10", setRods, 10, 5,8, 12, 12)
  59. button.setTable("20", setRods, 20, 11,14, 12, 12)
  60. button.setTable("30", setRods, 30, 17,20, 12, 12)
  61. button.setTable("40", setRods, 40, 5,8, 14, 14)
  62. button.setTable("50", setRods, 50, 11,14, 14, 14)
  63. button.setTable("60", setRods, 60, 17,20, 14, 14)
  64. button.setTable("70", setRods, 70, 5,8, 16, 16)
  65. button.setTable("80", setRods, 80, 11,14, 16, 16)
  66. button.setTable("90", setRods, 90, 17,20, 16, 16)
  67. button.setTable("+", rodPlus, "", 23, 25, 12, 12)
  68. button.setTable("-", rodMinus, "", 23, 25, 16, 16)
  69.  
  70. if steamReactor then
  71. button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  72. button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  73.  
  74. end
  75. button.screen()
  76. checkMode()
  77. reactorOnOff()
  78. menuMode()
  79. end
  80.  
  81. function turbineAutoMenu()
  82. m.setTextScale(1)
  83. button.clearTable()
  84. button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  85. button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  86. button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  87. button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  88. button.screen()
  89. checkMode()
  90. menuMode()
  91. end
  92.  
  93. function turbineManualMenu()
  94. m.setTextScale(1)
  95. button.clearTable()
  96. button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
  97. button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
  98. button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
  99. button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
  100. button.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8)
  101. button.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8)
  102. button.setTable("Coils On", coilsOn, "", 3, 13, 10, 10)
  103. button.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10)
  104. button.screen()
  105. checkMode()
  106. turbineOnOff()
  107. coilsOnOff()
  108. menuMode()
  109. end
  110.  
  111. function reactorMenu()
  112. menuType = "Reactor"
  113. displayScreen()
  114. end
  115.  
  116. function turbineMenu()
  117. menuType = "Turbine"
  118. displayScreen()
  119. end
  120.  
  121. function online()
  122. r.setActive(true)
  123. --button.flash("Online")
  124. end
  125.  
  126. function offline()
  127. r.setActive(false)
  128. --button.flash("Offline")
  129. end
  130.  
  131. function setTurbineOnline()
  132. t.setActive(true)
  133. --button.flash("Online")
  134. end
  135.  
  136. function setTurbineOffline()
  137. t.setActive(false)
  138. --button.flash("Offline")
  139. end
  140.  
  141. function reactorOnOff()
  142. button.setButton("Online", r.getActive())
  143. button.setButton("Offline", not r.getActive())
  144. end
  145.  
  146. function turbineOnOff()
  147. button.setButton("Online", t.getActive())
  148. button.setButton("Offline", not t.getActive())
  149. end
  150.  
  151. function coilsOnOff()
  152. button.setButton("Coils On", t.getInductorEngaged())
  153. button.setButton("Coils Off", not t.getInductorEngaged())
  154. end
  155.  
  156. function coilsOn()
  157. t.setInductorEngaged(true)
  158. end
  159.  
  160. function coilsOff()
  161. t.setInductorEngaged(false)
  162. end
  163.  
  164. function menuMode()
  165. if steamReactor then
  166. if menuType == "Reactor" then
  167. button.setButton("Reactor", true)
  168. button.setButton("Turbine", false)
  169. else
  170. button.setButton("Reactor", false)
  171. button.setButton("Turbine", true)
  172. end
  173. end
  174. end
  175.  
  176. function setRods(setLevel)
  177. print("Setting Rod Level: "..setLevel)
  178. button.flash(tostring(setLevel))
  179. r.setAllControlRodLevels(setLevel)
  180. fuelRodLevel()
  181. end
  182.  
  183. function rodPlus()
  184. button.flash("+")
  185. r.setAllControlRodLevels(rodLevel+1)
  186. fuelRodLevel()
  187. end
  188.  
  189. function rodMinus()
  190. button.flash("-")
  191. r.setAllControlRodLevels(rodLevel-1)
  192. fuelRodLevel()
  193. end
  194.  
  195. function checkMode()
  196. button.toggleButton(mode)
  197. end
  198.  
  199. function manualMode()
  200. mode = "Manual"
  201. manualMenu()
  202. end
  203.  
  204. function autoMode()
  205. mode = "Automatic"
  206. displayScreen()
  207. end
  208.  
  209. function comma_value(amount)
  210. local formatted = amount
  211. local swap = false
  212. if formatted < 0 then
  213. formatted = formatted*-1
  214. swap = true
  215. end
  216. while true do
  217. formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
  218. if k == 0 then
  219. break
  220. end
  221. end
  222. if swap then
  223. formatted = "-"..formatted
  224. end
  225. return formatted
  226. end
  227.  
  228. function displayEn()
  229. m.clear()
  230. m.setCursorPos(1,1)
  231. --print("Energy Use: "..energy)
  232. m.write("Energy Use: ")
  233. if energy < 0 then
  234. m.setTextColor(colors.red)
  235. else
  236. m.setTextColor(colors.green)
  237. end
  238. m.write(comma_value(math.floor(energy)).. "RF/t")
  239. m.setTextColor(colors.white)
  240. m.setCursorPos(1,2)
  241. m.write("Energy Stored: "..energyStoredPercent.."%")
  242. if menuType == "Reactor" then
  243. m.setCursorPos(1,3)
  244. m.write("Reactor is: ")
  245. if reactorOnline then
  246. m.setTextColor(colors.green)
  247. m.write("Online")
  248. else
  249. m.setTextColor(colors.red)
  250. m.write("Offline")
  251. end
  252. m.setTextColor(colors.white)
  253. m.setCursorPos(22,1)
  254. if steamReactor then
  255. m.write("Steam: ")
  256. m.setTextColor(colors.green)
  257. m.write(comma_value(math.floor(RFProduction)).."MB/t")
  258. else
  259. m.write("RF Gen: ")
  260. m.setTextColor(colors.green)
  261. m.write(comma_value(math.floor(RFProduction)).."RF/t")
  262. end
  263. m.setTextColor(colors.white)
  264. m.setCursorPos(22,2)
  265. m.write("Core Temp: "..math.floor(coreTemp).."c")
  266. m.setCursorPos(22,3)
  267. m.write("Fuel Use: "..fuelUse.."MB/t")
  268. else
  269. m.setCursorPos(1,3)
  270. m.write("Turbine is: ")
  271. if turbineOnline then
  272. m.setTextColor(colors.green)
  273. m.write("Online")
  274. else
  275. m.setTextColor(colors.red)
  276. m.write("Offline")
  277. end
  278. m.setCursorPos(1,4)
  279. m.setTextColor(colors.white)
  280. m.write("Reactor is: ")
  281. if reactorOnline then
  282. m.setTextColor(colors.green)
  283. m.write("Online")
  284. else
  285. m.setTextColor(colors.red)
  286. m.write("Offline")
  287. end
  288. m.setTextColor(colors.white)
  289. m.setCursorPos(22,1)
  290. m.write("RFGen: ")
  291. m.setTextColor(colors.green)
  292. m.write(comma_value(math.floor(turbineRFGen)).."RF/t")
  293. m.setTextColor(colors.white)
  294. m.setCursorPos(22,2)
  295. m.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM")
  296. m.setCursorPos(22,3)
  297. m.write("Steam: "..comma_value(turbineFluidRate).."MB/t")
  298. end
  299.  
  300. end
  301.  
  302. function checkEn()
  303. local tempEnergy = 0
  304. energyStored = p.getEnergyStored()
  305. energyMax = p.getMaxEnergyStored()
  306. energyStoredPercent = math.floor((energyStored/energyMax)*100)
  307. RFProduction = r.getEnergyProducedLastTick()
  308. fuelUse = r.getFuelConsumedLastTick()
  309. fuelUse = math.floor(fuelUse*100)
  310. fuelUse = fuelUse/100
  311. coreTemp = r.getFuelTemperature()
  312. reactorOnline = r.getActive()
  313. tempEnergy = p.getEnergyStored()
  314. sleep(0.1)
  315. energy = (p.getEnergyStored()-tempEnergy)/2
  316. energy = energy*numCapacitors
  317. if steamReactor then
  318. turbineOnline = t.getActive()
  319. turbineRotorSpeed = t.getRotorSpeed()
  320. turbineRFGen = t.getEnergyProducedLastTick()
  321. turbineFluidRate = t.getFluidFlowRate()
  322. end
  323. end
  324.  
  325. function fuelRodLevel()
  326. rodLevel = r.getControlRodLevel(0)
  327. --print(rodLevel)
  328. m.setCursorPos(30,5)
  329. m.write(tostring(rodLevel).."%")
  330. m.setBackgroundColor(colors.white)
  331. m.setCursorPos(28,6)
  332. m.write(" ")
  333. for i = 1,10 do
  334. m.setCursorPos(28,i+6)
  335. m.setBackgroundColor(colors.white)
  336. m.write(" ")
  337. m.setBackgroundColor(colors.yellow)
  338. m.write(" ")
  339. if rodLevel/10 >= i then
  340. m.setBackgroundColor(colors.red)
  341. else
  342. m.setBackgroundColor(colors.yellow)
  343. end
  344. m.write(" ")
  345. m.setBackgroundColor(colors.yellow)
  346. m.write(" ")
  347. m.setBackgroundColor(colors.white)
  348. m.write(" ")
  349. end
  350. m.setCursorPos(28,17)
  351. m.write(" ")
  352. m.setBackgroundColor(colors.black)
  353. end
  354.  
  355. function turbineInductorDisplay()
  356. turbineInductor = t.getInductorEngaged()
  357. m.setCursorPos(30,5)
  358. if turbineInductor then
  359. m.write("On")
  360. else
  361. m.write("Off")
  362. end
  363. m.setBackgroundColor(colors.gray)
  364. m.setCursorPos(28,6)
  365. m.write(" ")
  366. for i = 1,7 do
  367. m.setCursorPos(28,i+6)
  368. m.setBackgroundColor(colors.gray)
  369. m.write(" ")
  370. m.setBackgroundColor(colors.lightGray)
  371. m.write(" ")
  372. if i % 2 == 0 then
  373. m.setBackgroundColor(colors.gray)
  374. end
  375. m.write(" ")
  376. m.setBackgroundColor(colors.gray)
  377. m.write(" ")
  378. if i % 2 ~= 0 then
  379. m.setBackgroundColor(colors.lightGray)
  380. end
  381. m.write(" ")
  382. m.setBackgroundColor(colors.lightGray)
  383. m.write(" ")
  384. m.setBackgroundColor(colors.gray)
  385. m.write(" ")
  386. end
  387. for i = 8,10 do
  388. m.setCursorPos(28,i+6)
  389. m.setBackgroundColor(colors.gray)
  390. m.write(" ")
  391. m.setBackgroundColor(colors.lightGray)
  392. m.write(" ")
  393. if turbineInductor then
  394. m.setBackgroundColor(colors.red)
  395. else
  396. m.setBackgroundColor(colors.blue)
  397. end
  398. m.write(" ")
  399. m.setBackgroundColor(colors.gray)
  400. m.write(" ")
  401. if turbineInductor then
  402. m.setBackgroundColor(colors.red)
  403. else
  404. m.setBackgroundColor(colors.blue)
  405. end
  406. m.write(" ")
  407. m.setBackgroundColor(colors.lightGray)
  408. m.write(" ")
  409. m.setBackgroundColor(colors.gray)
  410. m.write(" ")
  411. end
  412. m.setCursorPos(28,17)
  413. m.write(" ")
  414. m.setBackgroundColor(colors.black)
  415. end
  416. function getClick()
  417. local event, side, x, y = os.pullEvent("monitor_touch")
  418. button.checkxy(x,y)
  419. end
  420.  
  421. function findOptFuelRods()
  422. m.clear()
  423. r.setActive(false)
  424. checkEn()
  425. displayEn()
  426. fuelRodLevel()
  427. while r.getFuelTemperature() > 99 do
  428. for i= 1,3 do
  429. checkEn()
  430. displayEn()
  431. fuelRodLevel()
  432. m.setCursorPos(3,6)
  433. m.write("Finding Optimal Rod Level")
  434. m.setCursorPos(3,7)
  435. m.write("Core Temp: "..r.getFuelTemperature())
  436. m.setCursorPos(3,8)
  437. m.write("Waiting for 99c")
  438. sleep(1)
  439. end
  440. end
  441. while r.getHotFluidAmount() > 10000 do
  442. for i = 1,3 do
  443. checkEn()
  444. displayEn()
  445. fuelRodLevel()
  446. m.setCursorPos(3,6)
  447. m.write("Finding Optimal Rod Level, please wait....")
  448. m.setCursorPos(3,7)
  449. m.write("Fluid Amount: "..comma_value(r.getHotFluidAmount()).."mb")
  450. m.setCursorPos(3,8)
  451. m.write("Waiting for 10,000mb")
  452. sleep(1)
  453. end
  454. end
  455. r.setAllControlRodLevels(99)
  456. r.setActive(true)
  457.  
  458. while r.getFuelTemperature() < 100 do
  459. for i = 1,5 do
  460. checkEn()
  461. displayEn()
  462. fuelRodLevel()
  463. m.setCursorPos(3,6)
  464. m.write("Set all rod levels to 99")
  465. m.setCursorPos(3,7)
  466. m.write("Waiting 5 seconds...")
  467. sleep(1)
  468. end
  469. end
  470. for i = 1,5 do
  471. checkEn()
  472. displayEn()
  473. fuelRodLevel()
  474. m.setCursorPos(3,6)
  475. m.write("Set all rod levels to 99")
  476. m.setCursorPos(3,7)
  477. m.write("Waiting 5 seconds...")
  478. sleep(1)
  479. end
  480. local tempMB = r.getEnergyProducedLastTick()
  481. print(tempMB.."MB/t of steam")
  482. local tempRodLevels = math.floor(730/tempMB)
  483. print("730/"..tempMB.." = "..tempRodLevels)
  484. tempRodLevels = 100-tempRodLevels+5
  485. print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels))
  486. r.setAllControlRodLevels(math.floor(tempRodLevels))
  487. print("Waiting 10 seconds to confirm...")
  488. for i = 1,10 do
  489. checkEn()
  490. displayEn()
  491. fuelRodLevel()
  492. m.setCursorPos(3,6)
  493. m.write("Estimated Level: "..tempRodLevels)
  494. m.setCursorPos(3,7)
  495. m.write("Waiting 10 seconds...")
  496. sleep(1)
  497. end
  498. tempMB = r.getEnergyProducedLastTick()
  499. while tempMB > 730 do
  500. tempRodLevels = tempRodLevels+1
  501. r.setAllControlRodLevels(math.floor(tempRodLevels))
  502. print("Setting Rod Levels to: "..tempRodLevels)
  503. for i = 1,5 do
  504. checkEn()
  505. displayEn()
  506. fuelRodLevel()
  507. m.setCursorPos(3,6)
  508. m.write("Getting below 730mb/t")
  509. m.setCursorPos(3,7)
  510. m.write("Currently at: "..tempMB)
  511. sleep(1)
  512. end
  513. tempMB = r.getEnergyProducedLastTick()
  514. end
  515. while tempMB < 730 do
  516. tempRodLevels = tempRodLevels -1
  517. r.setAllControlRodLevels(math.floor(tempRodLevels))
  518. print("Setting Rod Levels to: "..tempRodLevels)
  519. for i = 1,5 do
  520. checkEn()
  521. displayEn()
  522. fuelRodLevel()
  523. m.setCursorPos(3,6)
  524. m.write("Getting Above 730mb/t")
  525. m.setCursorPos(3,7)
  526. m.write("Currently at: "..tempMB)
  527. sleep(1)
  528. end
  529. tempMB = r.getEnergyProducedLastTick()
  530. end
  531. OptFuelRodLevel = tempRodLevels
  532. end
  533.  
  534.  
  535. function autoReactor()
  536. if not steamReactor then
  537. r.setAllControlRodLevels(0)
  538. if energyStoredPercent < turnOnAt then
  539. if not reactorOnline then
  540. online()
  541. end
  542. end
  543. if energyStoredPercent > turnOffAt then
  544. if reactorOnline then
  545. offline()
  546. end
  547. end
  548. else
  549. r.setAllControlRodLevels(OptFuelRodLevel)
  550. if energyStoredPercent < turnOnAt then
  551. --online()
  552. setTurbineOnline()
  553. coilsOn()
  554. end
  555. if energyStoredPercent > turnOffAt then
  556. --if turbineRotorSpeed > 1800 then
  557. -- offline()
  558. --else
  559. -- online()
  560. --end
  561. setTurbineOnline()
  562. coilsOff()
  563. end
  564. if turbineRotorSpeed > 1800 then
  565. offline()
  566. else
  567. online()
  568. end
  569. end
  570. end
  571.  
  572. function displayScreen()
  573. -- repeat
  574. checkEn()
  575. displayEn()
  576. if menuType == "Reactor" then
  577. fuelRodLevel()
  578. if mode == "Automatic" then
  579. autoMenu()
  580. autoReactor()
  581. else
  582. manualMenu()
  583. end
  584.  
  585. else
  586. turbineInductorDisplay()
  587. if mode == "Automatic" then
  588. turbineAutoMenu()
  589. autoReactor()
  590. else
  591. turbineManualMenu()
  592. end
  593.  
  594. end
  595.  
  596. timerCode = os.startTimer(1)
  597. local event, side, x, y
  598. repeat
  599. event, side, x, y = os.pullEvent()
  600. print(event)
  601. if event == "timer" then
  602. print(timerCode..":"..side)
  603. if timerCode ~= side then
  604. print("Wrong Code")
  605. else
  606. print("Right Code")
  607. end
  608. end
  609. until event~= "timer" or timerCode == side
  610. if event == "monitor_touch" then
  611. print(x..":"..y)
  612. button.checkxy(x,y)
  613. end
  614. -- until event ~= "timer"
  615. end
  616.  
  617. if steamReactor then
  618. findOptFuelRods()
  619. end
  620.  
  621. while true do
  622. displayScreen()
  623. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement