power distribution improvement

This commit is contained in:
Joachim Stolberg 2019-06-17 19:57:08 +02:00
parent ec00baf4d9
commit 1dba15733e
4 changed files with 21 additions and 19 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)