First stage of integrating Mauvebic's water flowing code. This is experimental
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Fri, 4 Jan 2013 05:15:23 +0000 (00:15 -0500)
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>
Fri, 4 Jan 2013 05:15:23 +0000 (00:15 -0500)
and doesn't move water yet - but at least it doesn't break anything :-)

autoplace.lua
devices.lua
flowing_logic.lua [new file with mode: 0644]
init.lua

index ef5bbda00931ec4f1947742e5506ebb10a54524c..1a53bf3e92a971a45fb7ebf4b046a3f2e4550ba4 100644 (file)
@@ -178,6 +178,14 @@ function pipes_scansurroundings(pos)
           (string.find(nym.name, "pipeworks:pump") ~= nil) then
                pym=1
        end
+
+-- ...extra devices specified via the function's parameters
+-- ...except that this part is not implemented yet
+--
+--     if (string.find(nym.name, "aero:outlet") ~= nil) then
+--             pxm, pxp, pym, and/or pyp = 1 depending on the needed rules     
+--     end
+
 end
 
 function pipe_look_for_stackable_tanks(pos)
index d88049884fe091d74edde1fac5c7b840beca9ebc..577979e13f5f56aa5d668ad0a72cbd3b676d1921 100644 (file)
@@ -35,6 +35,22 @@ pipe_valvehandle_off = {
        { -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
 }
 
+spigot_bottomstub = {
+       { -2/64, -16/64, -6/64,   2/64, 1/64, 6/64 },   -- pipe segment against -Y face
+       { -4/64, -16/64, -5/64,   4/64, 1/64, 5/64 },
+       { -5/64, -16/64, -4/64,   5/64, 1/64, 4/64 },
+       { -6/64, -16/64, -2/64,   6/64, 1/64, 2/64 },
+
+       { -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 },   -- (the flange for it)
+       { -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
+       { -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
+       { -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
+       { -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
+}
+
+entry_panel = {
+       { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
+}
 -- Now define the nodes.
 
 local states = { "on", "off" }
@@ -76,7 +92,11 @@ for s in ipairs(states) do
                groups = dgroups,
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
+               pipelike = 1,
+               on_construct = function(pos)
+                       local meta = minetest.env:get_meta(pos)
+                       meta:set_int("pipelike",1)
+               end,
                after_place_node = function(pos)
                        pipe_scanforobjects(pos)
                end,
@@ -122,7 +142,11 @@ for s in ipairs(states) do
                groups = dgroups,
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
+               pipelike = 1,
+               on_construct = function(pos)
+                       local meta = minetest.env:get_meta(pos)
+                       meta:set_int("pipelike",1)
+               end,
                after_place_node = function(pos)
                        pipe_scanforobjects(pos)
                end,
@@ -131,10 +155,6 @@ for s in ipairs(states) do
                end,
                drop = "pipeworks:valve_off",
                pipelike=1,
-               on_construct = function(pos)
-               local meta = minetest.env:get_meta(pos)
-               meta:set_int("pipelike",1)
-               end,
        })
 end
 
@@ -154,7 +174,6 @@ minetest.register_node("pipeworks:grating", {
        groups = {snappy=3, pipe=1},
        sounds = default.node_sound_wood_defaults(),
        walkable = true,
-       stack_max = 99,
        after_place_node = function(pos)
                pipe_scanforobjects(pos)
        end,
@@ -191,18 +210,17 @@ minetest.register_node("pipeworks:spigot", {
        groups = {snappy=3, pipe=1},
        sounds = default.node_sound_wood_defaults(),
        walkable = true,
-       stack_max = 99,
+       pipelike=1,
+       on_construct = function(pos)
+               local meta = minetest.env:get_meta(pos)
+               meta:set_int("pipelike",1)
+       end,
        after_place_node = function(pos)
                pipe_scanforobjects(pos)
        end,
        after_dig_node = function(pos)
                pipe_scanforobjects(pos)
        end,
-       pipelike=1,
-       on_construct = function(pos)
-       local meta = minetest.env:get_meta(pos)
-       meta:set_int("pipelike",1)
-       end,
        node_box = {
                type = "fixed",
                fixed = spigotboxes,
@@ -237,7 +255,6 @@ minetest.register_node("pipeworks:entry_panel", {
        groups = {snappy=3, pipe=1},
        sounds = default.node_sound_wood_defaults(),
        walkable = true,
-       stack_max = 99,
        after_place_node = function(pos)
                pipe_scanforobjects(pos)
        end,
@@ -281,7 +298,6 @@ for fill = 0, 10 do
                groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
                drop = "pipeworks:storage_tank_"..fill,
                after_place_node = function(pos)
                        pipe_look_for_stackable_tanks(pos)
@@ -312,7 +328,6 @@ for fill = 0, 10 do
                groups = sgroups,
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
                after_place_node = function(pos)
                        pipe_look_for_stackable_tanks(pos)
                        pipe_scanforobjects(pos)
diff --git a/flowing_logic.lua b/flowing_logic.lua
new file mode 100644 (file)
index 0000000..6fa37e3
--- /dev/null
@@ -0,0 +1,110 @@
+-- This file provides the actual flow and pathfinding logic that makes water
+-- move through the pipes.
+--
+-- Contributed by mauvebic, 2013-01-03, with tweaks by Vanessa Ezekowitz
+--
+
+local check4liquids = function(pos)
+       local coords = {
+               {x=pos.x,y=pos.y-1,z=pos.z},
+               {x=pos.x,y=pos.y+1,z=pos.z},
+               {x=pos.x-1,y=pos.y,z=pos.z},
+               {x=pos.x+1,y=pos.y,z=pos.z},
+               {x=pos.x,y=pos.y,z=pos.z-1},
+               {x=pos.x,y=pos.y,z=pos.z+1},    }
+       for i =1,6 do
+               local name = minetest.env:get_node(coords[i]).name
+               if string.find(name,'water') then return true end
+       end
+       return false
+end
+
+local check4inflows = function(pos,node)
+       local coords = {
+               {x=pos.x,y=pos.y-1,z=pos.z},
+               {x=pos.x,y=pos.y+1,z=pos.z},
+               {x=pos.x-1,y=pos.y,z=pos.z},
+               {x=pos.x+1,y=pos.y,z=pos.z},
+               {x=pos.x,y=pos.y,z=pos.z-1},
+               {x=pos.x,y=pos.y,z=pos.z+1},    }
+       local newnode = false
+       local source = false
+       for i =1,6 do
+               if newnode then break end
+               local name = minetest.env:get_node(coords[i]).name
+               if (name == 'pipeworks:pump_on' and check4liquids(coords[i])) or string.find(name,'_loaded') then
+                       if string.find(name,'_loaded') then
+                               local source = minetest.env:get_meta(coords[i]):get_string('source')
+                               if source == minetest.pos_to_string(pos) then break end
+                       end
+                       newnode = string.gsub(node.name,'empty','loaded')
+                       source = {x=coords[i].x,y=coords[i].y,z=coords[i].z}
+                       if newnode ~= nil then dbg(newnode) end
+               end
+       end
+       if newnode then dbg(newnode..' to replace '..node.name) end
+       if newnode then 
+               minetest.env:add_node(pos,{name=newnode}) 
+               minetest.env:get_meta(pos):set_string('source',minetest.pos_to_string(source))
+       end
+end
+
+local checksources = function(pos,node)
+       local sourcepos = minetest.string_to_pos(minetest.env:get_meta(pos):get_string('source'))
+       local source = minetest.env:get_node(sourcepos).name
+       local newnode = false
+       if not ((source == 'pipeworks:pump_on' and check4liquids(sourcepos)) or string.find(source,'_loaded') or source == 'ignore' ) then
+               newnode = string.gsub(node.name,'loaded','empty')
+       end
+
+       if newnode then dbg(newnode..' to replace '..node.name) end
+       if newnode then 
+               minetest.env:add_node(pos,{name=newnode}) 
+               minetest.env:get_meta(pos):set_string('source','')
+       end
+end
+
+local update_outlet = function(pos)
+       local top = minetest.env:get_node({x=pos.x,y=pos.y+1,z=pos.z}).name
+       if string.find(top,'_loaded') then
+               minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) 
+       elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
+               minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+       end
+end
+
+local spigot_check = function(pos,node)
+       local check = {{x=pos.x,y=pos.y,z=pos.z+1},{x=pos.x+1,y=pos.y,z=pos.z},{x=pos.x,y=pos.y,z=pos.z-1},{x=pos.x-1,y=pos.y,z=pos.z}  }
+       dbg(node.param2..' checking '..minetest.pos_to_string(check[node.param2+1])..' for spigot at '..minetest.pos_to_string(pos))
+       local top = minetest.env:get_node(check[node.param2+1]).name
+       dbg('found '..top)
+       if string.find(top,'_loaded') then
+               minetest.env:add_node({x=pos.x,y=pos.y-1,z=pos.z},{name='default:water_source'}) 
+       elseif minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name == 'default:water_source' then
+               minetest.env:remove_node({x=pos.x,y=pos.y-1,z=pos.z})
+       end
+end
+
+minetest.register_abm({
+       nodenames = empty_nodenames,
+       interval = 15,
+       chance = 1,
+       action = function(pos, node, active_object_count, active_object_count_wider) check4inflows(pos,node) end
+})
+
+minetest.register_abm({
+       nodenames = full_nodenames,
+       interval = 10,
+       chance = 1,
+       action = function(pos, node, active_object_count, active_object_count_wider) checksources(pos,node) end
+})
+
+minetest.register_abm({
+       nodenames = {'pipeworks:outlet','pipeworks:spigot'},
+       interval = 10,
+       chance = 1,
+       action = function(pos, node, active_object_count, active_object_count_wider) 
+               if node.name == 'pipeworks:outlet' then update_outlet(pos)
+               elseif node.name == 'pipeworks:spigot' then spigot_check(pos,node) end
+       end
+})
index b3ca809121fbfc3466c06440323b72e3233d2e79..fe85f406ebf46b7737a4f255ecbd53f2655e2360 100644 (file)
--- a/init.lua
+++ b/init.lua
 
 -- Un-comment the following dofile line to re-enable the old pipe nodes.
 -- dofile(minetest.get_modpath("pipeworks").."/oldpipes.lua")
+--
 
 minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
+local DEBUG = true
 
 pipe_leftstub = {
        { -32/64, -2/64, -6/64,   1/64, 2/64, 6/64 },   -- pipe segment against -X face
@@ -108,27 +110,10 @@ pipe_bendsphere = {
        { -3/64, -3/64, -5/64, 3/64, 3/64, 5/64 }
 }
 
-spigot_bottomstub = {
-       { -2/64, -16/64, -6/64,   2/64, 1/64, 6/64 },   -- pipe segment against -Y face
-       { -4/64, -16/64, -5/64,   4/64, 1/64, 5/64 },
-       { -5/64, -16/64, -4/64,   5/64, 1/64, 4/64 },
-       { -6/64, -16/64, -2/64,   6/64, 1/64, 2/64 },
-
-       { -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 },   -- (the flange for it)
-       { -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
-       { -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
-       { -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
-       { -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
-}
-
-entry_panel = {
-       { -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
-}
-
 --  Functions
 
 dbg = function(s)
-       if DEBUG == 1 then
+       if DEBUG then
                print('[PIPEWORKS] ' .. s)
        end
 end
@@ -150,6 +135,9 @@ end
 
 -- now define the nodes!
 
+local empty_nodenames = {}
+local full_nodenames = {}
+
 for xm = 0, 1 do
 for xp = 0, 1 do
 for ym = 0, 1 do
@@ -279,12 +267,11 @@ for zp = 0, 1 do
                groups = pgroups,
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
                drop = "pipeworks:pipe_110000_empty",
                pipelike=1,
                on_construct = function(pos)
-               local meta = minetest.env:get_meta(pos)
-               meta:set_int("pipelike",1)
+                       local meta = minetest.env:get_meta(pos)
+                       meta:set_int("pipelike",1)
                end,
                after_place_node = function(pos)
                        pipe_scanforobjects(pos)
@@ -310,12 +297,11 @@ for zp = 0, 1 do
                groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
                sounds = default.node_sound_wood_defaults(),
                walkable = true,
-               stack_max = 99,
                drop = "pipeworks:pipe_110000_empty",
                pipelike=1,
                on_construct = function(pos)
-               local meta = minetest.env:get_meta(pos)
-               meta:set_int("pipelike",1)
+                       local meta = minetest.env:get_meta(pos)
+                       meta:set_int("pipelike",1)
                end,
                after_place_node = function(pos)
                        pipe_scanforobjects(pos)
@@ -324,6 +310,8 @@ for zp = 0, 1 do
                        pipe_scanforobjects(pos)
                end
        })
+       table.insert(empty_nodenames,"pipeworks:pipe_"..pname.."_empty") -- for the abms
+       table.insert(full_nodenames,"pipeworks:pipe_"..pname.."_loaded") -- for bacon
 end
 end
 end
@@ -335,5 +323,6 @@ dofile(minetest.get_modpath("pipeworks").."/tubes.lua")
 dofile(minetest.get_modpath("pipeworks").."/devices.lua")
 dofile(minetest.get_modpath("pipeworks").."/autoplace.lua")
 dofile(minetest.get_modpath("pipeworks").."/crafts.lua")
+dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
 
 print("Pipeworks loaded!")