Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. function clean()
  2. term.setBackgroundColor(colors.black)
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. end
  6. function cleanMon()
  7. m.setBackgroundColor(colors.black)
  8. m.clear()
  9. m.setCursorPos(1,1)
  10. end
  11. function center(text,index,y)
  12. if index == m then
  13. screen = m
  14. elseif index == m2 then
  15. screen = m2
  16. else
  17. screen = tWindow[index]
  18. end
  19. w,h = screen.getSize()
  20. _text = tostring(text)
  21. sl = string.len(_text)
  22. screen.setCursorPos((w/2)-(sl/2),y)
  23. screen.write(_text)
  24. end
  25. clean()
  26. peripherals = peripheral.getNames()
  27. t = {}
  28. for i=1,#peripherals do
  29. --print(peripherals[i])
  30. type = peripheral.getType(peripherals[i])
  31. if type == "BigReactors-Turbine" then
  32. table.insert(t,peripheral.wrap(peripherals[i]))
  33. print("adding new turbine ")
  34. elseif type == "BigReactors-Reactor" then
  35. if not r then
  36. r = peripheral.wrap(peripherals[i])
  37. print("got the reactor")
  38. end
  39. end
  40. end
  41. m = peripheral.wrap("monitor_20")
  42. m2 = peripheral.wrap("monitor_21")
  43. if not r then
  44. error("No Reactor Found")
  45. end
  46. if not m then
  47. error("No Monitor Found")
  48. end
  49. if not m2 then
  50. error("No Secondary Monitor Found")
  51. end
  52. cleanMon()
  53. --cpu = term.redirect(m)
  54. clean()
  55.  
  56. -- Prepare Windows for Turbines
  57. -- 4 windows per line, 2 lines, 17 wide each, 20 high each
  58. tWindow = {}
  59. height = 8
  60. for i=1,#t do
  61. if i <= 4 then
  62. y = 4
  63. xsub = 0
  64. elseif i <= 8 then
  65. y = 4 + (1 + height)
  66. xsub = 4
  67. elseif i <= 12 then
  68. y = 4 + (1 + height) * 2
  69. xsub = 8
  70. else
  71. y = 4 + (1 + height) * 3
  72. xsub = 12
  73. end
  74. x = 1 + (17 * ((i-1) - xsub) ) + ((i-1)-xsub)
  75. --if i > 4 and i < 9 then
  76. -- x = x - i
  77. --end
  78. table.insert(tWindow,window.create(m,x,y,17,height,true))
  79.  
  80. end
  81.  
  82. -- Show Turbine Stats
  83. while true do
  84. center("TURBINES",m,1)
  85. center("--------",m,2)
  86.  
  87. x,y= 1,4
  88.  
  89. totalPowerGen = 0
  90. for i=1,#t do
  91. if t[i].getConnected() then
  92. tWindow[i].clear()
  93. center(i,i,1)
  94. if t[i].getActive() then
  95. tWindow[i].setBackgroundColor(colors.green)
  96. else
  97. tWindow[i].setBackgroundColor(colors.red)
  98. end
  99. center("POWER",i,2)
  100. tWindow[i].setBackgroundColor(colors.gray)
  101. center(math.floor(t[i].getEnergyStored()).. "RF",i,6)
  102. center(math.floor(t[i].getRotorSpeed()).." RPM",i,7)
  103. center(math.floor(t[i].getEnergyProducedLastTick()) .. "RF/T",i,8)
  104. if t[i].getInductorEngaged() then
  105. tWindow[i].setBackgroundColor(colors.green)
  106. else
  107. tWindow[i].setBackgroundColor(colors.red)
  108. end
  109. center("COIL ",i,4)
  110. tWindow[i].setBackgroundColor(colors.black)
  111. totalPowerGen = totalPowerGen + t[i].getEnergyProducedLastTick()
  112. end
  113. end
  114. -- Show Reactor Stats
  115. m2.clear()
  116. center("Reactor Info",m2,1)
  117. center("____________",m2,2)
  118. if r.getConnected() then
  119. if r.getActive() then
  120. m2.setBackgroundColor(colors.green)
  121. else
  122. m2.setBackgroundColor(colors.red)
  123. end
  124. center("POWER",m2,4)
  125. m2.setBackgroundColor(colors.black)
  126. center("Fuel Temp: " .. math.floor(r.getFuelTemperature()),m2,6)
  127. center("Case Temp: " .. math.floor(r.getCasingTemperature()),m2,7)
  128. center("Fuel Amount: ".. math.floor(r.getFuelAmount()).."/"..math.floor(r.getFuelAmountMax()),m2,8)
  129. center("Steam Created: " .. r.getHotFluidProducedLastTick().." mB/t",m2,9)
  130. center("Fuel Rate: ".. r.getFuelConsumedLastTick() .. " mB/t",m2,10)
  131. center("Fuel Reactivity: ".. math.floor(r.getFuelReactivity()).. "%",m2,11)
  132. loc = 15
  133. height = 10
  134. water = r.getCoolantAmount()
  135. waterMax = r.getCoolantAmountMax()
  136. waterBlock = waterMax/height
  137. numWaterBlocks = math.floor(water/waterBlock)
  138. steam = r.getHotFluidAmount()
  139. steamMax = r.getHotFluidAmountMax()
  140. steamBlock = steamMax/height
  141. numSteamBlocks = math.floor(steam/steamBlock)
  142. sw,sh = m2.getSize()
  143. m2.setBackgroundColor(colors.lightGray)
  144. for l=1,height do
  145. m2.setCursorPos(5,loc-l)
  146. m2.write(" ")
  147. m2.setCursorPos(8,loc-l)
  148. m2.write(" ")
  149. m2.setCursorPos(sw-5,loc-l)
  150. m2.write(" ")
  151. m2.setCursorPos(sw-8,loc-l)
  152. m2.write(" ")
  153. end
  154. m2.setCursorPos(5,loc - height - 1)
  155. m2.write(" ")
  156. m2.setCursorPos(sw-8,loc - height - 1)
  157. m2.write(" ")
  158. m2.setCursorPos(5,loc)
  159. m2.write(" ")
  160. m2.setCursorPos(sw-8,loc)
  161. m2.write(" ")
  162. m2.setBackgroundColor(colors.blue)
  163. for l=1,numWaterBlocks do
  164. m2.setCursorPos(6,loc-l)
  165. m2.write(" ")
  166. end
  167. m2.setBackgroundColor(colors.gray)
  168. for l=1,numSteamBlocks do
  169. m2.setCursorPos(sw-7,loc-l)
  170. m2.write(" ")
  171. end
  172. m2.setBackgroundColor(colors.black)
  173.  
  174. end
  175. timer = os.startTimer(.5)
  176. while true do
  177. event,side,x,y = os.pullEvent()
  178. if event == "timer" then
  179. break
  180. elseif event == "monitor_touch" then
  181. -- check coords for button push
  182. if side == "monitor_21" then
  183. local w,h = screen.getSize()
  184. powerX = (w/2)-(5/2)
  185. if x >= powerX and x <= powerX + 5 and y == 4 then
  186. if r.getActive() then
  187. -- disable input of yellorium
  188. rs.setBundledOutput("bottom",0)
  189. -- disable reactor
  190. r.setActive(false)
  191. -- dump fuel
  192. repeat
  193. r.doEjectFuel()
  194. sleep(.5)
  195. until r.getFuelAmount() < 1000
  196. else
  197. -- enable input of yellorium
  198. rs.setBundledOutput("bottom",colors.black)
  199. -- enable reactor
  200. r.setActive(true)
  201. end
  202. end
  203. break
  204. end
  205. end
  206.  
  207. end
  208. --os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement