TwitchBlade

reactorControl_0.0.8

Sep 15th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. c = require("component")
  2.  
  3.  
  4.  
  5. r = c.br_reactor
  6. tList = {}
  7. target = 0
  8. controlLevel = 0
  9. tTotals = {}
  10. tTotals["steamNeed"] = 0
  11. tTotals["energyOutput"] = 0
  12.  
  13.  
  14. function startReactor()
  15.   r.setActive(true)
  16.   r.setAllControlRodLevels(0)
  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, "getFluidFlowRate")
  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.   print(controlLevel)
  45.   r.setAllControlRodLevels(controlLevel)
  46. end
  47.  
  48. function tListBuild()
  49.   for k, v in c.list("br_turbine") do
  50.     tList[k] = {}
  51.     tList[k]["steamUsed"] = 0
  52.     tList[k]["isActive"] = false
  53.     tList[k]["coilsEngaged"] = false
  54.     tList[k]["rotorSpeed"] = 0
  55.     tList[k]["energyOutput"] = 0
  56.   end
  57. end
  58.  
  59. function tSpeedControl()
  60.  
  61. end
  62.  
  63. function tListData()
  64.   for k, v in pairs(tList) do
  65.     for l, b in pairs(tList[k]) do
  66.       print(tList[k][l])
  67.     end
  68.   end
  69. end
  70.  
  71.  
  72. --Main code block
  73. startTurbine()
  74. while true do
  75.   monReactor()
  76.   os.sleep(1)
  77. end
Advertisement
Add Comment
Please, Sign In to add comment