Advertisement
FakoTheGreat

Nutty Reactor v2.0

May 30th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. -- Cosmetic settings for the monitor
  2. local textScale = 1.5 --Size of text
  3. local tempDecimals = 3 --Decimal places to show for temperature
  4. local fuelDecimals = 3 --Decimal places to show for fuel usage
  5.  
  6. -- Settings for dealing with an overheating reactor
  7. local maxTemperature = 1500
  8. local tempWarningRatio = 0.75 --Ratio to change color for temp
  9. local failsafeMaxDraw = 20 --Max Percentage Draw
  10. local failsafeCooldown = 150 --Timer in Seconds
  11. local safeTemp = 1 --Temperature to resume normal operation at
  12.  
  13. -- Increases cooldown timer if reactor stays above max temp, and
  14. -- goes to 0 draw if timer reaches double failsafeCooldown
  15. local handleBadSettings = true
  16.  
  17. -- Use sides or modem names to connect the devices
  18. local monitorName = "top"
  19. local reactorName = "BigReactors-Reactor_0"
  20.  
  21. -- How long to wait before trying to connect if parts aren't ready
  22. -- Recommended values are 1 if next to computer, 5 if using modem.
  23. local monitorWait = 1
  24. local reactorWait = 1
  25.  
  26. --The first half of the warning messages
  27. local problemNotice = "OH NO!"
  28. local workingNotice = "AW YEAH!"
  29. local failsafeNotice = "TOO MUCH!"
  30.  
  31. --The string of characters (if any) that separates the two halves
  32. --of the warning messages
  33. local noticeSeparator = " - "
  34.  
  35. --The second half of the warning messages
  36. local offlineWarning = "Winging It"
  37. local emptyWarning = "Zero Stamina"
  38. local noDrawWarning = "Heavy Petting"
  39. local lightDrawWarning = "Light Penetration"
  40. local mediumDrawWarning = "Decent Penetration"
  41. local highDrawWarning = "BALLS DEEP!"
  42. local overheatWarning = "Need A Rest!"
  43.  
  44. --Used Internally - changing will do nothing
  45. local rodLevels = 0
  46. local currentWarning = ""
  47. local cooldownTimer = 0
  48. local warningColor = colors.white
  49. local emptyflag = 0
  50. local offlineflag = 0
  51. local flashflag = 0
  52. local overheated = false
  53. local monitor = nil
  54. local reactor = nil
  55.  
  56. while reactor == nil do
  57. reactor=peripheral.wrap(reactorName)
  58. if reactor == nil then
  59. print("Waiting for reactor peripheral")
  60. os.sleep(reactorWait)
  61. end
  62. end
  63.  
  64. print("Found reactor. Looking for monitor.")
  65.  
  66. while monitor == nil do
  67. monitor = peripheral.wrap(monitorName)
  68. if monitor == nil then
  69. print("Waiting for monitor to connect")
  70. os.sleep(monitorWait)
  71. end
  72. end
  73.  
  74. print("Monitor found.")
  75.  
  76. while not reactor.getConnected() do
  77. print("Waiting for reactor to connect.")
  78. os.sleep(reactorWait)
  79. end
  80.  
  81. print("Program Initialized - View Monitor.")
  82.  
  83. monitor.setTextScale(textScale)
  84. monitor.setBackgroundColor(colors.black)
  85.  
  86. function round(num, idp)
  87. local mult = 10^(idp or 0)
  88. return math.floor(num * mult + 0.5) / mult
  89. end
  90.  
  91. while true do
  92. monitor.clear()
  93. monitor.setCursorPos(1,1)
  94. monitor.setTextColor(colors.orange)
  95. monitor.write('Program has been initialized')
  96. monitor.setCursorPos(1,2)
  97. monitor.setTextColor(colors.white)
  98. monitor.write('Fuel Level - ')
  99. monitor.setTextColor(colors.yellow)
  100. monitor.write(math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5)..'% Fuel')
  101. monitor.setCursorPos(1,3)
  102. monitor.setTextColor(colors.white)
  103. monitor.write('Waste Level - ')
  104. monitor.setTextColor(colors.lightBlue)
  105. monitor.write(math.floor(((reactor.getWasteAmount()/reactor.getFuelAmountMax())*100)+0.5)..'% Waste')
  106. monitor.setCursorPos(1,5)
  107. monitor.setTextColor(colors.white)
  108. monitor.write('Control Rod Levels - ')
  109. monitor.setTextColor(colors.green)
  110. monitor.setCursorPos(1,6)
  111. monitor.write('Rod 1: '..(100-(reactor.getControlRodLevel(0)))..'% Thrust')
  112. monitor.setCursorPos(25,6)
  113. monitor.write('Rod 2: '..(100-(reactor.getControlRodLevel(1)))..'% Thrust')
  114. monitor.setCursorPos(1,7)
  115. monitor.write('Rod 3: '..(100-(reactor.getControlRodLevel(2)))..'% Thrust')
  116. monitor.setCursorPos(25,7)
  117. monitor.write('Rod 4: '..(100-(reactor.getControlRodLevel(3)))..'% Thrust')
  118. monitor.setCursorPos(1,8)
  119. monitor.write('Rod 5: '..(100-(reactor.getControlRodLevel(4)))..'% Thrust')
  120. monitor.setCursorPos(25,8)
  121. monitor.write('Rod 6: '..(100-(reactor.getControlRodLevel(5)))..'% Thrust')
  122. monitor.setCursorPos(1,9)
  123. monitor.write('Rod 7: '..(100-(reactor.getControlRodLevel(6)))..'% Thrust')
  124. monitor.setCursorPos(25,9)
  125. monitor.write('Rod 8: '..(100-(reactor.getControlRodLevel(7)))..'% Thrust')
  126. monitor.setCursorPos(1,10)
  127. monitor.write('Rod 9: '..(100-(reactor.getControlRodLevel(8)))..'% Thrust')
  128. monitor.setCursorPos(25,10)
  129. monitor.write('Rod 10: '..(100-(reactor.getControlRodLevel(9)))..'% Thrust')
  130. monitor.setCursorPos(1,11)
  131. monitor.write('Rod 11: '..(100-(reactor.getControlRodLevel(10)))..'% Thrust')
  132. monitor.setCursorPos(25,11)
  133. monitor.write('Rod 12: '..(100-(reactor.getControlRodLevel(11)))..'% Thrust')
  134. monitor.setCursorPos(1,12)
  135. monitor.write('Rod 13: '..(100-(reactor.getControlRodLevel(12)))..'% Thrust')
  136. monitor.setCursorPos(25,12)
  137. monitor.write('Rod 14: '..(100-(reactor.getControlRodLevel(13)))..'% Thrust')
  138. monitor.setCursorPos(1,13)
  139. monitor.write('Rod 15: '..(100-(reactor.getControlRodLevel(14)))..'% Thrust')
  140. monitor.setCursorPos(25,13)
  141. monitor.write('+10 more...')
  142. monitor.setCursorPos(1,15)
  143. monitor.setTextColor(colors.white)
  144. monitor.write('Temperature')
  145. monitor.setCursorPos(25,15)
  146. monitor.write("Fuel Usage")
  147. monitor.setCursorPos(1,16)
  148. if reactor.getFuelTemperature()>=(maxTemperature*tempWarningRatio) then
  149. monitor.setTextColor(colors.purple)
  150. elseif reactor.getFuelTemperature()>=maxTemperature then
  151. monitor.setTextColor(colors.red)
  152. else
  153. monitor.setTextColor(colors.green)
  154. end
  155. monitor.write(round(reactor.getFuelTemperature(), tempDecimals)..'C')
  156. monitor.setCursorPos(25,16)
  157. monitor.write(round(reactor.getFuelConsumedLastTick(), fuelDecimals)..'mB')
  158. monitor.setCursorPos(1,18)
  159. monitor.setTextColor(colors.white)
  160. monitor.write('Flux')
  161. monitor.setCursorPos(1,19)
  162. monitor.setTextColor(colors.green)
  163. monitor.write(reactor.getEnergyStored()..' RF Stored ')
  164.  
  165. if reactor.getEnergyProducedLastTick()>=500 and reactor.getEnergyProducedLastTick()<2000 then
  166. monitor.setTextColor(colors.orange)
  167. end
  168.  
  169. if reactor.getEnergyProducedLastTick()>=2000 then
  170. monitor.setTextColor(colors.red)
  171. end
  172.  
  173. monitor.write((math.floor(reactor.getEnergyProducedLastTick()+0.5))..'RF/t')
  174. monitor.setCursorPos(1,21)
  175. monitor.setTextColor(colors.orange)
  176. monitor.write('Warnings:')
  177.  
  178. if flashflag==0 then
  179. flashflag=1
  180. currentWarning = ""
  181. if offlineflag==1 then
  182. warningColor = colors.lightGray
  183. currentWarning = problemNotice..noticeSeparator..offlineWarning
  184. elseif emptyflag==1 then
  185. warningColor = colors.pink
  186. currentWarning = problemNotice..noticeSeparator..emptyWarning
  187. elseif cooldownTimer > 0 then
  188. currentWarning = failsafeNotice..noticeSeparator
  189. if overheated then
  190. warningColor = colors.green
  191. currentWarning = currentWarning..overheatWarning..' ('..cooldownTimer..')'
  192. end
  193. else
  194. currentWarning = workingNotice..noticeSeparator
  195. end
  196.  
  197. if emptyflag==0 and offlineflag==0 and not overheated then
  198. if reactor.getControlRodLevel(0)>99 then
  199. warningColor = colors.lightBlue
  200. currentWarning = currentWarning..noDrawWarning
  201. elseif reactor.getControlRodLevel(0)>75 then
  202. warningColor = colors.yellow
  203. currentWarning = currentWarning..lightDrawWarning
  204. elseif reactor.getControlRodLevel(0)>50 then
  205. warningColor = colors.orange
  206. currentWarning = currentWarning..mediumDrawWarning
  207. else
  208. warningColor = colors.red
  209. currentWarning = currentWarning..highDrawWarning
  210. end
  211. if cooldownTimer > 0 then
  212. warningColor = colors.green
  213. currentWarning = currentWarning..' ('..cooldownTimer..')'
  214. end
  215. end
  216.  
  217. monitor.setCursorPos(1,22)
  218. monitor.setTextColor(warningColor)
  219. monitor.write(currentWarning)
  220. else
  221. flashflag=0
  222. monitor.setCursorPos(1,22)
  223. monitor.clearLine()
  224. end
  225.  
  226. if emptyflag==0 and offlineflag==0 and not overheated then
  227. if reactor.getFuelTemperature() > maxTemperature and cooldownTimer == 0 then
  228. cooldownTimer = failsafeCooldown
  229. elseif reactor.getFuelTemperature() > maxTemperature and handleBadSettings then
  230. cooldownTimer = cooldownTimer + 1
  231. if cooldownTimer == failsafeCooldown * 2 then
  232. overheated = true
  233. end
  234. end
  235. if reactor.getEnergyStored()>= 1 then
  236. rodLevels = math.floor(reactor.getEnergyStored()/100000)
  237. else
  238. rodLevels = 0 --Full Draw
  239. end
  240. if cooldownTimer > 0 and rodLevels < (100 - failsafeMaxDraw) then
  241. rodLevels = (100 - failsafeMaxDraw)
  242. end
  243. reactor.setAllControlRodLevels(rodLevels)
  244. end
  245.  
  246. if overheated then
  247. reactor.setAllControlRodLevels(100)
  248. end
  249.  
  250. if reactor.getFuelAmount()<=100 and offlineflag==0 then
  251. reactor.setAllControlRodLevels(100)
  252. reactor.setActive(false)
  253. emptyflag=1
  254. else
  255. emptyflag=0
  256. end
  257.  
  258. if rs.getInput('top')==false and emptyflag==0 then
  259. reactor.setActive(true)
  260. offlineflag=0
  261. end
  262.  
  263. if rs.getInput('top')==true and emptyflag==0 then
  264. reactor.setActive(false)
  265. reactor.setAllControlRodLevels(100)
  266. offlineflag=1
  267. end
  268.  
  269. if cooldownTimer > 0 and reactor.getFuelTemperature() <= maxTemperature then
  270. cooldownTimer = cooldownTimer - 1
  271. if overheated and (cooldownTimer == 0 or reactor.getFuelTemperature() == 0) then
  272. overheated = false
  273. cooldownTimer = 0
  274. end
  275. end
  276.  
  277. sleep(1)
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement