working cylindrical tank

master
Izzy 2019-03-31 01:20:18 -06:00
parent c40f573755
commit 0a7804aa1c
2 changed files with 49 additions and 46 deletions

View File

@ -4,13 +4,9 @@ local function try_add_fluid(tpos)
-- find the bottom node
local tmeta = minetest.get_meta(tpos)
local tmdr = tmeta:to_table()
local tmd = tmdr.fields
if not tmd.bpos then
print("no bpos")
print(dump(tpos))
print(dump2(tmd))
local rbpos = tmeta:get_string("bpos")
if not rbpos then
--print("no bpos")
return
end
@ -19,46 +15,48 @@ local function try_add_fluid(tpos)
local npos = {x=tpos.x, y=tpos.y+1, z=tpos.z}
local tnet = bitumen.pipes.get_net(npos)
if not tnet or not tnet.fluid or tnet.fluid == "air" then
print("no tnet")
print(dump(tnet.fluid))
--print("no tnet")
--print(dump(tnet.fluid))
return
end
-- all the data is in the bottom node
local bpos = minetest.deserialize(tmd.bpos)
local bpos = minetest.deserialize(rbpos)
local bmeta = minetest.get_meta(bpos)
local bmdr = bmeta:to_table()
local bmd = bmdr.fields
bmd.fill = tonumber(bmd.fill)
bmd.capacity = tonumber(bmd.capacity)
print(dump(bmdr))
local fill = bmeta:get_int("fill")
local capacity = bmeta:get_int("capacity")
local fluid = bmeta:get_string("fluid")
-- check for full
if bmd.fill >= bmd.capacity then
print("empty")
if fill >= capacity then
--print("empty")
return
end
local remcap = bmd.capacity - bmd.fill
if fill > 0 and fluid ~= tnet.fluid then
--print("wrong fluid to take")
return
end
local remcap = capacity - fill
local taken, fluid = bitumen.pipes.take_fluid(npos, remcap)
local taken, tfluid = bitumen.pipes.take_fluid(npos, remcap)
if taken == 0 then
print("none taken")
--print("none taken")
return
end
-- set or change fluids
if bmd.fluid == "air" or bmd.fill == 0 then
bmd.fluid = fluid
tmd.fluid = fluid
tmeta:from_table(tmdr)
if fluid == "air" or fill == 0 then
bmeta:set_string("fluid", tfluid)
tmeta:set_string("fluid", tfluid)
end
bmd.fill = bmd.fill + taken
print("cyl tank fill: " .. bmd.fill .. " ("..bmd.fluid..")")
fill = fill + taken
--print("cyl tank fill: " .. fill .. " ("..tfluid..")")
bmeta:from_table(bmdr)
bmeta:set_int("fill", fill)
end
@ -67,31 +65,35 @@ local function try_give_fluid(bpos)
-- grab the output network
local npos = {x=bpos.x, y=bpos.y-1, z=bpos.z}
local tnet = bitumen.pipes.get_net(npos)
if not tnet or not tnet.fluid or tnet.fluid == "air" then
if not tnet then
--print("no bnet")
return
end
-- grab the data
local bmeta = minetest.get_meta(bpos)
local bmdr = bmeta:to_table()
local bmd = bmdr.fields
local fill = bmeta:get_int("fill")
local capacity = bmeta:get_int("capacity")
local fluid = bmeta:get_string("fluid")
-- check for empty
if bmd.fill <= 0 or bmd.fluid == "air" then
if fill <= 0 or fluid == "air" then
--print("tank empty " .. fluid .. " " ..fill)
return
end
local lift = bmd.capacity / (9 * 60)
local lift = capacity / (9 * 60)
local pushed = bitumen.pipes.push_fluid(npos, bmd.fluid, math.min(bmd.fill, 64), lift)
local pushed = bitumen.pipes.push_fluid(npos, fluid, math.min(fill, 64), lift)
if pushed == 0 then
--print("none pushed")
return
end
bmd.fill = math.max(bmd.fill - taken, 0)
print("cyl tank fill: " .. bmd.fill .. " ("..bmd.fluid..") [push]")
fill = math.max(fill - pushed, 0)
--print("cyl tank fill: " .. fill .. " ("..fluid..") [push]")
bmeta:from_table(bmdr)
bmeta:set_int("fill", fill)
end
@ -100,8 +102,8 @@ end
-- tank data is stored based on the bottom position
local function init_tank(tpos, bpos)
print(dump(tpos))
print(dump(bpos))
--print(dump(tpos))
--print(dump(bpos))
local fluid = "air"
local tnet = bitumen.pipes.get_net({x=tpos.x, y=tpos.y+1, z=tpos.z})
@ -115,10 +117,10 @@ local function init_tank(tpos, bpos)
}}
local tmeta = minetest.get_meta(tpos)
tmeta:from_table(tmetad)
print(dump2(tmeta:to_table()))
--print(dump2(tmeta:to_table()))
local cap = (tpos.y - bpos.y) * 60 * 9
print("capacity: ".. cap)
--print("capacity: ".. cap)
local bmeta = minetest.get_meta(bpos)
local bmetad = {fields = {

View File

@ -92,7 +92,7 @@ local function check_merge(pos)
return found_net, merge_list
end
-- merge a list if networks, if the are multiple nets in the list
-- merge a list of networks, if the are multiple nets in the list
local function try_merge(merge_list)
if #merge_list > 1 then
print("\n merging "..#merge_list.." networks")
@ -324,6 +324,7 @@ bitumen.pipes.push_fluid = function(pos, fluid, amount, extra_pressure)
end
local pnet = networks[phash]
--print("fluid: "..pnet.fluid.. ", buf: "..pnet.buffer)
if pnet.fluid == 'air' or pnet.buffer == 0 then
if minetest.registered_nodes[fluid]
and minetest.registered_nodes[fluid].groups.petroleum ~= nil then
@ -345,17 +346,17 @@ bitumen.pipes.push_fluid = function(pos, fluid, amount, extra_pressure)
return 0
end
local input_pres = pos.y + extra_pressure
local input_pres = math.floor(pos.y + extra_pressure + .5)
pnet.in_pressure = pnet.in_pressure or -32000
if pnet.in_pressure > input_pres then
if math.floor(pnet.in_pressure + .5) > input_pres then
print("backflow at intake: " .. pnet.in_pressure.. " > " ..input_pres )
return 0
end
pnet.in_pressure = math.max(pnet.in_pressure, input_pres)
print("net pressure: ".. pnet.in_pressure)
--print("net pressure: ".. pnet.in_pressure)
local rate = amount --math.max(1, math.ceil(ulevel / 2))
local cap = 64
@ -389,7 +390,7 @@ bitumen.pipes.take_fluid = function(pos, max_amount, backpressure)
end
local take = math.min(pnet.buffer, max_amount)
pnet.buffer = pnet.buffer - take
pnet.buffer = math.max(pnet.buffer - take, 0)
if pnet.buffer == 0 then
-- print("pipe drained " .. pnet.name) -- BUG: there might be a bug where a low pressure input can add fluid to the network with a higher spout, then a higher intake with low flow can raise the pressure of the previous fluid to the level of the comparatively lower spout
@ -603,7 +604,7 @@ minetest.register_abm({
pos.y = pos.y - 1
local bnode = minetest.get_node(pos)
local avail = 10 -- pnet.buffer / #pnet.outputs
local avail = math.min(10, pnet.buffer) -- pnet.buffer / #pnet.outputs
if bnode.name == pnet.fluid then
local blevel = minetest.get_node_level(pos)
local cap = 64 - blevel