2017-10-01 16:18:00 +02:00
|
|
|
-- flowable node registry: add entries and install ABMs if new flow logic is enabled
|
|
|
|
-- written 2017 by thetaepsilon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- use for hooking up ABMs as nodes are registered
|
|
|
|
local abmregister = pipeworks.flowlogic.abmregister
|
|
|
|
|
|
|
|
-- registration functions
|
|
|
|
pipeworks.flowables.register = {}
|
|
|
|
local register = pipeworks.flowables.register
|
|
|
|
|
|
|
|
-- some sanity checking for passed args, as this could potentially be made an external API eventually
|
|
|
|
local checkexists = function(nodename)
|
|
|
|
if type(nodename) ~= "string" then error("pipeworks.flowables nodename must be a string!") end
|
|
|
|
return pipeworks.flowables.list.all[nodename]
|
|
|
|
end
|
|
|
|
|
|
|
|
local insertbase = function(nodename)
|
|
|
|
if checkexists(nodename) then error("pipeworks.flowables duplicate registration!") end
|
|
|
|
pipeworks.flowables.list.all[nodename] = true
|
|
|
|
-- table.insert(pipeworks.flowables.list.nodenames, nodename)
|
|
|
|
end
|
|
|
|
|
2017-10-01 17:17:35 +02:00
|
|
|
local regwarning = function(kind, nodename)
|
|
|
|
local tail = ""
|
2017-10-03 21:38:56 +02:00
|
|
|
if not pipeworks.toggles.pressure_logic then tail = " but pressure logic not enabled" end
|
2017-10-04 19:54:51 +02:00
|
|
|
--pipeworks.logger(kind.." flow logic registry requested for "..nodename..tail)
|
2017-10-01 17:17:35 +02:00
|
|
|
end
|
|
|
|
|
2017-10-01 16:18:00 +02:00
|
|
|
-- Register a node as a simple flowable.
|
|
|
|
-- Simple flowable nodes have no considerations for direction of flow;
|
|
|
|
-- A cluster of adjacent simple flowables will happily average out in any direction.
|
|
|
|
register.simple = function(nodename)
|
|
|
|
insertbase(nodename)
|
|
|
|
pipeworks.flowables.list.simple[nodename] = true
|
|
|
|
table.insert(pipeworks.flowables.list.simple_nodenames, nodename)
|
2017-10-03 21:38:56 +02:00
|
|
|
if pipeworks.toggles.pressure_logic then
|
2017-10-01 16:18:00 +02:00
|
|
|
abmregister.balance(nodename)
|
|
|
|
end
|
2017-10-01 17:17:35 +02:00
|
|
|
regwarning("simple", nodename)
|
2017-10-01 16:18:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local checkbase = function(nodename)
|
|
|
|
if not checkexists(nodename) then error("pipeworks.flowables node doesn't exist as a flowable!") end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Register a node as a simple intake.
|
|
|
|
-- Expects node to be registered as a flowable (is present in flowables.list.all),
|
|
|
|
-- so that water can move out of it.
|
|
|
|
-- maxpressure is the maximum pipeline pressure that this node can drive.
|
|
|
|
-- possible WISHME here: technic-driven high-pressure pumps
|
|
|
|
register.intake_simple = function(nodename, maxpressure)
|
|
|
|
checkbase(nodename)
|
|
|
|
pipeworks.flowables.inputs.list[nodename] = { maxpressure=maxpressure }
|
|
|
|
table.insert(pipeworks.flowables.inputs.nodenames, nodename)
|
2017-10-03 21:38:56 +02:00
|
|
|
if pipeworks.toggles.pressure_logic then
|
2017-10-01 16:18:00 +02:00
|
|
|
abmregister.input(nodename, maxpressure, pipeworks.flowlogic.check_for_liquids_v2)
|
|
|
|
end
|
2017-10-01 17:17:35 +02:00
|
|
|
regwarning("simple intake", nodename)
|
2017-10-01 16:18:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Register a node as an output.
|
|
|
|
-- Expects node to already be a flowable.
|
2017-10-07 14:05:52 +02:00
|
|
|
-- upper and lower thresholds have different meanings depending on whether finite liquid mode is in effect.
|
|
|
|
-- if not (the default unless auto-detected),
|
|
|
|
-- nodes above their upper threshold have their outputfn invoked (and pressure deducted),
|
|
|
|
-- nodes between upper and lower are left idle,
|
|
|
|
-- and nodes below lower have their cleanup fn invoked (to say remove water sources).
|
|
|
|
-- the upper and lower difference acts as a hysteresis to try and avoid "gaps" in the flow.
|
|
|
|
-- if finite mode is on, upper is ignored and lower is used to determine whether to run outputfn;
|
|
|
|
-- cleanupfn is ignored in this mode as finite mode assumes something causes water to move itself.
|
|
|
|
register.output = function(nodename, upper, lower, outputfn)
|
2017-10-01 16:18:00 +02:00
|
|
|
checkbase(nodename)
|
|
|
|
pipeworks.flowables.outputs.list[nodename] = { threshold=threshold, outputfn=outputfn }
|
2017-10-03 21:38:56 +02:00
|
|
|
if pipeworks.toggles.pressure_logic then
|
2017-10-07 14:05:52 +02:00
|
|
|
abmregister.output(nodename, lower, outputfn)
|
2017-10-01 16:18:00 +02:00
|
|
|
end
|
2017-10-01 17:17:35 +02:00
|
|
|
regwarning("output node", nodename)
|
2017-10-01 16:18:00 +02:00
|
|
|
end
|
|
|
|
|
2017-10-07 14:15:42 +02:00
|
|
|
-- register a simple output:
|
|
|
|
-- drains pressure by attempting to place water in nearby nodes,
|
|
|
|
-- which can be set by passing a list of offset vectors.
|
|
|
|
-- will attempt to drain as many whole nodes as there are positions in the offset list.
|
2017-10-07 14:05:52 +02:00
|
|
|
-- for meanings of upper and lower, see register.output() above.
|
2017-10-07 14:15:42 +02:00
|
|
|
-- non-finite mode:
|
|
|
|
-- above upper pressure: places water sources as appropriate, keeps draining pressure.
|
|
|
|
-- below lower presssure: removes it's neighbour water sources.
|
|
|
|
-- finite mode:
|
|
|
|
-- same as for above pressure in non-finite mode,
|
|
|
|
-- but only drains pressure when water source nodes are actually placed.
|
2017-10-07 14:05:52 +02:00
|
|
|
register.output_simple = function(nodename, upper, lower, neighbours)
|
2017-10-07 13:16:36 +02:00
|
|
|
local outputfn = pipeworks.flowlogic.helpers.make_neighbour_output_fixed(neighbours)
|
2017-10-07 14:05:52 +02:00
|
|
|
register.output(nodename, upper, lower, outputfn)
|
2017-10-07 13:16:36 +02:00
|
|
|
end
|