summaryrefslogtreecommitdiff
path: root/pressure_logic
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-17 22:20:13 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-17 22:20:13 +0100
commit909b321f3c6c866f686ae31dfc59a4a932f4d9c6 (patch)
tree29140be43fc1636815ae2784377885a6c5435401 /pressure_logic
parentd68d3d5852ae01048c6c2702ac25530d7fd293a0 (diff)
downloadpipeworks-909b321f3c6c866f686ae31dfc59a4a932f4d9c6.tar
pipeworks-909b321f3c6c866f686ae31dfc59a4a932f4d9c6.tar.gz
pipeworks-909b321f3c6c866f686ae31dfc59a4a932f4d9c6.tar.bz2
pipeworks-909b321f3c6c866f686ae31dfc59a4a932f4d9c6.tar.xz
pipeworks-909b321f3c6c866f686ae31dfc59a4a932f4d9c6.zip
pressure logic: abms.lua: refactor balance_pressure() to move responsiblity for checking neighbour flow classes to get_neighbour_positions
Diffstat (limited to 'pressure_logic')
-rw-r--r--pressure_logic/abms.lua37
1 files changed, 20 insertions, 17 deletions
diff --git a/pressure_logic/abms.lua b/pressure_logic/abms.lua
index b79050b..d6152dc 100644
--- a/pressure_logic/abms.lua
+++ b/pressure_logic/abms.lua
@@ -148,7 +148,20 @@ local get_neighbour_positions = function(pos, node)
end
end
- return candidates
+ -- then, check each possible neighbour to see if they can be reached from this node.
+ -- for now, just check if it's in the simple table.
+ -- TODO: will need to add a single-face direction checking function for directional nodes
+ local connections = {}
+ for index, npos in ipairs(candidates) do
+ local nodename = minetest.get_node(npos).name
+ local is_simple = (pipeworks.flowables.list.simple[nodename])
+ if is_simple then
+ local neighbour = get_pressure_access(npos)
+ table.insert(connections, neighbour)
+ end
+ end
+
+ return connections
end
@@ -164,24 +177,14 @@ flowlogic.balance_pressure = function(pos, node, currentpressure)
local totalv = currentpressure
local totalc = 1
- local candidates = get_neighbour_positions(pos, node)
+ local connections = 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
- -- for now, just check if it's in the simple table.
- -- TODO: the "can flow from" logic in flowable_node_registry.lua
- local haspressure = (pipeworks.flowables.list.simple[nodename])
- if haspressure then
- local neighbour = get_pressure_access(npos)
- --pipeworks.logger("balance_pressure @ "..formatvec(pos).." "..nodename.." "..formatvec(npos).." added to neighbour set")
- local n = neighbour.get()
- table.insert(connections, neighbour)
- totalv = totalv + n
- totalc = totalc + 1
- end
+ -- for each neighbour, add neighbour's pressure to the total to balance out
+ for _, neighbour in ipairs(connections) do
+ local n = neighbour.get()
+ totalv = totalv + n
+ totalc = totalc + 1
end
-
local average = totalv / totalc
for _, target in ipairs(connections) do
target.set(average)