Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. -- Reactor Search
  2. local reactor = peripheral.find("BigReactors-Reactor")
  3. if reactor then
  4.  print("Reaktor gefunden")
  5. end
  6.  
  7. -- Create Variables
  8. --local targetspeed = 1845
  9. --local targetspeed = 2860
  10. --local targetspeed = 5480
  11. --local targetspeed = 6280
  12. --local targetspeed = 16280
  13. local targetspeed = 46590
  14. local speeddelay1 = 10
  15. local speeddelay2 = 100
  16. local active = 0
  17. local count = 0
  18. local monside = "right"
  19. local turbine = peripheral.find("BigReactors-Turbine")
  20.  
  21.  
  22.  
  23. mon = peripheral.wrap(monside)
  24. mon.clear()
  25. --term.redirect(mon)
  26.  
  27. --Setup Turbines
  28. if turbine then
  29.  print("Turbinen gefunden")
  30.  local periList = peripheral.getNames()
  31.  for i = 1, #periList do
  32.   if string.find(peripheral.getType(periList[i]), "Turbine") then
  33.    local aTurbine = peripheral.wrap(periList[i])
  34.    count = count +1
  35.    print(periList[i], ": ", aTurbine.getActive())
  36.    active = active +1
  37.    aTurbine.setActive(true)    aTurbine.setInductorEngaged(false)
  38.    sleep(0.1)
  39.    aTurbine.setInductorEngaged(true)
  40.    --aTurbine.setVentNone()
  41.    aTurbine.setVentOverflow()
  42.     aTurbine.setFluidFlowRateMax(2000)  
  43.   end
  44.  end
  45.  print(#periList, " Gerte")
  46.  print(active, " aktive Turbinen")
  47. end
  48. sleep(1)
  49.  
  50.  
  51.  
  52. -- Get Ready
  53. local turbines = active
  54. local steam = turbines *2000
  55. reactor.setActive(true)
  56. reactor.setAllControlRodLevels(50)
  57.  
  58.  
  59. -- Steuerung
  60. while true do
  61.  
  62.  -- Reactor control
  63.  if reactor.getHotFluidProducedLastTick() > steam - 100 then
  64.   level = reactor.getControlRodLevel(1)
  65.    reactor.setAllControlRodLevels(level +1)
  66.    print("+1")
  67.    local turnon = "+1"
  68. --     mon.setCursorPos(5,6)
  69. --     mon.write("+1")
  70.    local a = 5
  71.    local b = "false"
  72.    while a > 0 do
  73.     if reactor.getHotFluidProducedLastTick() < steam then
  74.      b = "true"
  75.      if b == "true" then
  76.       level = reactor.getControlRodLevel(1)
  77.       reactor.setAllControlRodLevels(level -1)
  78.       b = "false"
  79.      end
  80.     end
  81.     a = a -1
  82.    end
  83.  else
  84.   if reactor.getHotFluidProducedLastTick() < steam then
  85.    if reactor.getControlRodLevel(1) > 1 then
  86.     if reactor.getHotFluidProducedLastTick() < steam then
  87.      level = reactor.getControlRodLevel(1)
  88.      reactor.setAllControlRodLevels(level -1)
  89.      print("-1")
  90.      local turnon = "-1"
  91. --       mon.setCursorPos(5,6)
  92. --       mon.write("-1")
  93.      sleep(0.1)
  94.      periList = peripheral.getNames()
  95.     end
  96.    end
  97.   end
  98.  end
  99.  
  100.  
  101.  -- turbine control
  102.  local periList = peripheral.getNames()
  103.  for i = 1, #periList do
  104.   if string.find(periList[i], "Turbine") then
  105.    local aTurbine = peripheral.wrap(periList[i])
  106.    if aTurbine.getRotorSpeed() < (targetspeed - speeddelay1) then
  107.     aTurbine.setInductorEngaged(false)
  108.    end
  109.   end
  110.  end
  111.  sleep(0)
  112.  local periList = peripheral.getNames()
  113.  for i = 1, #periList do
  114.   if string.find(periList[i], "Turbine") then
  115.    local aTurbine = peripheral.wrap(periList[i])
  116.    if aTurbine.getRotorSpeed() < targetspeed and aTurbine.getActive() == false then
  117.     aTurbine.setActive(true)
  118.     steam = steam +2000
  119.    else
  120.     if aTurbine.getRotorSpeed() > targetspeed and aTurbine.getActive() == true then
  121.      aTurbine.setActive(false)
  122.      steam = steam -2000
  123.     end
  124.    end
  125.    if aTurbine.getEnergyStored() < 100 then
  126.     if aTurbine.getRotorSpeed() > (targetspeed - speeddelay2) then
  127.      aTurbine.setInductorEngaged(true)
  128.     end
  129.    end
  130.    if aTurbine.getEnergyStored() > 100 and aTurbine.getFluidFlowRateMax() >= 2000 then
  131.     aTurbine.setFluidFlowRateMax(50)
  132.     steam = steam -1950
  133.    end
  134.      if aTurbine.getEnergyStored() < 100 and aTurbine.getFluidFlowRateMax() <= 50 then
  135.        aTurbine.setFluidFlowRateMax(2000)
  136.        steam = steam +1950
  137.       end
  138.   end
  139.  end
  140.  
  141.  sleep(0,01)
  142.  
  143.  
  144.  -- print
  145.  shell.run("clear")
  146.  print("ControlRodLevel: ", reactor.getControlRodLevel(1))
  147.    mon.setCursorPos(1,1)
  148.    mon.write("Control Rod Level: ")
  149.    mon.setCursorPos(20,1)
  150.    mon.write(reactor.getControlRodLevel(1))
  151.  print("       SteamOut: ", reactor.getHotFluidProducedLastTick(), "/", steam)
  152.    mon.setCursorPos(7,2)
  153.    mon.write("Steam Out:        /")
  154.    mon.setCursorPos(18,2)
  155.    mon.write(reactor.getHotFluidProducedLastTick())
  156.    mon.setCursorPos(26,2)
  157.    mon.write(steam)
  158.  print("       Turbinen: ", active, "/", count)
  159.    mon.setCursorPos(7,3)
  160.    mon.write("Turbines:     /")
  161.    mon.setCursorPos(17,3)
  162.    mon.write(active)
  163.    mon.setCursorPos(22,3)
  164.    mon.write(count)
  165.  print("       Target Speed:  ", targetspeed)
  166.    mon.setCursorPos(7,4)
  167.    mon.write("Target Speed: ")
  168.    mon.setCursorPos(21,4)
  169.    mon.write(targetspeed)
  170.  --write turn on  
  171.    mon.setCursorPos(5,6)
  172.    mon.write(turnon)
  173.    
  174. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement