Advertisement
tonacho

reactor

Apr 24th, 2015
1,813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. cap = peripheral.find("tile_blockcapacitorbank_name")
  2. mon = peripheral.find("monitor")
  3. rea = peripheral.find("BigReactors-Reactor")
  4.  
  5. local numCapacitors = 3
  6. local enciendeA = 50
  7. local apagaA = 90
  8.  
  9. local energia = 0
  10. local energiaGuardada = 0
  11. local energiaMax = 0
  12. local enegiaGuardadaPorCiento = 0
  13. local produccionRF = 0
  14. local usoFuel = 0
  15. local tempCore = 0
  16. local reactorOnline = false
  17.  
  18. function enciende()
  19.    rea.setActive(true)
  20. end
  21.  
  22. function apaga()
  23.    rea.setActive(false)
  24. end
  25.  
  26. function comma_value(cantidad)
  27.     local formateo = cantidad
  28.     local swap = false
  29.     if formateo < 0 then
  30.         formateo = formateo*-1
  31.         swap = true
  32.     end
  33.     while true do
  34.     formateo, k = string.gsub(formateo, "^(%d+)(%d%d%d)", '%1,%2')
  35.         if k == 0 then
  36.             break
  37.         end
  38.     end
  39.     if swap then
  40.         formateo = "-"..formateo
  41.     end
  42.     return formateo
  43. end
  44.  
  45. function muestraEnergia()
  46. mon.clear()
  47. mon.setCursorPos(1,1)
  48. mon.write("Uso de Energia: ")
  49.     if energia < 0 then
  50.         mon.setTextColor(colors.red)
  51.     else
  52.         mon.setTextColor(colors.lime)
  53.     end
  54. mon.write(comma_value(math.floor(energia)).."RF/T")
  55. mon.setTextColor(colors.white)
  56. mon.setCursorPos(1,2)
  57. mon.write("Energia Almacenada: ")
  58.     if energiaGuardadaPorCiento < 55 then
  59.         mon.setTextColor(colors.red)
  60.     elseif energiaGuardadaPorCiento >= 55 and energiaGuardadaPorCiento <=85 then
  61.         mon.setTextColor(colors.yellow)
  62.     else
  63.         mon.setTextColor(colors.lime)
  64.     end
  65. mon.write(energiaGuardadaPorCiento.."%")
  66. mon.setTextColor(colors.white)
  67. mon.setCursorPos(1,3)
  68. mon.write("El Reactor esta: ")
  69.     if reactorOnline then
  70.         mon.setTextColor(colors.lime)
  71.         mon.write("ENCENDIDO")
  72.     else
  73.         mon.setTextColor(colors.red)
  74.         mon.write("APAGADORL")
  75.     end
  76. mon.setTextColor(colors.white)
  77. mon.setCursorPos(1,4)
  78. mon.write("Generacion de Rastafaris: ")
  79. mon.setTextColor(colors.lime)
  80. mon.write(comma_value(math.floor(produccionRF)).."RF/T")
  81. mon.setTextColor(colors.white)
  82. mon.setCursorPos(1,5)
  83. mon.write("Temperatura intenna: "..math.floor(tempCore).."c")
  84. mon.setCursorPos(1,6)
  85. mon.write("Uso de Combustible: "..usoFuel.."MB/T")
  86.  
  87. end
  88.  
  89.  
  90. function compruebaEnergia()
  91.     local energiaTemporal = 0
  92.     energiaGuardada = cap.getEnergyStored()
  93.     energiaMax = cap.getMaxEnergyStored()
  94.     energiaGuardadaPorCiento = math.floor((energiaGuardada/energiaMax)*100)
  95.     produccionRF = rea.getEnergyProducedLastTick()
  96.     usoFuel = rea.getFuelConsumedLastTick()
  97.     usoFuel = math.floor(usoFuel*100)
  98.     usoFuel = usoFuel/100
  99.     tempCore = rea.getFuelTemperature()
  100.     reactorOnline = rea.getActive()
  101.     energiaTemporal = cap.getEnergyStored()
  102.     sleep(0.1)
  103.     energia = (cap.getEnergyStored()-energiaTemporal)/2
  104.     energia = energia*numCapacitors
  105. end
  106.  
  107. function autoReactor()
  108.     rea.setAllControlRodLevels(0)
  109.     if energiaGuardadaPorCiento < enciendeA then
  110.         if not reactorOnline then
  111.             enciende()
  112.         end
  113.     end
  114.     if energiaGuardadaPorCiento > apagaA then
  115.         if reactorOnline then
  116.             apaga()
  117.         end
  118.     end
  119.  
  120. end
  121.  
  122. function muestraInfo()
  123.     -- Esta es la que se repite
  124.     compruebaEnergia()
  125.     muestraEnergia()
  126.     autoReactor()
  127.    
  128. end
  129.  
  130.  
  131. while true do
  132.  muestraInfo()
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement