Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Hello.")
- print(" ")
- event.ignoreAll()
- DEBUG_ACTIVE=false
- BELTSPEED=470
- -- Some basic functions toolbox
- raise = computer.panic
- -- String padding
- function pad(str, len) return (' '):rep(len-#str)..str end
- -- Sorted iterator
- function spairs(t) local keys = {} for k in pairs(t) do keys[#keys+1] = k end table.sort(keys) local i = 0
- return function() i = i + 1 if keys[i] then return keys[i], t[keys[i]] end end end
- -- Does a string startrs with another ?
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- -- Debug print
- function debug(text, force) if (DEBUG_ACTIVE or force==1) then print(text) end end
- -- I/O Pannel
- board = component.proxy(component.findComponent("Keybd"))[1]
- event.listen(board)
- modules = board.getModules(board)
- -- Register control panel buttons as events
- panels = {}
- for n, m in pairs(modules) do
- event.listen(m)
- debug("Listening to module " .. n .. " " .. m.internalName, 1)
- if m:getType().name == "ModuleTextDisplay_C" then table.insert(panels, m) end
- end
- -- Hook network components
- components = component.findComponent("")
- debug(#components .. " components in network")
- assemblers = {}
- for n, c in pairs(components) do
- comp = component.proxy(c)
- type = comp:getType().name
- debug(n..": "..type)
- if type=="Build_AssemblerMk1_C" then table.insert(assemblers, comp)
- elseif type=="Build_ConstructorMk1_C" then table.insert(assemblers, comp)
- elseif type=="Build_ManufacturerMk1_C" then table.insert(assemblers, comp)
- elseif type=="Mirror_Refinery_C" then table.insert(assemblers, comp)
- elseif type=="Build_OilRefinery_C" then table.insert(assemblers, comp)
- elseif type=="Build_Packager_C" then table.insert(assemblers, comp)
- end
- end
- print(#assemblers.." assemblers found.")
- clock = assemblers[1].potential
- -- Main loop
- while true do
- print("\n\n\n\n\n\nClock setting= "..clock)
- panels[1].text = "Clock= "..clock
- inputs = {}
- outputs = {}
- for _, ass in pairs(assemblers) do
- ass.potential = clock
- recipe = ass:getRecipe()
- prod = recipe:getProducts()
- dur = recipe.duration
- for _, i in pairs(recipe:getIngredients()) do
- inputs[i.type.name] = (inputs[i.type.name] or 0) + (i.amount / dur)
- end
- for _, i in pairs(recipe:getProducts()) do
- outputs[i.type.name] = (inputs[i.type.name] or 0) + (i.amount / dur)
- end
- end
- print("\n Item | flow | belts\n")
- for key, i in spairs(inputs) do
- print(pad(key, 20).." | ".. pad(""..-i*60*clock, 8) .."/mn | ".. math.floor(i*60*clock/BELTSPEED*100).. "%")
- end
- print("")
- for key, i in spairs(outputs) do
- print(pad(key, 20).." | ".. pad(""..i*60*clock, 8) .."/mn | ".. math.floor(i*60*clock/BELTSPEED*100) .. "%")
- end
- e, s, test = event.pull(10)
- if e ~= nil then
- print("--Event-- ".. s:getType().name.." "..e)
- if s:getType().name == "ModuleSwitch_C" then
- for _, ass in pairs(assemblers) do
- ass.standby = not s.state
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement