summaryrefslogtreecommitdiff
path: root/new_flow_logic
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-08 16:19:51 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-08 16:19:51 +0100
commiteaf6c33bae0912e15ac190df203b9b250545052b (patch)
tree8d21a2847c5c6957d9eafd579601693df9b04374 /new_flow_logic
parent32a24730f1ab8cd596ed2f4cf6eda1a58c877ecb (diff)
downloadpipeworks-eaf6c33bae0912e15ac190df203b9b250545052b.tar
pipeworks-eaf6c33bae0912e15ac190df203b9b250545052b.tar.gz
pipeworks-eaf6c33bae0912e15ac190df203b9b250545052b.tar.bz2
pipeworks-eaf6c33bae0912e15ac190df203b9b250545052b.tar.xz
pipeworks-eaf6c33bae0912e15ac190df203b9b250545052b.zip
new flow logic: abms.lua: implement node transitions
Diffstat (limited to 'new_flow_logic')
-rw-r--r--new_flow_logic/abms.lua51
1 files changed, 50 insertions, 1 deletions
diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua
index e83d50e..6abdd42 100644
--- a/new_flow_logic/abms.lua
+++ b/new_flow_logic/abms.lua
@@ -29,7 +29,7 @@ end
---local formatvec = function(vec) local sep="," return "("..tostring(vec.x)..sep..tostring(vec.y)..sep..tostring(vec.z)..")" end
+local formatvec = function(vec) local sep="," return "("..tostring(vec.x)..sep..tostring(vec.y)..sep..tostring(vec.z)..")" end
-- new version of liquid check
-- accepts a limit parameter to only delete water blocks that the receptacle can accept,
@@ -106,6 +106,13 @@ flowlogic.run = function(pos, node)
finitemode)
end
+ -- if node has pressure transitions: determine new node
+ if pipeworks.flowables.transitions.list[nodename] then
+ local newnode = flowlogic.run_transition(node, currentpressure)
+ --pipeworks.logger("flowlogic.run()@"..formatvec(pos).." transition, new node name = "..dump(newnode).." pressure "..tostring(currentpressure))
+ minetest.swap_node(pos, newnode)
+ end
+
-- set the new pressure
nodepressure.set(currentpressure)
end
@@ -240,3 +247,45 @@ flowlogic.run_output = function(pos, node, currentpressure, oldpressure, outputd
end
return result
end
+
+
+
+-- determine which node to switch to based on current pressure
+flowlogic.run_transition = function(node, currentpressure)
+ local simplesetdef = pipeworks.flowables.transitions.simple[node.name]
+ local result = node
+ local found = false
+
+ -- simple transition sets: assumes all nodes in the set share param values.
+ if simplesetdef then
+ -- assumes that the set has been checked to contain at least one element...
+ local nodename_prev = simplesetdef[1].nodename
+ local result_nodename = node.name
+
+ for index, element in ipairs(simplesetdef) do
+ -- find the highest element that is below the current pressure.
+ local threshold = element.threshold
+ if threshold > currentpressure then
+ result_nodename = nodename_prev
+ found = true
+ break
+ end
+ nodename_prev = element.nodename
+ end
+
+ -- use last element if no threshold is greater than current pressure
+ if not found then
+ result_nodename = nodename_prev
+ found = true
+ end
+
+ -- preserve param1/param2 values
+ result = { name=result_nodename, param1=node.param1, param2=node.param2 }
+ end
+
+ if not found then
+ pipeworks.logger("flowlogic.run_transition() BUG no transition definitions found! nodename="..nodename.." currentpressure="..tostring(currentpressure))
+ end
+
+ return result
+end