forked from minetest-mods/mesecons
Resume turnon/off calls as soon as area is loaded in case turnon/off calls end in unloaded territory
This commit is contained in:
parent
6afded8284
commit
1083539e9b
|
@ -20,24 +20,28 @@ function mesecon.queue:add_action(pos, func, params, time, overwritecheck, prior
|
||||||
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
|
owcheck=(overwritecheck and mesecon:tablecopy(overwritecheck)) or nil,
|
||||||
priority=priority}
|
priority=priority}
|
||||||
|
|
||||||
--print(dump(action))
|
|
||||||
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
|
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
|
||||||
if not MESECONS_GLOBALSTEP then
|
if not MESECONS_GLOBALSTEP then
|
||||||
mesecon.queue:execute(action)
|
mesecon.queue:execute(action)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local toremove = nil
|
||||||
-- Otherwise, add the action to the queue
|
-- Otherwise, add the action to the queue
|
||||||
if overwritecheck then -- check if old action has to be overwritten / removed:
|
if overwritecheck then -- check if old action has to be overwritten / removed:
|
||||||
for i, ac in ipairs(mesecon.queue.actions) do
|
for i, ac in ipairs(mesecon.queue.actions) do
|
||||||
if(mesecon:cmpPos(pos, ac.pos)
|
if(mesecon:cmpPos(pos, ac.pos)
|
||||||
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
|
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
|
||||||
table.remove(mesecon.queue.actions, i)
|
toremove = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (toremove ~= nil) then
|
||||||
|
table.remove(mesecon.queue.actions, i)
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(mesecon.queue.actions, action)
|
table.insert(mesecon.queue.actions, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -369,6 +369,12 @@ function mesecon:turnon(pos, rulename, recdepth)
|
||||||
recdepth = recdepth or 2
|
recdepth = recdepth or 2
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
|
if(node.name == "ignore") then
|
||||||
|
-- try turning on later again
|
||||||
|
mesecon.queue:add_action(
|
||||||
|
pos, "turnon", {rulename, recdepth + 1}, nil, rulename)
|
||||||
|
end
|
||||||
|
|
||||||
if mesecon:is_conductor_off(node, rulename) then
|
if mesecon:is_conductor_off(node, rulename) then
|
||||||
local rules = mesecon:conductor_get_rules(node)
|
local rules = mesecon:conductor_get_rules(node)
|
||||||
|
|
||||||
|
@ -385,12 +391,18 @@ function mesecon:turnon(pos, rulename, recdepth)
|
||||||
|
|
||||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
|
if(minetest.get_node(np).name == "ignore") then
|
||||||
|
-- try turning on later again
|
||||||
|
mesecon.queue:add_action(
|
||||||
|
np, "turnon", {rulename, recdepth + 1}, nil, rulename)
|
||||||
|
else
|
||||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||||
|
|
||||||
for _, rulename in ipairs(rulenames) do
|
for _, rulename in ipairs(rulenames) do
|
||||||
mesecon:turnon(np, rulename, recdepth + 1)
|
mesecon:turnon(np, rulename, recdepth + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif mesecon:is_effector(node.name) then
|
elseif mesecon:is_effector(node.name) then
|
||||||
mesecon:changesignal(pos, node, rulename, mesecon.state.on, recdepth)
|
mesecon:changesignal(pos, node, rulename, mesecon.state.on, recdepth)
|
||||||
if mesecon:is_effector_off(node.name) then
|
if mesecon:is_effector_off(node.name) then
|
||||||
|
@ -399,22 +411,38 @@ function mesecon:turnon(pos, rulename, recdepth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
|
||||||
|
mesecon:turnon(pos, rulename, recdepth)
|
||||||
|
end)
|
||||||
|
|
||||||
function mesecon:turnoff(pos, rulename, recdepth)
|
function mesecon:turnoff(pos, rulename, recdepth)
|
||||||
recdepth = recdepth or 0
|
recdepth = recdepth or 0
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
|
if(node.name == "ignore") then
|
||||||
|
-- try turning on later again
|
||||||
|
mesecon.queue:add_action(
|
||||||
|
pos, "turnoff", {rulename, recdepth + 1}, nil, rulename)
|
||||||
|
end
|
||||||
|
|
||||||
if mesecon:is_conductor_on(node, rulename) then
|
if mesecon:is_conductor_on(node, rulename) then
|
||||||
local rules = mesecon:conductor_get_rules(node)
|
local rules = mesecon:conductor_get_rules(node)
|
||||||
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2})
|
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2})
|
||||||
|
|
||||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
|
if(minetest.get_node(np).name == "ignore") then
|
||||||
|
-- try turning on later again
|
||||||
|
mesecon.queue:add_action(
|
||||||
|
np, "turnoff", {rulename, recdepth + 1}, nil, rulename)
|
||||||
|
else
|
||||||
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
local rulenames = mesecon:rules_link_rule_all(pos, rule)
|
||||||
|
|
||||||
for _, rulename in ipairs(rulenames) do
|
for _, rulename in ipairs(rulenames) do
|
||||||
mesecon:turnoff(np, rulename, recdepth + 1)
|
mesecon:turnoff(np, rulename, recdepth + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
elseif mesecon:is_effector(node.name) then
|
elseif mesecon:is_effector(node.name) then
|
||||||
mesecon:changesignal(pos, node, rulename, mesecon.state.off, recdepth)
|
mesecon:changesignal(pos, node, rulename, mesecon.state.off, recdepth)
|
||||||
if mesecon:is_effector_on(node.name)
|
if mesecon:is_effector_on(node.name)
|
||||||
|
@ -424,6 +452,10 @@ function mesecon:turnoff(pos, rulename, recdepth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
|
||||||
|
mesecon:turnoff(pos, rulename, recdepth)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
function mesecon:connected_to_receptor(pos, rulename)
|
function mesecon:connected_to_receptor(pos, rulename)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user