TwitchBlade

reactorControl_0.0.11

Sep 15th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. c = require("component")
  2.  
  3.  
  4.  
  5. r = c.br_reactor
  6. tList = {}
  7. controlLevel = 50
  8. tTotals = {}
  9. tTotals["steamNeed"] = 0
  10. tTotals["energyOutput"] = 0
  11. targetSpeed = 1800
  12.  
  13.  
  14. function startReactor()
  15.   r.setActive(true)
  16.   r.setAllControlRodLevels(50)
  17. end
  18.  
  19. function startTurbine()
  20.   tListBuild()
  21.   for k, v in pairs(tList) do
  22.     c.invoke(k, "setActive", true)
  23.     c.invoke(k, "setInductorEngaged", false)
  24.     c.invoke(k, "setFluidFlowRateMax", 1000)
  25.   end
  26. end
  27.  
  28. function updateTotals()
  29.   tTotals["steamNeed"] = 0
  30.   for k, v in pairs(tList) do
  31.     tTotals["steamNeed"] = tTotals["steamNeed"] + c.invoke(k, "getFluidFlowRateMax")
  32.     tTotals["energyOutput"] = tTotals["energyOutput"] + c.invoke(k, "getEnergyProducedLastTick")
  33.   end
  34.   print("steam needed " .. tostring(tTotals["steamNeed"]))
  35. end
  36.  
  37. function monReactor()
  38.   updateTotals()
  39.   if r.getHotFluidProducedLastTick() < tTotals["steamNeed"] then
  40.     if controlLevel > 0 then controlLevel = controlLevel - 1 end
  41.   else
  42.     if controlLevel < 100 then controlLevel = controlLevel + 1 end
  43.   end
  44.  
  45.   print(r.getContolRodLevel(1)
  46.   r.setAllControlRodLevels(controlLevel)
  47. end
  48.  
  49. function tListBuild()
  50.   for k, v in c.list("br_turbine") do
  51.     tList[k] = {}
  52.     tList[k]["steamUsed"] = c.invoke(k, "getFluidFlowRateMax")
  53.     tList[k]["isActive"] = false
  54.     tList[k]["coilsEngaged"] = false
  55.     tList[k]["rotorSpeed"] = 0
  56.     tList[k]["energyOutput"] = 0
  57.   end
  58. end
  59.  
  60. function tSpeedControl()
  61.   for k, v in pairs(tList) do
  62.     tList[k]["rotorSpeed"] = c.invoke(k, "getRotorSpeed")
  63.     if tList[k]["rotorSpeed"] > 1800 and tList[k]["rotorSpeed"] < 1810 then
  64.       tList[k]["steamUsed"] = tList[k]["steamUsed"] - 1
  65.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  66.     elseif tList[k]["rotorSpeed"] > 1900 then
  67.       tList[k]["steamUsed"] = tList[k]["steamUsed"] - 10
  68.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  69.     elseif tList[k]["rotorSpeed"] < 1800 and tList[k]["rotorSpeed"] > 1790 then
  70.       tList[k]["steamUsed"] = tList[k]["steamUsed"] + 1
  71.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  72.     elseif tList[k]["rotorSpeed"] < 1700 then
  73.       tList[k]["steamUsed"] = tList[k]["steamUsed"] + 10
  74.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  75.     end
  76.   end
  77. end
  78.  
  79. function tListData()
  80.   for k, v in pairs(tList) do
  81.     for l, b in pairs(tList[k]) do
  82.       print(tList[k][l])
  83.     end
  84.   end
  85. end
  86.  
  87.  
  88. --Main code block
  89. startTurbine()
  90. for i = 1,200 do
  91.   monReactor()
  92.   tSpeedControl()
  93.   os.sleep(0.1)
  94. end
  95. for i = 1,200 do
  96.   monReactor()
  97.   tSpeedControl()
  98.   os.sleep(2)
  99. end
Advertisement
Add Comment
Please, Sign In to add comment