TwitchBlade

0.2.7

Sep 15th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. c = require("component")
  2. e = require("event")
  3. t = require("term")
  4.  
  5.  
  6.  
  7. r = c.br_reactor
  8. tList = {}
  9. controlLevel = 50
  10. tTotals = {}
  11. tTotals["steamNeed"] = 0
  12. tTotals["energyOutput"] = 0
  13. targetSpeed = 1800
  14. event = {}
  15.  
  16. function startReactor()
  17.   r.setActive(true)
  18.   r.setAllControlRodLevels(50)
  19. end
  20.  
  21. function startTurbine()
  22.   tListBuild()
  23.   for k, v in pairs(tList) do
  24.     c.invoke(k, "setActive", true)
  25.     c.invoke(k, "setInductorEngaged", false)
  26.     c.invoke(k, "setFluidFlowRateMax", 2000)
  27.   end
  28. end
  29.  
  30. function updateTotals()
  31.   tTotals["steamNeed"] = 0
  32.   for k, v in pairs(tList) do
  33.     tTotals["steamNeed"] = tTotals["steamNeed"] + c.invoke(k, "getFluidFlowRateMax")
  34.     tTotals["energyOutput"] = tTotals["energyOutput"] + c.invoke(k, "getEnergyProducedLastTick")
  35.   end
  36.   print("steam needed " .. tostring(tTotals["steamNeed"]))
  37. end
  38.  
  39. function monReactor()
  40.   updateTotals()
  41.   if r.getHotFluidProducedLastTick() < tTotals["steamNeed"] then
  42.     if controlLevel > 0 then controlLevel = controlLevel - 1 end
  43.   else
  44.     if controlLevel < 100 then controlLevel = controlLevel + 1 end
  45.   end
  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]["lastRotorSpeed"] = c.invoke(k, "getRotorSpeed")
  54.     tList[k]["isActive"] = false
  55.     tList[k]["coilsEngaged"] = false
  56.     tList[k]["rotorSpeed"] = 0
  57.     tList[k]["energyOutput"] = 0
  58.     tList[k]["turbineStable"] = false
  59.   end
  60. end
  61.  
  62. function tSpeedControl()
  63.   for k, v in pairs(tList) do
  64.     print("Rotor speed " .. tList[k]["rotorSpeed"])
  65.   end
  66. end
  67.  
  68. function tListData()
  69.   for k, v in pairs(tList) do
  70.     for l, b in pairs(tList[k]) do
  71.       print(tList[k][l])
  72.     end
  73.   end
  74. end
  75.  
  76. function tStartup()
  77.   for k, v in pairs(tList) do
  78.     tList[k]["lastRotorSpeed"] = tList[k]["rotorSpeed"]
  79.     tList[k]["rotorSpeed"] = c.invoke(k, "getRotorSpeed")
  80.     if tList[k]["rotorSpeed"] <= 1000 then
  81.       tList[k]["coilsEngaged"] = false
  82.     else
  83.       tList[k]["coilsEngaged"] = true
  84.     end
  85.     acc = tList[k]["rotorSpeed"] - tList[k]["lastRotorSpeed"]
  86.     if acc <= 0 then
  87.       if tList[k]["rotorSpeed"] < 1780 then
  88.         c.invoke(k, "setFluidFlowRateMax", c.invoke(k, "getFluidFlowRateMax") + 10)
  89.         print("adding 10")
  90.       end
  91.     end
  92.     c.invoke(k, "setInductorEngaged", tList[k]["coilsEngaged"])
  93.   end
  94. end
  95.  
  96. --Main code block
  97. startTurbine()
  98. startReactor()
  99. tStartup()
  100. for k, v in pairs(tList) do
  101.   c.invoke(k, "setFluidFlowRateMax", 200)
  102. end
  103. while true do
  104.   event = {e.pull(1)}
  105.   if event[4] == 207 then
  106.     os.exit()
  107.   end
  108.   t.clear()
  109.   monReactor()
  110.   tSpeedControl()
  111. end
Advertisement
Add Comment
Please, Sign In to add comment