Advertisement
Nyfinscyf

Untitled

Apr 26th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. ---------------------------------------------------------------
  2. ---------------------------------------------------------------
  3. -- VARIABLES
  4. -- setup
  5. numCaps = 8
  6. enablePerc = 50
  7. disablePerc = 90
  8.  
  9. -- globals (don't change)
  10. numReacs = 0
  11. curEn = 0
  12. maxEn = 0
  13. percEn = 0
  14. usedEn = 0
  15. rfGen = 0
  16. reacsOnline = 0
  17. fuelUse = {}
  18. coreTemp = {}
  19. rfGens = {}
  20.  
  21. ---------------------------------------------------------------
  22. ---------------------------------------------------------------
  23. -- FIND PERIPHERALS
  24. cap = peripheral.find("tile_blockcapacitorbank_name")
  25. mon = peripheral.find("monitor")
  26. mon.setTextScale(1)
  27.  
  28. local names = {}
  29. local function filter(name)
  30. table.insert(names,name)
  31. return true
  32. end
  33.  
  34. peripheral.find("BigReactors-Reactor",filter)
  35.  
  36. numReacs = table.getn(names)
  37.  
  38. local reacs = {}
  39. for i=1,numReacs,1 do
  40. reacs[i] = peripheral.wrap(names[i])
  41. end
  42.  
  43. ---------------------------------------------------------------
  44. ---------------------------------------------------------------
  45. -- FUNCTIONS
  46. maxEn = cap.getMaxEnergyStored()
  47.  
  48. function process()
  49. -- Energy (Capacitors)
  50. curEn = cap.getEnergyStored()
  51. percEn = math.floor((curEn/maxEn)*100)
  52. sleep(0.1)
  53. usedEn = (cap.getEnergyStored()-curEn)/2
  54. usedEn = usedEn*numCaps
  55.  
  56.  
  57. -- Reactors
  58. if percEn < enablePerc then
  59. enableReactor = true
  60. disableReactor = false
  61. elseif percEn > disablePerc then
  62. disableReactor = true
  63. enableReactor = false
  64. else
  65. enableReactor = false
  66. disableReactor = false
  67. end
  68.  
  69. rfGen = 0
  70. reacsOnline = 0
  71. for i=1,numReacs,1 do
  72. -- rf gen
  73. rfGen = rfGen+reacs[i].getEnergyProducedLastTick()
  74. rfGens[i]=reacs[i].getEnergyProducedLastTick()
  75. -- auto enable-disable
  76. if enableReactor then
  77. reacs[i].setActive(enableReactor)
  78. end
  79. if disableReactor then
  80. reacs[i].setActive(false)
  81. end
  82. -- currently online
  83. if reacs[i].getActive() then
  84. reacsOnline = reacsOnline + 1
  85. end
  86. -- fuel use
  87. fuelUse[i] = reacs[i].getFuelConsumedLastTick()
  88. fuelUse[i] = math.floor(fuelUse[i]*100)
  89. fuelUse[i] = fuelUse[i]/100
  90. -- core temps
  91. coreTemp[i] = reacs[i].getFuelTemperature()
  92. end
  93. end
  94.  
  95. function display()
  96. -- clear
  97. mon.clear()
  98. mon.setTextColor(colors.white)
  99. -- general display
  100. mon.setCursorPos(1,1)
  101. mon.write("RF Total: "..math.floor((percEn*maxEn*numCaps)/1e8).."M/"..math.floor(maxEn/1e6)*numCaps.."M")
  102. --mon.write("RF Stored: "..percEn.."%")
  103.  
  104. sleep(0.1)
  105. mon.setCursorPos(21,1)
  106.  
  107. mon.write("RF Used: ")
  108. if usedEn < 0 then
  109. mon.setTextColor(colors.red)
  110. else
  111. mon.setTextColor(colors.green)
  112. end
  113. mon.write(usedEn.." RF/t")
  114. mon.setTextColor(colors.white)
  115.  
  116. mon.setCursorPos(21,2)
  117. mon.write("RF Gen: ")
  118. mon.setTextColor(colors.green)
  119. mon.write(math.floor(rfGen).." RF/t")
  120. mon.setTextColor(colors.white)
  121.  
  122. mon.setCursorPos(1,2)
  123. mon.write("Online: "..reacsOnline.." / "..numReacs)
  124.  
  125. local m = 38
  126. local max = math.floor(m*(percEn/100))
  127. mon.setCursorPos(1,3)
  128. mon.setBackgroundColor(colors.red)
  129. mon.write(" ")
  130. mon.setCursorPos(m+1,3)
  131. mon.write(" ")
  132.  
  133. mon.setCursorPos(2,3)
  134. mon.setTextColor(colors.white)
  135.  
  136. local text = ""..math.floor((percEn*maxEn*numCaps)/1e8).."M/"..math.floor(maxEn/1e6)*numCaps.."M".." ("..percEn.."%)"
  137. local offset = math.floor(m/2 - string.len(text)/2)
  138. for i=1,m,1 do
  139. if i < max then
  140. mon.setBackgroundColor(colors.green)
  141. else
  142. mon.setBackgroundColor(colors.black)
  143. end
  144. local k = i-offset
  145. if i >= offset and k <= string.len(text) then
  146. mon.write(string.sub(text,k,k))
  147. else
  148. mon.write(" ")
  149. end
  150. end
  151. mon.setBackgroundColor(colors.black)
  152.  
  153. -- individual display
  154. local div = math.ceil(numReacs/2)
  155. local x = 0
  156. local y = 4
  157. local numStats = 5
  158. for i=1,numReacs,1 do
  159. if i <= div then
  160. x = 1
  161. y = 5 + (i-1)*numStats
  162. else
  163. x = 21
  164. y = 5 + (i - div - 1)*numStats
  165. end
  166.  
  167. mon.setCursorPos(x,y)
  168. mon.setTextColor(colors.blue)
  169. mon.write("Reactor "..i..": ")
  170. mon.setCursorPos(x+2,y+1)
  171. mon.setTextColor(colors.yellow)
  172. mon.write("Fuel - "..fuelUse[i].." MB/t")
  173. mon.setCursorPos(x+2,y+2)
  174. mon.setTextColor(colors.orange)
  175. mon.write("Temp - "..math.floor(coreTemp[i]).."c")
  176. mon.setCursorPos(x+2,y+3)
  177. mon.setTextColor(colors.green)
  178. mon.write("RF Gen - "..math.floor(rfGens[i]).." RF/t")
  179. end
  180. end
  181.  
  182. ---------------------------------------------------------------
  183. ---------------------------------------------------------------
  184. -- MAIN LOOP
  185. while true do
  186. process()
  187. display()
  188. sleep(1)
  189. end
  190. ---------------------------------------------------------------
  191. ---------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement