Advertisement
Guest User

Reactor Hutti

a guest
Apr 13th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. function get_geraet(geraet)
  2. pList = peripheral.getNames()
  3. for i, name in pairs(pList) do
  4. if peripheral.getType(name) == geraet then
  5. return peripheral.wrap(name)
  6. end
  7. end
  8. return nil
  9. end
  10.  
  11. function printXY(X, Y, farbe, text)
  12. mon.setCursorPos(X,Y)
  13. mon.setTextColour(farbe)
  14. mon.write(text)
  15. end
  16.  
  17. verbrauch_array = {}
  18. for i = 1, 20 do
  19. verbrauch_array[i] = 0
  20. end
  21.  
  22. leistung_array = {}
  23. for i = 1, 20 do
  24. leistung_array[i] = 0
  25. end
  26.  
  27. while true do
  28. reactor = get_geraet("BigReactors-Reactor")
  29. mon = get_geraet("monitor")
  30.  
  31. -- Regelgrössen für den Reaktor
  32. speicher_min = 20
  33. speicher_max = 80
  34.  
  35. -- Regelung des Reaktors
  36. -- reactor.setAllControlRodLevels(100)
  37. speicher = math.floor(reactor.getEnergyStored() / 10000000 * 100)
  38. if speicher < speicher_min then
  39. cooling_level = 0
  40. elseif speicher > speicher_max then
  41. cooling_level = 100
  42. else
  43. cooling_level = math.abs(((speicher - speicher_min) / (speicher_max - speicher_min)) * 100)
  44. end
  45.  
  46.  
  47. -- leistung_ges = (100 - cooling_level) * reactor.getNumberOfControlRods()
  48.  
  49. -- rod_counter = 0
  50. -- repeat
  51. -- if leistung_ges > 50 then
  52. -- reactor.setControlRodLevel(rod_counter, 50)
  53. -- leistung_ges = leistung_ges - 50
  54. -- else
  55. -- reactor.setControlRodLevel(rod_counter, 100 - leistung_ges)
  56. -- leistung_ges = 0
  57. -- end
  58. -- rod_counter = rod_counter + 1
  59. -- until leistung_ges <= 0
  60.  
  61. reactor.setAllControlRodLevels(math.floor(cooling_level))
  62.  
  63. -- Ab jetzt nurnoch Anzeigen der Werte
  64. term.clear()
  65. term.setCursorPos(1,1)
  66. term.write("Steuerprogram für den Reaktor")
  67. term.setCursorPos(1,3)
  68. term.write("Zum Beenden Strg + T halten")
  69. term.setCursorPos(1,5)
  70. term.write(textutils.formatTime(os.time(), true))
  71.  
  72. assert ( get_geraet("BigReactors-Reactor"), "Kein Reaktor gefunden")
  73. assert ( get_geraet("monitor"), "Kein Monitor gefunden")
  74.  
  75. mon.setBackgroundColor(colors.black)
  76. mon.setTextScale(0.8)
  77. mon.clear()
  78.  
  79. zeile = 1
  80.  
  81. printXY(32, zeile, colors.yellow, textutils.formatTime(os.time(), true))
  82. printXY(1, zeile, colors.white, "CommLink: ")
  83. if reactor.getConnected() then
  84. printXY(11, zeile, colors.green, "UP")
  85. else
  86. printXY(11, zeile, colors.red, "DOWN")
  87. end
  88.  
  89. zeile = 2
  90.  
  91. printXY(1, zeile, colors.white, "Reaktor: ")
  92. if reactor.getActive() then
  93. printXY(10, zeile, colors.green, "AN @ " .. string.format("%d", reactor.getCasingTemperature()) .. "°C")
  94. else
  95. printXY(10, zeile, colors.red, "AUS")
  96. end
  97.  
  98. zeile = 4
  99.  
  100. printXY(1, zeile, colors.white, "Interner Speicher:")
  101. if speicher < speicher_min then
  102. printXY(20, zeile, colors.orange, string.format("%d", speicher) .. "%")
  103. elseif speicher > speicher_max then
  104. printXY(20, zeile, colors.blue, string.format("%d", speicher) .."%")
  105. else
  106. printXY(20, zeile, colors.green, string.format("%d", speicher) .. "%")
  107. end
  108.  
  109. zeile = 5
  110.  
  111. table.insert(leistung_array, 1, reactor.getEnergyProducedLastTick())
  112. table.remove(leistung_array)
  113. leistung = 0
  114. for i = 1, table.getn(leistung_array) do
  115. leistung = leistung + leistung_array[i]
  116. end
  117. leistung = leistung / table.getn(leistung_array)
  118.  
  119. printXY(1, zeile, colors.white, "Leistung:")
  120. printXY(11, zeile, colors.white, string.format("%d", leistung) .. " RF/t @ " .. string.format("%d", reactor.getFuelReactivity()) .. "%")
  121.  
  122. zeile = 7
  123.  
  124. printXY(1, zeile, colors.white, "Brennstoff:")
  125. brennstoff = reactor.getFuelAmount() / reactor.getFuelAmountMax() * 100
  126. if brennstoff > 80 then
  127. printXY(13, zeile, colors.green, string.format("%d", brennstoff) .. "%")
  128. elseif brennstoff < 20 then
  129. printXY(13, zeile, colors.red, string.format("%d", brennstoff))
  130. else
  131. printXY(13, zeile, colors.orange, string.format("%d", brennstoff))
  132. end
  133.  
  134. zeile = 8
  135.  
  136. table.insert(verbrauch_array, 1, reactor.getFuelConsumedLastTick())
  137. table.remove(verbrauch_array)
  138. verbrauch = 0
  139. for i = 1, table.getn(verbrauch_array) do
  140. verbrauch = verbrauch + verbrauch_array[i]
  141. end
  142. verbrauch = verbrauch / table.getn(verbrauch_array)
  143.  
  144. printXY(1, zeile, colors.white, "Verbrauch:")
  145. printXY(12, zeile, colors.cyan, string.format("%d", verbrauch * 1000) / 1000 .. " mB/t @ " .. string.format("%d", reactor.getFuelTemperature()) .. "°C")
  146.  
  147. zeile = 9
  148.  
  149. printXY(1, zeile, colors.white, "Lebensdauer:")
  150. printXY(14, zeile, colors.cyan, string.format("%d", 1/(verbrauch*0.02)) .. " s/Ingot")
  151.  
  152. sleep(1)
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement