Advertisement
Guest User

reactorControl

a guest
Aug 22nd, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- RD CC Reactor Control
  2. -- v 0.0.2
  3.  
  4. -- Dependancies:
  5. -- rdCore
  6.  
  7. -- Thank you for choosing this Big Reactors reactor
  8. -- control program for automating it with CC.
  9.  
  10. -- User Settings
  11.  
  12. -- Stored Power Threshold
  13. -- Set a custom stored power threshold to lower the
  14. -- reactor cores to in order to save power.
  15.  
  16. local reacStTh = 100 -- 1/100 Default: 100
  17.  
  18. -- Reactor Shutdown Threshold
  19. -- Should the reactor shut down after a particular
  20. -- point to conserve fuel. Must be set equal or
  21. -- higher then Stored Power Threshold.
  22.  
  23. local reacOf = false -- true/false Default: false
  24.  
  25. local reacOfTh = 100 -- 5/100 Default: 100
  26.  
  27. -- Reactor Name
  28. -- If a monitor is found, a name may be displayed
  29. -- for the reactor.
  30.  
  31. local reacName = ""
  32.  
  33. -- Debug Feedback
  34. -- For double-checking numbers through the monitor.
  35. -- Should not be needed unless issues or discrepancies
  36. -- arrise.
  37.  
  38. local debugF = true -- true/false Default: false
  39.  
  40. --====== DO NOT EDIT BELOW THIS POINT ======--
  41.  
  42.  
  43.  
  44. -- Reactor Variables
  45.  
  46. local function reUpdate()
  47.  
  48. reEn = tonumber(reactor.getEnergyStored())
  49. dBR("Reactor Stored Energy: "..reEn.." rf")
  50. reOn = reactor.getActive()
  51. dBR("Reactor State: "..reOn)
  52. reFuel = tonumber(reactor.getFuelAmount())
  53. dBR("Reactor Fuel: "..reFuel.." mB")
  54. reEnPr = tonumber(reactor.getEnergyProducedLastTick())
  55. dBR("Reactor Energy Produced: "..reEnPr.." rf/t")
  56. reWa = tonumber(reactor.getWasteAmount())
  57. dBR("Reactor Waste: "..eWa.." mB")
  58. reFuWa = tonumber(reactor.getFuelAmountMax())
  59. dBR("Reactor Fuel/Waste Contained: "..reFuWa.." mB")
  60. reEnPerc = math.floor((reEn/10000000)*100)
  61. dBR("Reactor Energy Filled Percentage: "..reEnPerc.."%")
  62. reFTemp = tonumber(reactor.getFuelTemp)
  63. dBR("Reactor Fuel Temp: "..reFTemp.." ° C")
  64. reCTemp = tonumber(reactor.getCasingTemp)
  65. dBR("Reactor Casing Temp: "..reFTemp.." ° C")
  66. reTemp = ((reCTemp+reFTemp)/2)
  67. dBR("Reactor Avg Temp: "..reTemp.." ° C")
  68.  
  69.  
  70. end
  71.  
  72. -- Debug readout function
  73.  
  74. local function dBR(var)
  75. if debugF == true then
  76. print(var)
  77. end
  78. end
  79.  
  80. -- Control Rod Controls
  81.  
  82. local function reCtrlRod()
  83. reUpdate()
  84. print(reEnPerc.."%.")
  85. if reEnPerc <= reacStTh then
  86. dBR("Changing Ctrl Rod Levels to "..reEnPerc.."%.")
  87. reactor.setAllControlRodLevels(reEnPerc)
  88. end
  89. end
  90.  
  91. -- Power Threshold
  92.  
  93. local function rePowThr()
  94. reUpdate()
  95. if reEnPerc > reacOfTh then
  96. reactor.setActive = false
  97. elseif reEnPerc < (reacOfTh-5) then
  98. reactor.setActive = true
  99. end
  100. end
  101.  
  102. -- Adv Monitor Functionality
  103.  
  104. -- monitor variables
  105.  
  106. maxX, maxY = term.getSize()
  107.  
  108. -- monitor functions
  109.  
  110. local function updateScreen()
  111. if monTest ~= nil then
  112. reUpdate()
  113. mon.clear()
  114. reacTitle()
  115. reacEnergy()
  116. reacReadout()
  117. end
  118. end
  119.  
  120. local function reacTitle()
  121. local progTitle = "RD Reactor Control ver "..progVer
  122. local reacTitle = reacName
  123. mon.setCursorPos(maxX/2-string.len(progTitle)/2,2)
  124. mon.setTextColor(colors.purple)
  125. mon.write(progTitle)
  126. if reacName ~= nil then
  127. mon.setCursorPos(maxX/2-string.len(reacTitle)/2,3)
  128. mon.setTextColor(colors.purple)
  129. mon.write(reacTitle)
  130. end
  131. end
  132.  
  133. local function put(text,x,y,color)
  134. term.setCursorPos(x,y)
  135. term.setTextColor(color or 1)
  136. term.write(text)
  137. end
  138.  
  139. local function reacEnergy()
  140. local enTitle = "Reactor RF Stored"
  141. local enAmt = reEn.." RF"
  142. local enPerc = reEnPerc.." %"
  143.  
  144. put(enTitle,maxX/2-string.len(enTitle), 5, colors.blue)
  145. put(enTitle,maxX/2-string.len(enAmt.." / "..enPerc), 7, colors.blue)
  146.  
  147. paintutils.drawLine(8,9,28,9,colors.white)
  148. paintutils.drawLine(8,9,(20*(reEnPerc/100))+8,9,colors.red)
  149. mon.setBackgroundColor(colors.black)
  150.  
  151. end
  152.  
  153. local function reacReadout()
  154.  
  155. end
  156.  
  157.  
  158. -- Find Reactor & Monitor Peripherals
  159.  
  160. local function getPeripherals()
  161.  
  162. reactor = peripheral.wrap(pSearch("BigReactors-Reactor"))
  163. monTest = peripheral.find("monitor")
  164.  
  165. if reactor.getConnected() == true then
  166. dBR("Reactor Connected")
  167. else
  168. print("Reactor Not Found")
  169. term.setTextColor(colors.red)
  170. print("Please relocate this computer next to the reactor's computer port!")
  171. term.setTextColor(colors.white)
  172. --break
  173. end
  174. if monTest ~= nil then
  175. mon = peripheral.wrap(pSearch("monitor"))
  176. dBR("Monitor Found")
  177. else
  178. dBR("Monitor Not Found")
  179. end
  180.  
  181. end
  182.  
  183. -- Main Program
  184.  
  185. local rdCTest = fs.exists("rdCore")
  186. local rdCPB = "vKDJH93Y"
  187. progVer = 0.0.2
  188.  
  189. if rdCTest == false then
  190. print("rdCore Api Not Found. Installing embedded version.")
  191. shell.run("pastebin", "get", "rdCPB", "rdCore")
  192. shell.run("rdCore")
  193. rdCTest = fs.exists("rdCore")
  194. if rdCTest == true then
  195. add2Start("rdReactorControl")
  196. print("rdCore Api ver "..rdCV.." Installed Successfully")
  197. else
  198. print("rdCore Api Unavailable. RD Reactor Control Unable to Start")
  199. --break
  200. end
  201. else
  202. print("rdCore Api Found")
  203. end
  204.  
  205. getPeripherals()
  206.  
  207. local temp = ("RD Reactor Control ver: "..progVer.." Initialized Successfully")
  208. local runs = 0
  209. print(temp)
  210.  
  211. while true do
  212. if runs == 0 then
  213. if req = 0 then
  214. break
  215. else
  216. print(temp)
  217. end
  218.  
  219. elseif runs == 5 then
  220.  
  221. updateScreen()
  222. runs == 1
  223. else
  224. runs ++
  225. end
  226.  
  227. reCtrlRod()
  228. if reacOf == true then
  229. rePowThr()
  230. end
  231.  
  232. sleep(2)
  233. end
  234. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement