From 37f646267301e2207d8f885ee6d00b633dd09ee7 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 5 Mar 2023 21:44:35 +0100 Subject: [PATCH] Improve transformer and electricmeter --- basic_machines/electronic_fab.lua | 2 +- basic_machines/quarry.lua | 2 +- basis/fly_lib.lua | 2 +- collider/detector.lua | 2 +- collider/magnet.lua | 2 +- doc/manual_DE.lua | 6 ++- doc/manual_EN.lua | 6 ++- lamps/growlight.lua | 8 ++-- locale/techage.de.tr | 34 +++++++++++--- locale/template.txt | 29 +++++++++--- logic/detector.lua | 4 +- manuals/manual_ta4_DE.md | 8 +++- manuals/manual_ta4_EN.md | 6 ++- move_controller/doorcontroller2.lua | 6 +-- power/formspecs.lua | 4 +- power/power_terminal2.lua | 2 +- ta4_power/electricmeter.lua | 69 ++++++++++++++++++++++++----- ta4_power/transformer.lua | 40 +++++++++++++---- 18 files changed, 172 insertions(+), 60 deletions(-) diff --git a/basic_machines/electronic_fab.lua b/basic_machines/electronic_fab.lua index 1ef1934..6084643 100644 --- a/basic_machines/electronic_fab.lua +++ b/basic_machines/electronic_fab.lua @@ -26,7 +26,7 @@ local recipes = techage.recipes local RecipeType = { [2] = "ta2_electronic_fab", - [3] = "ta3_electronic_fab", + [3] = "ta3_electronic_fab", [4] = "ta4_electronic_fab", } diff --git a/basic_machines/quarry.lua b/basic_machines/quarry.lua index b244222..71530ec 100644 --- a/basic_machines/quarry.lua +++ b/basic_machines/quarry.lua @@ -197,7 +197,7 @@ local function quarry_task(pos, crd, nvm) pos2.y = y_curr -- Restarting the server can detach the coroutine data. - -- Therefore, read nvm again. + -- Therefore, read nvm again. nvm = techage.get_nvm(pos) nvm.level = y_first - y_curr diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index 39ac390..193a06d 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -660,7 +660,7 @@ local function multi_move_nodes(pos, meta, nvm, lmove, max_speed, height, move2t return true end --- Move the nodes from lpos1 to lpos2. +-- Move the nodes from lpos1 to lpos2. -- * lpos1 is a list of nodes -- * lpos2 = lpos1 + move -- * pos and meta are controller block related diff --git a/collider/detector.lua b/collider/detector.lua index c5dee94..a9a8b1c 100644 --- a/collider/detector.lua +++ b/collider/detector.lua @@ -190,7 +190,7 @@ local function cable_inlets_turn_on_off(pos, on) techage.power_inlet_turn_on_off(pos2, nvm, on) end end - + local param2 = minetest.get_node(pos).param2 turn_on_off(pos, param2, Schedule[2]) turn_on_off(pos, param2, Schedule[3]) diff --git a/collider/magnet.lua b/collider/magnet.lua index 73dc365..0309421 100644 --- a/collider/magnet.lua +++ b/collider/magnet.lua @@ -132,7 +132,7 @@ minetest.register_node("techage:ta4_magnet", { nvm.running = nil return -2 end, - + on_turn_off = function(pos) local nvm = techage.get_nvm(pos) nvm.running = nil diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index 9e910d8..7e92bcc 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -1447,13 +1447,15 @@ techage.manual_DE.aText = { "\n", "Mit Hilfe eines Trenntransformators können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Trenntransformator kann Strom in beide Richtungen übertragen.\n".. "\n".. - "Der Trenntransformator kann bis zu 100 ku übertragen.\n".. + "Der Trenntransformator kann bis zu 300 ku übertragen. Der Maximalwert ist über das Schraubenschlüsselmenü einstellbar.\n".. "\n".. "\n".. "\n", "Mit Hilfe eines Stromzählers können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Stromzähler leitet den Strom nur in eine Richtungen weiter (Pfeil beachten). Die Menge an Strom (in kud) wird gemessen und angezeigt. Die Strommenge kann auch über das Kommando 'consumption' durch einen Lua Controller abgefragt werden.\n".. "\n".. - "Der Stromzähler kann bis zu 200 ku durchleiten.\n".. + "Der Stromzähler kann bis zu 200 ku durchleiten. Der Maximalwert ist über das Schraubenschlüsselmenü einstellbar.\n".. + "\n".. + "Über das Schraubenschlüsselmenü kann auch ein Countdown für die Leistungsabgabe eingegeben werden. Läuft dieser Countdown auf Null\\, schaltet sich der Stromzähler ab. Der Countdown kann über das Kommando 'countdown' abgefragt werden.\n".. "\n".. "\n".. "\n", diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 0e8365f..a2d3778 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -1457,13 +1457,15 @@ techage.manual_EN.aText = { "\n", "With the help of an isolating transformer\\, two power grids can be connected to form a larger network. The isolation transformer can transmit electricity in both directions.\n".. "\n".. - "The isolation transformer can transmit up to 100 ku. \n".. + "The isolation transformer can transmit up to 300 ku. The maximum value is adjustable via the wrench menu.\n".. "\n".. "\n".. "\n", "With the help of an electricity meter\\, two electricity networks can be connected to form a larger network. The electricity meter only transmits electricity in one direction (note arrow). The amount of electricity (in kud) is measured and displayed. The amount of electricity can also be queried by a Lua controller using the 'consumption' command.\n".. "\n".. - "The electricity meter can pass up to 200 ku. \n".. + "The electricity meter can pass up to 200 ku. The maximum value is adjustable via the wrench menu.\n".. + "\n".. + "A power output countdown can also be entered via the wrench menu. When this countdown reaches zero\\, the electricity meter switches off. The countdown can be queried using the 'countdown' command.\n".. "\n".. "\n".. "\n", diff --git a/lamps/growlight.lua b/lamps/growlight.lua index 119bcb0..10ce91d 100644 --- a/lamps/growlight.lua +++ b/lamps/growlight.lua @@ -181,15 +181,15 @@ local function contains(table, element) end function techage.register_flower(name) - if contains(Flowers, name) then - return + if contains(Flowers, name) then + return end Flowers[#Flowers+1] = name end function techage.register_plant(name) - if contains(Plants, name) then - return + if contains(Plants, name) then + return end Plants[name] = true end diff --git a/locale/techage.de.tr b/locale/techage.de.tr index ce57498..fd997ec 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -291,7 +291,6 @@ TA2 Cylinder=TA2 Zylinder ### detector.lua ### -Countdown=Countdown Counts down the number of items passed through@nand only triggers an 'on' command when it reaches zero.=Zählt die Anzahl der durchlaufenen Elemente herunter@nund löst nur dann einen 'ON'-Befehl aus, wenn er Null erreicht. Current countdown=Aktueller Zähler Current countdown value.=Aktueller Zählerwert. @@ -299,6 +298,11 @@ TA4 Collider Detector=TA4 Collider Detektor TA4 Collider Detector Core=TA4 Collider Detektorkern TA4 Detector=TA4 Detektor +### detector.lua ### +### electricmeter.lua ### + +Countdown=Countdown + ### detector.lua ### ### logic_block.lua ### ### tele.lua ### @@ -348,12 +352,11 @@ TA3 Door Controller=TA3 Tür Controller ### doorcontroller2.lua ### -Blocks are back=Blöcke sind wieder da -Blocks are disappeared=Blöcke sind verschwunden +Blocks exchanged=Blöcke ausgetauscht +Blocks reset=Blöcke rückgesetzt Click on all the blocks that are part of the door/gate=Klicke auf alle Blöcke, die Teil des Tores sind Ctrl,Inv=Ctrl,Inv -Remove=Entfernen -Set=Setzen +Exchange=Austauschen TA3 Door Controller II=TA3 Tür Controller II with door sound=mit Türgeräusch @@ -367,6 +370,11 @@ Record=Aufzeichnen Recording...=Aufzeichnung... block positions are stored.=Block Positionen gespeichert. +### doorcontroller2.lua ### +### movecontroller.lua ### + +Reset=Rücksetzen + ### drillbox.lua ### Build derrick=Errichte Ölturm @@ -388,7 +396,9 @@ TA Electric Cable=TA Stromkabel ### electricmeter.lua ### +Amount of power to be provided before the device turns off=Strommenge, die bereitgestellt werden soll, bis sich das Gerät ausschaltet Consumption=Verbrauch +Power countdown=Leistungs-Countdown TA4 Electric Meter=TA4 Stromzähler ### electricmeter.lua ### @@ -397,6 +407,12 @@ TA4 Electric Meter=TA4 Stromzähler Power=Strom +### electricmeter.lua ### +### transformer.lua ### + +Max. power=Max. Leistung +Maximum power passed through=Max. Leistung, die durchgeleitet werden soll + ### electrolyzer.lua ### Configurable value@nfor the current limit=Konfigurierbarer Wert@nfür die Strombegrenzung @@ -904,7 +920,6 @@ Error: Invalid distance !!=Fehler: Ungültige Entfernung !! Move distance=Entfernung Move distance (A to B)=Entfernung (A nach B) Operational mode=Betriebsmodus -Reset=Rücksetzen Switch to the remote controlled 'move xyz' mode=Wechseln in den ferngesteuerten 'move xyz'-Modus TA Rack and Pinion=TA Zahnstange TA4 Move Controller=TA4 Move Controller @@ -1000,7 +1015,7 @@ TA Power Pole Top 2 (for landlines)=TA Strommastkopf 2 (für Überlandleitungen) ### power_terminal2.lua ### -Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@ncon . . . . . print main consumers@n=Kommandos@nhelp . . . diesen Text ausgeben@ncls . . . . . Bildschirm löschen@ngen . . . . Alle Generatoren ausgeben@nsto . . . . . Alle Speichersysteme ausgeben@ncon . . . . . Hauptverbraucher ausgeben@n +Commands@nhelp . . . print this text@ncls . . . . clear screen@ngen . . print generators@nsto . . print storage systems@ncon1 . . print consumers with power consumption between 1 and 10 ku@ncon2 . . print consumers with power consumption with 10 ku or above@n=Commands@nhelp . . . diesen Text ausgeben@ncls . . . . lösche Bildschirm@ngen . . Generatoren ausgeben@nsto . . Speichersysteme ausgeben@ncon1 . . Verbraucher mit einem Verbrauch zw. 1 und 10 ku ausgeben@ncon2 . . Verbraucher ab 10 ku Verbrauch ausgeben@n Consumer=Verbraucher Network Data=Netzwerkdaten Number of consumers:=Anzahl der Verbraucher @@ -1511,6 +1526,11 @@ TA4 Collider Detector Worker=TA4 Collider Detektor Worker ##### not used anymore ##### +Blocks are back=Blöcke sind wieder da +Blocks are disappeared=Blöcke sind verschwunden +Remove=Entfernen +Set=Setzen +Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@ncon . . . . . print main consumers@n=Kommandos@nhelp . . . diesen Text ausgeben@ncls . . . . . Bildschirm löschen@ngen . . . . Alle Generatoren ausgeben@nsto . . . . . Alle Speichersysteme ausgeben@ncon . . . . . Hauptverbraucher ausgeben@n Handover to A=Übergabe an A Handover to B=Übergabe an B Number of the next movecontroller=Nummer des nächsten Move Controllers diff --git a/locale/template.txt b/locale/template.txt index c75c27a..41571f9 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -291,7 +291,6 @@ TA2 Cylinder= ### detector.lua ### -Countdown= Counts down the number of items passed through@nand only triggers an 'on' command when it reaches zero.= Current countdown= Current countdown value.= @@ -299,6 +298,11 @@ TA4 Collider Detector= TA4 Collider Detector Core= TA4 Detector= +### detector.lua ### +### electricmeter.lua ### + +Countdown= + ### detector.lua ### ### logic_block.lua ### ### tele.lua ### @@ -348,12 +352,11 @@ TA3 Door Controller= ### doorcontroller2.lua ### -Blocks are back= -Blocks are disappeared= +Blocks exchanged= +Blocks reset= Click on all the blocks that are part of the door/gate= Ctrl,Inv= -Remove= -Set= +Exchange= TA3 Door Controller II= with door sound= @@ -367,6 +370,11 @@ Record= Recording...= block positions are stored.= +### doorcontroller2.lua ### +### movecontroller.lua ### + +Reset= + ### drillbox.lua ### Build derrick= @@ -388,7 +396,9 @@ TA Electric Cable= ### electricmeter.lua ### +Amount of power to be provided before the device turns off= Consumption= +Power countdown= TA4 Electric Meter= ### electricmeter.lua ### @@ -397,6 +407,12 @@ TA4 Electric Meter= Power= +### electricmeter.lua ### +### transformer.lua ### + +Max. power= +Maximum power passed through= + ### electrolyzer.lua ### Configurable value@nfor the current limit= @@ -904,7 +920,6 @@ Error: Invalid distance !!= Move distance= Move distance (A to B)= Operational mode= -Reset= Switch to the remote controlled 'move xyz' mode= TA Rack and Pinion= TA4 Move Controller= @@ -1000,7 +1015,7 @@ TA Power Pole Top 2 (for landlines)= ### power_terminal2.lua ### -Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@ncon . . . . . print main consumers@n= +Commands@nhelp . . . print this text@ncls . . . . clear screen@ngen . . print generators@nsto . . print storage systems@ncon1 . . print consumers with power consumption between 1 and 10 ku@ncon2 . . print consumers with power consumption with 10 ku or above@n= Consumer= Network Data= Number of consumers:= diff --git a/logic/detector.lua b/logic/detector.lua index daf790c..d7985ba 100644 --- a/logic/detector.lua +++ b/logic/detector.lua @@ -167,7 +167,7 @@ local function ta_after_formspec(pos, fields, playername) local nvm = techage.get_nvm(pos) local val = M(pos):get_int("countdown") or 0 if val > 0 then - nvm.countdown = val + nvm.countdown = val else nvm.countdown = nil end @@ -326,7 +326,7 @@ techage.register_node({"techage:ta4_detector_off", "techage:ta4_detector_on"}, { if leftover ~= true then num_moved = num_moved - leftover:get_count() end - + if nvm.countdown and nvm.countdown > 0 then nvm.countdown = nvm.countdown - num_moved if nvm.countdown <= 0 then diff --git a/manuals/manual_ta4_DE.md b/manuals/manual_ta4_DE.md index 4ca0835..615bc7f 100644 --- a/manuals/manual_ta4_DE.md +++ b/manuals/manual_ta4_DE.md @@ -205,7 +205,7 @@ Mit Hilfe von Trenntransformator und Stromzähler können Netzwerke zu noch grö Mit Hilfe eines Trenntransformators können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Trenntransformator kann Strom in beide Richtungen übertragen. -Der Trenntransformator kann bis zu 100 ku übertragen. +Der Trenntransformator kann bis zu 300 ku übertragen. Der Maximalwert ist über das Schraubenschlüsselmenü einstellbar. [ta4_transformer|image] @@ -215,7 +215,11 @@ Der Trenntransformator kann bis zu 100 ku übertragen. Mit Hilfe eines Stromzählers können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Stromzähler leitet den Strom nur in eine Richtungen weiter (Pfeil beachten). Die Menge an Strom (in kud) wird gemessen und angezeigt. Die Strommenge kann auch über das Kommando `consumption` durch einen Lua Controller abgefragt werden. -Der Stromzähler kann bis zu 200 ku durchleiten. +Der Stromzähler kann bis zu 200 ku durchleiten. Der Maximalwert ist über das Schraubenschlüsselmenü einstellbar. + +Über das Schraubenschlüsselmenü kann auch ein Countdown für die Leistungsabgabe eingegeben werden. Läuft dieser Countdown auf Null, schaltet sich der Stromzähler ab. Der Countdown kann über das Kommando `countdown` abgefragt werden. + + [ta4_electricmeter|image] diff --git a/manuals/manual_ta4_EN.md b/manuals/manual_ta4_EN.md index d034e18..6e564fc 100644 --- a/manuals/manual_ta4_EN.md +++ b/manuals/manual_ta4_EN.md @@ -204,7 +204,7 @@ With the help of an isolating transformer and electricity meter, networks can be With the help of an isolating transformer, two power grids can be connected to form a larger network. The isolation transformer can transmit electricity in both directions. -The isolation transformer can transmit up to 100 ku. +The isolation transformer can transmit up to 300 ku. The maximum value is adjustable via the wrench menu. [ta4_transformer|image] @@ -212,7 +212,9 @@ The isolation transformer can transmit up to 100 ku. With the help of an electricity meter, two electricity networks can be connected to form a larger network. The electricity meter only transmits electricity in one direction (note arrow). The amount of electricity (in kud) is measured and displayed. The amount of electricity can also be queried by a Lua controller using the `consumption` command. -The electricity meter can pass up to 200 ku. +The electricity meter can pass up to 200 ku. The maximum value is adjustable via the wrench menu. + +A power output countdown can also be entered via the wrench menu. When this countdown reaches zero, the electricity meter switches off. The countdown can be queried using the `countdown` command. [ta4_electricmeter|image] diff --git a/move_controller/doorcontroller2.lua b/move_controller/doorcontroller2.lua index 175cb0e..828fd33 100644 --- a/move_controller/doorcontroller2.lua +++ b/move_controller/doorcontroller2.lua @@ -60,8 +60,8 @@ end local function get_new_nodename(item) local name = item:get_name() - if name == "" then - return "air" + if name == "" then + return "air" end return name end @@ -228,7 +228,7 @@ end -- Generate a table of currently available inventory and placed nodes local function available_nodes(pos, nvm, item_list) local nodes = {} - + for idx = 1, NUMSLOTS do local item = item_list[idx] if item and item:get_count() > 0 then diff --git a/power/formspecs.lua b/power/formspecs.lua index a982637..071b0ef 100644 --- a/power/formspecs.lua +++ b/power/formspecs.lua @@ -157,9 +157,9 @@ end function techage.formspec_meter(pos, x, y, label, value, unit) return "container[" .. x .. "," .. y .. "]" .. - "box[0,0;2.3,1.2;#395c74]" .. + "box[0,0;2.3,0.9;#395c74]" .. "label[0.2,0.0;" .. label .. ":]" .. - "label[0.2,0.5;" .. round(value) .. " " .. unit .. "]" .. + "label[0.2,0.4;" .. round(value) .. " " .. unit .. "]" .. "container_end[]" end diff --git a/power/power_terminal2.lua b/power/power_terminal2.lua index b8bcd58..cc13626 100644 --- a/power/power_terminal2.lua +++ b/power/power_terminal2.lua @@ -140,7 +140,7 @@ local function storages(pos) local resp = control.request(pos, Cable, outdir, "sto", "info") for _, item in ipairs(resp) do -- TA4/TA5 heatexchangers are no storage systems - if item.capa and item.capa > 1 then + if item.capa and item.capa > 1 then if item.running then local s = string.format("%s (%s): %s/%s kud", item.type, item.number, diff --git a/ta4_power/electricmeter.lua b/ta4_power/electricmeter.lua index ca10ad9..f55c216 100644 --- a/ta4_power/electricmeter.lua +++ b/ta4_power/electricmeter.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2022 Joachim Stolberg + Copyright (C) 2019-2023 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -24,25 +24,54 @@ local Cable = techage.ElectricCable local power = networks.power local control = networks.control +local WRENCH_MENU = { + { + type = "dropdown", + choices = "200 ku,150 ku,100 ku,50 ku,20 ku", + name = "current", + label = S("Max. power"), + tooltip = S("Maximum power passed through"), + default = "100 ku", + values = {200, 150, 100, 50, 20} + }, + { + type = "number", + name = "countdown", + label = S("Power countdown"), + tooltip = S("Amount of power to be provided before the device turns off"), + default = "0", + }, +} + +local function max_current(pos) + local meta = M(pos) + if meta:contains("current") then + local current = meta:get_int("current") + return current > 0 and current or PWR_PERF + end + return PWR_PERF +end local function formspec(self, pos, nvm, power) local units = (nvm.units or 0) / techage.CYCLES_PER_DAY + nvm.countdown = nvm.countdown or M(pos):get_int("countdown") power = power or 0 return "size[5,4]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. "box[0,-0.1;4.8,0.5;#c6e8ff]" .. + techage.wrench_image(4.4, -0.08) .. "label[0.2,-0.1;" .. minetest.colorize( "#000000", S("TA4 Electric Meter")).."]" .. - techage.formspec_power_bar(pos, 0.0, 0.7, S("Power"), power, PWR_PERF) .. + techage.formspec_power_bar(pos, 0.0, 0.7, S("Power"), power, max_current(pos)) .. techage.formspec_meter(pos, 2.5, 0.7, S("Consumption"), units, "kud") .. - "image_button[3.2,2.2;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + techage.formspec_meter(pos, 2.5, 1.7, S("Countdown"), nvm.countdown, "kud") .. + "image_button[3.2,3.0;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. "tooltip[3.2,2.2;1,1;" .. self:get_state_tooltip(nvm) .. "]" end local function start_node(pos, nvm, state) local outdir = M(pos):get_int("outdir") + nvm.load = 0 + nvm.countdown = M(pos):get_int("countdown") power.start_storage_calc(pos, Cable, outdir) outdir = networks.Flip[outdir] power.start_storage_calc(pos, Cable, outdir) @@ -71,11 +100,19 @@ local function node_timer(pos, elapsed) if techage.is_running(nvm) then local outdir2 = M(pos):get_int("outdir") local outdir1 = networks.Flip[outdir2] - data = power.transfer_simplex(pos, Cable, outdir1, Cable, outdir2, PWR_PERF) + local current = max_current(pos) + data = power.transfer_simplex(pos, Cable, outdir1, Cable, outdir2, current) if data then - nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * PWR_PERF + nvm.countdown = nvm.countdown or M(pos):get_int("countdown") + nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * current nvm.moved = data.moved nvm.units = (nvm.units or 0) + data.moved + if nvm.countdown > 0 then + nvm.countdown = nvm.countdown - (data.moved / techage.CYCLES_PER_DAY) + if nvm.countdown <= 0 then + State:stop(pos, nvm) + end + end end end if techage.is_activeformspec(pos) then @@ -118,7 +155,8 @@ local function get_generator_data(pos, outdir, tlib2) -- check for secondary/generator side if outdir == M(pos):get_int("outdir") then if techage.is_running(nvm) then - return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} + local current = max_current(pos) + return {level = (nvm.load or 0) / current, perf = current, capa = current * 2} end end end @@ -140,6 +178,7 @@ minetest.register_node("techage:ta4_electricmeter", { on_receive_fields = on_receive_fields, after_place_node = after_place_node, after_dig_node = after_dig_node, + ta4_formspec = WRENCH_MENU, get_generator_data = get_generator_data, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -156,6 +195,8 @@ techage.register_node({"techage:ta4_electricmeter"}, { local nvm = techage.get_nvm(pos) if topic == "consumption" then return math.floor((nvm.units or 0) / techage.CYCLES_PER_DAY) + elseif topic == "countdown" then + return math.floor((nvm.countdown or 0) + 0.5) else return State:on_receive_message(pos, topic, payload) end @@ -165,8 +206,12 @@ techage.register_node({"techage:ta4_electricmeter"}, { end, on_beduino_request_data = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) - if topic == 146 then -- Consumption - return 0, {math.floor((nvm.units or 0) / techage.CYCLES_PER_DAY)} + if topic == 146 then + if payload[1] == 0 then -- Consumption + return 0, {math.floor((nvm.units or 0) / techage.CYCLES_PER_DAY)} + else -- countdown + return 0, {math.floor((nvm.countdown or 0) + 0.5)} + end else return State:on_beduino_request_data(pos, topic, payload) end @@ -184,7 +229,7 @@ control.register_nodes({"techage:ta4_electricmeter"}, { type = S("TA4 Electric Meter"), number = meta:get_string("node_number") or "", running = techage.is_running(nvm) or false, - available = PWR_PERF, + available = max_current(pos), provided = nvm.moved or 0, termpoint = "-", } diff --git a/ta4_power/transformer.lua b/ta4_power/transformer.lua index d1ff216..82d86bc 100644 --- a/ta4_power/transformer.lua +++ b/ta4_power/transformer.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2022 Joachim Stolberg + Copyright (C) 2019-2023 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -24,17 +24,35 @@ local Cable = techage.ElectricCable local power = networks.power local control = networks.control +local WRENCH_MENU = { + { + type = "dropdown", + choices = "300 ku,200 ku,150 ku,100 ku,50 ku,20 ku", + name = "current", + label = S("Max. power"), + tooltip = S("Maximum power passed through"), + default = "100 ku", + values = {300, 200, 150, 100, 50, 20} + }, +} + +local function max_current(pos) + local meta = M(pos) + if meta:contains("current") then + local current = meta:get_int("current") + return current > 0 and current or PWR_PERF + end + return PWR_PERF +end local function formspec(self, pos, nvm, data) data = data or {curr_load1 = 0, curr_load2 = 0, max_capa1 = 0, max_capa2 = 0, moved = 0} return "size[7.5,5.2]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. "box[0,-0.1;7.3,0.5;#c6e8ff]".. + techage.wrench_image(6.9, -0.08) .. "label[0.2,-0.1;"..minetest.colorize( "#000000", S("TA4 Isolation Transformer")).."]".. techage.formspec_storage_bar(pos, 0.0, 0.7, S("Storage"), data.curr_load1, data.max_capa1).. - techage.formspec_power_bar(pos, 2.5, 0.7, S("Power"), data.moved, PWR_PERF).. + techage.formspec_power_bar(pos, 2.5, 0.7, S("Power"), data.moved, max_current(pos)).. techage.formspec_storage_bar(pos, 5.0, 0.7, S("Storage"), data.curr_load2, data.max_capa2).. "image_button[3.3,4.3;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. "tooltip[3.3,4.3;1,1;" .. self:get_state_tooltip(nvm) .. "]" @@ -42,6 +60,7 @@ end local function start_node(pos, nvm, state) local outdir = M(pos):get_int("outdir") + nvm.load = 0 power.start_storage_calc(pos, Cable, outdir) outdir = networks.Flip[outdir] power.start_storage_calc(pos, Cable, outdir) @@ -70,9 +89,10 @@ local function node_timer(pos, elapsed) if techage.is_running(nvm) then local outdir2 = M(pos):get_int("outdir") local outdir1 = networks.Flip[outdir2] - data = power.transfer_duplex(pos, Cable, outdir1, Cable, outdir2, PWR_PERF) + local current = max_current(pos) + data = power.transfer_duplex(pos, Cable, outdir1, Cable, outdir2, current) if data then - nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * PWR_PERF + nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * current nvm.moved = data.moved end end @@ -114,7 +134,8 @@ end local function get_generator_data(pos, outdir, tlib2) local nvm = techage.get_nvm(pos) if techage.is_running(nvm) then - return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} + local current = max_current(pos) + return {level = (nvm.load or 0) / current, perf = current, capa = current * 2} end end @@ -136,6 +157,7 @@ minetest.register_node("techage:ta4_transformer", { after_place_node = after_place_node, after_dig_node = after_dig_node, get_generator_data = get_generator_data, + ta4_formspec = WRENCH_MENU, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -169,7 +191,7 @@ control.register_nodes({"techage:ta4_transformer"}, { type = S("TA4 Isolation Transformer"), number = meta:get_string("node_number") or "", running = techage.is_running(nvm) or false, - available = PWR_PERF, + available = max_current(pos), provided = nvm.moved or 0, termpoint = "-", }