Fix some issues with power flowing

This commit is contained in:
mrkubax10 2023-11-21 20:28:09 +01:00
parent f3d05ac5bb
commit 68ddf0f149
4 changed files with 7 additions and 11 deletions

View File

@ -221,16 +221,16 @@ end
-- \brief Transfers power from source node to it's network, if sides is set then power will be only transfered to network connected to that sides
-- \param pos Vector with position of source node
-- \param (optional) sides table with Vectors
-- \param (optional) flowOverride number
-- \returns two values: true if any neighbouring node has room for more power, false otherwise
-- true if any power was transferred, false otherwise
industrialtest.api.powerFlow=function(pos,sides)
industrialtest.api.powerFlow=function(pos,sides,flowOverride)
local meta=minetest.get_meta(pos)
-- if machine doesn't have network map then it's not capable of transferring power
local network=industrialtest.api.getNetwork(meta)
if not network or #network==0 then
return false,false
end
local powerFlow=meta:get_int("industrialtest.powerFlow")
local endpointCount=0
for _,endpoint in ipairs(network) do
local endpointMeta=minetest.get_meta(endpoint.position)
@ -241,11 +241,11 @@ industrialtest.api.powerFlow=function(pos,sides)
if endpointCount==0 then
return false,false
end
local powerDistribution=math.floor(powerFlow/endpointCount)
local powerDistribution=math.floor((flowOverride and flowOverride or meta:get_int("industrialtest.powerFlow"))/endpointCount)
local transferred=false
local roomAvailable=false
for _,endpoint in ipairs(network) do
if not side or sides[endpoint.sourceSide] then
if not sides or sides[endpoint.sourceSide] then
local endpointMeta=minetest.get_meta(endpoint.position)
if powerDistribution<=endpoint.flow then
local transferredPower=industrialtest.api.transferPower(meta,endpointMeta,powerDistribution)

View File

@ -28,6 +28,7 @@ cable.onConstruct=function(pos)
if networks then
for _,network in ipairs(networks) do
industrialtest.api.createNetworkMapForNode(network)
minetest.get_node_timer(network):start(industrialtest.updateDelay)
end
end
end

View File

@ -241,7 +241,6 @@ reactor.activeOnTimer=function(pos,elapsed,meta,inv)
inv:set_stack("fuel",coolant,coolantStack)
end
if heat>200 then
-- TODO: Explode
minetest.remove_node(pos)
industrialtest.internal.explode(pos,#maxCluster*4)
return false,false

View File

@ -32,20 +32,16 @@ transformer.onTimer=function(pos,elapsed,meta)
local afterFlowLower=false
local afterFlowUpper=false
if powerAmount>=def._industrialtest_lowerFlow then
meta:set_int("industrialtest.powerFlow",def._industrialtest_lowerFlow)
afterFlowLower,_=industrialtest.api.powerFlow(pos,{
[1]=true,
[2]=true,
[3]=true,
[4]=true,
[6]=true
})
meta:set_int("industrialtest.powerFlow",industrialtest.api.ivPowerFlow)
},def._industrialtest_lowerFlow)
end
if powerAmount>=def._industrialtest_upperFlow then
meta:set_int("industrialtest.powerFlow",def._industrialtest_upperFlow)
afterFlowUpper,_=industrialtest.api.powerFlow(pos,{[5]=true})
meta:set_int("industrialtest.powerFlow",industrialtest.api.ivPowerFlow)
afterFlowUpper,_=industrialtest.api.powerFlow(pos,{[5]=true},def._industrialtest_upperFlow)
end
return powerAmount>0 and (afterFlowLower or afterFlowUpper),false
end