Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

power multiplication fix #655

Merged
merged 8 commits into from
Nov 29, 2024
16 changes: 8 additions & 8 deletions technic/machines/register/cables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function check_connections(pos)
return connections
end

local function clear_networks(pos)
function technic.clear_networks(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local placed = node.name ~= "air"
Expand All @@ -68,15 +68,15 @@ local function clear_networks(pos)

-- Actually add it to the (cached) network
-- !! IMPORTANT: ../switching_station.lua -> check_node_subp() must be kept in sync
technic.cables[minetest.hash_node_position(pos)] = network_id
pos.visited = 1
if technic.is_tier_cable(node.name, tier) then
-- Found a cable
technic.cables[minetest.hash_node_position(pos)] = network_id
table.insert(network.all_nodes,pos)
elseif technic.machines[tier][node.name] then
-- Found a machine
local eu_type = technic.machines[tier][node.name]
meta:set_string(tier.."_network", string.format("%.20g", network_id))
meta:set_int(tier.."_EU_timeout", 2)
if eu_type == technic.producer then
table.insert(network.PR_nodes, pos)
elseif eu_type == technic.receiver then
Expand Down Expand Up @@ -169,8 +169,8 @@ function technic.register_cable(tier, size)
node_box = node_box,
connects_to = {"group:technic_"..ltier.."_cable",
"group:technic_"..ltier, "group:technic_all_tiers"},
on_construct = clear_networks,
on_destruct = clear_networks,
on_construct = technic.clear_networks,
on_destruct = technic.clear_networks,
})

local xyz = {
Expand Down Expand Up @@ -209,8 +209,8 @@ function technic.register_cable(tier, size)
node_box = table.copy(node_box),
connects_to = {"group:technic_"..ltier.."_cable",
"group:technic_"..ltier, "group:technic_all_tiers"},
on_construct = clear_networks,
on_destruct = clear_networks,
on_construct = technic.clear_networks,
on_destruct = technic.clear_networks,
}
def.node_box.fixed = {
{-size, -size, -size, size, size, size},
Expand Down Expand Up @@ -295,7 +295,7 @@ end
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(pos)
return technic.clear_networks(pos)
end
end
end
Expand Down
34 changes: 24 additions & 10 deletions technic/machines/switching_station.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ end
-- Add a wire node to the LV/MV/HV network
-- Returns: indicator whether the cable is new in the network
local hash_node_position = minetest.hash_node_position
local function add_network_node(nodes, pos, network_id)
local function add_network_node(nodes, pos, network_id, cable)
SmallJoker marked this conversation as resolved.
Show resolved Hide resolved
local node_id = hash_node_position(pos)
technic.cables[node_id] = network_id
if cable then
technic.cables[node_id] = network_id
end
if nodes[node_id] then
return false
end
Expand All @@ -111,7 +113,7 @@ local function add_network_node(nodes, pos, network_id)
end

local function add_cable_node(nodes, pos, network_id, queue)
if add_network_node(nodes, pos, network_id) then
if add_network_node(nodes, pos, network_id, true) then
queue[#queue + 1] = pos
end
end
Expand All @@ -136,21 +138,31 @@ local check_node_subp = function(network, pos, machines, sw_pos, from_below, net
local meta = minetest.get_meta(pos)
-- Normal tostring() does not have enough precision, neither does meta:set_int()
-- Lua 5.1 bug: Cannot use hexadecimal notation for compression (see LuaJIT #911)
meta:set_string(network.tier.."_network", string.format("%.20g", network_id))
local network_str = string.format("%.20g", network_id)
local network_key = network.tier.."_network"
local m_network_str = meta:get_string(network_key)

if m_network_str == "" then
meta:set_string(network_key, network_str)
else
if m_network_str ~= network_str then
return
end
SmallJoker marked this conversation as resolved.
Show resolved Hide resolved
end

if eu_type == technic.producer then
add_network_node(network.PR_nodes, pos, network_id)
add_network_node(network.PR_nodes, pos, network_id, false)
elseif eu_type == technic.receiver then
add_network_node(network.RE_nodes, pos, network_id)
add_network_node(network.RE_nodes, pos, network_id, false)
elseif eu_type == technic.producer_receiver then
add_network_node(network.PR_nodes, pos, network_id)
add_network_node(network.RE_nodes, pos, network_id)
add_network_node(network.PR_nodes, pos, network_id, false)
add_network_node(network.RE_nodes, pos, network_id, false)
elseif eu_type == technic.battery then
add_network_node(network.BA_nodes, pos, network_id)
add_network_node(network.BA_nodes, pos, network_id, false)
elseif eu_type == "SPECIAL" and from_below and
not vector.equals(pos, sw_pos) then
-- Another switching station -> disable it
add_network_node(network.SP_nodes, pos, network_id)
add_network_node(network.SP_nodes, pos, network_id, false)
meta:set_int("active", 0)
end

Expand Down Expand Up @@ -455,6 +467,7 @@ local function switching_station_timeout_count(pos, tier)
local meta = minetest.get_meta(pos)
local timeout = meta:get_int(tier.."_EU_timeout")
if timeout <= 0 then
meta:set_string(tier.."_network", "")
meta:set_int(tier.."_EU_input", 0) -- Not needed anymore <-- actually, it is for supply converter
return true
else
Expand Down Expand Up @@ -482,6 +495,7 @@ minetest.register_abm({
if nodedef and nodedef.technic_on_disable then
nodedef.technic_on_disable(pos, node)
end
technic.clear_networks(pos)
end
end
end,
Expand Down