Only update the associated network(s) when placing/digging nodes
| | |
| | | return cable_tier[name] |
| | | end |
| | | |
| | | local function clear_networks() |
| | | technic.networks = {} |
| | | local function clear_networks(pos) |
| | | local positions = { |
| | | {x=pos.x+1, y=pos.y, z=pos.z}, |
| | | {x=pos.x-1, y=pos.y, z=pos.z}, |
| | | {x=pos.x, y=pos.y+1, z=pos.z}, |
| | | {x=pos.x, y=pos.y-1, z=pos.z}, |
| | | {x=pos.x, y=pos.y, z=pos.z+1}, |
| | | {x=pos.x, y=pos.y, z=pos.z-1}} |
| | | for _,connected_pos in pairs(positions) do |
| | | if technic.cables[minetest.hash_node_position(connected_pos)] then |
| | | technic.networks[technic.cables[minetest.hash_node_position(connected_pos)]] = nil |
| | | end |
| | | end |
| | | end |
| | | |
| | | function technic.register_cable(tier, size) |
| | |
| | | local function clear_nets_if_machine(pos, node) |
| | | for tier, machine_list in pairs(technic.machines) do |
| | | if machine_list[node.name] ~= nil then |
| | | return clear_networks() |
| | | return clear_networks(pos) |
| | | end |
| | | end |
| | | end |
| | |
| | | meta:set_float("active", false) |
| | | end, |
| | | technic_run = run, |
| | | technic_on_disable = run, |
| | | }) |
| | | |
| | | minetest.register_craft({ |
| | |
| | | -- This way the supplies are separated per network. |
| | | |
| | | technic.networks = {} |
| | | technic.cables = {} |
| | | |
| | | local S = technic.getter |
| | | |
| | |
| | | -------------------------------------------------- |
| | | |
| | | -- Add a wire node to the LV/MV/HV network |
| | | local add_new_cable_node = function(nodes, pos) |
| | | local add_new_cable_node = function(nodes, pos, network_id) |
| | | technic.cables[minetest.hash_node_position(pos)] = network_id |
| | | -- Ignore if the node has already been added |
| | | for i = 1, #nodes do |
| | | if pos.x == nodes[i].x and |
| | |
| | | end |
| | | |
| | | -- Generic function to add found connected nodes to the right classification array |
| | | local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below) |
| | | local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id) |
| | | technic.get_or_load_node(pos) |
| | | local meta = minetest.get_meta(pos) |
| | | local name = minetest.get_node(pos).name |
| | | |
| | | if technic.is_tier_cable(name, tier) then |
| | | add_new_cable_node(all_nodes, pos) |
| | | add_new_cable_node(all_nodes, pos,network_id) |
| | | elseif machines[name] then |
| | | --dprint(name.." is a "..machines[name]) |
| | | if machines[name] == technic.producer then |
| | | add_new_cable_node(PR_nodes, pos) |
| | | add_new_cable_node(PR_nodes, pos, network_id) |
| | | elseif machines[name] == technic.receiver then |
| | | add_new_cable_node(RE_nodes, pos) |
| | | add_new_cable_node(RE_nodes, pos, network_id) |
| | | elseif machines[name] == technic.producer_receiver then |
| | | add_new_cable_node(PR_nodes, pos) |
| | | add_new_cable_node(RE_nodes, pos) |
| | | add_new_cable_node(PR_nodes, pos, network_id) |
| | | add_new_cable_node(RE_nodes, pos, network_id) |
| | | elseif machines[name] == "SPECIAL" and |
| | | (pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and |
| | | from_below then |
| | | -- Another switching station -> disable it |
| | | add_new_cable_node(SP_nodes, pos) |
| | | add_new_cable_node(SP_nodes, pos, network_id) |
| | | meta:set_int("active", 0) |
| | | meta:set_string("active_pos", minetest.serialize(sw_pos)) |
| | | elseif machines[name] == technic.battery then |
| | | add_new_cable_node(BA_nodes, pos) |
| | | add_new_cable_node(BA_nodes, pos, network_id) |
| | | end |
| | | |
| | | meta:set_int(tier.."_EU_timeout", 2) -- Touch node |
| | |
| | | end |
| | | |
| | | -- Traverse a network given a list of machines and a cable type name |
| | | local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos) |
| | | local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos, network_id) |
| | | local pos = all_nodes[i] |
| | | local positions = { |
| | | {x=pos.x+1, y=pos.y, z=pos.z}, |
| | |
| | | {x=pos.x, y=pos.y, z=pos.z-1}} |
| | | --print("ON") |
| | | for i, cur_pos in pairs(positions) do |
| | | check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3) |
| | | check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id) |
| | | end |
| | | end |
| | | |
| | |
| | | local all_nodes = {pos1} |
| | | repeat |
| | | traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, |
| | | i, technic.machines[tier], tier, sw_pos) |
| | | i, technic.machines[tier], tier, sw_pos, minetest.hash_node_position(pos1)) |
| | | i = i + 1 |
| | | until all_nodes[i] == nil |
| | | technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes, |