Is there an easy way to remove a circuit connection from a number of objects all in one gulp? A destructor for these? I can't find a "circuit signal" filter in the destruction marker.
Reason: I've previously used circuit networks heavily on stations and whatnot, but given they're not really used much and gobble UPS, it'd probably smarter to remove them. But manually removing circuit networks from 144+ objects per station will get tedious...
Re: Bulk removing circuit connections?
Posted: Wed May 16, 2018 12:32 am
by quyxkh
That's mod territory, for a one-off you could, after pasting the blob below, do `/c for e in iterate_network(game.player.selected,green) do e.disconnect_neighbour(green) done`
/c
red = defines.wire_type.red
green = defines.wire_type.green
copper = defines.wire_type.copper
empty={}
function ckey(e,wire,post)
local pos=e.position
return pos.x/2^21+pos.y/2^42 + (post or 0)/2^44 + (wire or 0)/2^46
end
function copper_network_iterator(rs)
local ret,seen = rs[1],rs[2]
local r,k = ret[#ret] ret[#ret]=nil
if r then
for _,n in next,r.neighbours.copper do
k = ckey(n)
if not seen[k] then seen[k]=1 ret[#ret+1]=n end
end
end
return r
end
function iterate_copper_network(e)
local ret, seen = {e}, {[ckey(e)]=true}
return copper_network_iterator,{ret,seen}
end
circuit={['arithmetic-combinator']=2, ['decider-combinator']=2}
function network_iterator(rsw)
local ret,seen,wire = rsw[1], rsw[2], rsw[3]
local r,k = ret[#ret] ret[#ret]=nil
if r then
for _,n in next,r.e.circuit_connection_definitions or empty do
if n.wire == wire and n.source_circuit_id == r.post then
local e,post = n.target_entity, n.target_circuit_id
k = ckey(e,wire,post)
if not seen[k] then
seen[k]=1
ret[#ret+1] = {e=e, post=n.target_circuit_id}
end
end
end
return r.e
end
return nil
end
function iterate_network(e,w,c)
local wire,post = defines.wire_type[w] or w, c or circuit[e.type] or 1
if wire==copper then return iterate_copper_network(e) end
local ret, seen = {{e=e, post=post}}, {[ckey(e,wire,post)]=1}
return network_iterator,{ret,seen,wire}
end
function read_signals(e,w,c)
local r = {item={}, fluid={}, virtual={}}
if w=='both' or w=='all' then return {
red=read_signals(e,red,c),
green=read_signals(e,green,c)
}
end
local n = e.get_circuit_network(
defines.wire_type[w] or w, c or circuit[e.type] or 1)
for _,s in next,n and n.signals or empty do
r[s.signal.type][s.signal.name] = s.count
end
return r
end
Re: Bulk removing circuit connections?
Posted: Wed May 16, 2018 7:00 am
by Aeternus
Mkay, I want to do this with selected structures, not factory-wide. But that code snipplet should help, I should be able to combine it with the way the deconstruction planner works to create a selectable "circuit disconnector" item. Thanks