From 801d2f549225e8abb7029071d85fc3d46949dfd0 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 27 Sep 2021 21:34:24 +0200 Subject: [PATCH] Improve injector and detector --- basic_machines/consumer.lua | 1 + basic_machines/ta4_injector.lua | 5 +++-- basis/node_states.lua | 7 +++++++ locale/techage.de.tr | 6 +++--- locale/template.txt | 4 +++- logic/detector.lua | 18 +++++++++++++++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/basic_machines/consumer.lua b/basic_machines/consumer.lua index e37daaa..d132ce5 100644 --- a/basic_machines/consumer.lua +++ b/basic_machines/consumer.lua @@ -152,6 +152,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState formspec_func = tNode.formspec, on_state_change = tNode.on_state_change, can_start = tNode.can_start, + quick_start = tNode.quick_start, has_power = tNode.has_power or power_used and has_power or nil, start_node = power_used and start_node or nil, stop_node = power_used and stop_node or nil, diff --git a/basic_machines/ta4_injector.lua b/basic_machines/ta4_injector.lua index 919926d..15e6a02 100644 --- a/basic_machines/ta4_injector.lua +++ b/basic_machines/ta4_injector.lua @@ -175,7 +175,7 @@ local function pushing(pos, crd, meta, nvm) end end -local function keep_running(pos, elapsed) +local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) local crd = CRD(pos) pushing(pos, crd, M(pos), nvm) @@ -253,6 +253,7 @@ local _, node_name_ta3, node_name_ta4 = standby_ticks = STANDBY_TICKS, formspec = formspec, tubing = tubing, + quick_start = node_timer, after_place_node = function(pos, placer) local meta = M(pos) local node = minetest.get_node(pos) @@ -268,7 +269,7 @@ local _, node_name_ta3, node_name_ta4 = allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_move = function() return 0 end, on_receive_fields = on_receive_fields, - node_timer = keep_running, + node_timer = node_timer, on_rotate = screwdriver.disallow, groups = {choppy=2, cracky=2, crumbly=2}, diff --git a/basis/node_states.lua b/basis/node_states.lua index 0071893..162ee19 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -183,6 +183,7 @@ function NodeStates:new(attr) stop_node = attr.stop_node, formspec_func = attr.formspec_func, on_state_change = attr.on_state_change, + quick_start = attr.quick_start, } setmetatable(o, self) self.__index = self @@ -272,6 +273,12 @@ function NodeStates:start(pos, nvm) self.on_state_change(pos, state, RUNNING) end start_timer_delayed(pos, self.cycle_time) + + print("start", self.quick_start) + if self.quick_start then + print("quick_start") + self.quick_start(pos, 0) + end return true end return false diff --git a/locale/techage.de.tr b/locale/techage.de.tr index 0b114b4..4d0938b 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -228,9 +228,11 @@ TA2 Cylinder=TA2 Zylinder Configured Items=Konfigurierte Gegenstände Items which generate an 'on' command.@nIf empty, all passed items generate an 'on' command.=Items, die einen 'on'-Kommando generieren.@nWenn leer, generieren alle übergebenen Items einen 'on'-Befehl. +On Time=ON Zeit TA3 Detector=TA3 Detektor TA4 Detector=TA4 Detektor -Waiting time between two 'on' commands=Wartezeit zwischen zwei 'on'-Kommandos +The time after the 'off' command@nuntil the next 'on' command is accepted.=Die Zeit nach dem 'off' Kommando,@nbis das nächste 'on' Kommando akzeptiert wird. +The time between the 'on' and 'off' commands.=Die Zeit zwischen den 'on' und 'off' Kommandos. ### detector.lua ### ### logic_block.lua ### @@ -1159,5 +1161,3 @@ is a suitable place for a wind turbine!=ist ein geeigneter Ort für eine Windkra ##### not used anymore ##### - -Maximum command transmission frequency=Maximale Sendefrequenz für Kommandos diff --git a/locale/template.txt b/locale/template.txt index d560151..f687cb2 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -228,9 +228,11 @@ TA2 Cylinder= Configured Items= Items which generate an 'on' command.@nIf empty, all passed items generate an 'on' command.= +On Time= TA3 Detector= TA4 Detector= -Waiting time between two 'on' commands= +The time after the 'off' command@nuntil the next 'on' command is accepted.= +The time between the 'on' and 'off' commands.= ### detector.lua ### ### logic_block.lua ### diff --git a/logic/detector.lua b/logic/detector.lua index 11f6c8a..b89816e 100644 --- a/logic/detector.lua +++ b/logic/detector.lua @@ -19,14 +19,23 @@ local NDEF = function(pos) return (minetest.registered_nodes[techage.get_node_lv local logic = techage.logic local BLOCKING_TIME = 8 -- seconds +local ON_TIME = 1 local WRENCH_MENU = { + { + type = "dropdown", + choices = "1,2,4,6,8,12,16", + name = "ontime", + label = S("On Time") .. " [s]", + tooltip = S("The time between the 'on' and 'off' commands."), + default = "1", + }, { type = "dropdown", choices = "2,4,6,8,12,16,20", name = "blockingtime", label = S("Blocking Time") .. " [s]", - tooltip = S("Waiting time between two 'on' commands"), + tooltip = S("The time after the 'off' command\nuntil the next 'on' command is accepted."), default = "8", }, { @@ -48,8 +57,11 @@ local function switch_on(pos) else logic.swap_node(pos, "techage:ta4_detector_on") end - logic.send_on(pos, M(pos), 1) - mem.time = t + (tonumber(M(pos):get_string("blockingtime")) or BLOCKING_TIME) + local meta = M(pos) + local on_time = math.max(meta:get_int("ontime"), ON_TIME) + local blocking_time = tonumber(meta:get_string("blockingtime")) or BLOCKING_TIME + logic.send_on(pos, meta, on_time) + mem.time = t + blocking_time + on_time end end