lowering voltage on comparator

This commit is contained in:
Henry Behrendt 2021-08-24 20:57:47 +02:00
parent fa824a3c72
commit 7f679e5808
1 changed files with 6 additions and 5 deletions

View File

@ -46,13 +46,14 @@ local function comparator_turnon(params)
end end
function comparator_removevoltage(pos, link, voltage) function comparator_removevoltage(pos, link, voltage)
local frontiers = {{pos = pos, link = link}}
local signals = {}
local rec_on = {}
local cur_vol = voltage+1 local cur_vol = voltage+1
minetest.log("action", mesecon.postostring(pos) .. "-->" .. "comparator_removevoltage" .. " v="..cur_vol) minetest.log("action", mesecon.postostring(pos) .. "-->" .. "comparator_removevoltage" .. " v="..cur_vol)
local frontiers = {{pos = pos, link = link, voltage=cur_vol}}
local depth = 1 local depth = 1
while frontiers[1] do while frontiers[1] do
local f = table.remove(frontiers, 1) local f = table.remove(frontiers, 1)
@ -63,7 +64,7 @@ function comparator_removevoltage(pos, link, voltage)
local tmp_vol = (meta:get_string("mesecon_voltage")~="" and meta:get_int("mesecon_voltage") or 15) local tmp_vol = (meta:get_string("mesecon_voltage")~="" and meta:get_int("mesecon_voltage") or 15)
if tmp_vol<cur_vol and tmp_vol>=1 then if tmp_vol<f.voltage and tmp_vol>=1 then
--solange spannung niedriger wird --solange spannung niedriger wird
cur_vol = tmp_vol cur_vol = tmp_vol
meta:set_int("mesecon_voltage", 0) meta:set_int("mesecon_voltage", 0)
@ -72,7 +73,7 @@ function comparator_removevoltage(pos, link, voltage)
local np = vector.add(f.pos, r) local np = vector.add(f.pos, r)
-- check neighbors -- check neighbors
for _, l in pairs(mesecon.rules_link_rule_all(f.pos, r)) do for _, l in pairs(mesecon.rules_link_rule_all(f.pos, r)) do
table.insert(frontiers, {pos = np, link = l}) table.insert(frontiers, {pos = np, link = l, voltage=cur_vol})
end end
end end
end end