diff --git a/.test/akku.lua b/.test/akku.lua deleted file mode 100644 index 9537fc8..0000000 --- a/.test/akku.lua +++ /dev/null @@ -1,85 +0,0 @@ --- for lazy programmers -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 CYCLE_TIME = 2 -local PWR_PERF = 10 -local PWR_CAPA = 300 - -local Cable = techage.ElectricCable -local power = techage.power - -local function in_range(val, min, max) - if val < min then return min end - if val > max then return max end - return val -end - -local function formspec(pos, mem) - return "size[5,3]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "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.power.formspec_load_bar(-(mem.delivered or 0), PWR_PERF).."]".. - "label[4.2,2.5;Flow]" -end - -local function node_timer(pos, elapsed) - --print("node_timer akku "..S(pos)) - local mem = tubelib2.get_mem(pos) - if mem.running then - mem.delivered = power.secondary_alive(pos, mem, mem.capa, PWR_CAPA) - --print("provided", mem.delivered) - mem.capa = mem.capa - mem.delivered - mem.capa = in_range(mem.capa, 0, PWR_CAPA) - end - return mem.running -end - - -local function on_receive_fields(pos, formname, fields, player) - if minetest.is_protected(pos, player:get_player_name()) then - return - end - - local mem = tubelib2.get_mem(pos) - techage.power.network_changed(pos, mem) - - if fields.update then - M(pos):set_string("formspec", formspec(pos, mem)) - end -end - -minetest.register_node("techage:akku", { - description = "Akku", - tiles = { - -- up, down, right, left, back, front - 'techage_electric_button.png^techage_appl_source.png', - 'techage_electric_button.png^techage_appl_source.png', - 'techage_electric_button.png^techage_appl_source.png^techage_electric_plug.png', - 'techage_electric_button.png^techage_appl_source.png', - 'techage_electric_button.png^techage_appl_source.png', - 'techage_electric_button.png^techage_appl_source.png', - }, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - on_receive_fields = on_receive_fields, - on_timer = node_timer, -}) - -techage.power.register_node({"techage:akku"}, { - power_network = Cable, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - mem.running = true - mem.capa = 0 - minetest.get_node_timer(pos):start(CYCLE_TIME) - power.secondary_start(pos, mem, PWR_PERF, PWR_PERF) - M(pos):set_string("formspec", formspec(pos, mem)) - end, -}) diff --git a/energy_storage/heatexchanger1.lua b/energy_storage/heatexchanger1.lua index cde6fee..19d2b8d 100644 --- a/energy_storage/heatexchanger1.lua +++ b/energy_storage/heatexchanger1.lua @@ -66,7 +66,7 @@ local function play_sound(pos) if not mem.handle or mem.handle == -1 then mem.handle = minetest.sound_play("techage_booster", { pos = pos, - gain = 0.2, + gain = 0.3, max_hear_distance = 10, loop = true}) if mem.handle == -1 then @@ -88,12 +88,9 @@ local function stop_sound(pos) end local function on_power(pos) - play_sound(pos) end local function on_nopower(pos) - nvm.needed = 0 - stop_sound(pos) end local function start_node(pos, nvm) @@ -164,7 +161,9 @@ local function node_timer(pos, elapsed) local taken = 0 local given = 0 - if nvm.capa < (nvm.capa_max * 0.9) then + if nvm.capa < (nvm.capa_max * 0.9) and not nvm.charging then + taken = power.consumer_alive(pos, Cable, CYCLE_TIME) + elseif nvm.capa < nvm.capa_max and nvm.charging then taken = power.consumer_alive(pos, Cable, CYCLE_TIME) end if nvm.capa > 0 then @@ -193,6 +192,8 @@ local net_def = { pipe2 = { sides = {L = 1, R = 1}, ntype = "con1", + on_power = on_power, + on_nopower = on_nopower, }, } @@ -212,7 +213,7 @@ minetest.register_node("techage:heatexchanger1", { after_place_node = after_place_node, can_dig = can_dig, after_dig_node = after_dig_node, - --tubelib2_on_update2 = tubelib2_on_update2, + tubelib2_on_update2 = tubelib2_on_update2, networks = net_def, paramtype2 = "facedir", @@ -228,11 +229,10 @@ Cable:add_secondary_node_names({"techage:heatexchanger1"}) -- command interface techage.register_node({"techage:heatexchanger1"}, { on_transfer = function(pos, indir, topic, payload) - print("on_transfer") local nvm = techage.get_nvm(pos) -- used by heatexchanger2 if topic == "state" then - return nvm.capa_max, nvm.capa, PWR_PERF, math.max(nvm.needed, 0) + return nvm.capa_max, nvm.capa, PWR_PERF, math.max(nvm.needed or 0, 0) elseif topic == "integrity" then return inlet_cmnd(pos, "volume", payload) elseif topic == "state" then diff --git a/energy_storage/heatexchanger2.lua b/energy_storage/heatexchanger2.lua index a310ea3..a7e950d 100644 --- a/energy_storage/heatexchanger2.lua +++ b/energy_storage/heatexchanger2.lua @@ -80,7 +80,6 @@ local State = techage.NodeStates:new({ }) local function node_timer(pos, elapsed) - print("node_timer") local nvm = techage.get_nvm(pos) local res = check_TES_integrity(pos, nvm) if res ~= true then diff --git a/energy_storage/turbine.lua b/energy_storage/turbine.lua index fae2e80..a05aba0 100644 --- a/energy_storage/turbine.lua +++ b/energy_storage/turbine.lua @@ -145,18 +145,7 @@ techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, { if not transfer_heatexchanger3(pos, topic, payload) then return 0 end - local power = transfer_generator(pos, topic, payload) - if not power or power <= 0 and nvm.running then - swap_node(pos, "techage:ta4_turbine") - stop_sound(pos) - nvm.running = false - return 0 - elseif power and power > 0 and not nvm.running then - swap_node(pos, "techage:ta4_turbine_on") - play_sound(pos) - nvm.running = true - end - return power + return transfer_generator(pos, topic, payload) elseif topic == "start" then -- used by generator swap_node(pos, "techage:ta4_turbine_on") play_sound(pos) diff --git a/init.lua b/init.lua index d934fdd..abe4bd8 100644 --- a/init.lua +++ b/init.lua @@ -177,8 +177,6 @@ else dofile(MP.."/recipe_checker.lua") dofile(MP.."/.test/sink.lua") dofile(MP.."/.test/meta_node.lua") - --dofile(MP.."/.test/source.lua") - --dofile(MP.."/.test/accu.lua") -- Solar dofile(MP.."/solar/minicell.lua") diff --git a/power/node_api.lua b/power/node_api.lua index 009b9fe..e9f0bd5 100644 --- a/power/node_api.lua +++ b/power/node_api.lua @@ -162,13 +162,12 @@ function techage.power.consumer_alive(pos, Cable, cycle_time) local rv = (cycle_time / 2) + 1 if def["netID"] and def["calive"] and def["calive"] < rv then -- network available def["calive"] = rv + return def["taken"] or 0 elseif not def["cstate"] or def["cstate"] == RUNNING then local ndef = net_def(pos, Cable.tube_type) ndef.on_nopower(pos, Cable.tube_type) def["cstate"] = NOPOWER - return 0 end - return def["taken"] or 0 else local ndef = net_def(pos, Cable.tube_type) ndef.on_nopower(pos, Cable.tube_type) diff --git a/ta3_power/akkubox.lua b/ta3_power/akkubox.lua index 99437cc..87dbed4 100644 --- a/ta3_power/akkubox.lua +++ b/ta3_power/akkubox.lua @@ -43,6 +43,11 @@ local function formspec(self, pos, nvm) "image[4,1.7;1,2;"..techage.power.formspec_load_bar(needed, PWR_PERF).."]" end +local function on_power(pos) +end + +local function on_nopower(pos) +end local function start_node(pos, nvm, state) nvm.running = true @@ -159,6 +164,8 @@ local net_def = { sides = {R = 1}, ntype = {"gen2", "con2"}, nominal = PWR_PERF, + on_power = on_power, + on_nopower = on_nopower, }, }