Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.59 KB | None | 0 0
  1. reactor = component.proxy(component.list("warpdriveEnanReactorCore")())
  2. cell = component.proxy(component.list("capacitor_bank")())
  3. gpu = component.proxy(component.list("gpu")())
  4.  
  5. config = {
  6.     instability = 90,
  7.     instability_critical = 95,
  8.     energy = 65,
  9.     energy_critical = 95,
  10.     energy_out = 95000000,
  11.     energy_low_out = 1000000,
  12.     slow_out = false,
  13.     can_work = true,
  14.     exit = false
  15. }
  16.  
  17. for redstone_card in pairs(component.list("redstone")) do
  18.     redstone = component.proxy(redstone_card)
  19.     redstone.setWakeThreshold(1)
  20. end
  21.  
  22. function stop()
  23.     gpu.set(18, 6, "Выключение...        ")
  24.     reactor.release(true)
  25.     reactor.enable(false)
  26.     config.can_work = false
  27. end
  28.  
  29. function listener(...)
  30.     evt, _, _, code = computer.pullSignal(...)
  31.     if evt == "key_down" and code == 41 then
  32.         computer.beep()
  33.         stop()
  34.         config.exit = true
  35.     elseif not config.can_work and reactor.energy() == 0 and not state then
  36.         gpu.set(18, 6, "Выключен        ")
  37.         reactor.release(false)
  38.         if not config.exit then
  39.             config.can_work = true
  40.         else
  41.             if redstone then
  42.                 redstone.setWakeThreshold(0)
  43.             end
  44.             computer.shutdown()
  45.         end
  46.     end
  47. end
  48.  
  49. function sleep(timeout)
  50.     deadline = computer.uptime() + timeout
  51.     repeat
  52.         listener(deadline - computer.uptime())
  53.     until computer.uptime() >= deadline
  54. end
  55.  
  56. function check_instability()
  57.     if math.max(reactor.instability()) > config.instability_critical then    
  58.         stop()
  59.     end
  60. end
  61.  
  62. function start()
  63.     check_instability()
  64.     gpu.set(18, 6, "Работает...        ")
  65.     reactor.enable(false)
  66.     reactor.enable(true)
  67.     reactor.instabilityTarget(config.instability)
  68.     reactor.stabilizerEnergy(10000)
  69.     reactor.releaseAbove(config.energy_out)
  70. end
  71.  
  72. function drawStat()
  73.     gpu.set(17, 1, math.floor(math.max(reactor.instability())) .. "% ")
  74.     if config.slow_out then
  75.         slow_out = "Да "
  76.     else
  77.         slow_out = "Нет"
  78.     end
  79.     gpu.set(19, 2, slow_out)
  80.     gpu.set(17, 3, math.floor(cell_energy) .. "% ")
  81.     gpu.set(21, 4, math.floor(cell.getAverageInputPerTick()) .. "                ")
  82.     gpu.set(17, 5, math.floor(reactor_energy) .. "                ")
  83. end
  84.  
  85. function reactor_ctrl()
  86.     check_instability()
  87.     _, state = reactor.state()
  88.     reactor_energy = reactor.energy()
  89.     cell_energy = cell.getEnergyStored() / (cell.getMaxEnergyStored() / 100)
  90.     drawStat()
  91.     if config.can_work then
  92.         if cell_energy >= config.energy_critical and state then
  93.             stop()
  94.         elseif cell_energy < config.energy_critical and not state then
  95.             start()
  96.         elseif cell_energy > config.energy then
  97.             reactor.releaseAbove(config.energy_low_out)
  98.             if not config.slow_out then
  99.                 config.slow_out = true
  100.             end
  101.         elseif cell_energy < config.energy then
  102.             reactor.releaseAbove(config.energy_out)
  103.             if config.slow_out then
  104.                 config.slow_out = false
  105.             end
  106.         end
  107.     end
  108. end
  109.  
  110. gpu.bind(component.proxy(component.list("screen")()).address)
  111. gpu.setResolution(32, 16)
  112. gpu.set(1, 1, "Нестабильность:")
  113. gpu.set(1, 2, "Пониженный вывод:")
  114. gpu.set(1, 3, "Заряд батарей:")
  115. gpu.set(1, 4, "Выход энергии RF/T:")
  116. gpu.set(1, 5, "Заряд реактора:")
  117. gpu.set(1, 6, "Статус реактора:")
  118.  
  119. start()
  120.  
  121. while true do
  122.     sleep(1)
  123.     reactor_ctrl()
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement