TwitchBlade

0.0.14

Sep 15th, 2018
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.40 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.getControlRodLevel(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"] < 1830 then
  64.       tList[k]["steamUsed"] = tList[k]["steamUsed"] - 1
  65.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  66.     elseif tList[k]["rotorSpeed"] > 1830 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"] > 1770 then
  70.       tList[k]["steamUsed"] = tList[k]["steamUsed"] + 1
  71.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  72.     elseif tList[k]["rotorSpeed"] < 1770 then
  73.       tList[k]["steamUsed"] = tList[k]["steamUsed"] + 10
  74.       c.invoke(k, "setFluidFlowRateMax", tList[k]["steamUsed"])
  75.     end
  76.     if tList[k]["steamUsed"] < 0 then
  77.       tList[k]["steamUsed"] = 0
  78.     elseif tList[k]["steamUsed"] > 2000 then
  79.       tList[k]["steamUsed"] = 2000
  80.     end
  81.     print("turbine steam used " .. tostring(tList[k]["steamUsed"]))
  82.     if c.invoke(k, "getRotorSpeed") > 1800 then
  83.       tList[k]["coilsEngaged"] = true
  84.     elseif c.invoke(k, "getRotorSpeed") < 1600 then
  85.       tList[k]["coilsEngaged"] = false
  86.     end
  87.     c.invoke(k, "setInductorEngaged", tList[k]["coilsEngaged"])
  88.     print("Coils engaged " .. tostring(tList[k]["coilsEngaged"]))
  89.   end
  90. end
  91.  
  92. function tListData()
  93.   for k, v in pairs(tList) do
  94.     for l, b in pairs(tList[k]) do
  95.       print(tList[k][l])
  96.     end
  97.   end
  98. end
  99.  
  100.  
  101. --Main code block
  102. --startTurbine()
  103. --startReactor()
  104. while true do
  105.   timerCode = os.startTimer(1)
  106.   event, side, x, y
  107.   print(event)
  108.   repeat
  109.   event, side, x, y = os.pullEvent()
  110.     print(event)
  111.     if event == "timer" then
  112.       print(timerCode..":"..side)
  113.       if timerCode ~= side then
  114.         print("Wrong Code")
  115.       else
  116.         print("Right Code")
  117.       end
  118.     end
  119.   until event ~= "timer" or timerCode == side
  120.   print("this happened")
  121. end
  122. --for i = 1,2000 do
  123. --  monReactor()
  124. --  tSpeedControl()
  125. --  os.sleep(0.1)
  126. --end
Advertisement
Add Comment
Please, Sign In to add comment