generator bugfix

some logic items added
This commit is contained in:
Joachim Stolberg 2019-08-08 00:12:43 +02:00
parent a65aefbc36
commit e52cd2295c
3 changed files with 11 additions and 5 deletions

View File

@ -233,6 +233,9 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end
end,
on_node_load = function(pos)
local mem = tubelib2.get_mem(pos)
-- bug workaround, TODO: remove
mem.generating = mem.techage_state == techage.RUNNING
State:on_node_load(pos)
end,
})

View File

@ -120,6 +120,8 @@ local function node_timer(pos, elapsed)
mem.trigger = (mem.trigger or 1) - 1
if mem.trigger <= 0 then
power_switched(pos)
mem.generating = false
mem.provided = 0
end
return true
else

View File

@ -145,8 +145,8 @@ local function determine_master(pos)
local hash = 0
local master = nil
connection_walk(pos, function(pos, mem)
if mem.generating and mem.could_be_master then
mem.could_be_master = false
mem.generator_available = (mem.generator_available or 1) - 1
if mem.generating and mem.generator_available > 0 then
local new = minetest.hash_node_position(pos)
if hash <= new then
hash = new
@ -186,6 +186,8 @@ local function on_power_switch(pos)
local mem = tubelib2.get_mem(pos)
mem.master_pos = nil
mem.is_master = nil
-- used to check if generator is active
mem.generator_available = 2
local mpos = determine_master(pos)
store_master(pos, mpos)
@ -323,9 +325,8 @@ end
-- Called from every generator every 2 seconds
function techage.power.power_distribution(pos)
local mem = tubelib2.get_mem(pos)
--print("power_distribution", S(pos), mem.is_master)
-- timer is running, which is needed to be master
mem.could_be_master = true
-- used to check if generator is active
mem.generator_available = 2
if mem.is_master then
-- reset values for nect cycle
mem.needed1 = 0