Advertisement
koriar

corecomp

Feb 8th, 2021 (edited)
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. function periphSearch(type)
  2.    local names = peripheral.getNames()
  3.    local i, name
  4.    for i, name in pairs(names) do
  5.       if peripheral.getType(name) == type and name ~= "right" then
  6.          return peripheral.wrap(name)
  7.       end
  8.    end
  9.    return null
  10. end
  11.  
  12. -- notes
  13. -- It doesn't really know what to do if it should be charging but the reactor is taking more than it gives.
  14. -- It'll kind of naturally stop the gate, but the display is weird
  15.  
  16.  
  17. -- functions end
  18. -- peripheral setup start
  19.  
  20. monitor = peripheral.wrap("top")
  21.  
  22. if monitor == null then
  23.     monitor = periphSearch("monitor")
  24. end
  25.  
  26. if monitor ~= null then
  27.     term.redirect(monitor)
  28. end
  29.  
  30. gate1 = peripheral.wrap("back")
  31. core1 = periphSearch("draconic_rf_storage")
  32.  
  33. -- peripheral end
  34. -- variables
  35.  
  36. local energy, maxenergy, perenergy, transfer, state
  37.  
  38. --main loop start
  39.  
  40. while true do
  41.     sleep(1)
  42.     energy = core1.getEnergyStored()
  43.     maxenergy = core1.getMaxEnergyStored()
  44.     perenergy = math.floor(energy / maxenergy * 100)
  45.     term.clear()
  46.  
  47.     if perenergy < 50 then
  48.         gate1.setSignalLowFlow(0)
  49.         print("Reactor buffer below 50%. Stopping flow to public.")
  50.         print("Setting gate to ",gate1.getSignalLowFlow())
  51.     elseif perenergy >= 90 then
  52.         gate1.setSignalLowFlow(core1.getTransferPerTick() + gate1.getSignalLowFlow() + 1000)
  53.         print("Core is near full. Draining a bit.")
  54.         print("Current net rate is: ", core1.getTransferPerTick())
  55.         print("Setting gate to ",gate1.getSignalLowFlow())
  56.     elseif core1.getTransferPerTick() == 0 then
  57.         gate1.setSignalLowFlow(0)
  58.         print("It seems like the core isn't getting energy. Clamping output")
  59.         print("Setting gate to ",gate1.getSignalLowFlow())
  60.     elseif perenergy > 80 and perenergy <= 90 then
  61.         print("Core is bouncing between 80-90% so it doesn't just go crazy.")
  62.         print("Core percent full: ",perenergy,"%")
  63.         print("Core rate: ",core1.getTransferPerTick())
  64.         print("Gate Rate: ",gate1.getSignalLowFlow())
  65.     elseif perenergy >= 50 then
  66.         gate1.setSignalLowFlow(core1.getTransferPerTick() + gate1.getSignalLowFlow() - 1000)
  67.         print("Core is filling up. Trying to get the current rate to 1kRF")
  68.         print("Current rate is: ", core1.getTransferPerTick())
  69.         print("Setting gate to ",gate1.getSignalLowFlow())
  70.     else
  71.         print("I don't know how to react to the current state. Complain to Koriar.")
  72.         print("Core percent full: ",perenergy,"%")
  73.         print("Core rate: ",core1.getTransferPerTick())
  74.         print("Gate Rate: ",gate1.getSignalLowFlow())
  75.     end
  76.    
  77. end
  78.  
  79. --main loop end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement