diff --git a/api.lua b/api.lua index e33a396..57f7f65 100644 --- a/api.lua +++ b/api.lua @@ -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) diff --git a/cables.lua b/cables.lua index aa73a49..e173ce6 100644 --- a/cables.lua +++ b/cables.lua @@ -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 diff --git a/machines/nuclear_reactor.lua b/machines/nuclear_reactor.lua index 08ee313..277e964 100644 --- a/machines/nuclear_reactor.lua +++ b/machines/nuclear_reactor.lua @@ -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 diff --git a/machines/transformer.lua b/machines/transformer.lua index 9100e58..ad7bd2e 100644 --- a/machines/transformer.lua +++ b/machines/transformer.lua @@ -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