for a new power concept
This commit is contained in:
parent
e52cd2295c
commit
857def71e8
@ -8,7 +8,8 @@ local PWR_PERF = 10
|
||||
local PWR_CAPA = 300
|
||||
|
||||
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)
|
||||
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).."]"..
|
||||
"label[0.2,2.5;Load]"..
|
||||
"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]"
|
||||
end
|
||||
|
||||
@ -50,6 +51,7 @@ local function node_timer(pos, elapsed)
|
||||
--print("delivered = "..mem.delivered)
|
||||
return true
|
||||
end
|
||||
mem.delivered = 0
|
||||
return false
|
||||
end
|
||||
|
||||
@ -74,7 +76,7 @@ local function after_place_node(pos, placer)
|
||||
mem.generating = true
|
||||
mem.capa = 0
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
techage.power2.power_switched(pos)
|
||||
techage.power.power_switched(pos)
|
||||
on_rightclick(pos)
|
||||
end
|
||||
|
||||
@ -99,6 +101,6 @@ minetest.register_node("techage:akku", {
|
||||
on_timer = node_timer,
|
||||
})
|
||||
|
||||
techage.power2.register_node({"techage:akku"}, {
|
||||
techage.power.register_node({"techage:akku"}, {
|
||||
power_network = Cable,
|
||||
})
|
@ -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 M = minetest.get_meta
|
||||
|
||||
local PWR_NEEDED = 2
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_NEEDED = 5
|
||||
local CYCLE_TIME = 4
|
||||
|
||||
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 node = minetest.get_node(pos)
|
||||
@ -19,20 +19,31 @@ local function swap_node(pos, name)
|
||||
end
|
||||
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer sink "..S(pos))
|
||||
local function on_power(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)
|
||||
if got < PWR_NEEDED then
|
||||
swap_node(pos, "techage:sink")
|
||||
else
|
||||
swap_node(pos, "techage:sink_on")
|
||||
mem.power_available = true
|
||||
end
|
||||
return true
|
||||
end
|
||||
swap_node(pos, "techage:sink")
|
||||
return false
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -82,6 +93,7 @@ minetest.register_node("techage:sink_on", {
|
||||
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,
|
||||
on_power = on_power,
|
||||
})
|
@ -7,13 +7,13 @@ local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 15
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local provide_power = techage.power2.provide_power
|
||||
local provide_power = techage.power.provide_power
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer source "..S(pos))
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.generating then
|
||||
local delivered = provide_power(pos, PWR_CAPA)
|
||||
local provided = provide_power(pos, PWR_CAPA)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@ -29,7 +29,7 @@ local function on_rightclick(pos, node, clicker)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
mem.generating = false
|
||||
end
|
||||
techage.power2.power_switched(pos)
|
||||
techage.power.power_switched(pos)
|
||||
end
|
||||
|
||||
|
||||
@ -51,6 +51,6 @@ minetest.register_node("techage:source", {
|
||||
on_timer = node_timer,
|
||||
})
|
||||
|
||||
techage.power2.register_node({"techage:source"}, {
|
||||
techage.power.register_node({"techage:source"}, {
|
||||
power_network = Cable,
|
||||
})
|
@ -4,20 +4,18 @@ local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local on_network_change = techage.power2.on_network_change
|
||||
local power_switched = techage.power2.power_switched
|
||||
local power_switched = techage.power.power_switched
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
|
||||
mem.interrupted_dirs = mem.interrupted_dirs or {}
|
||||
mem.interrupted = not mem.interrupted
|
||||
print("switch", mem.interrupted)
|
||||
--print("switch", mem.interrupted)
|
||||
if mem.interrupted then
|
||||
mem.interrupted_dirs = {true, true, true, true, true, true}
|
||||
for dir,_ in pairs(mem.connections) do
|
||||
mem.interrupted_dirs[dir] = false
|
||||
--on_network_change(pos)
|
||||
power_switched(pos)
|
||||
mem.interrupted_dirs[dir] = true
|
||||
end
|
||||
@ -31,7 +29,7 @@ end
|
||||
minetest.register_node("techage:switch", {
|
||||
description = "Switch",
|
||||
tiles = {'techage_appl_switch_inv.png'},
|
||||
on_timer = node_timer,
|
||||
--on_timer = node_timer,
|
||||
on_rightclick = on_rightclick,
|
||||
|
||||
paramtype = "light",
|
Loading…
Reference in New Issue
Block a user