Advertisement
Sensei_nippletit

Fluid reactor control

Jan 26th, 2022 (edited)
557
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local math = require("math")
  5. local sides = require("sides")
  6. local tunnel = component.tunnel
  7. local gpu = component.gpu
  8.  
  9. local function get_redstone_proxy(redstone_n)
  10.   component.proxy(redstone_n).setOutput(sides.west, 0)
  11. end
  12.  
  13. local redstone_table = {
  14.   {redstone_1 = component.get("31d29c81-d6aa-43ec-9225-dc003dd0c588")},
  15.   {redstone_2 = component.get("c5186033-eaaa-4b1c-9ca1-3307eefbfd13")},
  16.   {redstone_3 = component.get("728e3d6c-127c-4cdd-9095-91007064cb56")},
  17.   {redstone_4 = component.get("1fe7fb6f-5457-4dd8-bf22-e16e9be17897")},
  18.   {redstone_5 = component.get("4e76885d-6658-452a-891f-c3e73a765330")},
  19.   {redstone_6 = component.get("b84b94b4-7b82-4fbb-a78b-315b15a31dfa")},
  20.   {redstone_7 = component.get("c7ca2131-f491-4231-a56d-9b14211ed963")},
  21.   {redstone_8 = component.get("92ddf86a-6639-423e-ab25-c6c6abf9b0eb")}
  22. }
  23.  
  24. local function reactor_shutdown()
  25.   i = 1
  26.   for k, v in pairs(redstone_table) do
  27.     for comp_name, comp_addr in pairs(v) do
  28.       get_redstone_proxy(comp_addr)
  29.       print("reactor "..i.." shutting down")
  30.       i = i + 1
  31.     end
  32.   end
  33. end
  34.  
  35. reactor_shutdown()
  36.  
  37. local transposer_1 = component.get("ef72dc37-6041-481b-862c-00e2a51e63f7")
  38. local transposer_2 = component.get("88c9aeaa-6c26-443d-8567-7418ffdf3f91")
  39. local transposer_3 = component.get("691bdc37-0919-44ca-8cfb-3f16140aa65f")
  40. local transposer_4 = component.get("25336fe5-99c6-446c-9e3a-3268210545c6")
  41. local transposer_5 = component.get("1823024b-91c7-43ed-b946-4eff7e90c86b")
  42. local transposer_6 = component.get("a62823bf-8077-42e8-b5c3-fa3f4847ac5a")
  43. local transposer_7 = component.get("de034f28-90d4-4f5e-bb75-93cf3f83298e")
  44. local transposer_8 = component.get("aa4e2e3f-ebf7-417d-92f9-d2f63cdcc7ed")
  45.  
  46. local transposer_table = {
  47. {transposer_1 = component.get("ef72dc37-6041-481b-862c-00e2a51e63f7")},
  48. {transposer_2 = component.get("88c9aeaa-6c26-443d-8567-7418ffdf3f91")},
  49. {transposer_3 = component.get("691bdc37-0919-44ca-8cfb-3f16140aa65f")},
  50. {transposer_4 = component.get("25336fe5-99c6-446c-9e3a-3268210545c6")},
  51. {transposer_5 = component.get("1823024b-91c7-43ed-b946-4eff7e90c86b")},
  52. {transposer_6 = component.get("a62823bf-8077-42e8-b5c3-fa3f4847ac5a")},
  53. {transposer_7 = component.get("de034f28-90d4-4f5e-bb75-93cf3f83298e")},
  54. {transposer_8 = component.get("aa4e2e3f-ebf7-417d-92f9-d2f63cdcc7ed")}
  55. }
  56.  
  57. local reactor_1 = component.get("b5fbca13-f6a8-4ee5-9bab-9592681cdec1")
  58. local reactor_2 = component.get("f8eb5468-23b1-49d1-beef-3a097e63cd11")
  59. local reactor_3 = component.get("e151fa4c-7ca5-4013-b801-9ab6ddea6303")
  60. local reactor_4 = component.get("f68d4a74-9346-4375-9de8-74e587970e0c")
  61. local reactor_5 = component.get("86422691-b4a9-4f39-b7be-68256adf09aa")
  62. local reactor_6 = component.get("921b3752-945a-426b-b297-d006a718459c")
  63. local reactor_7 = component.get("553fd0e7-3a87-477c-b328-54f920e04c07")
  64. local reactor_8 = component.get("4e5d8c47-4243-41de-bf13-4e92be338557")
  65.  
  66. local function rod_state(transposer_n)
  67.   check_nil = component.proxy(transposer_n).getStackInSlot(sides.west, 10)
  68.   i = 1
  69.   while check_nil == nil do
  70.     os.sleep(0.1)
  71.     print('waiting rod_state'..i)
  72.     i = i + 1
  73.   end
  74.   rod_state_result = component.proxy(transposer_n).getStackInSlot(sides.west, 10).damage
  75.   return rod_state_result
  76. end
  77.  
  78. local function rod_max_health(transposer_n)
  79.   check_nil = component.proxy(transposer_n).getStackInSlot(sides.west, 10)
  80.   i = 1
  81.   while check_nil == nil do
  82.     os.sleep(0.1)
  83.     print('waiting rod_max_health'..i)
  84.     i = i + 1
  85.   end
  86.   rod_max_health_result = component.proxy(transposer_n).getStackInSlot(sides.west, 10).maxDamage
  87.   return rod_max_health_result
  88. end
  89.  
  90. local function fuel_remaining(rod_state, rod_max_health)
  91.   fuel_remaining_result = (100 * (rod_max_health - rod_state) / rod_max_health)
  92.   return fuel_remaining_result
  93. end
  94.  
  95. local function core_heat(reactor_n)
  96.   current_heat_result = component.proxy(reactor_n).getHeat()
  97.   return current_heat_result
  98. end
  99.  
  100. local function max_heat(reactor_n)
  101.   max_heat_result = component.proxy(reactor_n).getMaxHeat()
  102.   return max_heat_result
  103. end
  104.  
  105. local function percentage_heat(core_heat, max_heat)
  106.   percentage_heat_result = math.floor((core_heat / max_heat) * 100)
  107.   return percentage_heat_result
  108. end
  109.  
  110. local function fuel_type_check(transposer_n)
  111.   check_nil = component.proxy(transposer_n).getStackInSlot(sides.west, 10)
  112.   i = 1
  113.   while check_nil == nil do
  114.     os.sleep(0.1)
  115.     print('waiting fuel_type_check'..i)
  116.     i = i + 1
  117.   end
  118.   fuel_type = component.proxy(transposer_n).getStackInSlot(sides.west, 10)["label"]
  119.   return fuel_type
  120. end
  121.  
  122. term.clear() -- uncomment
  123. local function reactor_control()
  124.   repeat
  125.    
  126.     reactor_shutdown()
  127.     os.sleep(5)
  128.     term.clear() -- uncomment
  129.  
  130.     i = 0
  131.     for i=1, 100 do
  132.       term.clearLine()
  133.       print("REACTOR CYCLE: "..i.."/100")
  134.       term.clearLine()
  135.  
  136.       -- local heat_table = {
  137.       -- {heat_1 = percentage_heat(core_heat(reactor_1), max_heat(reactor_1))},
  138.       -- {heat_2 = percentage_heat(core_heat(reactor_2), max_heat(reactor_2))},
  139.       -- {heat_3 = percentage_heat(core_heat(reactor_3), max_heat(reactor_3))},
  140.       -- {heat_4 = percentage_heat(core_heat(reactor_4), max_heat(reactor_4))},
  141.       -- {heat_5 = percentage_heat(core_heat(reactor_5), max_heat(reactor_5))},
  142.       -- {heat_6 = percentage_heat(core_heat(reactor_6), max_heat(reactor_6))},
  143.       -- {heat_7 = percentage_heat(core_heat(reactor_7), max_heat(reactor_7))},
  144.       -- {heat_8 = percentage_heat(core_heat(reactor_8), max_heat(reactor_8))}
  145.       -- }
  146.  
  147.       -- local fuel_table = {
  148.       -- {fuel_1 = fuel_remaining(rod_state(transposer_1), rod_max_health(transposer_1))},
  149.       -- {fuel_2 = fuel_remaining(rod_state(transposer_2), rod_max_health(transposer_2))},
  150.       -- {fuel_3 = fuel_remaining(rod_state(transposer_3), rod_max_health(transposer_3))},
  151.       -- {fuel_4 = fuel_remaining(rod_state(transposer_4), rod_max_health(transposer_4))},
  152.       -- {fuel_5 = fuel_remaining(rod_state(transposer_5), rod_max_health(transposer_5))},
  153.       -- {fuel_6 = fuel_remaining(rod_state(transposer_6), rod_max_health(transposer_6))},
  154.       -- {fuel_7 = fuel_remaining(rod_state(transposer_7), rod_max_health(transposer_7))},
  155.       -- {fuel_8 = fuel_remaining(rod_state(transposer_8), rod_max_health(transposer_8))}
  156.       -- }
  157.  
  158.       term.setCursor(1, 1)
  159.  
  160.       for i=1, 8 do
  161.  
  162.         local reactor_x = 'reactor_' .. i
  163.         local transposer_x = 'transposer_' .. i
  164.  
  165.         local reactor_heat = percentage_heat(core_heat(reactor_x), max_heat(reactor_x))
  166.         local reactor_fuel = fuel_remaining(rod_state(transposer_x), rod_max_health(transposer_x))
  167.  
  168.         if fuel_type_check(transposer_table[i]['transposer_' .. i]) == "Quad Fuel Rod (Depleted Uranium)" then
  169.           term.clearLine()
  170.           print("REACTOR " .. i .. " CORE: " .. 'FUEL DEPLETED')
  171.           term.clearLine()
  172.           print("REACTOR " .. i .. " FUEL: " .. 'FUEL DEPLETED\n')
  173.           tunnel.send('FUEL DEPLETED', 'FUEL DEPLETED')
  174.           component.proxy(redstone_table[i]['redstone_' .. i]).setOutput(sides.west, 0)
  175.                                                               -- transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSlot)
  176.           component.proxy(transposer_table[i]['transposer_' .. i]).transferItem(sides.west, sides.up, 1, 2, 15) -- REACTOR --> CHEST
  177.           component.proxy(transposer_table[i]['transposer_' .. i]).transferItem(sides.west, sides.up, 1, 10, 15) -- REACTOR --> CHEST
  178.           component.proxy(transposer_table[i]['transposer_' .. i]).transferItem(sides.up, sides.west, 1, 1, 2) -- REACTOR <-- CHEST
  179.           component.proxy(transposer_table[i]['transposer_' .. i]).transferItem(sides.up, sides.west, 1, 1, 10) -- REACTOR <-- CHEST
  180.         else
  181.           if reactor_heat > 1 then
  182.             component.proxy(redstone_table[i]['redstone_'.. i]).setOutput(sides.west, 0)
  183.           else
  184.             component.proxy(redstone_table[i]['redstone_'.. i]).setOutput(sides.west, 1)
  185.           end
  186.           term.clearLine()
  187.           print("REACTOR " .. i .. " CORE: " .. reactor_heat .. " %")
  188.           term.clearLine()
  189.           print("REACTOR " .. i .. " FUEL: " .. reactor_fuel .. " %\n")
  190.           tunnel.send(reactor_heat, reactor_fuel)
  191.         end
  192.       end
  193.       term.clearLine()
  194.  
  195.       event.pull(0.05, "interrupted")
  196.  
  197.     end
  198.  
  199.   until event.pull(0.05) == "interrupted"
  200.  
  201.   return reactor_shutdown()
  202. end
  203.  
  204. local function myerrorhandler(err)
  205.    print("ERROR:", err)
  206. end
  207.  
  208. if xpcall(reactor_control, myerrorhandler) then
  209.   reactor_control()
  210. else
  211.   -- term.clear()
  212.   reactor_shutdown()
  213.   print("error in program, terminating..")
  214. end
  215.  
  216.  
  217. -- for i=1, 8 do
  218. --   heat = percentage_heat(core_heat('reactor_'..i), max_heat('reactor_'..i))
  219. --   fuel = fuel_remaining(rod_state('transposer_'..i), rod_max_health('transposer_'..i))
  220. --   if fuel_type_check(transposer_table[i]['transposer_'..i]) == "Quad Fuel Rod (Depleted Uranium)" then
  221. --     term.clearLine()
  222. --     print("REACTOR " ..i.. " CORE: " .. 'FUEL DEPLETED')
  223. --     term.clearLine()
  224. --     print("REACTOR " ..i.. " FUEL: " .. 'FUEL DEPLETED\n')
  225. --     tunnel.send('FUEL DEPLETED', 'FUEL DEPLETED')
  226. --     component.proxy(redstone_table[i]['redstone_'..i]).setOutput(sides.west, 0)
  227. --                                                         -- transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSlot)
  228. --     component.proxy(transposer_table[i]['transposer_'..i]).transferItem(sides.west, sides.up, 1, 2, 15) -- REACTOR --> CHEST
  229. --     component.proxy(transposer_table[i]['transposer_'..i]).transferItem(sides.west, sides.up, 1, 10, 15) -- REACTOR --> CHEST
  230. --     component.proxy(transposer_table[i]['transposer_'..i]).transferItem(sides.up, sides.west, 1, 1, 2) -- REACTOR <-- CHEST
  231. --     component.proxy(transposer_table[i]['transposer_'..i]).transferItem(sides.up, sides.west, 1, 1, 10) -- REACTOR <-- CHEST
  232. --   else
  233. --     if heat_table[i]['heat_'..i] > 1 then
  234. --       component.proxy(redstone_table[i]['redstone_'..i]).setOutput(sides.west, 0)
  235. --     else
  236. --       component.proxy(redstone_table[i]['redstone_'..i]).setOutput(sides.west, 1)
  237. --     end
  238. --     term.clearLine()
  239. --     print("REACTOR " ..i.. " CORE: " .. heat_table[i]['heat_'..i] .. " %")
  240. --     term.clearLine()
  241. --     print("REACTOR " ..i.. " FUEL: " .. fuel_table[i]['fuel_'..i] .. " %\n")
  242. --     tunnel.send(heat_table[i]['heat_'..i], fuel_table[i]['fuel_'..i])
  243. --   end
  244. -- end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement