Could you send me the savegame please (via forum https://forums.factorio.com/memberlist.php?mode=viewprofile&u=73318 or discord (Sladki#3245)). It seems that I've messed up with DC network.
/c
local function wire_connections(entity, wire, connections)
connections = connections or {}
connections[entity.unit_number] = {
entity = entity,
neighbours = {}
}
for _, connected in pairs(entity.circuit_connected_entities[wire]) do
table.insert(connections[entity.unit_number].neighbours, connected)
if not connections[connected.unit_number] then
connections = wire_connections(connected, wire, connections)
end
end
return connections
end
for _, dc in pairs(game.player.surface.find_entities_filtered({
name = "sdc-dc-small",
force = game.player.force
})) do
for _, wire in pairs({ "red", "green" }) do
local connections = wire_connections(dc, wire)
for _, action in pairs({
"disconnect_neighbour",
"connect_neighbour"
}) do
local target = { wire = defines.wire_type[wire] }
for _, connection in pairs(connections) do
for _, neighbour in pairs(connection.neighbours) do
target.target_entity = neighbour
connection.entity[action](target)
end
end
end
end
end