2017-09-27 19:00:18 +03:00
|
|
|
-- register new flow logic ABMs
|
2017-09-27 19:54:03 +03:00
|
|
|
-- written 2017 by thetaepsilon
|
2017-09-27 19:00:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 01:02:11 +03:00
|
|
|
local register = {}
|
|
|
|
pipeworks.flowlogic.abmregister = register
|
|
|
|
|
2017-10-01 14:34:20 +03:00
|
|
|
local flowlogic = pipeworks.flowlogic
|
2017-10-01 01:02:11 +03:00
|
|
|
|
2017-10-01 14:34:20 +03:00
|
|
|
-- A possible DRY violation here...
|
|
|
|
-- DISCUSS: should it be possible later on to raise the the rate of ABMs, or lower the chance?
|
|
|
|
-- Currently all the intervals and chances are hardcoded below.
|
2017-10-01 01:02:11 +03:00
|
|
|
|
2017-10-01 01:22:04 +03:00
|
|
|
-- register a node name for the pressure balancing ABM.
|
|
|
|
-- currently this only exists as a per-node function to allow nodes to be registered outside pipeworks.
|
2017-10-01 00:41:38 +03:00
|
|
|
local register_abm_balance = function(nodename)
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = { nodename },
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-10-01 14:34:20 +03:00
|
|
|
flowlogic.balance_pressure(pos, node)
|
2017-10-01 00:41:38 +03:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2017-10-01 01:02:11 +03:00
|
|
|
register.balance = register_abm_balance
|
2017-09-27 19:00:18 +03:00
|
|
|
|
2017-10-01 14:28:22 +03:00
|
|
|
-- register a node for the input ABM.
|
|
|
|
-- intakefn is run on the node to determine how much water can be taken (and update it's environment accordingly).
|
|
|
|
-- maxpressure is the maximum pressure that this input can drive, beyond which pressure will not be raised.
|
2017-10-01 02:44:14 +03:00
|
|
|
local register_abm_input = function(nodename, maxpressure, intakefn)
|
2017-09-27 19:00:18 +03:00
|
|
|
minetest.register_abm({
|
2017-10-01 00:56:12 +03:00
|
|
|
nodenames = { nodename },
|
2017-09-27 19:00:18 +03:00
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-10-01 14:34:20 +03:00
|
|
|
flowlogic.run_input(pos, node, maxpressure, intakefn)
|
2017-09-27 19:00:18 +03:00
|
|
|
end
|
|
|
|
})
|
2017-10-01 00:56:12 +03:00
|
|
|
end
|
2017-10-01 01:02:11 +03:00
|
|
|
register.input = register_abm_input
|
2017-10-01 00:56:12 +03:00
|
|
|
|
2017-10-01 14:34:20 +03:00
|
|
|
-- register a node for the output ABM.
|
|
|
|
-- threshold determines the minimum pressure, over which outputfn is called.
|
|
|
|
-- outputfn is then given the current pressure, and returns the pressure relieved by the output process.
|
|
|
|
-- outputfn is expected to update environment, nearby world etc. as appropriate for the node.
|
|
|
|
local register_abm_output = function(nodename, threshold, outputfn)
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = { nodename },
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
flowlogic.run_output(pos, node, threshold, outputfn)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
register.output = register_abm_output
|
|
|
|
|
2017-10-01 01:22:04 +03:00
|
|
|
-- old spigot ABM code, not yet migrated
|
|
|
|
--[[
|
2017-09-27 19:25:16 +03:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = { spigot_on, spigot_off },
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
pipeworks.run_spigot_output(pos, node)
|
|
|
|
end
|
|
|
|
})
|
2017-10-01 01:22:04 +03:00
|
|
|
]]
|