Advertisement
Guest User

Test

a guest
Apr 1st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. local monitors = {peripheral.find("monitor")}
  2. local mon = monitors[1]
  3. local reactors = {peripheral.find("BigReactors-Reactor")}
  4.  
  5. local refresh = true
  6. mon.setBackgroundColor(colors.black)
  7. mon.setTextColor(colors.white)
  8. mon.setTextScale(1)
  9. mon.clear()
  10.  
  11. local currentRfTotal = 1
  12. local currentRfTick = 1
  13. local currentFuelConsumedLastTick = 0.00001
  14.  
  15. local rfPerTickMax = 1
  16. local minPowerRod = 60
  17. local maxPowerRod = 80
  18. local currentRodLevel = 1
  19.  
  20. function synDraw()
  21. term.redirect(mon)
  22. paintutils.drawBox(2, 2, 60, 18, colors.lightGray)
  23. paintutils.drawLine(3, 10, 59, 10, colors.lightGray)
  24. paintutils.drawLine(30, 3, 30, 17, colors.lightGray)
  25.  
  26. paintutils.drawPixel(1, 1, colors.black)
  27.  
  28. mon.setCursorPos(10, 2)
  29. mon.write(" Reactor 1: ")
  30. mon.setCursorPos(10, 10)
  31. mon.write(" Reactor 2: ")
  32. mon.setCursorPos(39, 2)
  33. mon.write(" Reactor 3: ")
  34. mon.setCursorPos(38, 10)
  35. mon.write(" All Reactors: ")
  36.  
  37. refreshSingleReactor()
  38. end
  39.  
  40. -- Power up the reactor
  41.  
  42. function powerUp(m,n,reactorNum)
  43. local reactor = reactors[reactorNum]
  44. reactor.setActive(true)
  45. end
  46.  
  47. -- Power down the reactor
  48.  
  49. function powerDown(m,n,reactorNum)
  50. local reactor = reactors[reactorNum]
  51. reactor.setActive(false)
  52. end
  53.  
  54. -- Calculate and adjusts the level of the rods
  55.  
  56. function adjustRodsLevel(reactorNum)
  57. local reactor = reactors[reactorNum]
  58. local rfTotalMax = 10000000
  59. local currentRfTotal = reactor.getEnergyStored()
  60.  
  61. differenceMinMax = maxPowerRod - minPowerRod
  62.  
  63. maxPower = (rfTotalMax/100) * maxPowerRod
  64. minPower = (rfTotalMax/100) * minPowerRod
  65.  
  66. if currentRfTotal >= maxPower then
  67. currentRfTotal = maxPower
  68. end
  69.  
  70. if currentRfTotal <= minPower then
  71. currentRfTotal = minPower
  72. end
  73.  
  74. currentRfTotal = currentRfTotal - (rfTotalMax/100) * minPowerRod
  75.  
  76. local rfInBetween = (rfTotalMax/100) * differenceMinMax
  77. local rodLevel = math.ceil((currentRfTotal/rfInBetween)*100)
  78.  
  79. reactor.setAllControlRodLevels(rodLevel)
  80. end
  81.  
  82. -- Makes and Handles the Draw Function
  83.  
  84. function refreshSingleReactor()
  85. local rfPerTick = 0
  86. local rfTotal = 0
  87. local rfTotalMax = 10000000
  88. local rfPerTickTotal = 0
  89. local reactorsTotal = 3
  90.  
  91. repeat
  92. local reactor = reactors[reactorsTotal]
  93. local reactorTick = reactor
  94. rfTotal = reactor.getEnergyStored()
  95. rfPerTick = math.floor(reactor.getEnergyProducedLastTick())
  96. rodLevel = math.floor(reactor.getControlRodLevel(0))
  97. fuelPerTick = reactor.getFuelConsumedLastTick();
  98.  
  99. if reactorsTotal == 1 then
  100. startX = 5
  101. startY = 4
  102. elseif reactorsTotal == 2 then
  103. startX = 5
  104. startY = 12
  105. elseif reactorsTotal == 3 then
  106. startX = 33
  107. startY = 4
  108. end
  109.  
  110. rfPerTickTotal = math.floor(reactorTick.getEnergyProducedLastTick())
  111. currentRfTick = rfPerTick
  112. rfPerTickMax = rfPerTick
  113. rfPerTick = tonumber(rfPerTick)
  114. mon.setCursorPos(startX,startY)
  115. mon.write("RF/TICK: "..comma_value(rfPerTick).." RF ")
  116.  
  117. currentRfTotal = rfTotal
  118. rfTotal = tonumber(rfTotal)
  119. mon.setCursorPos(startX,startY+1)
  120. mon.write("RF STORED: "..comma_value(rfTotal).." RF ")
  121.  
  122. currentRodLevel = rodLevel
  123. mon.setCursorPos(startX,startY+2)
  124. mon.write("CONTROL ROD LEVEL: "..rodLevel.. "% ")
  125.  
  126. currentFuelConsumedLastTick = fuelPerTick
  127. mon.setCursorPos(startX,startY+3)
  128. mon.write("FUEL USAGE: "..format_num(tonumber(fuelPerTick)).." mb/t ")
  129. adjustRodsLevel(reactorsTotal)
  130. if reactorsTotal == 1 then
  131. rfTick1 = rfPerTickTotal
  132. rfStored1 = rfTotal
  133. fuelTick1 = fuelPerTick
  134. elseif reactorsTotal == 2 then
  135. rfTick2 = rfPerTickTotal
  136. rfStored2 = rfTotal
  137. fuelTick2 = fuelPerTick
  138. elseif reactorsTotal == 3 then
  139. rfTick3 = rfPerTickTotal
  140. rfStored3 = rfTotal
  141. fuelTick3 = fuelPerTick
  142. end
  143. sleep(0.01)
  144. reactorsTotal = reactorsTotal - 1
  145. until reactorsTotal == 0
  146. rfPerTickTotalAll = rfTick1 + rfTick2 + rfTick3
  147. totalRFStoredAll = rfStored1 + rfStored2 + rfStored3
  148. totalFuelUsageAll = fuelTick1 + fuelTick2 + fuelTick3
  149. mon.setCursorPos(33,13)
  150. mon.write("RF PER TICK: "..comma_value(rfPerTickTotalAll).." RF ")
  151. mon.setCursorPos(33,14)
  152. mon.write("RF STORED: "..comma_value(totalRFStoredAll).." RF ")
  153. mon.setCursorPos(33,15)
  154. mon.write("FUEL USAGE: "..comma_value(totalFuelUsageAll).." mb/t ")
  155. end
  156.  
  157. --Add Commas and Round Decimals
  158.  
  159. function comma_value(amount)
  160. local formatted = amount
  161. while true do
  162. formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
  163. if (k==0) then
  164. break
  165. end
  166. end
  167. return formatted
  168. end
  169.  
  170. function round(val, decimal)
  171. if (decimal) then
  172. return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
  173. else
  174. return math.floor(val+0.5)
  175. end
  176. end
  177.  
  178. function format_num(amount, decimal, prefix, neg_prefix)
  179. local str_amount, formatted, famount, remain
  180.  
  181. decimal = decimal or 2
  182. neg_prefix = neg_prefix or "-"
  183.  
  184. famount = math.abs(round(amount,decimal))
  185. famount = math.floor(famount)
  186.  
  187. remain = round(math.abs(amount) - famount, decimal)
  188.  
  189. formatted = comma_value(famount)
  190.  
  191. if (decimal > 0) then
  192. remain = string.sub(tostring(remain),3)
  193. formatted = formatted .. "." .. remain ..
  194. string.rep("0", decimal - string.len(remain))
  195. end
  196.  
  197. formatted = (prefix or "") .. formatted
  198.  
  199. if (amount<0) then
  200. if (neg_prefix=="()") then
  201. formatted = "("..formatted ..")"
  202. else
  203. formatted = neg_prefix .. formatted
  204. end
  205. end
  206.  
  207. return formatted
  208. end
  209.  
  210. -- Starts the Loop
  211. refresh = true
  212. while refresh do
  213. synDraw()
  214. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement