2017-09-27 18:00:18 +02:00
|
|
|
-- register new flow logic ABMs
|
2017-09-27 18:54:03 +02:00
|
|
|
-- written 2017 by thetaepsilon
|
2017-09-27 18:00:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 00:02:11 +02:00
|
|
|
local register = {}
|
|
|
|
pipeworks.flowlogic.abmregister = register
|
|
|
|
|
2017-10-01 13:34:20 +02:00
|
|
|
local flowlogic = pipeworks.flowlogic
|
2017-10-01 00:02:11 +02:00
|
|
|
|
2017-10-01 13:34:20 +02: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 00:02:11 +02:00
|
|
|
|
2017-10-07 17:12:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- register node list for the main logic function.
|
|
|
|
-- see flowlogic.run() in abms.lua.
|
2017-10-07 18:33:42 +02:00
|
|
|
|
2017-10-07 17:12:36 +02:00
|
|
|
local register_flowlogic_abm = function(nodename)
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = { nodename },
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
flowlogic.run(pos, node)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2017-10-07 18:33:42 +02:00
|
|
|
register.flowlogic = register_flowlogic_abm
|
2017-10-07 17:12:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 00:22:04 +02: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-07 18:33:42 +02:00
|
|
|
--[[
|
2017-09-30 23:41:38 +02: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 13:34:20 +02:00
|
|
|
flowlogic.balance_pressure(pos, node)
|
2017-09-30 23:41:38 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2017-10-01 00:02:11 +02:00
|
|
|
register.balance = register_abm_balance
|
2017-10-07 18:33:42 +02:00
|
|
|
]]
|
2017-09-27 18:00:18 +02:00
|
|
|
|
2017-10-01 13:28:22 +02: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 01:44:14 +02:00
|
|
|
local register_abm_input = function(nodename, maxpressure, intakefn)
|
2017-09-27 18:00:18 +02:00
|
|
|
minetest.register_abm({
|
2017-09-30 23:56:12 +02:00
|
|
|
nodenames = { nodename },
|
2017-09-27 18:00:18 +02:00
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2017-10-01 13:34:20 +02:00
|
|
|
flowlogic.run_input(pos, node, maxpressure, intakefn)
|
2017-09-27 18:00:18 +02:00
|
|
|
end
|
|
|
|
})
|
2017-09-30 23:56:12 +02:00
|
|
|
end
|
2017-10-01 00:02:11 +02:00
|
|
|
register.input = register_abm_input
|
2017-09-30 23:56:12 +02:00
|
|
|
|
2017-10-01 13:34:20 +02: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 00:22:04 +02:00
|
|
|
-- old spigot ABM code, not yet migrated
|
|
|
|
--[[
|
2017-09-27 18:25:16 +02: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 00:22:04 +02:00
|
|
|
]]
|