Advertisement
Altaric

Satisfactory factory

Jun 27th, 2021
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. print("Hello.")
  2. print(" ")
  3. event.ignoreAll()
  4. DEBUG_ACTIVE=false
  5. BELTSPEED=470
  6.  
  7. -- Some basic functions toolbox
  8. raise = computer.panic
  9. -- String padding
  10. function pad(str, len)  return (' '):rep(len-#str)..str end  
  11. -- Sorted iterator
  12. function spairs(t)    local keys = {}    for k in pairs(t) do keys[#keys+1] = k end    table.sort(keys)    local i = 0
  13.     return function()        i = i + 1        if keys[i] then            return keys[i], t[keys[i]]        end    end end
  14. -- Does a string startrs with another ?
  15. function string.starts(String,Start)
  16.    return string.sub(String,1,string.len(Start))==Start
  17. end
  18. -- Debug print
  19. function debug(text, force) if (DEBUG_ACTIVE or force==1) then print(text) end  end
  20.  
  21.  
  22. -- I/O Pannel
  23. board = component.proxy(component.findComponent("Keybd"))[1]
  24. event.listen(board)
  25. modules = board.getModules(board)
  26.  
  27. -- Register control panel buttons as events
  28. panels = {}
  29. for n, m in pairs(modules) do
  30.   event.listen(m)
  31.   debug("Listening to module " .. n .. " " .. m.internalName, 1)  
  32.   if m:getType().name == "ModuleTextDisplay_C" then table.insert(panels, m) end
  33. end
  34.  
  35.  
  36. -- Hook network components
  37. components = component.findComponent("")
  38. debug(#components .. " components in network")
  39. assemblers = {}
  40. for n, c in pairs(components) do
  41.   comp = component.proxy(c)
  42.  
  43.   type = comp:getType().name
  44.   debug(n..": "..type)
  45.   if     type=="Build_AssemblerMk1_C" then table.insert(assemblers, comp)
  46.   elseif type=="Build_ConstructorMk1_C" then table.insert(assemblers, comp)
  47.   elseif type=="Build_ManufacturerMk1_C" then table.insert(assemblers, comp)
  48.   elseif type=="Mirror_Refinery_C" then table.insert(assemblers, comp)
  49.   elseif type=="Build_OilRefinery_C" then table.insert(assemblers, comp)
  50.   elseif type=="Build_Packager_C" then table.insert(assemblers, comp)
  51.   end
  52. end
  53. print(#assemblers.." assemblers found.")
  54.  
  55. clock = assemblers[1].potential
  56.  
  57. -- Main loop
  58. while true do
  59.   print("\n\n\n\n\n\nClock setting= "..clock)
  60.   panels[1].text = "Clock= "..clock
  61.   inputs = {}
  62.   outputs = {}
  63.   for _, ass in pairs(assemblers) do
  64.     ass.potential = clock
  65.     recipe = ass:getRecipe()
  66.     prod = recipe:getProducts()
  67.     dur = recipe.duration
  68.     for _, i in pairs(recipe:getIngredients()) do
  69.       inputs[i.type.name] = (inputs[i.type.name] or 0) + (i.amount / dur)
  70.     end
  71.     for _, i in pairs(recipe:getProducts()) do
  72.       outputs[i.type.name] = (inputs[i.type.name] or 0) + (i.amount / dur)
  73.     end
  74.   end
  75.  
  76.   print("\n        Item         |    flow     | belts\n")
  77.   for key, i in spairs(inputs) do
  78.     print(pad(key, 20).." | ".. pad(""..-i*60*clock, 8) .."/mn | ".. math.floor(i*60*clock/BELTSPEED*100).. "%")
  79.   end
  80.   print("")
  81.   for key, i in spairs(outputs) do
  82.     print(pad(key, 20).." | ".. pad(""..i*60*clock, 8) .."/mn | ".. math.floor(i*60*clock/BELTSPEED*100) .. "%")
  83.   end
  84.  
  85.   e, s, test = event.pull(10)
  86.   if e ~= nil then
  87.     print("--Event-- ".. s:getType().name.." "..e)
  88.     if s:getType().name == "ModuleSwitch_C" then
  89.       for _, ass in pairs(assemblers) do
  90.         ass.standby = not s.state
  91.       end
  92.     end
  93.   end
  94. end
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement