for a new power concept

master
Joachim Stolberg 2019-08-08 14:43:45 +02:00
parent e52cd2295c
commit 857def71e8
4 changed files with 35 additions and 23 deletions

View File

@ -8,7 +8,8 @@ local PWR_PERF = 10
local PWR_CAPA = 300 local PWR_CAPA = 300
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local secondary_power = techage.power2.secondary_power local secondary_power = techage.power.secondary_power
local power_switched = techage.power.power_switched
local function in_range(val, min, max) local function in_range(val, min, max)
if val < min then return min end if val < min then return min end
@ -24,7 +25,7 @@ local function formspec(pos, mem)
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.capa or 0).."]".. "image[0,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.capa or 0).."]"..
"label[0.2,2.5;Load]".. "label[0.2,2.5;Load]"..
"button[1.1,1;1.8,1;update;Update]".. "button[1.1,1;1.8,1;update;Update]"..
"image[4,0.5;1,2;"..techage.power2.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]".. "image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]"..
"label[4.2,2.5;Flow]" "label[4.2,2.5;Flow]"
end end
@ -50,6 +51,7 @@ local function node_timer(pos, elapsed)
--print("delivered = "..mem.delivered) --print("delivered = "..mem.delivered)
return true return true
end end
mem.delivered = 0
return false return false
end end
@ -74,7 +76,7 @@ local function after_place_node(pos, placer)
mem.generating = true mem.generating = true
mem.capa = 0 mem.capa = 0
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
techage.power2.power_switched(pos) techage.power.power_switched(pos)
on_rightclick(pos) on_rightclick(pos)
end end
@ -99,6 +101,6 @@ minetest.register_node("techage:akku", {
on_timer = node_timer, on_timer = node_timer,
}) })
techage.power2.register_node({"techage:akku"}, { techage.power.register_node({"techage:akku"}, {
power_network = Cable, power_network = Cable,
}) })

View File

@ -3,11 +3,11 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local PWR_NEEDED = 2 local PWR_NEEDED = 5
local CYCLE_TIME = 2 local CYCLE_TIME = 4
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local consume_power = techage.power2.consume_power local consume_power = techage.power.consume_power
local function swap_node(pos, name) local function swap_node(pos, name)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -19,20 +19,31 @@ local function swap_node(pos, name)
end end
local function node_timer(pos, elapsed) local function on_power(pos)
--print("node_timer sink "..S(pos))
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.running then --print("sink on_power", mem.running)
mem.timer_running = (mem.timer_running or 1) - 1
if mem.running and mem.timer_running >= 0 then
local got = consume_power(pos, PWR_NEEDED) local got = consume_power(pos, PWR_NEEDED)
if got < PWR_NEEDED then if got < PWR_NEEDED then
swap_node(pos, "techage:sink") swap_node(pos, "techage:sink")
else else
swap_node(pos, "techage:sink_on") swap_node(pos, "techage:sink_on")
mem.power_available = true
end end
return true
end end
swap_node(pos, "techage:sink") end
return false
local function node_timer(pos, elapsed)
--print("node_timer sink "..S(pos))
local mem = tubelib2.get_mem(pos)
if mem.running and not mem.power_available then
--print("sink not triggered")
swap_node(pos, "techage:sink")
end
mem.power_available = false
mem.timer_running = CYCLE_TIME/2 + 1
return true
end end
@ -82,6 +93,7 @@ minetest.register_node("techage:sink_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
techage.power2.register_node({"techage:sink", "techage:sink_on"}, { techage.power.register_node({"techage:sink", "techage:sink_on"}, {
power_network = Cable, power_network = Cable,
on_power = on_power,
}) })

View File

@ -7,13 +7,13 @@ local CYCLE_TIME = 2
local PWR_CAPA = 15 local PWR_CAPA = 15
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local provide_power = techage.power2.provide_power local provide_power = techage.power.provide_power
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
--print("node_timer source "..S(pos)) --print("node_timer source "..S(pos))
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
if mem.generating then if mem.generating then
local delivered = provide_power(pos, PWR_CAPA) local provided = provide_power(pos, PWR_CAPA)
return true return true
end end
return false return false
@ -29,7 +29,7 @@ local function on_rightclick(pos, node, clicker)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
mem.generating = false mem.generating = false
end end
techage.power2.power_switched(pos) techage.power.power_switched(pos)
end end
@ -51,6 +51,6 @@ minetest.register_node("techage:source", {
on_timer = node_timer, on_timer = node_timer,
}) })
techage.power2.register_node({"techage:source"}, { techage.power.register_node({"techage:source"}, {
power_network = Cable, power_network = Cable,
}) })

View File

@ -4,20 +4,18 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local Cable = techage.ElectricCable local Cable = techage.ElectricCable
local on_network_change = techage.power2.on_network_change local power_switched = techage.power.power_switched
local power_switched = techage.power2.power_switched
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {} mem.interrupted_dirs = mem.interrupted_dirs or {}
mem.interrupted = not mem.interrupted mem.interrupted = not mem.interrupted
print("switch", mem.interrupted) --print("switch", mem.interrupted)
if mem.interrupted then if mem.interrupted then
mem.interrupted_dirs = {true, true, true, true, true, true} mem.interrupted_dirs = {true, true, true, true, true, true}
for dir,_ in pairs(mem.connections) do for dir,_ in pairs(mem.connections) do
mem.interrupted_dirs[dir] = false mem.interrupted_dirs[dir] = false
--on_network_change(pos)
power_switched(pos) power_switched(pos)
mem.interrupted_dirs[dir] = true mem.interrupted_dirs[dir] = true
end end
@ -31,7 +29,7 @@ end
minetest.register_node("techage:switch", { minetest.register_node("techage:switch", {
description = "Switch", description = "Switch",
tiles = {'techage_appl_switch_inv.png'}, tiles = {'techage_appl_switch_inv.png'},
on_timer = node_timer, --on_timer = node_timer,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
paramtype = "light", paramtype = "light",