mirror of
https://github.com/minetest-mods/technic.git
synced 2024-09-27 15:00:18 +02:00
parent
6106921393
commit
260ab8c0fd
|
@ -38,7 +38,6 @@ end
|
||||||
|
|
||||||
local function clear_networks(pos)
|
local function clear_networks(pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local placed = node.name ~= "air"
|
local placed = node.name ~= "air"
|
||||||
local positions = check_connections(pos)
|
local positions = check_connections(pos)
|
||||||
if #positions < 1 then return end
|
if #positions < 1 then return end
|
||||||
|
@ -66,7 +65,6 @@ local function clear_networks(pos)
|
||||||
if technic.is_tier_cable(name, tier) then
|
if technic.is_tier_cable(name, tier) then
|
||||||
table.insert(network.all_nodes,pos)
|
table.insert(network.all_nodes,pos)
|
||||||
elseif technic.machines[tier][node.name] then
|
elseif technic.machines[tier][node.name] then
|
||||||
meta:set_string(tier.."_network",minetest.pos_to_string(sw_pos))
|
|
||||||
if technic.machines[tier][node.name] == technic.producer then
|
if technic.machines[tier][node.name] == technic.producer then
|
||||||
table.insert(network.PR_nodes,pos)
|
table.insert(network.PR_nodes,pos)
|
||||||
elseif technic.machines[tier][node.name] == technic.receiver then
|
elseif technic.machines[tier][node.name] == technic.receiver then
|
||||||
|
|
|
@ -135,36 +135,37 @@ local function add_cable_node(nodes, pos, network_id, queue)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Generic function to add found connected nodes to the right classification array
|
-- 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, network_id, queue)
|
local function check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id, queue)
|
||||||
|
|
||||||
local distance_to_switch = vector.distance(pos, sw_pos)
|
local distance_to_switch = vector.distance(pos, sw_pos)
|
||||||
if distance_to_switch > switch_max_range then
|
if distance_to_switch > switch_max_range then
|
||||||
-- max range exceeded
|
-- max range exceeded
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
technic.get_or_load_node(pos)
|
technic.get_or_load_node(pos)
|
||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
|
|
||||||
if technic.is_tier_cable(name, tier) then
|
if technic.is_tier_cable(name, tier) then
|
||||||
add_cable_node(all_nodes, pos,network_id, queue)
|
add_cable_node(all_nodes, pos, network_id, queue)
|
||||||
elseif machines[name] then
|
elseif machines[name] then
|
||||||
--dprint(name.." is a "..machines[name])
|
--dprint(name.." is a "..machines[name])
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local net_id_key = tier.."_network"
|
local pos_hash = minetest.hash_node_position(pos)
|
||||||
local net_id_new = network_id
|
local net_id_new = network_id
|
||||||
local net_id_old = meta:get_string(net_id_key)
|
local net_id_old = technic.cables[pos_hash]
|
||||||
if net_id_old == "" then
|
if net_id_old == nil then
|
||||||
meta:set_string(net_id_key, net_id_new)
|
technic.cables[pos_hash] = net_id_new
|
||||||
elseif net_id_old ~= net_id_new then
|
elseif net_id_old ~= net_id_new then
|
||||||
-- do not allow running pos from multiple networks, also disable switch
|
-- do not allow running pos from multiple networks, also disable switch
|
||||||
overloaded_networks[net_id_old] = minetest.get_us_time() + (overload_reset_time * 1000 * 1000)
|
overloaded_networks[net_id_old] = minetest.get_us_time() + (overload_reset_time * 1000 * 1000)
|
||||||
overloaded_networks[net_id_new] = overloaded_networks[net_id_old]
|
overloaded_networks[net_id_new] = overloaded_networks[net_id_old]
|
||||||
-- delete caches for conflicting network
|
-- delete caches for conflicting network
|
||||||
technic.networks[net_id_old] = nil
|
technic.networks[net_id_old] = nil
|
||||||
meta:set_string(net_id_key, net_id_new)
|
technic.cables[pos] = net_id_new
|
||||||
meta:set_string("infotext",S("Network Overloaded"))
|
meta:set_string("infotext",S("Network Overloaded"))
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if machines[name] == technic.producer then
|
if machines[name] == technic.producer then
|
||||||
|
@ -186,10 +187,11 @@ local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nod
|
||||||
|
|
||||||
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Traverse a network given a list of machines and a cable type name
|
-- 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, pos, machines, tier, sw_pos, network_id, queue)
|
local function traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, network_id, queue)
|
||||||
local positions = {
|
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-1, y=pos.y, z=pos.z},
|
{x=pos.x-1, y=pos.y, z=pos.z},
|
||||||
|
@ -198,18 +200,21 @@ local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_no
|
||||||
{x=pos.x, y=pos.y, z=pos.z+1},
|
{x=pos.x, y=pos.y, z=pos.z+1},
|
||||||
{x=pos.x, y=pos.y, z=pos.z-1}}
|
{x=pos.x, y=pos.y, z=pos.z-1}}
|
||||||
for i, cur_pos in pairs(positions) do
|
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, network_id, queue)
|
if not check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id, queue) then
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local touch_nodes = function(list, tier)
|
local function touch_nodes(list, tier)
|
||||||
for _, pos in ipairs(list) do
|
for _, pos in ipairs(list) do
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_network = function(network_id, sw_pos, pos1, tier)
|
local function get_network(network_id, sw_pos, pos1, tier)
|
||||||
local cached = technic.networks[network_id]
|
local cached = technic.networks[network_id]
|
||||||
if cached and cached.tier == tier then
|
if cached and cached.tier == tier then
|
||||||
touch_nodes(cached.PR_nodes, tier)
|
touch_nodes(cached.PR_nodes, tier)
|
||||||
|
@ -233,8 +238,10 @@ local get_network = function(network_id, sw_pos, pos1, tier)
|
||||||
while next(queue) do
|
while next(queue) do
|
||||||
local to_visit = {}
|
local to_visit = {}
|
||||||
for _, pos in ipairs(queue) do
|
for _, pos in ipairs(queue) do
|
||||||
traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes,
|
if not traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes,
|
||||||
pos, technic.machines[tier], tier, sw_pos, network_id, to_visit)
|
pos, technic.machines[tier], tier, sw_pos, network_id, to_visit) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
queue = to_visit
|
queue = to_visit
|
||||||
end
|
end
|
||||||
|
@ -312,7 +319,7 @@ technic.switching_station_run = function(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = minetest.get_node(pos1).name
|
local name = minetest.get_node(pos1).name
|
||||||
local network_id = tostring(minetest.hash_node_position(pos1))
|
local network_id = minetest.hash_node_position(pos1)
|
||||||
-- Check if network is overloaded / conflicts with another network
|
-- Check if network is overloaded / conflicts with another network
|
||||||
if overloaded_networks[network_id] then
|
if overloaded_networks[network_id] then
|
||||||
local remaining = reset_overloaded(network_id)
|
local remaining = reset_overloaded(network_id)
|
||||||
|
@ -327,7 +334,7 @@ technic.switching_station_run = function(pos)
|
||||||
local tier = technic.get_cable_tier(name)
|
local tier = technic.get_cable_tier(name)
|
||||||
if tier then
|
if tier then
|
||||||
PR_nodes, BA_nodes, RE_nodes = get_network(network_id, pos, pos1, tier)
|
PR_nodes, BA_nodes, RE_nodes = get_network(network_id, pos, pos1, tier)
|
||||||
if overloaded_networks[network_id] then return end
|
if overloaded_networks[network_id] or PR_nodes == false then return end
|
||||||
else
|
else
|
||||||
--dprint("Not connected to a network")
|
--dprint("Not connected to a network")
|
||||||
meta:set_string("infotext", S("%s Has No Network"):format(machine_name))
|
meta:set_string("infotext", S("%s Has No Network"):format(machine_name))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user