Merge pull request #134 from Novatux/master

Fix a few bugs that caused effectors not to turn off sometimes
This commit is contained in:
Jeija 2014-03-20 09:28:03 +01:00
commit 2cab6aa5ef

View File

@ -469,9 +469,10 @@ function mesecon:connected_to_receptor(pos, rulename)
if not rules then return false end if not rules then return false end
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 rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
if mesecon:rules_link(np, pos) then for _, rname in ipairs(rulenames) do
if mesecon:find_receptor_on(np, {}, mesecon:invertRule(rule)) then local np = mesecon:addPosRule(pos, rname)
if mesecon:find_receptor_on(np, {}, mesecon:invertRule(rname)) then
return true return true
end end
end end
@ -501,9 +502,10 @@ function mesecon:find_receptor_on(pos, checked, rulename)
-- add current position to checked -- add current position to checked
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z, metaindex = metaindex}) table.insert(checked, {x=pos.x, y=pos.y, z=pos.z, metaindex = metaindex})
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 rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
if mesecon:rules_link(np, pos) then for _, rname in ipairs(rulenames) do
if mesecon:find_receptor_on(np, checked, mesecon:invertRule(rule)) then local np = mesecon:addPosRule(pos, rname)
if mesecon:find_receptor_on(np, checked, mesecon:invertRule(rname)) then
return true return true
end end
end end
@ -566,6 +568,26 @@ function mesecon:rules_link_rule_all(output, rule) --output/input are positions
return rules return rules
end end
function mesecon:rules_link_rule_all_inverted(input, rule)
--local irule = mesecon:invertRule(rule)
local output = mesecon:addPosRule(input, rule)
local outputnode = minetest.get_node(output)
local outputrules = mesecon:get_any_outputrules (outputnode)
if not outputrules then
return {}
end
local rules = {}
for _, outputrule in ipairs(mesecon:flattenrules(outputrules)) do
if mesecon:cmpPos(mesecon:addPosRule(output, outputrule), input) then
if outputrule.sx == nil or rule.sx == nil or mesecon:cmpSpecial(outputrule, rule) then
rules[#rules+1] = mesecon:invertRule(outputrule)
end
end
end
return rules
end
function mesecon:rules_link_anydir(pos1, pos2) function mesecon:rules_link_anydir(pos1, pos2)
return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1) return mesecon:rules_link(pos1, pos2) or mesecon:rules_link(pos2, pos1)
end end
@ -577,21 +599,23 @@ function mesecon:is_powered(pos, rule)
if not rule then if not rule then
for _, rule in ipairs(mesecon:flattenrules(rules)) do for _, rule in ipairs(mesecon:flattenrules(rules)) do
local np = mesecon:addPosRule(pos, rule) local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
local nn = minetest.get_node(np) for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname)
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rule)) or mesecon:is_receptor_on (nn.name)) local nn = minetest.get_node(np)
and mesecon:rules_link(np, pos) then if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true return true
end
end end
end end
else else
local np = mesecon:addPosRule(pos, rule) local rulenames = mesecon:rules_link_rule_all_inverted(pos, rule)
local nn = minetest.get_node(np) for _, rname in ipairs(rulenames) do
local np = mesecon:addPosRule(pos, rname)
if (mesecon:is_conductor_on (nn, mesecon:invertRule(rule)) or mesecon:is_receptor_on (nn.name)) local nn = minetest.get_node(np)
and mesecon:rules_link(np, pos) then if (mesecon:is_conductor_on (nn, mesecon:invertRule(rname)) or mesecon:is_receptor_on (nn.name)) then
return true return true
end
end end
end end