mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-28 16:27:28 +01:00
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,
|
||||
priority=priority}
|
||||
|
||||
--print(dump(action))
|
||||
-- if not using the queue, (MESECONS_GLOBALSTEP off), just execute the function an we're done
|
||||
if not MESECONS_GLOBALSTEP then
|
||||
mesecon.queue:execute(action)
|
||||
return
|
||||
end
|
||||
|
||||
local toremove = nil
|
||||
-- Otherwise, add the action to the queue
|
||||
if overwritecheck then -- check if old action has to be overwritten / removed:
|
||||
for i, ac in ipairs(mesecon.queue.actions) do
|
||||
if(mesecon:cmpPos(pos, ac.pos)
|
||||
and mesecon:cmpAny(overwritecheck, ac.owcheck)) then
|
||||
table.remove(mesecon.queue.actions, i)
|
||||
toremove = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (toremove ~= nil) then
|
||||
table.remove(mesecon.queue.actions, i)
|
||||
end
|
||||
|
||||
table.insert(mesecon.queue.actions, action)
|
||||
end
|
||||
|
||||
|
@ -368,6 +368,12 @@ end
|
||||
function mesecon:turnon(pos, rulename, recdepth)
|
||||
recdepth = recdepth or 2
|
||||
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
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
@ -385,10 +391,16 @@ function mesecon:turnon(pos, rulename, recdepth)
|
||||
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local rulenames = mesecon:rules_link_rule_all(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)
|
||||
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnon(np, rulename, recdepth + 1)
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnon(np, rulename, recdepth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
@ -399,20 +411,36 @@ function mesecon:turnon(pos, rulename, recdepth)
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth)
|
||||
mesecon:turnon(pos, rulename, recdepth)
|
||||
end)
|
||||
|
||||
function mesecon:turnoff(pos, rulename, recdepth)
|
||||
recdepth = recdepth or 0
|
||||
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
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
minetest.swap_node(pos, {name = mesecon:get_conductor_off(node, rulename), param2 = node.param2})
|
||||
|
||||
for _, rule in ipairs(mesecon:rule2meta(rulename, rules)) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
local rulenames = mesecon:rules_link_rule_all(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)
|
||||
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnoff(np, rulename, recdepth + 1)
|
||||
for _, rulename in ipairs(rulenames) do
|
||||
mesecon:turnoff(np, rulename, recdepth + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_effector(node.name) then
|
||||
@ -424,6 +452,10 @@ function mesecon:turnoff(pos, rulename, recdepth)
|
||||
end
|
||||
end
|
||||
|
||||
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth)
|
||||
mesecon:turnoff(pos, rulename, recdepth)
|
||||
end)
|
||||
|
||||
|
||||
function mesecon:connected_to_receptor(pos, rulename)
|
||||
local node = minetest.get_node(pos)
|
||||
|
Loading…
Reference in New Issue
Block a user