Advertisement
Entityreborn

Untitled

Jan 20th, 2022
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. local t = peripheral.find("turbine")
  2. local r = peripheral.find("fissionReactor")
  3. local i = peripheral.find("inductionMatrix")
  4. local m = peripheral.find("monitor")
  5.  
  6. local onCooldown = false
  7. local energyFull = false
  8.  
  9. local function nothing()
  10. end
  11.  
  12. local function formatNumber(count, aNumber)
  13.     return ("%0." .. count .. "f"):format(aNumber)
  14. end
  15.  
  16. local function formatBigNumber(work, append, sizes)
  17.     if (work == 0) then return work .. append end
  18.   local i = math.floor(math.log(work) / math.log(1000)) + 1
  19.   return tostring(string.format("%0.2f", (work / 1000 ^ (i - 1)))) .. sizes[i] .. append
  20. end
  21.  
  22. local function formatEnergy(num)
  23.     return formatBigNumber(num, "fe", {"","K","M","G","T"})
  24. end
  25.  
  26. local function formatLiquid(num)
  27.     return formatBigNumber(num, "B", {"m","","K","M","G"})
  28. end
  29.  
  30. while (true)
  31. do
  32.     sleep(1);
  33.  
  34.     -- induction
  35.     local inductionEnergyPct = i.getEnergyFilledPercentage()
  36.     local inductionEnergy = i.getEnergy()
  37.     local inductionEnergyMax = i.getMaxEnergy()
  38.  
  39.     -- reactor
  40.     local reactorSteamPct = r.getHeatedCoolantFilledPercentage()
  41.     local reactorSteam = r.getHeatedCoolant().amount
  42.     local reactorCoolantPct = r.getCoolantFilledPercentage()
  43.     local reactorCoolant = r.getCoolant().amount
  44.     local reactorTemp = r.getTemperature()
  45.     local reactorBurnRate = r.getBurnRate()
  46.     local reactorStatus = r.getStatus()
  47.  
  48.     -- turbine
  49.     local turbineSteamPct = t.getSteamFilledPercentage()
  50.     local turbineSteam = t.getSteam()
  51.     local turbineEnergyProd = t.getProductionRate()
  52.  
  53.     local desiredAction = r.activate -- r.activate, r.scram, nothing
  54.  
  55.     if (inductionEnergyPct > 0.95 and not energyFull)
  56.     then
  57.         desiredAction = r.scram
  58.         energyFull = true
  59.     end
  60.  
  61.     if (inductionEnergyPct < 0.1 and energyFull)
  62.     then
  63.         desiredAction = r.activate
  64.         energyFull = false
  65.     end
  66.  
  67.     if (reactorSteamPct > 0.9 or reactorCoolantPct < 0.1 and not onCooldown)
  68.     then
  69.         desiredAction = r.scram
  70.         onCooldown = true
  71.     end
  72.  
  73.     if (reactorSteamPct < 0.9 and reactorCoolantPct > 0.9 and onCooldown)
  74.     then
  75.         desiredAction = r.activate
  76.         onCooldown = false
  77.     end
  78.  
  79.     desiredAction()
  80.  
  81.     m.clear()
  82.     m.setCursorPos(1, 1)
  83.     m.write("Energy stored:   " .. formatNumber(2, inductionEnergyPct * 100) .. "%")
  84.     m.setCursorPos(1, 2)
  85.     m.write("                 " .. formatEnergy(inductionEnergy) .. " / " .. formatEnergy(inductionEnergyMax))
  86.  
  87.     m.setCursorPos(1, 4)
  88.     m.write("Reactor burnrate:" .. reactorBurnRate .. "mB/t")
  89.     m.setCursorPos(1, 5)
  90.     m.write("Reactor coolant: " .. formatNumber(2, reactorCoolantPct * 100) .. "% (" .. formatLiquid(reactorCoolant) .. ")")
  91.     m.setCursorPos(1, 6)
  92.     m.write("Reactor steam:   " .. formatNumber(2, reactorSteamPct * 100) .. "% (" .. formatLiquid(reactorSteam) .. ")")
  93.     m.setCursorPos(1, 7)
  94.     m.write("Reactor temp:    " .. formatNumber(2, reactorTemp) .. "K")
  95.  
  96.     m.setCursorPos(1, 9)
  97.     m.write("Turbine prod:    " .. formatEnergy(turbineEnergyProd) .. "")
  98.     m.setCursorPos(1, 10)
  99.     m.write("Turbine steam:   " .. formatNumber(2, turbineSteamPct * 100) .. "% (" .. formatLiquid(turbineSteam) .. ")")
  100. end
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement