From 1dba15733e31799212f054081a44f514bb795738 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 17 Jun 2019 19:57:08 +0200 Subject: [PATCH] power distribution improvement --- basis/consumer.lua | 2 +- furnace/booster.lua | 19 ++++++++++--------- lamps/lib.lua | 5 +++-- power/power.lua | 14 +++++++------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/basis/consumer.lua b/basis/consumer.lua index 05c4d0e..bc76c13 100644 --- a/basis/consumer.lua +++ b/basis/consumer.lua @@ -38,7 +38,7 @@ local consume_power = techage.power.consume_power local power_available = techage.power.power_available local function can_start(pos, mem, state) - return power_available(pos) + return power_available(pos, CRD(pos).power_consumption) end local function start_node(pos, mem, state) diff --git a/furnace/booster.lua b/furnace/booster.lua index da239dd..c59a413 100644 --- a/furnace/booster.lua +++ b/furnace/booster.lua @@ -42,7 +42,6 @@ local function swap_node(pos, name) end local function node_timer(pos, elapsed) - --print("node_timer sink "..S(pos)) local mem = tubelib2.get_mem(pos) if mem.running then local got = consume_power(pos, PWR_NEEDED) @@ -68,7 +67,7 @@ minetest.register_node("techage:ta3_booster", { "techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png", + "techage_filling_ta3.png^techage_appl_hole_electric.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png", }, @@ -80,7 +79,7 @@ minetest.register_node("techage:ta3_booster", { M(pos):set_int("indir", indir) infotext(pos, "stopped") end, - on_time = node_timer, + on_timer = node_timer, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -96,7 +95,7 @@ minetest.register_node("techage:ta3_booster_on", { "techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png", + "techage_filling_ta3.png^techage_appl_hole_electric.png^techage_frame_ta3.png", { image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png", backface_culling = false, @@ -119,7 +118,7 @@ minetest.register_node("techage:ta3_booster_on", { }, }, - on_time = node_timer, + on_timer = node_timer, paramtype2 = "facedir", groups = {not_in_creative_inventory = 1}, diggable = false, @@ -130,7 +129,7 @@ minetest.register_node("techage:ta3_booster_on", { techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { power_network = Power, - conn_sides = {"F", "B", "U", "D"}, + conn_sides = {"F", "B", "U", "D", "L"}, }) -- for intra machine communication @@ -139,18 +138,20 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { if M(pos):get_int("indir") == in_dir then local mem = tubelib2.get_mem(pos) if topic == "power" then - return power_available(pos) + return mem.running elseif topic == "start" then - if power_available(pos) then + if power_available(pos, PWR_NEEDED) then mem.running = true - swap_node(pos, "techage:ta3_booster_on") + node_timer(pos, 2) infotext(pos, "running") + minetest.get_node_timer(pos):start(CYCLE_TIME) else infotext(pos, "no power") end elseif topic == "stop" then mem.running = false swap_node(pos, "techage:ta3_booster") + minetest.get_node_timer(pos):stop() if mem.has_power then infotext(pos, "stopped") else diff --git a/lamps/lib.lua b/lamps/lib.lua index faea531..d555805 100644 --- a/lamps/lib.lua +++ b/lamps/lib.lua @@ -8,6 +8,7 @@ local CYCLE_TIME = 2 local Cable = techage.ElectricCable local consume_power = techage.power.consume_power +local power_available = techage.power.power_available local function swap_node(pos, postfix) local node = techage.get_node_lvm(pos) @@ -40,9 +41,9 @@ local function lamp_on_rightclick(pos, node, clicker) return end local mem = tubelib2.get_mem(pos) - if not mem.running then + if not mem.running and power_available(pos, PWR_NEEDED) then mem.running = true - node_timer(pos, 2) + swap_node(pos, "on") minetest.get_node_timer(pos):start(CYCLE_TIME) else mem.running = false diff --git a/power/power.lua b/power/power.lua index 9f2a21e..f6ea44c 100644 --- a/power/power.lua +++ b/power/power.lua @@ -350,17 +350,17 @@ function techage.power.secondary_power(pos, provide, needed) return 0 end -function techage.power.power_available(pos) +function techage.power.power_available(pos, needed) local mem = tubelib2.get_mem(pos) - if mem.is_master then - return mem.reserve - elseif mem.master_pos then + if mem.master_pos then mem = tubelib2.get_mem(mem.master_pos) + if needed then + -- for next cycle + mem.needed1 = (mem.needed1 or 0) + needed + end return mem.reserve - else - return false end - + return false end function techage.power.percent(max_val, curr_val)