Advertisement
FakoTheGreat

Sov Adjusted Reactor

Jun 5th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.46 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 = "back"
  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 = "Warning!"
  28. local workingNotice = "Operational"
  29. local failsafeNotice = "Error!"
  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 = "Offline"
  37. local emptyWarning = "No Fuel"
  38. local noDrawWarning = "No Draw"
  39. local lightDrawWarning = "Low Power Mode"
  40. local mediumDrawWarning = "Medium Power Mode"
  41. local highDrawWarning = "High Power Mode"
  42. local overheatWarning = "Overheated - Cooling Down"
  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)))..'% Depth')
  112. monitor.setCursorPos(25,6)
  113. monitor.write('Rod  2:  '..(100-(reactor.getControlRodLevel(1)))..'% Depth')
  114. monitor.setCursorPos(1,7)
  115. monitor.write('Rod  3:  '..(100-(reactor.getControlRodLevel(2)))..'% Depth')
  116. monitor.setCursorPos(25,7)
  117. monitor.write('Rod  4:  '..(100-(reactor.getControlRodLevel(3)))..'% Depth')
  118. monitor.setCursorPos(1,8)
  119. monitor.write('Rod  5:  '..(100-(reactor.getControlRodLevel(4)))..'% Depth')
  120. monitor.setCursorPos(25,8)
  121. monitor.write('Rod  6:  '..(100-(reactor.getControlRodLevel(5)))..'% Depth')
  122. monitor.setCursorPos(1,9)
  123. monitor.write('Rod  7:  '..(100-(reactor.getControlRodLevel(6)))..'% Depth')
  124. monitor.setCursorPos(25,9)
  125. monitor.write('Rod  8:  '..(100-(reactor.getControlRodLevel(7)))..'% Depth')
  126. monitor.setCursorPos(1,10)
  127. monitor.write('Rod  9:  '..(100-(reactor.getControlRodLevel(8)))..'% Depth')
  128. monitor.setCursorPos(1,15)
  129. monitor.setTextColor(colors.white)
  130. monitor.write('Temperature')
  131. monitor.setCursorPos(25,15)
  132. monitor.write("Fuel Usage")
  133. monitor.setCursorPos(1,16)
  134. if reactor.getFuelTemperature()>=(maxTemperature*tempWarningRatio) then
  135.     monitor.setTextColor(colors.purple)
  136. elseif reactor.getFuelTemperature()>=maxTemperature then
  137.     monitor.setTextColor(colors.red)
  138. else
  139.     monitor.setTextColor(colors.green)
  140. end
  141. monitor.write(round(reactor.getFuelTemperature(), tempDecimals)..'C')
  142. monitor.setCursorPos(25,16)
  143. monitor.write(round(reactor.getFuelConsumedLastTick(), fuelDecimals)..'mB')
  144. monitor.setCursorPos(1,18)
  145. monitor.setTextColor(colors.white)
  146. monitor.write('Flux')
  147. monitor.setCursorPos(1,19)
  148. monitor.setTextColor(colors.green)
  149. monitor.write(reactor.getEnergyStored()..' RF Stored')
  150.  
  151. if reactor.getEnergyProducedLastTick()>=500 and reactor.getEnergyProducedLastTick()<2000 then
  152.     monitor.setTextColor(colors.orange)
  153. end
  154.  
  155. if reactor.getEnergyProducedLastTick()>=2000 then
  156.     monitor.setTextColor(colors.red)
  157. end
  158.  
  159. monitor.setCursorPos(25,19)
  160. monitor.write((math.floor(reactor.getEnergyProducedLastTick()+0.5))..'RF/t')
  161. monitor.setCursorPos(1,21)
  162. monitor.setTextColor(colors.orange)
  163. monitor.write('Warnings:')
  164.  
  165. if flashflag==0 then
  166.   flashflag=1
  167.   currentWarning = ""
  168.   if offlineflag==1 then
  169.     warningColor = colors.lightGray
  170.     currentWarning = problemNotice..noticeSeparator..offlineWarning
  171.   elseif emptyflag==1 then
  172.     warningColor = colors.pink
  173.     currentWarning = problemNotice..noticeSeparator..emptyWarning
  174.   elseif cooldownTimer > 0 then
  175.     currentWarning = failsafeNotice..noticeSeparator
  176.     if overheated then
  177.       warningColor = colors.green
  178.       currentWarning = currentWarning..overheatWarning..' ('..cooldownTimer..')'
  179.     end
  180.   else
  181.     currentWarning = workingNotice..noticeSeparator
  182.   end
  183.  
  184.   if emptyflag==0 and offlineflag==0 and not overheated then
  185.     if reactor.getControlRodLevel(0)>99 then
  186.       warningColor = colors.lightBlue
  187.       currentWarning = currentWarning..noDrawWarning
  188.     elseif reactor.getControlRodLevel(0)>75 then
  189.       warningColor = colors.yellow
  190.       currentWarning = currentWarning..lightDrawWarning
  191.     elseif reactor.getControlRodLevel(0)>50 then
  192.       warningColor = colors.orange
  193.       currentWarning = currentWarning..mediumDrawWarning
  194.     else
  195.       warningColor = colors.red
  196.       currentWarning = currentWarning..highDrawWarning
  197.     end
  198.     if cooldownTimer > 0 then
  199.       warningColor = colors.green
  200.       currentWarning = currentWarning..' ('..cooldownTimer..')'
  201.     end
  202.   end
  203.  
  204.   monitor.setCursorPos(1,22)
  205.   monitor.setTextColor(warningColor)
  206.   monitor.write(currentWarning)
  207. else
  208.   flashflag=0
  209.   monitor.setCursorPos(1,22)
  210.   monitor.clearLine()
  211. end
  212.  
  213. if emptyflag==0 and offlineflag==0 and not overheated then
  214.   if reactor.getFuelTemperature() > maxTemperature and cooldownTimer == 0 then
  215.     cooldownTimer = failsafeCooldown
  216.   elseif reactor.getFuelTemperature() > maxTemperature and handleBadSettings then
  217.     cooldownTimer = cooldownTimer + 1
  218.     if cooldownTimer == failsafeCooldown * 2 then
  219.       overheated = true
  220.     end
  221.   end
  222.   if reactor.getEnergyStored()>= 1 then
  223.     rodLevels = math.floor(reactor.getEnergyStored()/100000)
  224.   else
  225.     rodLevels = 0 --Full Draw
  226.   end
  227.   if cooldownTimer > 0 and rodLevels < (100 - failsafeMaxDraw) then
  228.     rodLevels = (100 - failsafeMaxDraw)
  229.   end
  230.   reactor.setAllControlRodLevels(rodLevels)
  231. end
  232.  
  233. if overheated then
  234.   reactor.setAllControlRodLevels(100)
  235. end
  236.  
  237. if reactor.getFuelAmount()<=100 and offlineflag==0 then
  238.     reactor.setAllControlRodLevels(100)
  239.     reactor.setActive(false)
  240.     emptyflag=1
  241. else
  242.     emptyflag=0
  243. end
  244.  
  245. if rs.getInput('top')==false and emptyflag==0 then
  246.     reactor.setActive(true)
  247.     offlineflag=0
  248. end
  249.  
  250. if rs.getInput('top')==true and emptyflag==0 then
  251.     reactor.setActive(false)
  252.     reactor.setAllControlRodLevels(100)
  253.     offlineflag=1
  254. end
  255.  
  256. if cooldownTimer > 0 and reactor.getFuelTemperature() <= maxTemperature then
  257.   cooldownTimer = cooldownTimer - 1
  258.   if overheated and (cooldownTimer == 0 or reactor.getFuelTemperature() == 0) then
  259.       overheated = false
  260.       cooldownTimer = 0
  261.   end
  262. end
  263.  
  264. sleep(1)
  265. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement