Generate network map while constructing generator for testing

This commit is contained in:
2023-11-13 20:37:50 +01:00
parent c02bddb433
commit c3b49b68e1
4 changed files with 58 additions and 46 deletions

20
api.lua
View File

@@ -269,7 +269,7 @@ local function addNodeToNetwork(pos,networkMasterPos)
networks=minetest.deserialize(meta:get_string("industrialtest.networks"))
end
for _,network in ipairs(networks) do
if network==networkMasterPos then
if network.x==networkMasterPos.x and network.y==networkMasterPos.y and network.z==networkMasterPos.z then
return
end
end
@@ -308,7 +308,7 @@ industrialtest.api.createNetworkMap=function(pos)
while #workers>0 do
for i=1,#workers do
local worker=workers[i]
local connections=industrialtest.api.getConnections(worker.position,"i")
connections=industrialtest.api.getConnections(worker.position,"i")
if #connections==0 then
table.remove(workers,i)
break
@@ -355,6 +355,22 @@ industrialtest.api.createNetworkMap=function(pos)
return map
end
industrialtest.api.removeNodeFromNetwork=function(pos,nodePos)
local meta=minetest.get_meta(pos)
local network=minetest.deserialize(meta:get_string("industrialtest.network"))
local removed=false
for key,node in ipairs(network) do
if node.position.x==nodePos.x and node.position.y==nodePos.y and node.position.z==nodePos.z then
table.remove(network,key)
removed=true
break
end
end
if removed then
meta:set_string("industrialtest.network",minetest.serialize(network))
end
end
-- \brief Creates network map and writes it to node metadata at pos
-- \param pos Vector
-- \returns nil