power distribution improvement
This commit is contained in:
parent
ec00baf4d9
commit
1dba15733e
@ -38,7 +38,7 @@ local consume_power = techage.power.consume_power
|
|||||||
local power_available = techage.power.power_available
|
local power_available = techage.power.power_available
|
||||||
|
|
||||||
local function can_start(pos, mem, state)
|
local function can_start(pos, mem, state)
|
||||||
return power_available(pos)
|
return power_available(pos, CRD(pos).power_consumption)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_node(pos, mem, state)
|
local function start_node(pos, mem, state)
|
||||||
|
@ -42,7 +42,6 @@ local function swap_node(pos, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function node_timer(pos, elapsed)
|
local function node_timer(pos, elapsed)
|
||||||
--print("node_timer sink "..S(pos))
|
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
if mem.running then
|
if mem.running then
|
||||||
local got = consume_power(pos, PWR_NEEDED)
|
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_appl_arrow.png^techage_frame_ta3.png",
|
||||||
"techage_filling_ta3.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_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^techage_frame_ta3.png",
|
||||||
"techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^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)
|
M(pos):set_int("indir", indir)
|
||||||
infotext(pos, "stopped")
|
infotext(pos, "stopped")
|
||||||
end,
|
end,
|
||||||
on_time = node_timer,
|
on_timer = node_timer,
|
||||||
|
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2, crumbly=2, choppy=2},
|
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_appl_arrow.png^techage_frame_ta3.png",
|
||||||
"techage_filling_ta3.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_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",
|
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png",
|
||||||
backface_culling = false,
|
backface_culling = false,
|
||||||
@ -119,7 +118,7 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
on_time = node_timer,
|
on_timer = node_timer,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {not_in_creative_inventory = 1},
|
groups = {not_in_creative_inventory = 1},
|
||||||
diggable = false,
|
diggable = false,
|
||||||
@ -130,7 +129,7 @@ minetest.register_node("techage:ta3_booster_on", {
|
|||||||
|
|
||||||
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
||||||
power_network = Power,
|
power_network = Power,
|
||||||
conn_sides = {"F", "B", "U", "D"},
|
conn_sides = {"F", "B", "U", "D", "L"},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- for intra machine communication
|
-- 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
|
if M(pos):get_int("indir") == in_dir then
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
if topic == "power" then
|
if topic == "power" then
|
||||||
return power_available(pos)
|
return mem.running
|
||||||
elseif topic == "start" then
|
elseif topic == "start" then
|
||||||
if power_available(pos) then
|
if power_available(pos, PWR_NEEDED) then
|
||||||
mem.running = true
|
mem.running = true
|
||||||
swap_node(pos, "techage:ta3_booster_on")
|
node_timer(pos, 2)
|
||||||
infotext(pos, "running")
|
infotext(pos, "running")
|
||||||
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
else
|
else
|
||||||
infotext(pos, "no power")
|
infotext(pos, "no power")
|
||||||
end
|
end
|
||||||
elseif topic == "stop" then
|
elseif topic == "stop" then
|
||||||
mem.running = false
|
mem.running = false
|
||||||
swap_node(pos, "techage:ta3_booster")
|
swap_node(pos, "techage:ta3_booster")
|
||||||
|
minetest.get_node_timer(pos):stop()
|
||||||
if mem.has_power then
|
if mem.has_power then
|
||||||
infotext(pos, "stopped")
|
infotext(pos, "stopped")
|
||||||
else
|
else
|
||||||
|
@ -8,6 +8,7 @@ local CYCLE_TIME = 2
|
|||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local consume_power = techage.power.consume_power
|
local consume_power = techage.power.consume_power
|
||||||
|
local power_available = techage.power.power_available
|
||||||
|
|
||||||
local function swap_node(pos, postfix)
|
local function swap_node(pos, postfix)
|
||||||
local node = techage.get_node_lvm(pos)
|
local node = techage.get_node_lvm(pos)
|
||||||
@ -40,9 +41,9 @@ local function lamp_on_rightclick(pos, node, clicker)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local mem = tubelib2.get_mem(pos)
|
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
|
mem.running = true
|
||||||
node_timer(pos, 2)
|
swap_node(pos, "on")
|
||||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||||
else
|
else
|
||||||
mem.running = false
|
mem.running = false
|
||||||
|
@ -350,17 +350,17 @@ function techage.power.secondary_power(pos, provide, needed)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.power.power_available(pos)
|
function techage.power.power_available(pos, needed)
|
||||||
local mem = tubelib2.get_mem(pos)
|
local mem = tubelib2.get_mem(pos)
|
||||||
if mem.is_master then
|
if mem.master_pos then
|
||||||
return mem.reserve
|
|
||||||
elseif mem.master_pos then
|
|
||||||
mem = tubelib2.get_mem(mem.master_pos)
|
mem = tubelib2.get_mem(mem.master_pos)
|
||||||
|
if needed then
|
||||||
|
-- for next cycle
|
||||||
|
mem.needed1 = (mem.needed1 or 0) + needed
|
||||||
|
end
|
||||||
return mem.reserve
|
return mem.reserve
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function techage.power.percent(max_val, curr_val)
|
function techage.power.percent(max_val, curr_val)
|
||||||
|
Loading…
Reference in New Issue
Block a user