summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-17 22:01:29 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-17 22:01:29 +0100
commitd68d3d5852ae01048c6c2702ac25530d7fd293a0 (patch)
treead7764fdc84213676740be18b9d38498822efe37
parenta7c171940e2a8ac5333095837a6ede80644453a6 (diff)
downloadpipeworks-d68d3d5852ae01048c6c2702ac25530d7fd293a0.tar
pipeworks-d68d3d5852ae01048c6c2702ac25530d7fd293a0.tar.gz
pipeworks-d68d3d5852ae01048c6c2702ac25530d7fd293a0.tar.bz2
pipeworks-d68d3d5852ae01048c6c2702ac25530d7fd293a0.tar.xz
pipeworks-d68d3d5852ae01048c6c2702ac25530d7fd293a0.zip
pressure logic: abms.lua: move neighbour candidates calculation to separate function
-rw-r--r--pressure_logic/abms.lua30
1 files changed, 19 insertions, 11 deletions
diff --git a/pressure_logic/abms.lua b/pressure_logic/abms.lua
index c14c124..b79050b 100644
--- a/pressure_logic/abms.lua
+++ b/pressure_logic/abms.lua
@@ -130,17 +130,7 @@ end
-flowlogic.balance_pressure = function(pos, node, currentpressure)
- -- local dname = "flowlogic.balance_pressure()@"..formatvec(pos).." "
- -- check the pressure of all nearby flowable nodes, and average it out.
-
- -- pressure handles to average over
- local connections = {}
- -- unconditionally include self in nodes to average over.
- -- result of averaging will be returned as new pressure for main flow logic callback
- local totalv = currentpressure
- local totalc = 1
-
+local get_neighbour_positions = function(pos, node)
-- get list of node neighbours.
-- if this node is directional and only flows on certain sides,
-- invoke the callback to retrieve the set.
@@ -158,6 +148,24 @@ flowlogic.balance_pressure = function(pos, node, currentpressure)
end
end
+ return candidates
+end
+
+
+
+flowlogic.balance_pressure = function(pos, node, currentpressure)
+ -- local dname = "flowlogic.balance_pressure()@"..formatvec(pos).." "
+ -- check the pressure of all nearby flowable nodes, and average it out.
+
+ -- pressure handles to average over
+ local connections = {}
+ -- unconditionally include self in nodes to average over.
+ -- result of averaging will be returned as new pressure for main flow logic callback
+ local totalv = currentpressure
+ local totalc = 1
+
+ local candidates = get_neighbour_positions(pos, node)
+
-- then handle neighbours, but if not a pressure node don't consider them at all
for _, npos in ipairs(candidates) do
local nodename = minetest.get_node(npos).name