Taw_

Untitled

Jul 3rd, 2016
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. local modem = peripheral.wrap("back")
  2.  
  3. local reactorSetup = "XFFX.XFFXCXXC.CXXCXCCX.XCCXFXXF.FXXFFXXF.FXXFXCCX.XCCX"
  4.  
  5. local reactorData = {}
  6.  
  7. local totalEU = 0
  8.  
  9. local FUEL = "reactorUraniumDual"
  10. local VENT = "reactorVentGold"
  11. local SPREAD = "reactorVentSpread"
  12. local DEPLETED = "reactorUraniumDualdepleted"
  13.  
  14. local toggle = 0
  15.  
  16. local alarm = false;
  17.  
  18. function getSetupItem(i)
  19. return string.sub(reactorSetup,i,i)
  20. end
  21.  
  22. function printMon(mon,text)
  23. mon.write(text)
  24. local x,y = mon.getCursorPos()
  25. mon.setCursorPos(1,y+1)
  26. end
  27.  
  28. function setTextColor(mon,color)
  29. if not mon then mon = term end
  30. if mon.isColor() then mon.setTextColor(color) end
  31. end
  32.  
  33. function setBackgroundColor(mon,color)
  34. if not mon then mon = term end
  35. if mon.isColor() then mon.setBackgroundColor(color) end
  36. end
  37.  
  38. function controlReactor(reactorName)
  39. local r = peripheral.wrap(reactorName)
  40. local i
  41. local missingVents = false
  42. for i=1,r.getInventorySize() do
  43. local data = r.getStackInSlot(i)
  44. if data then
  45. if data.name == FUEL then
  46. --ok
  47. elseif data.name == VENT then
  48. --ok
  49. elseif data.name == SPREAD then
  50. --ok
  51. elseif data.name == DEPLETED then
  52. --eject item downward
  53. r.pushItem("DOWN",i);
  54. end
  55. end
  56. end
  57.  
  58. for i=1,r.getInventorySize() do
  59. local data = r.getStackInSlot(i)
  60. if not data then
  61. --check what should go here
  62. --pull that thing into here
  63. if getSetupItem(i) == "F" then
  64. --pull item in from above into that position
  65. r.pullItemIntoSlot("UP",2,1,i)
  66. elseif getSetupItem(i) == "X" then
  67. --There should be a vent here but there isn't!
  68. missingVents = true
  69. end
  70. end
  71. end
  72.  
  73. local data = {}
  74. data["name"] = reactorName
  75. data["missingVents"] = missingVents and "true" or "false"
  76. data["energy"] = r.getEUOutput() * 5
  77. data["heat"] = r.getHeat()
  78. data["maxHeat"] = r.getMaxHeat()
  79. data["active"] = r.isActive() and "true" or "false"
  80. if data.heat > 0 then
  81. alarm = true
  82. end
  83. reactorData[reactorName] = data
  84. totalEU = totalEU + data.energy
  85. end
  86.  
  87. function render(mon)
  88. if not mon then
  89. mon = term
  90. end
  91. if mon.setTextScale then
  92. mon.setTextScale(0.5)
  93. end
  94.  
  95. local w,h = mon.getSize()
  96. setTextColor(mon,colors.white)
  97. mon.clear()
  98. mon.setCursorPos(1,1)
  99. for name,data in pairs(reactorData) do
  100. printMon(mon,"Name: "..name)
  101. printMon(mon,"EU/t: "..data.energy)
  102. printMon(mon,"Heat: "..data.heat.."/"..data.maxHeat)
  103. printMon(mon,"Active: "..data.active)
  104. printMon(mon,"Missing vents? "..data.missingVents)
  105. printMon(mon,"")
  106. end
  107. setTextColor(mon,colors.red)
  108. mon.setCursorPos(1,h)
  109. mon.write("Total EU/t: "..totalEU.." ("..(totalEU*4).." RF/t)")
  110. setTextColor(mon,colors.green)
  111. mon.setCursorPos(w-9,1)
  112. local i
  113. for i = 1,10 do
  114. mon.write(math.floor(math.random()*10))
  115. end
  116. end
  117.  
  118. function update()
  119. totalEU = 0
  120. reactorData = {}
  121. alarm = false
  122. local names = modem.getNamesRemote()
  123. for i=1,#names do
  124. if modem.getTypeRemote(names[i]) == "nuclear_reactor" then
  125. controlReactor(names[i])
  126. end
  127.  
  128. end
  129.  
  130. for i=1,#names do
  131. if modem.getTypeRemote(names[i]) == "monitor" then
  132. render(peripheral.wrap(names[i]))
  133. end
  134. end
  135. end
  136.  
  137. while true do
  138. update()
  139. render()
  140. toggle = (toggle + 1) % 8
  141. redstone.setOutput("bottom",toggle < 4)
  142. redstone.setOutput("top",alarm)
  143. sleep(0.1)
  144. end
Advertisement
Add Comment
Please, Sign In to add comment