summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-08 17:38:28 +0100
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-10-08 17:38:28 +0100
commitd5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087 (patch)
treee478f8600024075e3ef786c03a74d454d01d5396
parentce0983d239c4c855b7f6fd9d96d352c03c5d88b0 (diff)
downloadpipeworks-d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087.tar
pipeworks-d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087.tar.gz
pipeworks-d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087.tar.bz2
pipeworks-d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087.tar.xz
pipeworks-d5e3f1cf68a15d7e14cc44eb8e58e49dbb6aa087.zip
new flow logic: implement post-transition hook with mesecons support, add mesecons transition rules for flow sensor
-rw-r--r--devices.lua2
-rw-r--r--new_flow_logic/abms.lua24
-rw-r--r--new_flow_logic/flowable_node_registry.lua1
-rw-r--r--new_flow_logic/flowable_node_registry_install.lua12
4 files changed, 37 insertions, 2 deletions
diff --git a/devices.lua b/devices.lua
index 2a7afc9..5203bf3 100644
--- a/devices.lua
+++ b/devices.lua
@@ -526,7 +526,7 @@ new_flow_logic_register.simple(nodename_sensor_empty)
new_flow_logic_register.simple(nodename_sensor_loaded)
-- activate flow sensor at roughly half the pressure pumps drive pipes
local sensor_pressure_set = { { nodename_sensor_empty, 0.0 }, { nodename_sensor_loaded, 1.0 } }
-new_flow_logic_register.transition_simple_set(sensor_pressure_set)
+new_flow_logic_register.transition_simple_set(sensor_pressure_set, { mesecons=pipeworks.mesecons_rules })
diff --git a/new_flow_logic/abms.lua b/new_flow_logic/abms.lua
index 6abdd42..38ae4b6 100644
--- a/new_flow_logic/abms.lua
+++ b/new_flow_logic/abms.lua
@@ -111,6 +111,7 @@ flowlogic.run = function(pos, node)
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)
+ flowlogic.run_transition_post(pos, newnode)
end
-- set the new pressure
@@ -289,3 +290,26 @@ flowlogic.run_transition = function(node, currentpressure)
return result
end
+
+-- post-update hook for run_transition
+-- among other things, updates mesecons if present.
+-- node here means the new node, returned from run_transition() above
+flowlogic.run_transition_post = function(pos, node)
+ local mesecons_def = minetest.registered_nodes[node.name].mesecons
+ local mesecons_rules = pipeworks.flowables.transitions.mesecons[node.name]
+ if minetest.global_exists("mesecon") and (mesecons_def ~= nil) and mesecons_rules then
+ if type(mesecons_def) ~= "table" then
+ pipeworks.logger("flowlogic.run_transition_post() BUG mesecons def for "..node.name.."not a table: got "..tostring(mesecons_def))
+ else
+ local receptor = mesecons_def.receptor
+ if receptor then
+ local state = receptor.state
+ if state == mesecon.state.on then
+ mesecon.receptor_on(pos, mesecons_rules)
+ elseif state == mesecon.state.off then
+ mesecon.receptor_off(pos, mesecons_rules)
+ end
+ end
+ end
+ end
+end
diff --git a/new_flow_logic/flowable_node_registry.lua b/new_flow_logic/flowable_node_registry.lua
index 7651928..2523803 100644
--- a/new_flow_logic/flowable_node_registry.lua
+++ b/new_flow_logic/flowable_node_registry.lua
@@ -32,6 +32,7 @@ pipeworks.flowables.outputs.list = {}
pipeworks.flowables.transitions = {}
pipeworks.flowables.transitions.list = {} -- master list
pipeworks.flowables.transitions.simple = {} -- nodes that change based purely on pressure
+pipeworks.flowables.transitions.mesecons = {} -- table of mesecons rules to apply on transition
diff --git a/new_flow_logic/flowable_node_registry_install.lua b/new_flow_logic/flowable_node_registry_install.lua
index e4a5744..c8f6889 100644
--- a/new_flow_logic/flowable_node_registry_install.lua
+++ b/new_flow_logic/flowable_node_registry_install.lua
@@ -145,8 +145,9 @@ local simpleseterror = function(msg)
end
local simple_transitions = pipeworks.flowables.transitions.simple
-register.transition_simple_set = function(nodeset)
+register.transition_simple_set = function(nodeset, extras)
local set = {}
+ if extras == nil then extras = {} end
local length = #nodeset
if length < 2 then simpleseterror("nodeset needs at least two elements!") end
@@ -175,4 +176,13 @@ register.transition_simple_set = function(nodeset)
--pipeworks.logger("register.transition_simple_set() after sort: nodename "..element.nodename.." value "..tostring(element.threshold))
simple_transitions[element.nodename] = set
end
+
+ -- handle extra options
+ -- if mesecons rules table was passed, set for each node
+ if extras.mesecons then
+ local mesecons_rules = pipeworks.flowables.transitions.mesecons
+ for _, element in ipairs(set) do
+ mesecons_rules[element.nodename] = extras.mesecons
+ end
+ end
end