summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2012-08-13 04:37:58 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2012-08-13 04:37:58 -0400
commit2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c (patch)
tree1e95a88f641c775a2a2f6a4df7920275adfcd4d1
parent84e4f4cc6ee889324a57bf3fceaea01de646c0f4 (diff)
parentc20a4b3a897b2c55ec6dd7b84fb6404c387d16d0 (diff)
downloadmesecons-2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c.tar
mesecons-2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c.tar.gz
mesecons-2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c.tar.bz2
mesecons-2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c.tar.xz
mesecons-2f5ccf5b4f47f3bcfaa2c25c001b83b1b78cf99c.zip
Merge branch 'master' of github.com:Jeija/minetest-mod-mesecons
-rw-r--r--mesecons/init.lua9
-rw-r--r--mesecons/internal_api.lua29
-rw-r--r--mesecons/services.lua12
-rw-r--r--mesecons/wires.lua4
4 files changed, 39 insertions, 15 deletions
diff --git a/mesecons/init.lua b/mesecons/init.lua
index 0af1503..6715a2f 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -98,7 +98,6 @@ dofile(minetest.get_modpath("mesecons").."/settings.lua")
--Internal API
dofile(minetest.get_modpath("mesecons").."/internal_api.lua");
-
-- API API API API API API API API API API API API API API API API API API
function mesecon:add_receptor_node(nodename, rules, get_rules) --rules table is optional; if rules depend on param2 pass (nodename, nil, function get_rules)
@@ -152,13 +151,16 @@ function mesecon:receptor_off(pos, rules)
rules = mesecon:get_rules("default")
end
+ local checked = {}
+ local connected = false
local i = 1
while rules[i]~=nil do
local np = {}
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- if not mesecon:connected_to_pw_src(np, {}) then
+ connected, checked = mesecon:connected_to_pw_src(np, checked)
+ if not connected then
mesecon:turnoff(np)
end
i=i+1
@@ -220,3 +222,6 @@ print("[MESEcons] Main mod Loaded!")
--The actual wires
dofile(minetest.get_modpath("mesecons").."/wires.lua");
+
+--Services like turnoff receptor on dignode and so on
+dofile(minetest.get_modpath("mesecons").."/services.lua");
diff --git a/mesecons/internal_api.lua b/mesecons/internal_api.lua
index d382328..7570091 100644
--- a/mesecons/internal_api.lua
+++ b/mesecons/internal_api.lua
@@ -288,21 +288,27 @@ end
function mesecon:connected_to_pw_src(pos, checked)
+ if checked == nil then
+ checked = {}
+ end
+ local connected
local i = 1
+
while checked[i] ~= nil do --find out if node has already been checked
if checked[i].x == pos.x and checked[i].y == pos.y and checked[i].z == pos.z then
- return false
+ return false, checked
end
i = i + 1
end
+
checked[i] = {x=pos.x, y=pos.y, z=pos.z} --add current node to checked
local node = minetest.env:get_node_or_nil(pos)
- if node == nil then return false end
+ if node == nil then return false, checked end
if mesecon:is_conductor_on(node.name) or mesecon:is_conductor_off(node.name) then
- if mesecon:is_powered_from_receptor(pos) then --return if conductor is powered
- return true
+ if mesecon:is_powered_by_receptor(pos) then --return if conductor is powered
+ return true, checked
end
local rules = mesecon:get_rules("default") --TODO: Use conductor specific rules
@@ -312,16 +318,17 @@ function mesecon:connected_to_pw_src(pos, checked)
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- if mesecon:connected_to_pw_src(np, checked) == true then
- return true
+ connected, checked = mesecon:connected_to_pw_src(np, checked)
+ if connected then
+ return true
end
i=i+1
end
end
- return false
+ return false, checked
end
-function mesecon:is_powered_from_receptor(pos)
+function mesecon:is_powered_by_receptor(pos)
local rcpt
local rcpt_pos = {}
local rcpt_checked = {} --using a checked array speeds this up
@@ -361,7 +368,7 @@ function mesecon:is_powered_from_receptor(pos)
return false
end
-function mesecon:is_powered_from_conductor(pos)
+function mesecon:is_powered_by_conductor(pos)
local k=1
rules=mesecon:get_rules("default") --TODO: use conductor specific rules
@@ -375,11 +382,11 @@ function mesecon:is_powered_from_conductor(pos)
end
function mesecon:is_powered(pos)
- return mesecon:is_powered_from_conductor(pos) or mesecon:is_powered_from_receptor(pos)
+ return mesecon:is_powered_by_conductor(pos) or mesecon:is_powered_by_receptor(pos)
end
function mesecon:updatenode(pos)
- if mesecon:connected_to_pw_src(pos, {}) then
+ if mesecon:connected_to_pw_src(pos) then
mesecon:turnon(pos)
else
mesecon:turnoff(pos)
diff --git a/mesecons/services.lua b/mesecons/services.lua
new file mode 100644
index 0000000..cf3b78b
--- /dev/null
+++ b/mesecons/services.lua
@@ -0,0 +1,12 @@
+minetest.register_on_dignode(
+ function(pos, oldnode, digger)
+ if mesecon:is_conductor_on(oldnode.name) then
+ local i = 1
+ mesecon:receptor_off(pos)
+ end
+
+ if mesecon:is_receptor_node(oldnode.name) then
+ mesecon:receptor_off(pos)
+ end
+ end
+)
diff --git a/mesecons/wires.lua b/mesecons/wires.lua
index e4c7e6a..450aae2 100644
--- a/mesecons/wires.lua
+++ b/mesecons/wires.lua
@@ -87,8 +87,8 @@ for zmy=0, 1 do
if zpy == 1 then table.insert(nodebox, box_zpy) end
if xmy == 1 then table.insert(nodebox, box_xmy) end
if zmy == 1 then table.insert(nodebox, box_zmy) end
- nobump = xp+zp+xm+zm
- if adjx and adjz and (nobump > 2) then
+
+ if adjx and adjz and (xp + zp + xm + zm > 2) then
table.insert(nodebox, box_bump1)
table.insert(nodebox, box_bump2)
tiles_off = {