Notify network about network master destruction

This commit is contained in:
mrkubax10 2023-11-15 19:42:25 +01:00
parent 07ac7b3b54
commit 4d430980bf

34
api.lua
View File

@ -224,11 +224,8 @@ end
industrialtest.api.powerFlow=function(pos)
local meta=minetest.get_meta(pos)
-- if machine doesn't have network map then it's not capable of transferring power
if not meta:contains("industrialtest.network") then
return false,false
end
local network=minetest.deserialize(meta:get_string("industrialtest.network"))
if #network==0 then
local network=industrialtest.api.getNetwork(meta)
if not network or #network==0 then
return false,false
end
local powerFlow=meta:get_int("industrialtest.powerFlow")
@ -291,9 +288,10 @@ end
-- \brief Creates network map starting from node at pos, optionally omitting node at omit
-- \param pos vector
-- \param (optional) addCables bool
-- \param (optional) omit Vector
-- \returns table with network map
industrialtest.api.createNetworkMap=function(pos,omit)
industrialtest.api.createNetworkMap=function(pos,addCables,omit)
local workers={}
local map={}
local connections=industrialtest.api.getConnections(pos,"i")
@ -313,6 +311,12 @@ industrialtest.api.createNetworkMap=function(pos,omit)
distance=1,
flow=def._industrialtest_cableFlow
})
if addCables then
table.insert(map,{
position=conn,
distance=0
})
end
else
local meta=minetest.get_meta(conn)
table.insert(map,{
@ -354,6 +358,12 @@ industrialtest.api.createNetworkMap=function(pos,omit)
worker.flow=clampFlow(conn,worker.flow)
directionAssigned=true
end
if addCables then
table.insert(map,{
position=conn,
distance=worker.distance+1,
})
end
else
table.insert(map,{
position=conn,
@ -400,7 +410,7 @@ end
-- \returns nil
industrialtest.api.createNetworkMapForNode=function(pos,omit)
local meta=minetest.get_meta(pos)
local network=industrialtest.api.createNetworkMap(pos,omit)
local network=industrialtest.api.createNetworkMap(pos,false,omit)
meta:set_string("industrialtest.network",minetest.serialize(network))
end
@ -425,6 +435,16 @@ industrialtest.api.isAttachedToNetwork=function(meta)
return networks
end
-- \brief Returns network master network from it's meta, if meta doesn't contain network map then function returns false
-- \param meta MetaDataRef
-- \returns table or bool
industrialtest.api.getNetwork=function(meta)
if not meta:contains("industrialtest.network") then
return false
end
return minetest.deserialize(meta:get_string("industrialtest.network"))
end
-- \brief Starts node timer of neighbouring nodes with center node
-- \param pos Vector with position of center node
-- \returns nil