From 05f0fe64bdc2b153f50f508a296001a81c548bf6 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 25 Jan 2020 23:15:44 +0100 Subject: [PATCH] complete restructured --- .test/sink.lua | 109 +++-- basic_machines/autocrafter.lua | 35 +- basic_machines/distributor.lua | 75 +-- basic_machines/electronic_fab.lua | 35 +- basic_machines/forceload.lua | 16 +- basic_machines/funnel.lua | 52 +- basic_machines/gravelrinser.lua | 43 +- basic_machines/gravelsieve.lua | 33 +- basic_machines/grinder.lua | 38 +- basic_machines/liquidsampler.lua | 31 +- basic_machines/pusher.lua | 22 +- basic_machines/source.lua | 304 ++++++++---- basis/command.lua | 11 +- basis/consumer.lua | 276 ----------- basis/firebox_lib.lua | 74 +-- basis/fuel_lib.lua | 176 ------- basis/lib.lua | 50 +- basis/mark2.lua | 40 ++ basis/networks.lua | 155 ++++-- basis/node_states.lua | 183 +++---- basis/recipe_lib.lua | 2 +- coal_power_station/akkubox.lua | 186 ------- coal_power_station/boiler_base.lua | 27 +- coal_power_station/boiler_top.lua | 259 ++-------- coal_power_station/cooler.lua | 76 +-- coal_power_station/firebox.lua | 216 ++------ coal_power_station/generator.lua | 172 ++++--- coal_power_station/power_terminal.lua | 180 ------- coal_power_station/turbine.lua | 126 +++-- doc/manual_DE.lua | 2 +- energy_storage/heatexchanger.lua | 4 +- fermenter/gasflare.lua | 4 +- furnace/cooking.lua | 2 +- furnace/furnace_top.lua | 2 +- hydrogen/electrolyzer.lua | 170 ++++--- hydrogen/hydrogen.lua | 34 -- init.lua | 228 +++++---- iron_age/coalburner.lua | 4 + iron_age/lighter.lua | 6 +- items/baborium.lua | 2 +- items/barrel.lua | 30 ++ items/basalt.lua | 121 +++-- items/petroleum.lua | 14 +- liquids/liquid.lua | 4 +- liquids/tank.lua | 143 +----- manuals/manual_ta2_DE.md | 4 +- nodes/test.lua | 549 --------------------- oil/gasflare.lua | 4 +- oil/generator.lua | 280 ----------- power/api.md | 65 --- power/drive_axle.lua | 22 +- power/electric_cable.lua | 25 +- power/junction.lua | 24 +- power/junctionbox.lua | 32 +- power/power.lua | 678 -------------------------- power/power2.lua | 270 ---------- power/power_line.lua | 205 ++++---- power/powerswitch.lua | 323 ------------ power/schedule.lua | 58 +-- power/steam_pipe.lua | 17 +- power/ta4_cable.lua | 170 ------- sounds/techage_turbine.ogg | Bin 16295 -> 9526 bytes steam_engine/boiler.lua | 307 +++--------- steam_engine/cylinder.lua | 101 ++-- steam_engine/firebox.lua | 44 +- steam_engine/flywheel.lua | 181 ++++--- steam_engine/gearbox.lua | 117 ----- textures/techage_flywheel.png | Bin 1335 -> 1621 bytes textures/techage_flywheel8.png | Bin 2135 -> 5162 bytes textures/techage_form_level_bg.png | Bin 219 -> 213 bytes textures/techage_form_level_fg.png | Bin 219 -> 213 bytes textures/techage_gas_inv.png | Bin 866 -> 1689 bytes tools/repairkit.lua | 8 +- tools/trowel.lua | 2 +- 74 files changed, 1917 insertions(+), 5341 deletions(-) delete mode 100644 basis/consumer.lua delete mode 100644 basis/fuel_lib.lua delete mode 100644 coal_power_station/akkubox.lua delete mode 100644 coal_power_station/power_terminal.lua delete mode 100644 hydrogen/hydrogen.lua delete mode 100644 nodes/test.lua delete mode 100644 oil/generator.lua delete mode 100644 power/api.md delete mode 100644 power/power.lua delete mode 100644 power/power2.lua delete mode 100644 power/powerswitch.lua delete mode 100644 power/ta4_cable.lua delete mode 100644 steam_engine/gearbox.lua diff --git a/.test/sink.lua b/.test/sink.lua index cb737ea..1db427e 100644 --- a/.test/sink.lua +++ b/.test/sink.lua @@ -1,10 +1,24 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2020 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + Demo for a electrical power consuming node + +]]-- + -- 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 P2S = minetest.pos_to_string local M = minetest.get_meta +local S = techage.S local PWR_NEEDED = 5 -local CYCLE_TIME = 4 +local CYCLE_TIME = 2 local Cable = techage.ElectricCable local power = techage.power @@ -18,59 +32,74 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function on_power(pos, mem) - if mem.running then - swap_node(pos, "techage:sink_on") - minetest.get_node_timer(pos):start(CYCLE_TIME) - M(pos):set_string("infotext", "on") - end +local function on_power(pos) + print("on_power sink "..P2S(pos)) + swap_node(pos, "techage:sink_on") + M(pos):set_string("infotext", "on") end -local function on_nopower(pos, mem) +local function on_nopower(pos) + print("on_nopower sink "..P2S(pos)) swap_node(pos, "techage:sink") - M(pos):set_string("infotext", "nopower") + M(pos):set_string("infotext", "off") end local function node_timer(pos, elapsed) - --print("node_timer sink "..S(pos)) - local mem = tubelib2.get_mem(pos) - power.consumer_alive(pos, mem) - return mem.running + --print("node_timer sink "..P2S(pos)) + local nvm = techage.get_nvm(pos) + power.consumer_alive(pos, Cable, CYCLE_TIME) +-- if not techage.power.power_available(pos, Cable) then +-- nvm.running = false +-- swap_node(pos, "techage:sink") +-- power.consumer_stop(pos, Cable) +-- minetest.get_node_timer(pos):stop() +-- M(pos):set_string("infotext", "off") +-- end + return true end local function on_rightclick(pos, node, clicker) - local mem = tubelib2.get_mem(pos) - if not mem.running and power.power_available(pos, mem, PWR_NEEDED) then - mem.running = true - power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) + local nvm = techage.get_nvm(pos) + if not nvm.running and power.power_available(pos, Cable) then + nvm.running = true + -- swap will be performed via on_power() + power.consumer_start(pos, Cable, CYCLE_TIME) + minetest.get_node_timer(pos):start(CYCLE_TIME) M(pos):set_string("infotext", "...") else - mem.running = false + nvm.running = false swap_node(pos, "techage:sink") - power.consumer_stop(pos, mem) + power.consumer_stop(pos, Cable) minetest.get_node_timer(pos):stop() M(pos):set_string("infotext", "off") end end --- --- Modul shows the usage of the power2 alternative function set --- local function after_place_node(pos) - local mem = tubelib2.init_mem(pos) + local nvm = techage.get_nvm(pos) M(pos):set_string("infotext", "off") - techage.power.after_place_node(pos) + Cable:after_place_node(pos) end local function after_dig_node(pos, oldnode) - techage.power.after_dig_node(pos, oldnode) - tubelib2.del_mem(pos) + Cable:after_dig_node(pos) + techage.del_mem(pos) end -local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) - techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) +local function tubelib2_on_update2(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2) end +local net_def = { + ele1 = { + sides = techage.networks.AllSides, -- Cable connection sides + ntype = "con1", + on_power = on_power, + on_nopower = on_nopower, + nominal = PWR_NEEDED, + }, +} + minetest.register_node("techage:sink", { description = "Sink", tiles = {'techage_electric_button.png'}, @@ -79,13 +108,13 @@ minetest.register_node("techage:sink", { on_rightclick = on_rightclick, after_place_node = after_place_node, after_dig_node = after_dig_node, - after_tube_update = after_tube_update, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, paramtype = "light", light_source = 0, - sunlight_propagates = true, paramtype2 = "facedir", - groups = {choppy=2, cracky=2, crumbly=2}, + groups = {choppy = 2, cracky = 2, crumbly = 2}, is_ground_content = false, sounds = default.node_sound_wood_defaults(), }) @@ -98,22 +127,18 @@ minetest.register_node("techage:sink_on", { on_rightclick = on_rightclick, after_place_node = after_place_node, after_dig_node = after_dig_node, - after_tube_update = after_tube_update, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, paramtype = "light", light_source = minetest.LIGHT_MAX, - sunlight_propagates = true, paramtype2 = "facedir", diggable = false, drop = "", - groups = {not_in_creative_inventory=1}, + groups = {not_in_creative_inventory = 1}, is_ground_content = false, sounds = default.node_sound_wood_defaults(), }) --- Alternative registration function -techage.power.enrich_node({"techage:sink", "techage:sink_on"}, { - power_network = Cable, - on_power = on_power, - on_nopower = on_nopower, -}) +Cable:add_secondary_node_names({"techage:sink", "techage:sink_on"}) + diff --git a/basic_machines/autocrafter.lua b/basic_machines/autocrafter.lua index cc3240d..9e24a80 100644 --- a/basic_machines/autocrafter.lua +++ b/basic_machines/autocrafter.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -28,16 +28,17 @@ local STANDBY_TICKS = 6 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 4 -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) return "size[8,9.2]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. "list[context;recipe;0,0;3,3;]".. "image[2.9,1;1,1;techage_form_arrow.png]".. - "image[3.8,0;1,1;"..techage.get_power_image(pos, mem).."]".. + "image[3.8,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "list[context;output;3.8,1;1,1;]".. - "image_button[3.8,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "image_button[3.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[3.8,2;1,1;"..self:get_state_tooltip(nvm).."]".. "list[context;src;0,3.2;8,2;]".. "list[context;dst;5,0;3,3;]".. "list[current_player;main;0,5.4;8,4;]" .. @@ -77,21 +78,21 @@ local function get_craft(pos, inventory, hash) return craft end -local function autocraft(pos, crd, mem, inv) +local function autocraft(pos, crd, nvm, inv) local craft = get_craft(pos, inv) if not craft then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end local output_item = craft.output.item if output_item:get_name() == "" then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end -- check if we have enough room in dst if not inv:room_for_item("dst", output_item) then - crd.State:blocked(pos, mem) + crd.State:blocked(pos, nvm) return end local consumption = craft.consumption @@ -99,7 +100,7 @@ local function autocraft(pos, crd, mem, inv) -- check if we have enough material available for itemname, number in pairs(consumption) do if (not inv_index[itemname]) or inv_index[itemname] < number then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end end @@ -116,27 +117,27 @@ local function autocraft(pos, crd, mem, inv) inv:add_item("dst", craft.decremented_input.items[i]) end - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() - autocraft(pos, crd, mem, inv) + autocraft(pos, crd, nvm, inv) end -- note, that this function assumes allready being updated to virtual items -- and doesn't handle recipes with stacksizes > 1 local function after_recipe_change(pos, inventory) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) -- if we emptied the grid, there's no point in keeping it running or cached if inventory:is_empty("recipe") then autocrafterCache[minetest.hash_node_position(pos)] = nil inventory:set_stack("output", 1, "") - crd.State:stop(pos, mem) + crd.State:stop(pos, nvm) return end local recipe = inventory:get_list("recipe") @@ -159,7 +160,7 @@ local function after_recipe_change(pos, inventory) craft = craft or get_craft(pos, inventory, hash) local output_item = craft.output.item inventory:set_stack("output", 1, output_item) - crd.State:stop(pos, mem) + crd.State:stop(pos, nvm) end -- clean out unknown items and groups, which would be handled like unknown items in the crafting grid @@ -271,8 +272,8 @@ 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) - CRD(pos).State:state_button_event(pos, mem, fields) + local nvm = techage.get_nvm(pos) + CRD(pos).State:state_button_event(pos, nvm, fields) end local function can_dig(pos, player) diff --git a/basic_machines/distributor.lua b/basic_machines/distributor.lua index e018719..5c8de71 100644 --- a/basic_machines/distributor.lua +++ b/basic_machines/distributor.lua @@ -122,7 +122,7 @@ local function blocking_checkbox(pos, filter) return "" end -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) local filter = minetest.deserialize(M(pos):get_string("filter")) or {false,false,false,false} local order = order_checkbox(pos, filter) local blocking = blocking_checkbox(pos, filter) @@ -134,7 +134,8 @@ local function formspec(self, pos, mem) order.. blocking.. "image[2,1.5;1,1;techage_form_arrow.png]".. - "image_button[2,3;1,1;"..self:get_state_button_image(mem)..";state_button;]".. + "image_button[2,3;1,1;"..self:get_state_button_image(nvm)..";state_button;]".. + "tooltip[2,3;1,1;"..self:get_state_tooltip(nvm).."]".. "checkbox[3,0;filter1;On;"..dump(filter[1]).."]".. "checkbox[3,1;filter2;On;"..dump(filter[2]).."]".. "checkbox[3,2;filter3;On;"..dump(filter[3]).."]".. @@ -184,7 +185,7 @@ local function allow_metadata_inventory_move(pos, from_list, from_index, to_list end -local function push_item(pos, filter, item_name, num_items, mem) +local function push_item(pos, filter, item_name, num_items, nvm) local idx = 1 local num_pushed = 0 local num_ports = #filter @@ -196,7 +197,7 @@ local function push_item(pos, filter, item_name, num_items, mem) local num_to_push = math.min(amount, num_items - num_pushed) if techage.push_items(pos, push_dir, ItemStack(item_name.." "..num_to_push)) then num_pushed = num_pushed + num_to_push - mem.port_counter[push_dir] = (mem.port_counter[push_dir] or 0) + num_to_push + nvm.port_counter[push_dir] = (nvm.port_counter[push_dir] or 0) + num_to_push end -- filter start offset idx = idx + 1 @@ -208,14 +209,14 @@ local function push_item(pos, filter, item_name, num_items, mem) end -- move items to output slots -local function distributing(pos, inv, crd, mem) +local function distributing(pos, inv, crd, nvm) local item_filter, open_ports = get_filter_settings(pos) local sum_num_pushed = 0 local num_pushed = 0 local blocking_mode = M(pos):get_int("blocking") == 1 -- start searching after last position - local offs = mem.last_index or 1 + local offs = nvm.last_index or 1 for i = 1, SRC_INV_SIZE do local idx = ((i + offs - 1) % 8) + 1 @@ -227,35 +228,35 @@ local function distributing(pos, inv, crd, mem) if item_filter[item_name] then -- Push items based on filter - num_pushed = push_item(pos, item_filter[item_name], item_name, num_to_push, mem) + num_pushed = push_item(pos, item_filter[item_name], item_name, num_to_push, nvm) elseif blocking_mode and #open_ports > 0 then -- Push items based on open ports - num_pushed = push_item(pos, open_ports, item_name, num_to_push, mem) + num_pushed = push_item(pos, open_ports, item_name, num_to_push, nvm) end if not blocking_mode and num_pushed == 0 and #open_ports > 0 then -- Push items based on open ports - num_pushed = push_item(pos, open_ports, item_name, num_to_push, mem) + num_pushed = push_item(pos, open_ports, item_name, num_to_push, nvm) end sum_num_pushed = sum_num_pushed + num_pushed stack:take_item(num_pushed) inv:set_stack("src", idx, stack) if sum_num_pushed >= crd.num_items then - mem.last_index = idx + nvm.last_index = idx break end end if num_pushed == 0 then - crd.State:blocked(pos, mem) + crd.State:blocked(pos, nvm) else - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS, sum_num_pushed) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS, sum_num_pushed) end end -local function sequencing(pos, inv, crd, mem) +local function sequencing(pos, inv, crd, nvm) local _,open_ports, filter_items = get_filter_settings(pos) - local offs = mem.last_index or 1 + local offs = nvm.last_index or 1 local num_filters = 0 -- already processed local num_pushed = 0 local push_dir = open_ports[1] or 1 @@ -278,32 +279,32 @@ local function sequencing(pos, inv, crd, mem) num_filters = num_filters + 1 end - mem.last_index = offs + nvm.last_index = offs if blocked then - crd.State:blocked(pos, mem) + crd.State:blocked(pos, nvm) elseif num_pushed == 0 then - crd.State:standby(pos, mem) + crd.State:standby(pos, nvm) else - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS, num_pushed) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS, num_pushed) end end -- move items to the output slots local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) - mem.port_counter = mem.port_counter or {} + local nvm = techage.get_nvm(pos) + nvm.port_counter = nvm.port_counter or {} local crd = CRD(pos) local inv = M(pos):get_inventory() if not inv:is_empty("src") then if M(pos):get_int("order") == 1 then - sequencing(pos, inv, crd, mem) + sequencing(pos, inv, crd, nvm) else - distributing(pos, inv, crd, mem) + distributing(pos, inv, crd, nvm) end else - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) end - return crd.State:is_active(mem) + return crd.State:is_active(nvm) end local function on_receive_fields(pos, formname, fields, player) @@ -323,8 +324,8 @@ local function on_receive_fields(pos, formname, fields, player) filter[4] = fields.filter4 == "true" elseif fields.order ~= nil then meta:set_int("order", fields.order == "true" and 1 or 0) - local mem = tubelib2.get_mem(pos) - mem.last_index = 1 -- start from the beginning + local nvm = techage.get_nvm(pos) + nvm.last_index = 1 -- start from the beginning elseif fields.blocking ~= nil then meta:set_int("blocking", fields.blocking == "true" and 1 or 0) end @@ -332,11 +333,11 @@ local function on_receive_fields(pos, formname, fields, player) filter_settings(pos) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if fields.state_button ~= nil then - crd.State:state_button_event(pos, mem, fields) + crd.State:state_button_event(pos, nvm, fields) else - meta:set_string("formspec", formspec(crd.State, pos, mem)) + meta:set_string("formspec", formspec(crd.State, pos, nvm)) end end @@ -353,8 +354,8 @@ local function change_filter_settings(pos, slot, val) filter_settings(pos) - local mem = tubelib2.get_mem(pos) - meta:set_string("formspec", formspec(CRD(pos).State, pos, mem)) + local nvm = techage.get_nvm(pos) + meta:set_string("formspec", formspec(CRD(pos).State, pos, nvm)) return true end @@ -460,22 +461,22 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = on_metadata_inventory_move = function(pos, from_list, from_index, to_list) if from_list ~= "src" or to_list ~= "src" then filter_settings(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) end end, on_metadata_inventory_put = function(pos, listname) if listname ~= "src" then filter_settings(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) end end, on_metadata_inventory_take = function(pos, listname) if listname ~= "src" then filter_settings(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) end end, diff --git a/basic_machines/electronic_fab.lua b/basic_machines/electronic_fab.lua index 0c08737..be16aa4 100644 --- a/basic_machines/electronic_fab.lua +++ b/basic_machines/electronic_fab.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -18,7 +18,7 @@ local M = minetest.get_meta local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end local S = techage.S -local STANDBY_TICKS = 10 +local STANDBY_TICKS = 5 local COUNTDOWN_TICKS = 6 local CYCLE_TIME = 6 @@ -29,17 +29,17 @@ local RecipeType = { [2] = "ta2_electronic_fab", [4] = "ta4_electronic_fab", } -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) local rtype = RecipeType[CRD(pos).stage] return "size[8.4,8.4]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. "list[context;src;0,0;2,4;]".. - recipes.formspec(2.2, 0, rtype, mem).. + recipes.formspec(2.2, 0, rtype, nvm).. "list[context;dst;6.4,0;2,4;]".. - "image_button[3.7,3.3;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "tooltip[3.7,3.3;1,1;"..self:get_state_tooltip(mem).."]".. + "image_button[3.7,3.3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[3.7,3.3;1,1;"..self:get_state_tooltip(nvm).."]".. "list[current_player;main;0.2,4.5;8,4;]".. "listring[context;dst]".. "listring[current_player;main]".. @@ -74,15 +74,15 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player return stack:get_count() end -local function making(pos, crd, mem, inv) +local function making(pos, crd, nvm, inv) local rtype = RecipeType[crd.stage] - local recipe = recipes.get(mem, rtype) + local recipe = recipes.get(nvm, rtype) local output = ItemStack(recipe.output.name.." "..recipe.output.num) if inv:room_for_item("dst", output) then for _,item in ipairs(recipe.input) do local input = ItemStack(item.name.." "..item.num) if not inv:contains_item("src", input) then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end end @@ -91,20 +91,19 @@ local function making(pos, crd, mem, inv) inv:remove_item("src", input) end inv:add_item("dst", output) - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) return end - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() if inv then - making(pos, crd, mem, inv) + making(pos, crd, nvm, inv) end - return crd.State:is_active(mem) end local function on_receive_fields(pos, formname, fields, player) @@ -112,15 +111,15 @@ local function on_receive_fields(pos, formname, fields, player) return end - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) - if not mem.running then + if not nvm.running then recipes.on_receive_fields(pos, formname, fields, player) end - crd.State:state_button_event(pos, mem, fields) - M(pos):set_string("formspec", formspec(crd.State, pos, mem)) + crd.State:state_button_event(pos, nvm, fields) + M(pos):set_string("formspec", formspec(crd.State, pos, nvm)) end local function can_dig(pos, player) diff --git a/basic_machines/forceload.lua b/basic_machines/forceload.lua index fb2bdc8..d16c5c9 100644 --- a/basic_machines/forceload.lua +++ b/basic_machines/forceload.lua @@ -113,7 +113,7 @@ local function formspec(name) default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "label[0,0;List of your Forceload Blocks:]".. + "label[0,0;"..S("List of your Forceload Blocks:").."]".. "tablecolumns[text,width=1.2;text,width=12;text,width=1.6;text,width=12]".. "table[0,0.6;6.8,8.4;output;"..table.concat(tRes, ",")..";1]" end @@ -121,7 +121,7 @@ end minetest.register_node("techage:forceload", { - description = "Techage Forceload Block", + description = S("Techage Forceload Block"), tiles = { -- up, down, right, left, back, front 'techage_filling_ta2.png^techage_frame_ta2_top.png', @@ -142,13 +142,13 @@ minetest.register_node("techage:forceload", { if add_pos(pos, placer) then minetest.forceload_block(pos, true) local pos1, pos2, num, max = get_data(pos, placer) - M(pos):set_string("infotext", "Area "..P2S(pos1).." to "..P2S(pos2).." loaded!\n".. - "Punch the block to make the area visible.") - chat(placer, "Area ("..num.."/"..max..") "..P2S(pos1).." to "..P2S(pos2).." loaded!") + M(pos):set_string("infotext", "Area "..P2S(pos1).." to "..P2S(pos2).." "..S("loaded").."!\n".. + S("Punch the block to make the area visible.")) + chat(placer, "Area ("..num.."/"..max..") "..P2S(pos1).." to "..P2S(pos2).." "..S("loaded").."!") techage.mark_region(placer:get_player_name(), pos1, pos2) M(pos):set_string("owner", placer:get_player_name()) else - chat(placer, "Area already loaded or max. number of Forceload Blocks reached!") + chat(placer, S("Area already loaded or max. number of Forceload Blocks reached!")) minetest.remove_node(pos) return itemstack end @@ -220,7 +220,7 @@ end) minetest.register_chatcommand("forceload", { params = "", - description = "Forceloadblöcke der Umgebung 64x64x64 anzeigen", + description = S("Show all forceload blocks in a 64x64x64 range"), func = function(name, param) if minetest.check_player_privs(name, "superminer") then local player = minetest.get_player_by_name(name) @@ -230,7 +230,7 @@ minetest.register_chatcommand("forceload", { shoe_flbs(pos, name, 64) end else - return false, "Priv missing" + return false, S("Priv missing") end end, }) diff --git a/basic_machines/funnel.lua b/basic_machines/funnel.lua index 17c379e..670bbf8 100644 --- a/basic_machines/funnel.lua +++ b/basic_machines/funnel.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -18,16 +18,16 @@ local S = techage.S local CYCLE_TIME = 2 -local function start_node(pos, mem) - mem.running = true +local function start_node(pos, nvm) + nvm.running = true minetest.get_node_timer(pos):start(CYCLE_TIME) local meta = M(pos) local own_num = meta:get_string("node_number") meta:set_string("infotext", S("TA3 Funnel").." "..own_num.." : running") end -local function stop_node(pos, mem) - mem.running = false +local function stop_node(pos, nvm) + nvm.running = false minetest.get_node_timer(pos):stop() local meta = M(pos) local own_num = meta:get_string("node_number") @@ -48,9 +48,9 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player return stack:get_count() end -local function formspec(mem) +local function formspec(nvm) local state = techage.STOPPED - if mem.running then + if nvm.running then state = techage.RUNNING end return "size[9,7]".. @@ -65,8 +65,8 @@ local function formspec(mem) end local function scan_for_objects(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if not mem.running then + local nvm = techage.get_nvm(pos) + if not nvm.running then return false end local meta = minetest.get_meta(pos) @@ -125,14 +125,14 @@ minetest.register_node("techage:ta3_funnel", { after_place_node = function(pos, placer) local meta = M(pos) - local mem = tubelib2.init_mem(pos) - mem.running = false + local nvm = techage.get_nvm(pos) + nvm.running = false local own_num = techage.add_node(pos, "techage:ta3_funnel") local node = minetest.get_node(pos) meta:set_string("node_number", own_num) meta:set_string("owner", placer:get_player_name()) meta:set_string("infotext", S("TA3 Funnel").." "..own_num.." : stopped") - meta:set_string("formspec", formspec(mem)) + meta:set_string("formspec", formspec(nvm)) meta:set_int("pull_dir", techage.side_to_indir("R", node.param2)) end, @@ -144,15 +144,15 @@ minetest.register_node("techage:ta3_funnel", { end local meta = M(pos) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if fields.state_button ~= nil then - if mem.running then - stop_node(pos, mem) + if nvm.running then + stop_node(pos, nvm) else - start_node(pos, mem) + start_node(pos, nvm) end end - meta:set_string("formspec", formspec(mem)) + meta:set_string("formspec", formspec(nvm)) end, can_dig = function(pos, player) @@ -165,7 +165,7 @@ minetest.register_node("techage:ta3_funnel", { after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.remove_node(pos) - tubelib2.del_mem(pos) + techage.del_nem(pos) end, allow_metadata_inventory_put = allow_metadata_inventory_put, @@ -194,28 +194,28 @@ techage.register_node({"techage:ta3_funnel"}, { end end, on_recv_message = function(pos, src, topic, payload) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if topic == "state" then - if mem.running then + if nvm.running then return "running" else return "stopped" end elseif topic == "on" then - if not mem.running then - start_node(pos, mem) + if not nvm.running then + start_node(pos, nvm) end elseif topic == "off" then - if mem.running then - stop_node(pos, mem) + if nvm.running then + stop_node(pos, nvm) end else return "unsupported" end end, on_node_load = function(pos) - local mem = tubelib2.get_mem(pos) - if mem.running then + local nvm = techage.get_nvm(pos) + if nvm.running then minetest.get_node_timer(pos):start(CYCLE_TIME) end end, diff --git a/basic_machines/gravelrinser.lua b/basic_machines/gravelrinser.lua index a3f7311..f052fa7 100644 --- a/basic_machines/gravelrinser.lua +++ b/basic_machines/gravelrinser.lua @@ -25,7 +25,7 @@ local CYCLE_TIME = 4 local Probability = {} -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) return "size[8,8]".. default.gui_bg.. default.gui_bg_img.. @@ -33,9 +33,10 @@ local function formspec(self, pos, mem) "list[context;src;0,0;3,3;]".. "item_image[0,0;1,1;default:gravel]".. "image[0,0;1,1;techage_form_mask.png]".. - "image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]".. + "image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "image[3.5,1;1,1;techage_form_arrow.png]".. - "image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]".. "list[context;dst;5,0;3,3;]".. "list[current_player;main;0,4;8,4;]".. "listring[context;dst]".. @@ -101,11 +102,13 @@ local function determine_water_dir(pos) end local function set_velocity(obj, pos, vel) - obj:set_acceleration({x = 0, y = 0, z = 0}) - local p = obj:get_pos() - if p then - obj:set_pos({x=p.x, y=p.y-0.3, z=p.z}) - obj:set_velocity(vel) + if obj then + obj:set_acceleration({x = 0, y = 0, z = 0}) + local p = obj:get_pos() + if p then + obj:set_pos({x=p.x, y=p.y-0.3, z=p.z}) + obj:set_velocity(vel) + end end end @@ -126,12 +129,12 @@ local function get_random_gravel_ore() end end -local function washing(pos, crd, mem, inv) +local function washing(pos, crd, nvm, inv) -- for testing purposes if inv:contains_item("src", ItemStack("default:stick")) then add_object({x=pos.x, y=pos.y+1, z=pos.z}, "default:stick") inv:remove_item("src", ItemStack("default:stick")) - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) return end @@ -143,32 +146,32 @@ local function washing(pos, crd, mem, inv) add_object({x=pos.x, y=pos.y+1, z=pos.z}, ore) end else - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end if not inv:room_for_item("dst", dst) then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end inv:add_item("dst", dst) inv:remove_item("src", src) - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() - washing(pos, crd, mem, inv) - return crd.State:is_active(mem) + washing(pos, crd, nvm, inv) + return crd.State:is_active(nvm) 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) - CRD(pos).State:state_button_event(pos, mem, fields) + local nvm = techage.get_nvm(pos) + CRD(pos).State:state_button_event(pos, nvm, fields) end local function can_dig(pos, player) @@ -346,6 +349,6 @@ minetest.register_lbm({ }) -techage.add_rinser_recipe({input="techage:sieved_gravel", output="techage:usmium_nuggets", probability=40}) -techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=20}) +techage.add_rinser_recipe({input="techage:sieved_gravel", output="techage:usmium_nuggets", probability=30}) +techage.add_rinser_recipe({input="techage:sieved_gravel", output="default:copper_lump", probability=15}) diff --git a/basic_machines/gravelsieve.lua b/basic_machines/gravelsieve.lua index 9bfd149..46cc1b3 100644 --- a/basic_machines/gravelsieve.lua +++ b/basic_machines/gravelsieve.lua @@ -19,15 +19,15 @@ local S = techage.S -- Consumer Related Data local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end -local STANDBY_TICKS = 10 -local COUNTDOWN_TICKS = 10 +local STANDBY_TICKS = 6 +local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 4 local get_random_gravel_ore = techage.gravelsieve_get_random_gravel_ore local get_random_basalt_ore = techage.gravelsieve_get_random_basalt_ore -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) return "size[8,8]".. default.gui_bg.. default.gui_bg_img.. @@ -35,9 +35,10 @@ local function formspec(self, pos, mem) "list[context;src;0,0;3,3;]".. "item_image[0,0;1,1;default:gravel]".. "image[0,0;1,1;techage_form_mask.png]".. - "image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]".. + "image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "image[3.5,1;1,1;techage_form_arrow.png]".. - "image_button[3.5,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]".. "list[context;dst;5,0;3,3;]".. "list[current_player;main;0,4;8,4;]".. "listring[context;dst]".. @@ -60,8 +61,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) end local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() + local inv = M(pos):get_inventory() local stack = inv:get_stack(from_list, from_index) return allow_metadata_inventory_put(pos, to_list, to_index, stack, player) end @@ -73,39 +73,38 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player return stack:get_count() end -local function sieving(pos, crd, mem, inv) +local function sieving(pos, crd, nvm, inv) local src, dst if inv:contains_item("src", ItemStack("techage:basalt_gravel")) then dst, src = get_random_basalt_ore(), ItemStack("techage:basalt_gravel") elseif inv:contains_item("src", ItemStack("default:gravel")) then dst, src = get_random_gravel_ore(), ItemStack("default:gravel") else - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end if not inv:room_for_item("dst", dst) then - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) return end inv:add_item("dst", dst) inv:remove_item("src", src) - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() - sieving(pos, crd, mem, inv) - return crd.State:is_active(mem) + sieving(pos, crd, nvm, inv) 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) - CRD(pos).State:state_button_event(pos, mem, fields) + local nvm = techage.get_nvm(pos) + CRD(pos).State:state_button_event(pos, nvm, fields) end local function can_dig(pos, player) @@ -158,7 +157,7 @@ local tubing = { end, on_push_item = function(pos, in_dir, stack) local meta = minetest.get_meta(pos) - if meta:get_int("push_dir") == in_dir or in_dir == 5 then + if meta:get_int("push_dir") == in_dir or in_dir == 5 then local inv = M(pos):get_inventory() CRD(pos).State:start_if_standby(pos) return techage.put_items(inv, "src", stack) diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua index 8e68021..77f07bf 100644 --- a/basic_machines/grinder.lua +++ b/basic_machines/grinder.lua @@ -14,11 +14,11 @@ -- for lazy programmers local M = minetest.get_meta +local S = techage.S + -- Consumer Related Data local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end -local S = techage.S - local STANDBY_TICKS = 6 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 4 @@ -27,7 +27,7 @@ local CYCLE_TIME = 4 -- Grinder recipes local Recipes = {} -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) return "size[8,8]".. default.gui_bg.. default.gui_bg_img.. @@ -35,9 +35,10 @@ local function formspec(self, pos, mem) "list[context;src;0,0;3,3;]".. "item_image[0,0;1,1;default:cobble]".. "image[0,0;1,1;techage_form_mask.png]".. - "image[3.5,0;1,1;"..techage.get_power_image(pos, mem).."]".. + "image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "image[3.5,1;1,1;techage_form_arrow.png]".. - "image_button[3.5,2;1,1;"..self:get_state_button_image(mem)..";state_button;]".. + "image_button[3.5,2;1,1;"..self:get_state_button_image(nvm)..";state_button;]".. + "tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]".. "list[context;dst;5,0;3,3;]".. "item_image[5,0;1,1;default:gravel]".. "image[5,0;1,1;techage_form_mask.png]".. @@ -84,39 +85,39 @@ local function src_to_dst(src_stack, idx, num_items, inv, dst_name) return false end -local function grinding(pos, crd, mem, inv) +local function grinding(pos, crd, nvm, inv) local num_items = 0 for idx,stack in ipairs(inv:get_list("src")) do if not stack:is_empty() then local name = stack:get_name() if Recipes[name] then if src_to_dst(stack, idx, crd.num_items, inv, Recipes[name]) then - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) else - crd.State:blocked(pos, mem) + crd.State:blocked(pos, nvm) end else - crd.State:fault(pos, mem) + crd.State:fault(pos, nvm) end return end end - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() - grinding(pos, crd, mem, inv) + grinding(pos, crd, nvm, inv) 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) - CRD(pos).State:state_button_event(pos, mem, fields) + local nvm = techage.get_nvm(pos) + CRD(pos).State:state_button_event(pos, nvm, fields) end local function can_dig(pos, player) @@ -183,7 +184,12 @@ local tubing = { end end, on_recv_message = function(pos, src, topic, payload) - return CRD(pos).State:on_receive_message(pos, topic, payload) + local resp = CRD(pos).State:on_receive_message(pos, topic, payload) + if resp then + return resp + else + return "unsupported" + end end, on_node_load = function(pos) CRD(pos).State:on_node_load(pos) @@ -294,3 +300,5 @@ techage.add_grinder_recipe({input="default:acacia_tree", output="default:acacia_ techage.add_grinder_recipe({input="default:aspen_tree", output="default:aspen_leaves 8"}) +local ndef = minetest.registered_nodes["techage:ta2_grinder_pas"] or {} +print("techage:ta2_grinder_pas", dump(ndef.tubelib2_on_update2)) diff --git a/basic_machines/liquidsampler.lua b/basic_machines/liquidsampler.lua index f9a75f1..f58aaad 100644 --- a/basic_machines/liquidsampler.lua +++ b/basic_machines/liquidsampler.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -23,16 +23,17 @@ local STANDBY_TICKS = 4 local COUNTDOWN_TICKS = 2 local CYCLE_TIME = 8 -local function formspec(self, pos, mem) +local function formspec(self, pos, nvm) return "size[9,8.5]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. "list[context;src;0,0;1,4;]".. "image[0,0;1,1;bucket.png]".. - "image[1,0;1,1;"..techage.get_power_image(pos, mem).."]".. + "image[1,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "image[1,1.5;1,1;techage_form_arrow.png]".. - "image_button[1,3;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "image_button[1,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[1,3;1,1;"..self:get_state_tooltip(nvm).."]".. "list[context;dst;2,0;7,4;]".. "list[current_player;main;0.5,4.5;8,4;]".. "listring[current_player;main]".. @@ -73,7 +74,7 @@ local function test_liquid(node) end end -local function sample_liquid(pos, crd, mem, inv) +local function sample_liquid(pos, crd, nvm, inv) local meta = M(pos) local water_pos = minetest.string_to_pos(meta:get_string("water_pos")) local giving_back = test_liquid(techage.get_node_lvm(water_pos)) @@ -83,29 +84,29 @@ local function sample_liquid(pos, crd, mem, inv) minetest.remove_node(water_pos) inv:remove_item("src", ItemStack("bucket:bucket_empty")) inv:add_item("dst", ItemStack(giving_back)) - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) else - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) end else - crd.State:fault(pos, mem) + crd.State:fault(pos, nvm) end end local function keep_running(pos, elapsed) --if tubelib.data_not_corrupted(pos) then - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) local inv = M(pos):get_inventory() - sample_liquid(pos, crd, mem, inv) + sample_liquid(pos, crd, nvm, inv) 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) - CRD(pos).State:state_button_event(pos, mem, fields) + local nvm = techage.get_nvm(pos) + CRD(pos).State:state_button_event(pos, nvm, fields) end local function can_dig(pos, player) @@ -121,7 +122,7 @@ local tiles = {} -- '{power}' will be replaced by the power PNG tiles.pas = { -- up, down, right, left, back, front - "techage_filling_ta#.png^techage_appl_hole_electric.png^techage_frame_ta#_top.png", + "techage_filling_ta#.png^{power}^techage_frame_ta#_top.png", "techage_filling_ta#.png^techage_frame_ta#.png", "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png", "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png", @@ -130,7 +131,7 @@ tiles.pas = { } tiles.act = { -- up, down, right, left, back, front - "techage_filling_ta#.png^techage_appl_hole_electric.png^techage_frame_ta#_top.png", + "techage_filling_ta#.png^{power}^techage_frame_ta#_top.png", "techage_filling_ta#.png^techage_frame_ta#.png", "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_outp.png", "techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_inp.png", @@ -189,7 +190,6 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = inv:set_size("dst", 28) local water_pos = techage.get_pos(pos, "B") M(pos):set_string("water_pos", minetest.pos_to_string(water_pos)) - techage.power.set_conn_dirs(pos, {"U"}) end, can_dig = can_dig, node_timer = keep_running, @@ -201,6 +201,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 = sounds = default.node_sound_wood_defaults(), num_items = {0,1,2,4}, power_consumption = {0,3,5,8}, + power_sides = {U=1}, }) minetest.register_craft({ diff --git a/basic_machines/pusher.lua b/basic_machines/pusher.lua index f4f9391..46678dd 100644 --- a/basic_machines/pusher.lua +++ b/basic_machines/pusher.lua @@ -33,7 +33,7 @@ local STANDBY_TICKS = 10 local COUNTDOWN_TICKS = 10 local CYCLE_TIME = 2 -local function pushing(pos, crd, meta, mem) +local function pushing(pos, crd, meta, nvm) local pull_dir = meta:get_int("pull_dir") local push_dir = meta:get_int("push_dir") local items = techage.pull_items(pos, pull_dir, crd.num_items) @@ -41,29 +41,29 @@ local function pushing(pos, crd, meta, mem) if techage.push_items(pos, push_dir, items) ~= true then -- place item back techage.unpull_items(pos, pull_dir, items) - crd.State:blocked(pos, mem) + crd.State:blocked(pos, nvm) return end - crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) return end - crd.State:idle(pos, mem) + crd.State:idle(pos, nvm) end local function keep_running(pos, elapsed) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) local crd = CRD(pos) - pushing(pos, crd, M(pos), mem) - crd.State:is_active(mem) + pushing(pos, crd, M(pos), nvm) + crd.State:is_active(nvm) end local function on_rightclick(pos, node, clicker) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if not minetest.is_protected(pos, clicker:get_player_name()) then - if CRD(pos).State:get_state(mem) == techage.STOPPED then - CRD(pos).State:start(pos, mem) + if CRD(pos).State:get_state(nvm) == techage.STOPPED then + CRD(pos).State:start(pos, nvm) else - CRD(pos).State:stop(pos, mem) + CRD(pos).State:stop(pos, nvm) end end end diff --git a/basic_machines/source.lua b/basic_machines/source.lua index 8c5095e..ce742e7 100644 --- a/basic_machines/source.lua +++ b/basic_machines/source.lua @@ -3,12 +3,12 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information - TA2/TA3/TA4 Power Source + TA2/TA3/TA4 Power Test Source ]]-- @@ -17,39 +17,74 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S -local TA2_Power = techage.Axle -local TA3_Power = techage.SteamPipe -local TA4_Power = techage.ElectricCable +local Axle = techage.Axle +local Pipe = techage.SteamPipe +local Cable = techage.ElectricCable local power = techage.power +local networks = techage.networks local STANDBY_TICKS = 4 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 2 local PWR_CAPA = 20 -local function formspec(self, pos, mem) - return "size[8,7]".. +local function formspec(self, pos, nvm) + return "size[4,4]".. + "box[0,-0.1;3.8,0.5;#c6e8ff]".. + "label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "image[6,0.5;1,2;"..techage.power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. - "image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[2.5,1;1.8,1;update;"..S("Update").."]".. - "list[current_player;main;0,3;8,4;]".. - default.get_hotbar_bg(0, 3) + power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end -local function start_node(pos, mem, state) - mem.generating = true - power.generator_start(pos, mem, PWR_CAPA) - techage.switch_axles(pos, true) +-- Axles texture animation +local function switch_axles(pos, on) + local outdir = M(pos):get_int("outdir") + Axle:switch_tube_line(pos, outdir, on and "on" or "off") end -local function stop_node(pos, mem, state) - mem.generating = false - mem.provided = 0 - power.generator_stop(pos, mem) - techage.switch_axles(pos, false) +local function start_node2(pos, nvm, state) + nvm.generating = true + local outdir = M(pos):get_int("outdir") + power.generator_start(pos, Axle, CYCLE_TIME, outdir) + switch_axles(pos, true) +end + +local function stop_node2(pos, nvm, state) + nvm.generating = false + nvm.provided = 0 + local outdir = M(pos):get_int("outdir") + power.generator_stop(pos, Axle, outdir) + switch_axles(pos, false) +end + +local function start_node3(pos, nvm, state) + nvm.generating = true + local outdir = M(pos):get_int("outdir") + power.generator_start(pos, Pipe, CYCLE_TIME, outdir) +end + +local function stop_node3(pos, nvm, state) + nvm.generating = false + nvm.provided = 0 + local outdir = M(pos):get_int("outdir") + power.generator_stop(pos, Pipe, outdir) +end + +local function start_node4(pos, nvm, state) + nvm.generating = true + local outdir = M(pos):get_int("outdir") + power.generator_start(pos, Cable, CYCLE_TIME, outdir) +end + +local function stop_node4(pos, nvm, state) + nvm.generating = false + nvm.provided = 0 + local outdir = M(pos):get_int("outdir") + power.generator_stop(pos, Cable, outdir) end local State2 = techage.NodeStates:new({ @@ -57,8 +92,8 @@ local State2 = techage.NodeStates:new({ cycle_time = CYCLE_TIME, standby_ticks = STANDBY_TICKS, formspec_func = formspec, - start_node = start_node, - stop_node = stop_node, + start_node = start_node2, + stop_node = stop_node2, }) local State3 = techage.NodeStates:new({ @@ -66,8 +101,8 @@ local State3 = techage.NodeStates:new({ cycle_time = CYCLE_TIME, standby_ticks = STANDBY_TICKS, formspec_func = formspec, - start_node = start_node, - stop_node = stop_node, + start_node = start_node3, + stop_node = stop_node3, }) local State4 = techage.NodeStates:new({ @@ -75,39 +110,153 @@ local State4 = techage.NodeStates:new({ cycle_time = CYCLE_TIME, standby_ticks = STANDBY_TICKS, formspec_func = formspec, - start_node = start_node, - stop_node = stop_node, + start_node = start_node4, + stop_node = stop_node4, }) -local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.generating then - local provided = power.generator_alive(pos, mem) +local function node_timer2(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State2, pos, nvm)) end - return mem.generating + return true end -local tStates = {0, State2, State3, State4} +local function node_timer3(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + nvm.provided = power.generator_alive(pos, Pipe, CYCLE_TIME, outdir) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State3, pos, nvm)) + end + return true +end -local function on_receive_fields(pos, formname, fields, player) +local function node_timer4(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State4, pos, nvm)) + end + return true +end + +local function on_receive_fields2(pos, formname, fields, player) if minetest.is_protected(pos, player:get_player_name()) then return end - local mem = tubelib2.get_mem(pos) - local state = tStates[mem.state_num or 2] - state:state_button_event(pos, mem, fields) - - if fields.update then - M(pos):set_string("formspec", formspec(state, pos, mem)) - end + local nvm = techage.get_nvm(pos) + State2:state_button_event(pos, nvm, fields) + M(pos):set_string("formspec", formspec(State2, pos, nvm)) end -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - local state = tStates[mem.state_num or 2] - M(pos):set_string("formspec", formspec(state, pos, mem)) +local function on_receive_fields3(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local nvm = techage.get_nvm(pos) + State3:state_button_event(pos, nvm, fields) + M(pos):set_string("formspec", formspec(State3, pos, nvm)) end +local function on_receive_fields4(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local nvm = techage.get_nvm(pos) + State4:state_button_event(pos, nvm, fields) + M(pos):set_string("formspec", formspec(State4, pos, nvm)) +end + +local function on_rightclick2(pos, node, clicker) + techage.set_activeformspec(pos, clicker) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State2, pos, nvm)) +end + +local function on_rightclick3(pos, node, clicker) + techage.set_activeformspec(pos, clicker) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State3, pos, nvm)) +end + +local function on_rightclick4(pos, node, clicker) + techage.set_activeformspec(pos, clicker) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State4, pos, nvm)) +end + +local function after_place_node2(pos) + local nvm = techage.get_nvm(pos) + State2:node_init(pos, nvm, "") + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State2, pos, nvm)) + Axle:after_place_node(pos) +end + +local function after_place_node3(pos) + local nvm = techage.get_nvm(pos) + State3:node_init(pos, nvm, "") + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State3, pos, nvm)) + Pipe:after_place_node(pos) +end + +local function after_place_node4(pos) + local nvm = techage.get_nvm(pos) + State4:node_init(pos, nvm, "") + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State4, pos, nvm)) + Cable:after_place_node(pos) +end + +local function after_dig_node2(pos, oldnode) + Axle:after_dig_node(pos) + techage.del_mem(pos) +end + +local function after_dig_node3(pos, oldnode) + Pipe:after_dig_node(pos) + techage.del_mem(pos) +end + +local function after_dig_node4(pos, oldnode) + Cable:after_dig_node(pos) + techage.del_mem(pos) +end + +local function tubelib2_on_update2(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2) +end + +local net_def2 = { + axle = { + sides = {R = 1}, + ntype = "gen1", + nominal = PWR_CAPA, + }, +} + +local net_def3 = { + pipe1 = { + sides = {R = 1}, + ntype = "gen1", + nominal = PWR_CAPA, + }, +} + +local net_def4 = { + ele1 = { + sides = {R = 1}, + ntype = "gen1", + nominal = PWR_CAPA, + }, +} + + minetest.register_node("techage:t2_source", { description = S("Axle Power Source"), tiles = { @@ -123,9 +272,13 @@ minetest.register_node("techage:t2_source", { groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, is_ground_content = false, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, + on_receive_fields = on_receive_fields2, + on_rightclick = on_rightclick2, + on_timer = node_timer2, + after_place_node = after_place_node2, + after_dig_node = after_dig_node2, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def2, }) minetest.register_node("techage:t3_source", { @@ -143,9 +296,13 @@ minetest.register_node("techage:t3_source", { groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, is_ground_content = false, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, + on_receive_fields = on_receive_fields3, + on_rightclick = on_rightclick3, + on_timer = node_timer3, + after_place_node = after_place_node3, + after_dig_node = after_dig_node3, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def3, }) minetest.register_node("techage:t4_source", { @@ -163,40 +320,15 @@ minetest.register_node("techage:t4_source", { groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, is_ground_content = false, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, + on_receive_fields = on_receive_fields4, + on_rightclick = on_rightclick4, + on_timer = node_timer4, + after_place_node = after_place_node4, + after_dig_node = after_dig_node4, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def4, }) -techage.power.register_node({"techage:t2_source"}, { - conn_sides = {"R"}, - power_network = TA2_Power, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State2:node_init(pos, mem, "") - mem.state_num = 2 - on_rightclick(pos) - end, -}) - -techage.power.register_node({"techage:t3_source"}, { - conn_sides = {"R"}, - power_network = TA3_Power, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State3:node_init(pos, mem, "") - mem.state_num = 3 - on_rightclick(pos) - end, -}) - -techage.power.register_node({"techage:t4_source"}, { - conn_sides = {"R"}, - power_network = TA4_Power, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State4:node_init(pos, mem, "") - mem.state_num = 4 - on_rightclick(pos) - end, -}) +Axle:add_secondary_node_names({"techage:t2_source"}) +--Pipe:add_secondary_node_names({"techage:t3_source"}) +Cable:add_secondary_node_names({"techage:t4_source"}) diff --git a/basis/command.lua b/basis/command.lua index 85ce9a2..4b64851 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -103,7 +103,7 @@ local function register_lbm(name, nodenames) run_at_every_load = true, action = function(pos, node) if NodeDef[node.name] and NodeDef[node.name].on_node_load then - NodeDef[node.name].on_node_load(pos) + NodeDef[node.name].on_node_load(pos, node) end end }) @@ -180,6 +180,15 @@ function techage.get_node_number(pos) return nil end +function techage.get_pos(pos, side) + local node = techage.get_node_lvm(pos) + local dir = nil + if node.name ~= "air" and node.name ~= "ignore" then + dir = side_to_dir(side, node.param2) + end + return tubelib2.get_pos(pos, dir) +end + -- Function is used for available nodes with lost numbers, only. function techage.get_new_number(pos, name) -- store position diff --git a/basis/consumer.lua b/basis/consumer.lua deleted file mode 100644 index d2e747f..0000000 --- a/basis/consumer.lua +++ /dev/null @@ -1,276 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - Consumer node basis functionality. - It handles: - - up to 3 stages of nodes (TA2/TA3/TA4) - - power consumption - - node state handling - - registration of passive and active nodes - - Tube connections are on left and right side (from left to right) - - Power connection are on front and back side (front or back) -]]-- - --- 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 D = techage.Debug - --- Consumer Related Data -local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end -local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end - -local power = techage.power - -local function has_power(pos, mem, state) - if D.con then D.dbg("consumer has_power", state) end - if not power.power_available(pos, mem, 0) then - -- force to set to NOPOWER - local crd = CRD(pos) - techage.power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption) - return false - end - return true -end - -local function start_node(pos, mem, state) - local crd = CRD(pos) - if D.con then D.dbg("consumer start_node", state) end - power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption) -end - -local function stop_node(pos, mem, state) - if D.con then D.dbg("consumer stop_node", state) end - power.consumer_stop(pos, mem) -end - -local function on_power(pos, mem) - if D.con then D.dbg("consumer on_power") end - local crd = CRD(pos) - crd.State:start(pos, mem) -end - -local function on_nopower(pos, mem) - if D.con then D.dbg("consumer on_nopower") end - local crd = CRD(pos) - crd.State:nopower(pos, mem) -end - -local function node_timer(pos, elapsed) - local crd = CRD(pos) - local mem = tubelib2.get_mem(pos) - local state = mem.techage_state - if techage.needs_power(mem) then - power.consumer_alive(pos, mem) - end - -- call the node timer routine - if techage.is_operational(mem) then - crd.node_timer(pos, crd.cycle_time) - end - return crd.State:is_active(mem) -end - -local function prepare_tiles(tiles, stage, power_png) - local tbl = {} - for _,item in ipairs(tiles) do - if type(item) == "string" then - tbl[#tbl+1] = item:gsub("#", stage):gsub("{power}", power_png) - else - local temp = table.copy(item) - temp.image = temp.image:gsub("#", stage):gsub("{power}", power_png) - tbl[#tbl+1] = temp - end - end - return tbl -end - --- 'validStates' is optional and can be used to e.g. enable --- only one TA2 node {false, true, false, false} -function techage.register_consumer(base_name, inv_name, tiles, tNode, validStates) - local names = {} - validStates = validStates or {true, true, true, true} - for stage = 2,4 do - local name_pas = "techage:ta"..stage.."_"..base_name.."_pas" - local name_act = "techage:ta"..stage.."_"..base_name.."_act" - local name_inv = "TA"..stage.." "..inv_name - names[#names+1] = name_pas - - if validStates[stage] then - local on_recv_message = tNode.tubing.on_recv_message - if stage > 2 then - on_recv_message = function(pos, src, topic, payload) - return "unsupported" - end - end - - local power_network - local power_png = 'techage_axle_clutch.png' - local power_used = tNode.power_consumption ~= nil - -- power needed? - if power_used then - if stage > 2 then - power_network = techage.ElectricCable - power_png = 'techage_appl_hole_electric.png' - else - power_network = techage.Axle - power_png = 'techage_axle_clutch.png' - end - power_network:add_secondary_node_names({name_pas, name_act}) - end - - local tState = techage.NodeStates:new({ - node_name_passive = name_pas, - node_name_active = name_act, - infotext_name = name_inv, - cycle_time = tNode.cycle_time, - standby_ticks = tNode.standby_ticks, - formspec_func = tNode.formspec, - on_state_change = tNode.on_state_change, - can_start = tNode.can_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, - }) - - local tConsumer = { - stage = stage, - State = tState, - -- number of items to be processed per cycle - num_items = tNode.num_items and tNode.num_items[stage], - power_consumption = power_used and - tNode.power_consumption[stage] or 0, - node_timer = tNode.node_timer, - cycle_time = tNode.cycle_time, - } - - tNode.groups.not_in_creative_inventory = 0 - - minetest.register_node(name_pas, { - description = name_inv, - tiles = prepare_tiles(tiles.pas, stage, power_png), - consumer = tConsumer, - drawtype = tNode.drawtype, - node_box = tNode.node_box, - selection_box = tNode.selection_box, - - -- will be overwritten in case, power is used - after_place_node = function(pos, placer, itemstack, pointed_thing) - local meta = M(pos) - local mem = tubelib2.init_mem(pos) - local node = minetest.get_node(pos) - meta:set_int("push_dir", techage.side_to_indir("L", node.param2)) - meta:set_int("pull_dir", techage.side_to_indir("R", node.param2)) - local number = "-" - if stage > 2 then - number = techage.add_node(pos, name_pas) - end - if tNode.after_place_node then - tNode.after_place_node(pos, placer, itemstack, pointed_thing) - end - CRD(pos).State:node_init(pos, mem, number) - end, - -- will be overwritten in case, power is used - after_dig_node = function(pos, oldnode, oldmetadata, digger) - if tNode.after_dig_node then - tNode.after_dig_node(pos, oldnode, oldmetadata, digger) - end - techage.remove_node(pos) - tubelib2.del_mem(pos) - end, - - can_dig = tNode.can_dig, - on_rotate = screwdriver.disallow, - on_timer = node_timer, - on_receive_fields = tNode.on_receive_fields, - on_rightclick = tNode.on_rightclick, - allow_metadata_inventory_put = tNode.allow_metadata_inventory_put, - allow_metadata_inventory_move = tNode.allow_metadata_inventory_move, - allow_metadata_inventory_take = tNode.allow_metadata_inventory_take, - on_metadata_inventory_move = tNode.on_metadata_inventory_move, - on_metadata_inventory_put = tNode.on_metadata_inventory_put, - on_metadata_inventory_take = tNode.on_metadata_inventory_take, - networks = tNode.networks, - tubelib2_on_update2 = tNode.tubelib2_on_update2, - - paramtype = tNode.paramtype, - paramtype2 = "facedir", - groups = table.copy(tNode.groups), - is_ground_content = false, - sounds = tNode.sounds, - }) - - tNode.groups.not_in_creative_inventory = 1 - - minetest.register_node(name_act, { - description = name_inv, - tiles = prepare_tiles(tiles.act, stage, power_png), - consumer = tConsumer, - drawtype = tNode.drawtype, - node_box = tNode.node_box, - selection_box = tNode.selection_box, - - on_rotate = screwdriver.disallow, - on_timer = node_timer, - on_receive_fields = tNode.on_receive_fields, - on_rightclick = tNode.on_rightclick, - allow_metadata_inventory_put = tNode.allow_metadata_inventory_put, - allow_metadata_inventory_move = tNode.allow_metadata_inventory_move, - allow_metadata_inventory_take = tNode.allow_metadata_inventory_take, - on_metadata_inventory_move = tNode.on_metadata_inventory_move, - on_metadata_inventory_put = tNode.on_metadata_inventory_put, - on_metadata_inventory_take = tNode.on_metadata_inventory_take, - networks = tNode.networks, - tubelib2_on_update2 = tNode.tubelib2_on_update2, - - paramtype = tNode.paramtype, - paramtype2 = "facedir", - drop = "", - diggable = false, - groups = tNode.groups, - is_ground_content = false, - sounds = tNode.sounds, - }) - - if power_used then - techage.power.register_node({name_pas, name_act}, { - conn_sides = {"F", "B"}, - power_network = power_network, - on_power = on_power, - on_nopower = on_nopower, - after_place_node = function(pos, placer, itemstack, pointed_thing) - local meta = M(pos) - local mem = tubelib2.init_mem(pos) - local node = techage.get_node_lvm(pos) - meta:set_int("push_dir", techage.side_to_indir("L", node.param2)) - meta:set_int("pull_dir", techage.side_to_indir("R", node.param2)) - local number = "-" - if stage > 2 then - number = techage.add_node(pos, name_pas) - end - if tNode.after_place_node then - tNode.after_place_node(pos, placer, itemstack, pointed_thing) - end - CRD(pos).State:node_init(pos, mem, number) - end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - if tNode.after_dig_node then - tNode.after_dig_node(pos, oldnode, oldmetadata, digger) - end - techage.remove_node(pos) - tubelib2.del_mem(pos) - end, - }) - end - techage.register_node({name_pas, name_act}, tNode.tubing) - end - end - return names[1], names[2], names[3] -end diff --git a/basis/firebox_lib.lua b/basis/firebox_lib.lua index 2765e12..a465807 100644 --- a/basis/firebox_lib.lua +++ b/basis/firebox_lib.lua @@ -46,40 +46,24 @@ local function determine_burntimes() end minetest.after(1, determine_burntimes) -function techage.firebox.formspec(mem) +function techage.firebox.formspec(nvm) local fuel_percent = 0 - if mem.running then - fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) - end - if mem.power_level then - return "size[8,6.5]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "list[current_name;fuel;1,0.5;1,1;]".. - "image[2,0.5;1,1;default_furnace_fire_bg.png^[lowpart:".. - fuel_percent..":default_furnace_fire_fg.png]".. - "label[4.5,0.1;"..S("Power")..":]".. - "dropdown[6,0;1.8;power_level;25%,50%,75%,100%;"..mem.power_level.."]".. - "button[1,1.5;1.8,1;update;"..S("Update").."]".. - "list[current_player;main;0,2.8;8,4;]".. - "listring[current_name;fuel]".. - "listring[current_player;main]".. - default.get_hotbar_bg(0, 2.8) - else - return "size[8,6]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "list[current_name;fuel;1,0.5;1,1;]".. - "image[3,0.5;1,1;default_furnace_fire_bg.png^[lowpart:".. - fuel_percent..":default_furnace_fire_fg.png]".. - "button[5,0.5;1.8,1;update;"..S("Update").."]".. - "list[current_player;main;0,2;8,4;]".. - "listring[current_name;fuel]".. - "listring[current_player;main]".. - default.get_hotbar_bg(0, 2) + if nvm.running then + fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1) end + return "size[8,6]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "box[0,-0.1;7.8,0.5;#c6e8ff]".. + "label[3,-0.1;"..minetest.colorize( "#000000", S("Firebox")).."]".. + "list[current_name;fuel;3,1;1,1;]".. + "image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:".. + fuel_percent..":default_furnace_fire_fg.png]".. + "list[current_player;main;0,2.3;8,4;]".. + "listring[current_name;fuel]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 2.3) end function techage.firebox.can_dig(pos, player) @@ -104,30 +88,10 @@ function techage.firebox.allow_metadata_inventory_take(pos, listname, index, sta return stack:get_count() end -local PowerLevel = { - ["25%"] = 1, - ["50%"] = 2, - ["75%"] = 3, - ["100%"] = 4, -} - -function techage.firebox.on_receive_fields(pos, formname, fields, player) - if minetest.is_protected(pos, player:get_player_name()) then - return - end - if fields.update then - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", techage.firebox.formspec(mem)) - end - if fields.power_level then - local mem = tubelib2.get_mem(pos) - mem.power_level = PowerLevel[fields.power_level] - end -end - function techage.firebox.on_rightclick(pos, node, clicker) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", techage.firebox.formspec(mem)) + local nvm = techage.get_nvm(pos) + techage.set_activeformspec(pos, clicker) + M(pos):set_string("formspec", techage.firebox.formspec(nvm)) end function techage.firebox.swap_node(pos, name) diff --git a/basis/fuel_lib.lua b/basis/fuel_lib.lua deleted file mode 100644 index 4a589c3..0000000 --- a/basis/fuel_lib.lua +++ /dev/null @@ -1,176 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - Oil fuel burning lib - -]]-- - -local S2P = minetest.string_to_pos -local P2S = minetest.pos_to_string -local M = minetest.get_meta -local S = techage.S -local ValidOilFuels = techage.firebox.ValidOilFuels -local Burntime = techage.firebox.Burntime -local CAPACITY = 50 - -techage.fuel = {} -techage.fuel.CAPACITY = CAPACITY - - - - -local function formspec_fuel(x, y, mem) - local itemname = "" - if mem.liquid and mem.liquid.name and mem.liquid.amount and mem.liquid.amount > 0 then - itemname = mem.liquid.name.." "..mem.liquid.amount - end - local fuel_percent = 0 - if mem.running then - fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) - end - return "container["..x..","..y.."]".. - "background[0,0;3,1.05;techage_form_grey.png]".. - "list[context;fuel;0,0;1,1;]".. - techage.item_image(1, 0, itemname).. - "image[2,0;1,1;default_furnace_fire_bg.png^[lowpart:".. - fuel_percent..":default_furnace_fire_fg.png]".. - "container_end[]" -end - -techage.fuel.formspec_fuel = formspec_fuel - - -function techage.fuel.formspec(mem) - local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") - return "size[8,5]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - formspec_fuel(1, 0, mem).. - "button[5,0;2,1;update;"..update.."]".. - "list[current_player;main;0,1.3;8,4;]" -end - -local function fill_container(pos, inv, mem) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - local empty_container = inv:get_stack("fuel", 1):get_name() - local full_container = liquid.get_full_container(empty_container, mem.liquid.name) - if empty_container and full_container then - local ldef = liquid.get_liquid_def(full_container) - if ldef and mem.liquid.amount - ldef.size >= 0 then - inv:remove_item("fuel", ItemStack(empty_container)) - inv:add_item("fuel", ItemStack(full_container)) - mem.liquid.amount = mem.liquid.amount - ldef.size - end - end -end - -local function empty_container(pos, inv, mem) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - local stack = inv:get_stack("fuel", 1) - if stack:get_count() == 1 then - local ldef = liquid.get_liquid_def(stack:get_name()) - if ldef and ValidOilFuels[ldef.inv_item] then - if not mem.liquid.name or ldef.inv_item == mem.liquid.name then - if mem.liquid.amount + ldef.size <= CAPACITY then - inv:remove_item("fuel", stack) - inv:add_item("fuel", ItemStack(ldef.container)) - mem.liquid.amount = mem.liquid.amount + ldef.size - mem.liquid.name = ldef.inv_item - end - end - end - end -end - -local function move_item(pos, stack) - local mem = tubelib2.get_mem(pos) - local inv = M(pos):get_inventory() - if liquid.is_container_empty(stack:get_name()) then - fill_container(pos, inv, mem) - else - empty_container(pos, inv, mem) - end - M(pos):set_string("formspec", techage.fuel.formspec(mem)) -end - -function techage.fuel.move_item(pos, stack, formspec) - local mem = tubelib2.get_mem(pos) - local inv = M(pos):get_inventory() - if liquid.is_container_empty(stack:get_name()) then - fill_container(pos, inv, mem) - else - empty_container(pos, inv, mem) - end - M(pos):set_string("formspec", formspec(pos, mem)) -end - -function techage.fuel.allow_metadata_inventory_put(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - return 1 -end - -function techage.fuel.allow_metadata_inventory_take(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - return stack:get_count() -end - -function techage.fuel.on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.after(0.5, move_item, pos, stack) -end - -function techage.fuel.can_dig(pos, player) - if minetest.is_protected(pos, player:get_player_name()) then - return false - end - local mem = tubelib2.get_mem(pos) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - local inv = M(pos):get_inventory() - return inv:is_empty("fuel") and mem.liquid.amount == 0 -end - -function techage.fuel.on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - mem.countdown = 10 - M(pos):set_string("formspec", techage.fuel.formspec(mem)) -end - -function techage.fuel.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) - mem.countdown = 10 - M(pos):set_string("formspec", techage.fuel.formspec(mem)) -end - -function techage.fuel.formspec_update(pos, mem) - if mem.countdown and mem.countdown > 0 then - mem.countdown = mem.countdown - 1 - M(pos):set_string("formspec", techage.fuel.formspec(mem)) - end -end - --- name is the fuel item name --- category is 4 (all burner) to 1 (gasoline) -function techage.fuel.burntime(name, category) - if ValidOilFuels[name] and ValidOilFuels[name] <= category then - return Burntime[name] or 0.01 -- not zero ! - end - return 0.01 -- not zero ! -end - \ No newline at end of file diff --git a/basis/lib.lua b/basis/lib.lua index c763a87..d9ebd2e 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -48,7 +48,7 @@ function techage.rotate_wallmounted(param2) return offs + rot end -function techage.range(val, min, max) +function techage.in_range(val, min, max) val = tonumber(val) if val < min then return min end if val > max then return max end @@ -100,8 +100,6 @@ function techage.get_node_lvm(pos) return node end - - -- -- Functions used to hide electric cable and biogas pipes -- @@ -167,7 +165,7 @@ local function determine_ocean_ids() for name, _ in pairs(minetest.registered_biomes) do if string.find(name, "ocean") then local id = minetest.get_biome_id(name) - print(id, name) + --print(id, name) techage.OceanIdTbl[id] = true end end @@ -191,3 +189,47 @@ function techage.item_image(x, y, itemname) "tooltip["..x..","..y..";1,1;"..tooltip(itemname)..";#0C3D32;#FFFFFF]" end +function techage.mydump(o, indent, nested, level) + local t = type(o) + if not level and t == "userdata" then + -- when userdata (e.g. player) is passed directly, print its metatable: + return "userdata metatable: " .. techage.mydump(getmetatable(o)) + end + if t ~= "table" then + return basic_dump(o) + end + -- Contains table -> true/nil of currently nested tables + nested = nested or {} + if nested[o] then + return "" + end + nested[o] = true + indent = " " + level = level or 1 + local t = {} + local dumped_indexes = {} + for i, v in ipairs(o) do + t[#t + 1] = techage.mydump(v, indent, nested, level + 1) + dumped_indexes[i] = true + end + for k, v in pairs(o) do + if not dumped_indexes[k] then + if type(k) ~= "string" or not is_valid_identifier(k) then + k = "["..techage.mydump(k, indent, nested, level + 1).."]" + end + v = techage.mydump(v, indent, nested, level + 1) + t[#t + 1] = k.." = "..v + end + end + nested[o] = nil + if indent ~= "" then + local indent_str = string.rep(indent, level) + local end_indent_str = string.rep(indent, level - 1) + return string.format("{%s%s%s}", + indent_str, + table.concat(t, ","..indent_str), + end_indent_str) + end + return "{"..table.concat(t, ", ").."}" +end + diff --git a/basis/mark2.lua b/basis/mark2.lua index 6902c14..70ae626 100644 --- a/basis/mark2.lua +++ b/basis/mark2.lua @@ -65,3 +65,43 @@ minetest.register_entity(":techage:position_cube", { end, }) +function techage.mark_side(name, pos, dir, nametag, color, time) + local v = vector.multiply(tubelib2.Dir6dToVector[dir or 0], 0.7) + local pos2 = vector.add(pos, v) + + local marker = minetest.add_entity(pos2, "techage:position_side") + if marker ~= nil then + marker:set_nametag_attributes({color = color, text = nametag}) + marker:get_luaentity().player_name = name + if dir == 2 or dir == 4 then + marker:setyaw(math.pi / 2) + end + + if not marker_region[name] then + marker_region[name] = {} + end + marker_region[name][#marker_region[name] + 1] = marker + end + minetest.after(time or 30, techage.unmark_position, name) +end + +minetest.register_entity(":techage:position_side", { + initial_properties = { + visual = "upright_sprite", + textures = {"techage_side_mark.png"}, + physical = false, + visual_size = {x = 1.1, y = 1.1, z = 1.1}, + collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55}, + glow = 8, + }, + on_step = function(self, dtime) + if marker_region[self.player_name] == nil then + self.object:remove() + return + end + end, + on_punch = function(self, hitter) + techage.unmark_position(self.player_name) + end, +}) + diff --git a/basis/networks.lua b/basis/networks.lua index 6080997..df9579b 100644 --- a/basis/networks.lua +++ b/basis/networks.lua @@ -53,15 +53,32 @@ local function output(network, valid) --print("Network ("..valid.."): "..table.concat(tbl, ", ")) end +local function hidden_node(pos, net_name) + local name = M(pos):get_string("techage_hidden_nodename") + local ndef = minetest.registered_nodes[name] + if ndef and ndef.networks then + return ndef.networks[net_name] or {} + end + return {} +end + -- return the node definition local networks table local function net_def(pos, net_name) local ndef = minetest.registered_nodes[techage.get_node_lvm(pos).name] - return ndef and ndef.networks and ndef.networks[net_name] or {} + if ndef and ndef.networks then + return ndef.networks[net_name] or {} + else -- hidden junction + return hidden_node(pos, net_name) + end end -local function net_def2(node_name, net_name) +local function net_def2(pos, node_name, net_name) local ndef = minetest.registered_nodes[node_name] - return ndef and ndef.networks and ndef.networks[net_name] or {} + if ndef and ndef.networks then + return ndef.networks[net_name] or {} + else -- hidden junction + return hidden_node(pos, net_name) + end end local function connected(tlib2, pos, dir) @@ -71,6 +88,10 @@ local function connected(tlib2, pos, dir) if not num then return end return Flip[dir] == d1 or Flip[dir] == d2 end + -- secondary nodes allowed? + if not tlib2.force_to_use_tubes then + return tlib2:is_secondary_node(pos, dir) + end return false end @@ -114,25 +135,28 @@ local function get_node_connections(pos, net_name) return tbl end --- determine all node sides with tube connections +-- store all node sides with tube connections as nodemeta local function node_connections(pos, tlib2) local node = techage.get_node_lvm(pos) local val = 0 - local sides = net_def2(node.name, tlib2.tube_type).sides - + local ndef = net_def2(pos, node.name, tlib2.tube_type) + local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node) + print("node_connections", node.name, dump(sides)) if sides then for dir = 1,6 do val = val * 2 local side = DirToSide[outdir_to_dir(dir, node.param2)] if sides[side] then + print(side, sides[side], P2S(pos), dir, connected(tlib2, pos, dir)) if connected(tlib2, pos, dir) then + techage.mark_side("singleplayer", pos, dir, "node_connections", "", 1)-------------------- val = val + 1 end end end M(pos):set_int(tlib2.tube_type.."_conn", val) else - error(pos, "sides missing") + --error(pos, "sides missing") end end @@ -147,14 +171,30 @@ local function pos_already_reached(pos) end -- check if the given pipe dir into the node is valid -local function valid_indir(indir, node, net_name) - local ndef = net_def2(node.name, net_name) - if not ndef or not ndef.sides then return false end +local function valid_indir(pos, indir, node, net_name) + local ndef = net_def2(pos, node.name, net_name) + local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node) local side = DirToSide[indir_to_dir(indir, node.param2)] - if not ndef.sides[side] then return false end + if not sides or sides and not sides[side] then return false end return true end +local function is_junction(pos, name, tube_type) + local ndef = net_def2(pos, name, tube_type) + -- ntype can be a string or an array of strings or nil + if ndef.ntype == "junc" then + return true + end + if type(ndef.ntype) == "table" then + for _,ntype in ipairs(ndef.ntype) do + if ntype == "junc" then + return true + end + end + end + return false +end + -- do the walk through the tubelib2 network -- indir is the direction which should not be covered by the walk -- (coming from there) @@ -162,18 +202,20 @@ end local function connection_walk(pos, outdirs, indir, node, tlib2, clbk) if clbk then clbk(pos, indir, node) end --techage.mark_position("singleplayer", pos, "walk", "", 1) - if outdirs or net_def2(node.name, tlib2.tube_type).ntype == "junc" then + --print("connection_walk", node.name, outdirs or is_junction(pos, node.name, tlib2.tube_type)) + if outdirs or is_junction(pos, node.name, tlib2.tube_type) then for _,outdir in pairs(outdirs or get_node_connections(pos, tlib2.tube_type)) do + techage.mark_side("singleplayer", pos, outdir, "connection_walk", "", 3)-------------------- + --print("get_node_connections", node.name, outdir) local pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir) local node = techage.get_node_lvm(pos2) - if pos2 and not pos_already_reached(pos2) and valid_indir(indir2, node, tlib2.tube_type) then + if pos2 and not pos_already_reached(pos2) and valid_indir(pos2, indir2, node, tlib2.tube_type) then connection_walk(pos2, nil, indir2, node, tlib2, clbk) end end end end - local function collect_network_nodes(pos, outdir, tlib2) Route = {} NumNodes = 0 @@ -183,17 +225,24 @@ local function collect_network_nodes(pos, outdir, tlib2) local net_name = tlib2.tube_type -- outdir corresponds to the indir coming from connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node) - local ntype = net_def2(node.name, net_name).ntype - if ntype then + local ndef = net_def2(pos, node.name, net_name) + -- ntype can be a string or an array of strings or nil + local ntypes = ndef.ntype or {} + if type(ntypes) == "string" then + ntypes = {ntypes} + end + for _,ntype in ipairs(ntypes) do if not netw[ntype] then netw[ntype] = {} end - netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir} + netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir, nominal = ndef.nominal or 0} end end) netw.best_before = minetest.get_gametime() + BEST_BEFORE + netw.num_nodes = NumNodes return netw end -- keep data base small and valid +-- needed for networks without scheduler local function remove_outdated_networks() local to_be_deleted = {} local t = minetest.get_gametime() @@ -230,10 +279,6 @@ techage.networks.AllSides = Sides -- table for all 6 node sides -- techage.networks.side_to_outdir(pos, side) techage.networks.side_to_outdir = side_to_outdir --- check if the given pipe dir into the node is valid --- valid_indir(pos, indir, param2, net_name) ---techage.networks.valid_indir = valid_indir - -- techage.networks.node_connections(pos, tlib2) techage.networks.node_connections = node_connections @@ -245,44 +290,66 @@ function techage.networks.connection_walk(pos, outdir, tlib2, clbk) NumNodes = 0 pos_already_reached(pos) -- don't consider the start pos local node = techage.get_node_lvm(pos) - connection_walk(pos, {outdir}, Flip[outdir], node, tlib2, clbk) + connection_walk(pos, outdir and {outdir}, Flip[outdir], node, tlib2, clbk) return NumNodes end -function techage.networks.get_network(netID, tlib2) - if Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then - Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE - return Networks[tlib2.tube_type][netID] +function techage.networks.get_network(tube_type, netID) + if Networks[tube_type] and Networks[tube_type][netID] then + Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE + return Networks[tube_type][netID] end end -function techage.networks.set_network(netID, tlib2, network) +function techage.networks.set_network(tube_type, netID, network) if netID then - if not Networks[tlib2.tube_type] then - Networks[tlib2.tube_type] = {} + if not Networks[tube_type] then + Networks[tube_type] = {} end - Networks[tlib2.tube_type][netID] = network - Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE + Networks[tube_type][netID] = network + Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE end end -function techage.networks.trigger_network(netID, tlib2) - if not Networks[tlib2.tube_type] then - Networks[tlib2.tube_type] = {} - end - Networks[tlib2.tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE -end -function techage.networks.delete_network(netID, tlib2) - if Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then - Networks[tlib2.tube_type][netID] = nil +-- +-- Power API +-- +function techage.networks.has_network(tube_type, netID) + local netw = Networks[tube_type] and Networks[tube_type][netID] + if netw then + netw.alive = 1 + netw.best_before = minetest.get_gametime() + BEST_BEFORE + return netw end end -function techage.networks.connections(pos, tlib2) - for _,dir in ipairs(get_node_connections(pos, tlib2.tube_type)) do - print(({"North", "East", "South", "West", "Down", "Up"})[dir]) +function techage.networks.build_network(pos, outdir, tlib2, netID) + local netw = collect_network_nodes(pos, outdir, tlib2) + Networks[tlib2.tube_type] = Networks[tlib2.tube_type] or {} + Networks[tlib2.tube_type][netID] = netw + netw.alive = 1 + techage.schedule.start(tlib2.tube_type, netID) +end + +function techage.networks.delete_network(tube_type, netID) + if Networks[tube_type] then + Networks[tube_type][netID] = nil + end +end + +function techage.networks.delete_network(tube_type, netID) + if Networks[tube_type] and Networks[tube_type][netID] then + Networks[tube_type][netID] = nil end end - \ No newline at end of file +--function techage.networks.connections(pos, tlib2) +-- for _,dir in ipairs(get_node_connections(pos, tlib2.tube_type)) do +-- print(({"North", "East", "South", "West", "Down", "Up"})[dir]) +-- end +--end + +-- Get node tubelib2 connections as table of outdirs +-- techage.networks.get_node_connections(pos, net_name) +techage.networks.get_node_connections = get_node_connections diff --git a/basis/node_states.lua b/basis/node_states.lua index a7689d3..f53b673 100644 --- a/basis/node_states.lua +++ b/basis/node_states.lua @@ -51,10 +51,10 @@ Node states: | FAULT none no no | STOPPED none no no -Node mem data: +Node nvm data: "techage_state" - node state, like "RUNNING" "techage_item_meter" - node item/runtime counter - "techage_countdown" - countdown to stadby mode + "techage_countdown" - countdown to standby mode ]]-- -- for lazy programmers @@ -95,7 +95,7 @@ function techage.state_button(state) return "techage_inv_button_off.png" end -function techage.get_power_image(pos, mem) +function techage.get_power_image(pos, nvm) local node = techage.get_node_lvm(pos) local s = "3" -- electrical power if string.find(node.name, "techage:ta2") then @@ -124,12 +124,12 @@ local STOPPED = techage.STOPPED techage.NodeStates = {} local NodeStates = techage.NodeStates -local function can_start(pos, mem) +local function can_start(pos, nvm) --if false, node goes in FAULT return true end -local function has_power(pos, mem) +local function has_power(pos, nvm) --if false, node goes in NOPOWER return true end @@ -144,14 +144,14 @@ local function swap_node(pos, name) end -- true if node_timer should be executed -function techage.is_operational(mem) - local state = mem.techage_state or STOPPED +function techage.is_operational(nvm) + local state = nvm.techage_state or STOPPED return state < NOPOWER end -- consumes power -function techage.needs_power(mem) - local state = mem.techage_state or STOPPED +function techage.needs_power(nvm) + local state = nvm.techage_state or STOPPED return state < BLOCKED end @@ -159,8 +159,8 @@ function techage.needs_power2(state) return state < BLOCKED end -function techage.get_state_string(mem) - return techage.StateStrings[mem.techage_state or STOPPED] +function techage.get_state_string(nvm) + return techage.StateStrings[nvm.techage_state or STOPPED] end function NodeStates:new(attr) @@ -184,15 +184,15 @@ function NodeStates:new(attr) return o end -function NodeStates:node_init(pos, mem, number) - mem.techage_state = STOPPED +function NodeStates:node_init(pos, nvm, number) + nvm.techage_state = STOPPED M(pos):set_string("node_number", number) if self.infotext_name then M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped") end - mem.techage_item_meter = 0 + nvm.techage_item_meter = 0 if self.formspec_func then - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end end @@ -207,11 +207,11 @@ local function start_timer_delayed(pos, cycle_time) end end -function NodeStates:stop(pos, mem) - local state = mem.techage_state or STOPPED - mem.techage_state = STOPPED +function NodeStates:stop(pos, nvm) + local state = nvm.techage_state or STOPPED + nvm.techage_state = STOPPED if self.stop_node then - self.stop_node(pos, mem, state) + self.stop_node(pos, nvm, state) end if self.node_name_passive then swap_node(pos, self.node_name_passive) @@ -221,8 +221,8 @@ function NodeStates:stop(pos, mem) M(pos):set_string("infotext", self.infotext_name.." "..number..": stopped") end if self.formspec_func then - mem.ta_state_tooltip = "stopped" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = "stopped" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if self.on_state_change then self.on_state_change(pos, state, STOPPED) @@ -233,23 +233,23 @@ function NodeStates:stop(pos, mem) return true end -function NodeStates:start(pos, mem) - local state = mem.techage_state or STOPPED +function NodeStates:start(pos, nvm) + local state = nvm.techage_state or STOPPED if state ~= RUNNING and state ~= FAULT then - local res = self.can_start(pos, mem, state) + local res = self.can_start(pos, nvm, state) if res ~= true then - self:fault(pos, mem, res) + self:fault(pos, nvm, res) return false end - if not self.has_power(pos, mem, state) then - self:nopower(pos, mem) + if not self.has_power(pos, nvm, state) then + self:nopower(pos, nvm) return false end - mem.techage_state = RUNNING + nvm.techage_state = RUNNING if self.start_node then - self.start_node(pos, mem, state) + self.start_node(pos, nvm, state) end - mem.techage_countdown = 1 + nvm.techage_countdown = 1 if self.node_name_active then swap_node(pos, self.node_name_active) end @@ -258,8 +258,8 @@ function NodeStates:start(pos, mem) M(pos):set_string("infotext", self.infotext_name.." "..number..": running") end if self.formspec_func then - mem.ta_state_tooltip = "running" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = "running" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if minetest.get_node_timer(pos):is_started() then minetest.get_node_timer(pos):stop() @@ -273,10 +273,10 @@ function NodeStates:start(pos, mem) return false end -function NodeStates:standby(pos, mem) - local state = mem.techage_state or STOPPED +function NodeStates:standby(pos, nvm) + local state = nvm.techage_state or STOPPED if state == RUNNING then - mem.techage_state = STANDBY + nvm.techage_state = STANDBY if self.node_name_passive then swap_node(pos, self.node_name_passive) end @@ -285,8 +285,8 @@ function NodeStates:standby(pos, mem) M(pos):set_string("infotext", self.infotext_name.." "..number..": standby") end if self.formspec_func then - mem.ta_state_tooltip = "standby" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = "standby" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if self.on_state_change then self.on_state_change(pos, state, STANDBY) @@ -298,10 +298,10 @@ function NodeStates:standby(pos, mem) end -- special case of standby for pushing nodes -function NodeStates:blocked(pos, mem) - local state = mem.techage_state or STOPPED +function NodeStates:blocked(pos, nvm) + local state = nvm.techage_state or STOPPED if state == RUNNING then - mem.techage_state = BLOCKED + nvm.techage_state = BLOCKED if self.node_name_passive then swap_node(pos, self.node_name_passive) end @@ -310,8 +310,8 @@ function NodeStates:blocked(pos, mem) M(pos):set_string("infotext", self.infotext_name.." "..number..": blocked") end if self.formspec_func then - mem.ta_state_tooltip = "blocked" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = "blocked" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if self.on_state_change then self.on_state_change(pos, state, BLOCKED) @@ -322,10 +322,10 @@ function NodeStates:blocked(pos, mem) return false end -function NodeStates:nopower(pos, mem, err_string) - local state = mem.techage_state or RUNNING +function NodeStates:nopower(pos, nvm, err_string) + local state = nvm.techage_state or RUNNING if state ~= NOPOWER then - mem.techage_state = NOPOWER + nvm.techage_state = NOPOWER if self.node_name_passive then swap_node(pos, self.node_name_passive) end @@ -334,8 +334,8 @@ function NodeStates:nopower(pos, mem, err_string) M(pos):set_string("infotext", self.infotext_name.." "..number..": no power") end if self.formspec_func then - mem.ta_state_tooltip = err_string or "no power" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = err_string or "no power" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if self.on_state_change then self.on_state_change(pos, state, NOPOWER) @@ -346,11 +346,11 @@ function NodeStates:nopower(pos, mem, err_string) return false end -function NodeStates:fault(pos, mem, err_string) - local state = mem.techage_state or STOPPED +function NodeStates:fault(pos, nvm, err_string) + local state = nvm.techage_state or STOPPED err_string = err_string or "fault" if state == RUNNING or state == STOPPED then - mem.techage_state = FAULT + nvm.techage_state = FAULT if self.node_name_passive then swap_node(pos, self.node_name_passive) end @@ -359,8 +359,8 @@ function NodeStates:fault(pos, mem, err_string) M(pos):set_string("infotext", self.infotext_name.." "..number..": "..err_string) end if self.formspec_func then - mem.ta_state_tooltip = err_string or "fault" - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + nvm.ta_state_tooltip = err_string or "fault" + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) end if self.on_state_change then self.on_state_change(pos, state, FAULT) @@ -371,90 +371,90 @@ function NodeStates:fault(pos, mem, err_string) return false end -function NodeStates:get_state(mem) - return mem.techage_state or techage.STOPPED +function NodeStates:get_state(nvm) + return nvm.techage_state or techage.STOPPED end -- keep the timer running? -function NodeStates:is_active(mem) - local state = mem.techage_state or STOPPED +function NodeStates:is_active(nvm) + local state = nvm.techage_state or STOPPED return state < FAULT end function NodeStates:start_if_standby(pos) - local mem = tubelib2.get_mem(pos) - if mem.techage_state == STANDBY then - self:start(pos, mem) + local nvm = techage.get_nvm(pos) + if nvm.techage_state == STANDBY then + self:start(pos, nvm) end end -- To be called if node is idle. -- If countdown reaches zero, the node is set to STANDBY. -function NodeStates:idle(pos, mem) - local countdown = (mem.techage_countdown or 0) - 1 - mem.techage_countdown = countdown +function NodeStates:idle(pos, nvm) + local countdown = (nvm.techage_countdown or 0) - 1 + nvm.techage_countdown = countdown if countdown <= 0 then - self:standby(pos, mem) + self:standby(pos, nvm) end end -- To be called after successful node action to raise the timer -- and keep the node in state RUNNING -function NodeStates:keep_running(pos, mem, val, num_items) +function NodeStates:keep_running(pos, nvm, val, num_items) -- set to RUNNING if not already done - if mem.techage_state ~= RUNNING then - self:start(pos, mem) + if nvm.techage_state ~= RUNNING then + self:start(pos, nvm) end - mem.techage_countdown = val or 4 - mem.techage_item_meter = (mem.techage_item_meter or 0) + (num_items or 1) + nvm.techage_countdown = val or 4 + nvm.techage_item_meter = (nvm.techage_item_meter or 0) + (num_items or 1) end -- Start/stop node based on button events. -- if function returns false, no button was pressed -function NodeStates:state_button_event(pos, mem, fields) +function NodeStates:state_button_event(pos, nvm, fields) if fields.state_button ~= nil then - local state = mem.techage_state or STOPPED + local state = nvm.techage_state or STOPPED if state == STOPPED or state == STANDBY or state == BLOCKED then - if not self:start(pos, mem) and (state == STANDBY or state == BLOCKED) then - self:stop(pos, mem) + if not self:start(pos, nvm) and (state == STANDBY or state == BLOCKED) then + self:stop(pos, nvm) end elseif state == RUNNING or state == FAULT or state == NOPOWER then - self:stop(pos, mem) + self:stop(pos, nvm) end return true end return false end -function NodeStates:get_state_button_image(mem) - local state = mem.techage_state or STOPPED +function NodeStates:get_state_button_image(nvm) + local state = nvm.techage_state or STOPPED return techage.state_button(state) end -function NodeStates:get_state_tooltip(mem) - local tp = mem.ta_state_tooltip or "" +function NodeStates:get_state_tooltip(nvm) + local tp = nvm.ta_state_tooltip or "" return tp..";#0C3D32;#FFFFFF" end -- command interface function NodeStates:on_receive_message(pos, topic, payload) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if topic == "on" then - self:start(pos, tubelib2.get_mem(pos)) + self:start(pos, techage.get_nvm(pos)) return true elseif topic == "off" then - self:stop(pos, tubelib2.get_mem(pos)) + self:stop(pos, techage.get_nvm(pos)) return true elseif topic == "state" then local node = techage.get_node_lvm(pos) if node.name == "ignore" then -- unloaded node? return "unloaded" end - return techage.get_state_string(tubelib2.get_mem(pos)) + return techage.get_state_string(techage.get_nvm(pos)) elseif topic == "counter" then - return mem.techage_item_meter or 1 + return nvm.techage_item_meter or 1 elseif topic == "clear_counter" then - mem.techage_item_meter = 0 + nvm.techage_item_meter = 0 return true elseif topic == "fuel" then local inv = M(pos):get_inventory() @@ -470,7 +470,7 @@ end -- repair corrupt node data function NodeStates:on_node_load(pos, not_start_timer) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) -- Meta data corrupt? local number = M(pos):get_string("node_number") @@ -478,7 +478,7 @@ function NodeStates:on_node_load(pos, not_start_timer) minetest.log("warning", "[TA] Node at "..S(pos).." has no node_number") local name = techage.get_node_lvm(pos).name local number = techage.add_node(pos, name) - self:node_init(pos, mem, number) + self:node_init(pos, nvm, number) return end @@ -499,12 +499,12 @@ function NodeStates:on_node_load(pos, not_start_timer) end -- state corrupt? - local state = mem.techage_state or 0 + local state = nvm.techage_state or 0 if state == 0 then if minetest.get_node_timer(pos):is_started() then - mem.techage_state = RUNNING + nvm.techage_state = RUNNING else - mem.techage_state = STOPPED + nvm.techage_state = STOPPED end elseif state == RUNNING and not not_start_timer then minetest.get_node_timer(pos):start(self.cycle_time) @@ -515,7 +515,12 @@ function NodeStates:on_node_load(pos, not_start_timer) end if self.formspec_func then - M(pos):set_string("formspec", self.formspec_func(self, pos, mem)) + M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) + end + + -- power available? + if nvm.techage_state == RUNNING and not self.has_power(pos, nvm, state) then + self:nopower(pos, nvm) end end diff --git a/basis/recipe_lib.lua b/basis/recipe_lib.lua index 85af1b9..68ede2a 100644 --- a/basis/recipe_lib.lua +++ b/basis/recipe_lib.lua @@ -18,7 +18,7 @@ local M = minetest.get_meta local Recipes = {} -- {rtype = {ouput = {....},...}} local RecipeList = {} -- {rtype = {,...}} -local range = techage.range +local range = techage.in_range techage.recipes = {} diff --git a/coal_power_station/akkubox.lua b/coal_power_station/akkubox.lua deleted file mode 100644 index 64aef00..0000000 --- a/coal_power_station/akkubox.lua +++ /dev/null @@ -1,186 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA3 Akku Box - -]]-- - --- for lazy programmers -local M = minetest.get_meta -local S = techage.S - -local CYCLE_TIME = 2 -local PWR_PERF = 10 -local PWR_CAPA = 2000 - -local Power = 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(self, 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).."]".. - "label[0.2,2.5;Load]".. - "button[1.1,1;1.8,1;update;"..S("Update").."]".. - "image_button[3,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "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 start_node(pos, mem, state) - mem.running = true - mem.delivered = 0 - power.secondary_start(pos, mem, PWR_PERF, PWR_PERF) -end - -local function stop_node(pos, mem, state) - mem.running = false - mem.delivered = 0 - power.secondary_stop(pos, mem) -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:ta3_akku", - cycle_time = CYCLE_TIME, - standby_ticks = 0, - formspec_func = formspec, - start_node = start_node, - stop_node = stop_node, -}) - -local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.running then - mem.delivered = power.secondary_alive(pos, mem, mem.capa, PWR_CAPA) - 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) - State:state_button_event(pos, mem, fields) - - if fields.update then - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) - end -end - -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) -end - -local function get_capa(itemstack) - local meta = itemstack:get_meta() - if meta then - return in_range(meta:get_int("capa") * (PWR_CAPA/100), 0, 3000) - end - return 0 -end - -local function set_capa(pos, oldnode, digger, capa) - local node = ItemStack(oldnode.name) - local meta = node:get_meta() - capa = techage.power.percent(PWR_CAPA, capa) - capa = (math.floor((capa or 0) / 5)) * 5 - meta:set_int("capa", capa) - local text = S("TA3 Akku Box").." ("..capa.." %)" - meta:set_string("description", text) - local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) - local left_over = inv:add_item("main", node) - if left_over:get_count() > 0 then - minetest.add_item(pos, node) - end -end - -minetest.register_node("techage:ta3_akku", { - description = S("TA3 Akku Box"), - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta3.png^techage_frame_ta3_top.png", - "techage_filling_ta3.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole_electric.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png", - }, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, - drop = "", -- don't remove, item will be added via 'set_capa' - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - -techage.power.register_node({"techage:ta3_akku"}, { - conn_sides = {"R"}, - power_network = Power, - after_place_node = function(pos, placer, itemstack) - local meta = M(pos) - local mem = tubelib2.init_mem(pos) - local own_num = techage.add_node(pos, "techage:ta3_akku") - meta:set_string("owner", placer:get_player_name()) - meta:set_string("infotext", S("TA3 Akku Box").." "..own_num) - State:node_init(pos, mem, own_num) - mem.capa = get_capa(itemstack) - on_rightclick(pos) - end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - local mem = tubelib2.get_mem(pos) - set_capa(pos, oldnode, digger, mem.capa) - end, -}) - --- for logical communication -techage.register_node({"techage:ta3_akku"}, { - on_recv_message = function(pos, src, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "capa" then - return techage.power.percent(PWR_CAPA, mem.capa) - else - return State:on_receive_message(pos, topic, payload) - end - end, - on_node_load = function(pos) - local meta = M(pos) - if meta:get_string("node_number") == "" then - local own_num = techage.add_node(pos, "techage:ta3_akku") - meta:set_string("node_number", own_num) - meta:set_string("infotext", S("TA3 Akku Box").." "..own_num) - end - end, -}) - -minetest.register_craft({ - output = "techage:ta3_akku", - recipe = { - {"default:tin_ingot", "default:tin_ingot", "default:wood"}, - {"default:copper_ingot", "default:copper_ingot", "techage:electric_cableS"}, - {"techage:iron_ingot", "techage:iron_ingot", "default:wood"}, - }, -}) diff --git a/coal_power_station/boiler_base.lua b/coal_power_station/boiler_base.lua index fc4d9cc..2a2960e 100644 --- a/coal_power_station/boiler_base.lua +++ b/coal_power_station/boiler_base.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -17,6 +17,15 @@ local M = minetest.get_meta local S = techage.S local Pipe = techage.SteamPipe +local networks = techage.networks + +local function after_place_node(pos) + Pipe:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + Pipe:after_dig_node(pos) +end minetest.register_node("techage:coalboiler_base", { description = S("TA3 Boiler Base"), @@ -28,7 +37,8 @@ minetest.register_node("techage:coalboiler_base", { fixed = {-13/32, -16/32, -13/32, 13/32, 16/32, 13/32}, }, - on_construct = tubelib2.init_mem, + after_place_node = after_place_node, + after_dig_node = after_dig_node, paramtype = "light", paramtype2 = "facedir", @@ -38,21 +48,12 @@ minetest.register_node("techage:coalboiler_base", { sounds = default.node_sound_stone_defaults(), }) -techage.power.register_node({"techage:coalboiler_base"}, { - conn_sides = {"F"}, - power_network = Pipe, -}) +Pipe:add_secondary_node_names({"techage:coalboiler_base"}) -- for logical communication techage.register_node({"techage:coalboiler_base"}, { on_transfer = function(pos, in_dir, topic, payload) - if topic == "start" then - return true - elseif topic == "stop" then - return true - elseif topic == "running" then - return true - end + return true end }) diff --git a/coal_power_station/boiler_top.lua b/coal_power_station/boiler_top.lua index 6a3c1e5..feb0a35 100644 --- a/coal_power_station/boiler_top.lua +++ b/coal_power_station/boiler_top.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -17,206 +17,40 @@ local M = minetest.get_meta local S = techage.S local CYCLE_TIME = 4 -local STANDBY_TICKS = 2 -local COUNTDOWN_TICKS = 20 -local HEAT_STEP = 10 local WATER_CONSUMPTION = 0.1 -local MAX_WATER = 10 local Pipe = techage.SteamPipe +local boiler = techage.boiler -local function transfer(pos, topic, payload) - return techage.transfer(pos, "F", topic, payload, Pipe, - {"techage:turbine", "techage:turbine_on"}) -end - -local Water = { - ["bucket:bucket_river_water"] = true, - ["bucket:bucket_water"] = true, - ["bucket:bucket_empty"] = true, -} - -local function formspec(self, pos, mem) - local temp = mem.temperature or 20 - local ratio = mem.power_ratio or 0 - return "size[8,7]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "image_button[0,0.2;1,1;techage_form_inventory.png;storage;;true;false;]".. - "list[context;water;1,0.2;1,1;]".. - "image_button[0,1.6;1,1;techage_form_input.png;input;;true;false;]".. - "list[context;input;1,1.6;1,1;]".. - "image[1,1.6;1,1;bucket_water.png]".. - "image[1,1.6;1,1;techage_form_mask.png]".. - "image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:".. - temp..":techage_form_temp_fg.png]".. - "image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]".. - "image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[3,1.5;2,1;update;"..S("Update").."]".. - "list[current_player;main;0,3;8,4;]".. - "listring[current_name;water]".. - "listring[current_player;main]".. - default.get_hotbar_bg(0, 3) -end - -local function can_start(pos, mem, state) - return mem.temperature and mem.temperature >= 80 -end - -local function start_node(pos, mem, state) - mem.running = transfer(pos, "start", nil) - mem.power_ratio = 0 -end - -local function stop_node(pos, mem, state) - transfer(pos, "stop", nil) - mem.running = false - mem.power_ratio = 0 -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:coalboiler_top", - cycle_time = CYCLE_TIME, - standby_ticks = STANDBY_TICKS, - has_item_meter = false, - formspec_func = formspec, - can_start = can_start, - start_node = start_node, - stop_node = stop_node, -}) - -local function get_water(pos) - local inv = M(pos):get_inventory() - local items = inv:get_stack("water", 1) - if items:get_count() > 0 then - local taken = items:take_item(1) - inv:set_stack("water", 1, items) - return true - end - return false -end - -local function water_temperature(pos, mem) - mem.temperature = mem.temperature or 20 - if mem.fire_trigger then - mem.temperature = math.min(mem.temperature + HEAT_STEP, 100) - else - mem.temperature = math.max(mem.temperature - HEAT_STEP, 20) - end - mem.fire_trigger = false - - if mem.water_level == 0 then - if get_water(pos) then - mem.water_level = 100 - else - mem.temperature = 20 - end - end - return mem.temperature -end - -local function steaming(pos, mem, temp) - local wc = WATER_CONSUMPTION * (mem.power_ratio or 1) - mem.water_level = math.max((mem.water_level or 0) - wc, 0) - mem.running = transfer(pos, "running", nil) - if not mem.running then - State:fault(pos, mem) - elseif temp > 20 then - if temp < 80 then - State:stop(pos, mem) - minetest.get_node_timer(pos):start(CYCLE_TIME) - else - State:keep_running(pos, mem, COUNTDOWN_TICKS) - end +local function steaming(pos, nvm, temp) + if temp >= 80 then + local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1) + nvm.water_level = math.max((nvm.water_level or 0) - wc, 0) end end local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - local temp = water_temperature(pos, mem) - if State:is_active(mem) then - steaming(pos, mem, temp) + local nvm = techage.get_nvm(pos) + local temp = boiler.water_temperature(pos, nvm) + steaming(pos, nvm, temp) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", boiler.formspec(pos, nvm)) end - return mem.temperature > 20 + return temp > 20 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) - mem.temperature = mem.temperature or 20 - State:state_button_event(pos, mem, fields) - - if fields.update then - if mem.temperature > 20 then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end - M(pos):set_string("formspec", formspec(State, pos, mem)) +local function after_place_node(pos) + local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + if node.name == "techage:coalboiler_base" then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", boiler.formspec(pos, nvm)) + Pipe:after_place_node(pos) end end - -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) - if not minetest.get_node_timer(pos):is_started() then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end -end - -local function can_dig(pos, player) - local inv = M(pos):get_inventory() - local mem = tubelib2.get_mem(pos) - return inv:is_empty("input") and not mem.running -end - -local function move_to_water(pos) - local inv = M(pos):get_inventory() - local water_stack = inv:get_stack("water", 1) - local input_stack = inv:get_stack("input", 1) - - if input_stack:get_name() == "bucket:bucket_empty" then - if input_stack:get_count() == 1 then - if water_stack:get_count() > 0 then - water_stack:set_count(water_stack:get_count() - 1) - input_stack = ItemStack("bucket:bucket_water") - inv:set_stack("water", 1, water_stack) - inv:set_stack("input", 1, input_stack) - end - end - elseif water_stack:get_count() < MAX_WATER then - if water_stack:get_count() == 0 then - water_stack = ItemStack("default:water_source") - else - water_stack:set_count(water_stack:get_count() + 1) - end - input_stack = ItemStack("bucket:bucket_empty") - inv:set_stack("water", 1, water_stack) - inv:set_stack("input", 1, input_stack) - end -end - - -local function allow_metadata_inventory_put(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - if listname == "input" and Water[stack:get_name()] then - return stack:get_count() - end - return 0 -end - -local function allow_metadata_inventory_take(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - if listname == "input" then - return stack:get_count() - end - return 0 +local function after_dig_node(pos, oldnode) + Pipe:after_dig_node(pos) + techage.del_mem(pos) end minetest.register_node("techage:coalboiler_top", { @@ -229,23 +63,12 @@ minetest.register_node("techage:coalboiler_top", { fixed = {-13/32, -48/32, -13/32, 13/32, 16/32, 13/32}, }, - can_dig = can_dig, + can_dig = boiler.can_dig, on_timer = node_timer, - allow_metadata_inventory_put = allow_metadata_inventory_put, - allow_metadata_inventory_take = allow_metadata_inventory_take, - allow_metadata_inventory_move = function(pos) return 0 end, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - - on_construct = function(pos) - local inv = M(pos):get_inventory() - inv:set_size('water', 1) - inv:set_size('input', 1) - end, - - on_metadata_inventory_put = function(pos) - minetest.after(0.5, move_to_water, pos) - end, + on_rightclick = boiler.on_rightclick, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + on_punch = boiler.on_punch, paramtype = "light", paramtype2 = "facedir", @@ -255,36 +78,28 @@ minetest.register_node("techage:coalboiler_top", { sounds = default.node_sound_metal_defaults(), }) -techage.power.register_node({"techage:coalboiler_top"}, { - conn_sides = {"F"}, - power_network = Pipe, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State:node_init(pos, mem, "") - local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) - if node.name == "techage:coalboiler_base" then - on_rightclick(pos) - end - end, -}) +Pipe:add_secondary_node_names({"techage:coalboiler_top"}) + techage.register_node({"techage:coalboiler_top"}, { on_transfer = function(pos, in_dir, topic, payload) if topic == "trigger" then - local mem = tubelib2.get_mem(pos) - mem.fire_trigger = true + local nvm = techage.get_nvm(pos) + nvm.fire_trigger = true if not minetest.get_node_timer(pos):is_started() then minetest.get_node_timer(pos):start(CYCLE_TIME) end - if mem.running then - mem.power_ratio = transfer(pos, topic, payload) - return mem.power_ratio + if (nvm.temperature or 20) > 80 then + nvm.power_ratio = techage.transfer(pos, "F", "trigger", nil, Pipe, { + "techage:turbine", "techage:turbine_on"}) or 0 + return nvm.power_ratio + else + return 0 end end - end + end, }) - minetest.register_craft({ output = "techage:coalboiler_top", recipe = { diff --git a/coal_power_station/cooler.lua b/coal_power_station/cooler.lua index 9e2a6f5..1725ca9 100644 --- a/coal_power_station/cooler.lua +++ b/coal_power_station/cooler.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -23,28 +23,47 @@ local function transfer(pos, in_dir, topic, payload) {"techage:coalboiler_base"}) end -local function swap_node(pos, name) - local node = techage.get_node_lvm(pos) - if node.name == name then - return - end - node.name = name - minetest.swap_node(pos, node) +local function after_place_node(pos) + Pipe:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + Pipe:after_dig_node(pos) + techage.del_mem(pos) end minetest.register_node("techage:cooler", { description = S("TA3 Cooler"), tiles = { -- up, down, right, left, back, front - "techage_filling_ta3.png^techage_appl_cooler.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_appl_cooler.png^techage_frame_ta3.png", + { + image = "techage_filling4_ta3.png^techage_appl_cooler4.png^techage_frame4_ta3.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.4, + }, + }, + { + image = "techage_filling4_ta3.png^techage_appl_cooler4.png^techage_frame4_ta3.png", + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.4, + }, + }, "techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png", "techage_filling_ta3.png^techage_frame_ta3.png^techage_steam_hole.png", "techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png", "techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png", }, - on_construct = tubelib2.init_mem, + after_place_node = after_place_node, + after_dig_node = after_dig_node, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -53,8 +72,9 @@ minetest.register_node("techage:cooler", { sounds = default.node_sound_wood_defaults(), }) - +-- legacy node minetest.register_node("techage:cooler_on", { + description = S("TA3 Cooler"), tiles = { -- up, down, right, left, back, front { @@ -83,41 +103,23 @@ minetest.register_node("techage:cooler_on", { "techage_filling_ta3.png^techage_frame_ta3.png^techage_cooler.png", }, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + paramtype2 = "facedir", - groups = {not_in_creative_inventory=1}, - diggable = false, + drop = "techage:cooler", + groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1}, on_rotate = screwdriver.disallow, is_ground_content = false, sounds = default.node_sound_wood_defaults(), }) --- for mechanical pipe connections -techage.power.register_node({"techage:cooler", "techage:cooler_on"}, { - conn_sides = {"L", "R"}, - power_network = Pipe, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - swap_node(pos, "techage:cooler") - end, -}) +Pipe:add_secondary_node_names({"techage:cooler", "techage:cooler_on"}) -- for logical communication techage.register_node({"techage:cooler", "techage:cooler_on"}, { on_transfer = function(pos, in_dir, topic, payload) - if topic == "start" then - if transfer(pos, in_dir, topic, nil) then - swap_node(pos, "techage:cooler_on") - return true - end - elseif topic == "stop" then - swap_node(pos, "techage:cooler") - return transfer(pos, in_dir, topic, nil) - elseif topic == "running" then - if transfer(pos, in_dir, topic, nil) then - return true - end - swap_node(pos, "techage:cooler") - end - return false + return transfer(pos, in_dir, topic, payload) end }) diff --git a/coal_power_station/firebox.lua b/coal_power_station/firebox.lua index 3dabb9f..9634035 100644 --- a/coal_power_station/firebox.lua +++ b/coal_power_station/firebox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -18,12 +18,9 @@ local M = minetest.get_meta local S = techage.S local firebox = techage.firebox -local fuel = techage.fuel -local Pipe = techage.LiquidPipe -local liquid = techage.liquid local CYCLE_TIME = 2 -local EFFICIENCY = 0.5 +local BURN_CYCLE_FACTOR = 0.5 local function firehole(pos, on) local param2 = techage.get_node_lvm(pos).param2 @@ -38,38 +35,39 @@ local function firehole(pos, on) end local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.running then - -- trigger generator and provide power ratio 0..1 - local ratio = techage.transfer( + local nvm = techage.get_nvm(pos) + if nvm.running then + local power = techage.transfer( {x=pos.x, y=pos.y+2, z=pos.z}, nil, -- outdir "trigger", -- topic - (mem.power_level or 4)/4.0, -- payload + nil, -- payload nil, -- network {"techage:coalboiler_top"} -- nodenames ) - ratio = math.max((ratio or 0.02), 0.02) - mem.burn_cycles = (mem.burn_cycles or 0) - ratio - if mem.burn_cycles <= 0 then + nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.02), 0.02) + if nvm.burn_cycles <= 0 then local taken = firebox.get_fuel(pos) if taken then - mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) * EFFICIENCY / CYCLE_TIME - mem.burn_cycles_total = mem.burn_cycles + nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR + nvm.burn_cycles_total = nvm.burn_cycles else - mem.running = false + nvm.running = false firehole(pos, false) - M(pos):set_string("formspec", firebox.formspec(mem)) + M(pos):set_string("formspec", firebox.formspec(nvm)) return false end end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", firebox.formspec(nvm)) + end return true end end -local function start_firebox(pos, mem) - if not mem.running then - mem.running = true +local function start_firebox(pos, nvm) + if not nvm.running then + nvm.running = true node_timer(pos, 0) firehole(pos, true) minetest.get_node_timer(pos):start(CYCLE_TIME) @@ -98,17 +96,15 @@ minetest.register_node("techage:coalfirebox", { can_dig = firebox.can_dig, allow_metadata_inventory_put = firebox.allow_metadata_inventory_put, allow_metadata_inventory_take = firebox.allow_metadata_inventory_take, - on_receive_fields = firebox.on_receive_fields, on_rightclick = firebox.on_rightclick, on_construct = function(pos) - local mem = tubelib2.init_mem(pos) techage.add_node(pos, "techage:coalfirebox") - mem.running = false - mem.burn_cycles = 0 - mem.power_level = 4 + local nvm = techage.get_nvm(pos) + nvm.running = false + nvm.burn_cycles = 0 local meta = M(pos) - meta:set_string("formspec", firebox.formspec(mem)) + meta:set_string("formspec", firebox.formspec(nvm)) local inv = meta:get_inventory() inv:set_size('fuel', 1) firehole(pos, false) @@ -119,9 +115,9 @@ minetest.register_node("techage:coalfirebox", { end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - local mem = tubelib2.get_mem(pos) - start_firebox(pos, mem) - M(pos):set_string("formspec", firebox.formspec(mem)) + local nvm = techage.get_nvm(pos) + start_firebox(pos, nvm) + M(pos):set_string("formspec", firebox.formspec(nvm)) end, }) @@ -188,128 +184,6 @@ minetest.register_node("techage:coalfirehole_on", { groups = {not_in_creative_inventory=1}, }) -local function on_timer2(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.running then - fuel.formspec_update(pos, mem) - -- trigger generator and provide power ratio 0..1 - local ratio = techage.transfer( - {x=pos.x, y=pos.y+2, z=pos.z}, - nil, -- outdir - "trigger", -- topic - (mem.power_level or 4)/4.0, -- payload - nil, -- network - {"techage:coalboiler_top"} -- nodenames - ) - ratio = math.max((ratio or 0.02), 0.02) - mem.burn_cycles = (mem.burn_cycles or 0) - ratio - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - if mem.burn_cycles <= 0 then - if mem.liquid.amount > 0 then - mem.liquid.amount = mem.liquid.amount - 1 - mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME - mem.burn_cycles_total = mem.burn_cycles - else - mem.running = false - mem.liquid.name = nil - firehole(pos, false) - M(pos):set_string("formspec", fuel.formspec(mem)) - return false - end - end - return true - end -end - -local function start_firebox2(pos, mem) - if not mem.running and mem.liquid.amount > 0 then - mem.running = true - on_timer2(pos, 0) - firehole(pos, true) - minetest.get_node_timer(pos):start(CYCLE_TIME) - M(pos):set_string("formspec", fuel.formspec(mem)) - end -end - -minetest.register_node("techage:oilfirebox", { - description = S("TA3 Power Station Oil Burner"), - inventory_image = "techage_oil_boiler_inv.png", - tiles = {"techage_coal_boiler_mesh_top.png"}, - drawtype = "mesh", - mesh = "techage_cylinder_12.obj", - selection_box = { - type = "fixed", - fixed = {-13/32, -16/32, -13/32, 13/32, 16/32, 13/32}, - }, - - paramtype = "light", - paramtype2 = "facedir", - on_rotate = screwdriver.disallow, - groups = {cracky=2}, - is_ground_content = false, - sounds = default.node_sound_stone_defaults(), - - on_timer = on_timer2, - can_dig = fuel.can_dig, - allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, - allow_metadata_inventory_put = fuel.allow_metadata_inventory_put, - on_receive_fields = fuel.on_receive_fields, - on_rightclick = fuel.on_rightclick, - - on_construct = function(pos) - local mem = tubelib2.init_mem(pos) - techage.add_node(pos, "techage:oilfirebox") - mem.running = false - mem.burn_cycles = 0 - mem.liquid = {} - mem.liquid.amount = 0 - local meta = M(pos) - meta:set_string("formspec", fuel.formspec(mem)) - local inv = meta:get_inventory() - inv:set_size('fuel', 1) - firehole(pos, false) - end, - - on_destruct = function(pos) - firehole(pos, nil) - end, - - on_metadata_inventory_put = function(pos, listname, index, stack, player) - local mem = tubelib2.get_mem(pos) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - minetest.after(1, start_firebox2, pos, mem) - fuel.on_metadata_inventory_put(pos, listname, index, stack, player) - end, - - liquid = { - capa = fuel.CAPACITY, - fuel_cat = fuel.BT_BITUMEN, - peek = liquid.srv_peek, - put = function(pos, indir, name, amount) - if fuel.valid_fuel(name, fuel.BT_BITUMEN) then - local leftover = liquid.srv_put(pos, indir, name, amount) - local mem = tubelib2.get_mem(pos) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - start_firebox2(pos, mem) - return leftover - end - return amount - end, - take = liquid.srv_take, - }, - networks = { - pipe = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, - }, -}) - -Pipe:add_secondary_node_names({"techage:oilfirebox"}) - techage.register_node({"techage:coalfirebox"}, { on_pull_item = function(pos, in_dir, num) @@ -321,8 +195,8 @@ techage.register_node({"techage:coalfirebox"}, { if firebox.Burntime[stack:get_name()] then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local mem = tubelib2.get_mem(pos) - start_firebox(pos, mem) + local nvm = techage.get_nvm(pos) + start_firebox(pos, nvm) return techage.put_items(inv, "fuel", stack) end return false @@ -333,9 +207,9 @@ techage.register_node({"techage:coalfirebox"}, { return techage.put_items(inv, "fuel", stack) end, on_recv_message = function(pos, src, topic, payload) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if topic == "state" then - if mem.running then + if nvm.running then return "running" else return "stopped" @@ -350,23 +224,6 @@ techage.register_node({"techage:coalfirebox"}, { end, }) -techage.register_node({"techage:oilfirebox"}, { - on_recv_message = function(pos, src, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "state" then - if mem.running then - return "running" - else - return "stopped" - end - elseif topic == "fuel" then - return mem.liquid and mem.liquid.amount and mem.liquid.amount - else - return "unsupported" - end - end, -}) - minetest.register_craft({ output = "techage:coalfirebox", recipe = { @@ -376,21 +233,14 @@ minetest.register_craft({ }, }) -minetest.register_craft({ - output = "techage:oilfirebox", - recipe = { - {'', 'techage:coalfirebox', ''}, - {'', 'techage:ta3_barrel_empty', ''}, - {'', '', ''}, - }, -}) - minetest.register_lbm({ label = "[techage] Power Station firebox", - name = "techage:steam_engine", - nodenames = {"techage:coalfirebox", "techage:oilfirebox"}, + name = "techage:coalfirebox", + nodenames = {"techage:coalfirebox"}, run_at_every_load = true, action = function(pos, node) + local nvm = techage.get_nvm(pos) + nvm.running = true minetest.get_node_timer(pos):start(CYCLE_TIME) end }) diff --git a/coal_power_station/generator.lua b/coal_power_station/generator.lua index 4547b7e..5008933 100644 --- a/coal_power_station/generator.lua +++ b/coal_power_station/generator.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -23,32 +23,42 @@ local PWR_CAPA = 80 local Cable = techage.ElectricCable local power = techage.power +local networks = techage.networks -local function formspec(self, pos, mem) - return "size[8,7]".. +local function formspec(self, pos, nvm) + return "size[4,4]".. + "box[0,-0.1;3.8,0.5;#c6e8ff]".. + "label[1,-0.1;"..minetest.colorize( "#000000", S("Generator")).."]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "image[6,0.5;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. - "image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[2,1.5;2,1;update;"..S("Update").."]".. - "list[current_player;main;0,3;8,4;]".. - default.get_hotbar_bg(0, 3) + power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end -local function can_start(pos, mem, state) - return (mem.firebox_trigger or 0) > 0 -- by means of firebox +local function transfer_turbine(pos, topic, payload) + return techage.transfer(pos, "L", topic, payload, nil, + {"techage:turbine", "techage:turbine_on"}) end -local function start_node(pos, mem, state) - mem.generating = true -- needed for power distribution - power.generator_start(pos, mem, PWR_CAPA) +local function can_start(pos, nvm, state) + return (nvm.firebox_trigger or 0) > 0 -- by means of firebox end -local function stop_node(pos, mem, state) - mem.generating = false - power.generator_stop(pos, mem) - mem.provided = 0 +local function start_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.generator_start(pos, Cable, CYCLE_TIME, outdir) + transfer_turbine(pos, "start") + nvm.running = true +end + +local function stop_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.generator_stop(pos, Cable, outdir) + nvm.provided = 0 + transfer_turbine(pos, "stop") + nvm.running = false end local State = techage.NodeStates:new({ @@ -64,42 +74,63 @@ local State = techage.NodeStates:new({ }) local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.generating then - mem.firebox_trigger = (mem.firebox_trigger or 0) - 1 - if mem.firebox_trigger <= 0 then - State:nopower(pos, mem) - mem.generating = false - power.generator_stop(pos, mem) - mem.provided = 0 - else - mem.provided = power.generator_alive(pos, mem) - State:keep_running(pos, mem, COUNTDOWN_TICKS) - end + local nvm = techage.get_nvm(pos) + nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1 + if nvm.firebox_trigger <= 0 then + State:nopower(pos, nvm) + stop_node(pos, nvm, State) + transfer_turbine(pos, "stop") + else + local outdir = M(pos):get_int("outdir") + nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir) + State:keep_running(pos, nvm, COUNTDOWN_TICKS) end - return State:is_active(mem) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return State:is_active(nvm) 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) - State:state_button_event(pos, mem, fields) - - if fields.update then - M(pos):set_string("formspec", formspec(State, pos, mem)) - end + local nvm,_ = techage.get_nvm(pos, true) + State:state_button_event(pos, nvm, fields) end -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) - if mem.generating then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end +local function on_rightclick(pos, node, clicker) + local nvm = techage.get_nvm(pos) + techage.set_activeformspec(pos, clicker) + M(pos):set_string("formspec", formspec(State, pos, nvm)) end +local function after_place_node(pos) + local nvm = techage.get_nvm(pos) + local number = techage.add_node(pos, "techage:generator") + State:node_init(pos, nvm, number) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + Cable:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + Cable:after_dig_node(pos) + techage.del_mem(pos) +end + +local function tubelib2_on_update2(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2) +end + +local net_def = { + ele1 = { + sides = {R = 1}, + ntype = "gen1", + nominal = PWR_CAPA, + }, +} + minetest.register_node("techage:generator", { description = S("TA3 Generator"), tiles = { @@ -111,9 +142,15 @@ minetest.register_node("techage:generator", { "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png", "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_generator.png^[transformFX]", }, + on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_timer = node_timer, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, + paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -154,6 +191,11 @@ minetest.register_node("techage:generator_on", { on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_timer = node_timer, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, + drop = "", paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, @@ -163,38 +205,15 @@ minetest.register_node("techage:generator_on", { sounds = default.node_sound_wood_defaults(), }) -minetest.register_craft({ - output = "techage:generator", - recipe = { - {"basic_materials:steel_bar", "dye:green", "default:wood"}, - {"", "basic_materials:gear_steel", "techage:electric_cableS"}, - {"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"}, - }, -}) +Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"}) -techage.power.register_node({"techage:generator", "techage:generator_on"}, { - conn_sides = {"R"}, - power_network = Cable, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - local number = techage.add_node(pos, "techage:generator") - State:node_init(pos, mem, number) - on_rightclick(pos) - end, -}) - --- for logical communication techage.register_node({"techage:generator", "techage:generator_on"}, { on_transfer = function(pos, in_dir, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "power_level" then - local mem = tubelib2.get_mem(pos) - mem.power_level = payload - elseif topic == "trigger" then - mem.firebox_trigger = 3 - mem.power_level = payload - if mem.generating then - return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02) + local nvm = techage.get_nvm(pos) + if topic == "trigger" then + nvm.firebox_trigger = 3 + if nvm.running then + return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1) else return 0 end @@ -209,7 +228,18 @@ techage.register_node({"techage:generator", "techage:generator_on"}, { end end, on_node_load = function(pos) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) State:on_node_load(pos) end, }) +minetest.register_craft({ + output = "techage:generator", + recipe = { + {"basic_materials:steel_bar", "dye:green", "default:wood"}, + {"", "basic_materials:gear_steel", "techage:electric_cableS"}, + {"default:wood", "techage:iron_ingot", "basic_materials:steel_bar"}, + }, +}) + + diff --git a/coal_power_station/power_terminal.lua b/coal_power_station/power_terminal.lua deleted file mode 100644 index a4df465..0000000 --- a/coal_power_station/power_terminal.lua +++ /dev/null @@ -1,180 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA3 Power Terminal - -]]-- - --- for lazy programmers -local S2P = minetest.string_to_pos -local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end -local M = minetest.get_meta -local N = function(pos) return minetest.get_node(pos).name end -local S = techage.S - -local CYCLE_TIME = 2 -local PWR_CAPA = 0.1 -local COUNTDOWN = 5 - -local Cable = techage.ElectricCable -local power = techage.power - -local function collect_network_data(pos, mem) - local data = { - fuel = {}, - wind = {}, - solar = {}, - akku = {}, - stor = {}, - elec = {}, - fcel = {}, - other = {}, - } - local add = function(tbl, mem, nomi, real) - tbl.num = (tbl.num or 0) + 1 - tbl.load = (tbl.load or 0) + (((mem.pwr_node_alive_cnt or 0) > 0) and 1 or 0) - tbl.nomi = (tbl.nomi or 0) + (nomi or 0) - tbl.real = (tbl.real or 0) + (((mem.pwr_node_alive_cnt or 0) > 0) and (real or 0) or 0) - end - - local nnodes = techage.power.limited_connection_walk(pos, - function(pos, node, mem, num_hops, num_nodes) - if node.name == "techage:generator" or node.name == "techage:generator_on" then - add(data.fuel, mem, mem.pwr_available, mem.provided) - elseif node.name == "techage:ta3_akku" then - add(data.akku, mem, mem.pwr_could_provide, mem.delivered) - elseif node.name == "techage:heatexchanger1" then - add(data.stor, mem, mem.pwr_could_provide, mem.delivered) - elseif node.name == "techage:tiny_generator" or node.name == "techage:tiny_generator_on" then - add(data.fuel, mem, mem.pwr_available, mem.provided) - elseif node.name == "techage:ta4_solar_inverter" then - add(data.solar, mem, mem.pwr_available, mem.delivered) - elseif node.name == "techage:ta4_wind_turbine" then - add(data.wind, mem, mem.pwr_available, mem.delivered) - elseif node.name == "techage:ta4_fuelcell" or node.name == "techage:ta4_fuelcell_on" then - add(data.fcel, mem, mem.pwr_available, mem.provided) - elseif node.name == "techage:ta4_electrolyzer" or node.name == "techage:ta4_electrolyzer_on" then - add(data.elec, mem, -(mem.pwr_could_need or 0), -(mem.consumed or 0)) - elseif mem.pwr_needed and mem.pwr_needed > 0 then - local nomi = -mem.pwr_needed - local real = (mem.pwr_node_alive_cnt or 0) > 0 and -mem.pwr_needed - add(data.other, mem, nomi, real) - end - end - ) - return data, nnodes -end - -local function formspec(pos, mem) - local data, nnodes = collect_network_data(pos, mem) - local get = function(kind) - return (data[kind].load or 0).." / "..(data[kind].num or 0).." : ".. - (data[kind].real or 0).." / "..(data[kind].nomi or 0).. " ku" - end - - local alarm = "" - if nnodes > (techage.MAX_NUM_NODES - 50) then - alarm = " (max. "..(techage.MAX_NUM_NODES).." !!!)" - end - local update = mem.countdown > 0 and mem.countdown or S("Update") - return "size[9.5,8.2]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "label[2,0.0;"..S("Network Data").."]".. - "label[1,0.7;"..S("(Num. nodes loaded / max. : Power current / max.)").."]".. - "label[0,1.4;"..S("TA3 Coal/oil")..":]".. "label[5,1.4;"..get("fuel").."]".. - "label[0,2.1;"..S("TA3 Akku")..":]".. "label[5,2.1;"..get("akku").."]".. - "label[0,2.8;"..S("TA4 Solar Inverter")..":]".. "label[5,2.8;"..get("solar").."]".. - "label[0,3.5;"..S("TA4 Wind Turbine")..":]".. "label[5,3.5;"..get("wind").."]".. - "label[0,4.2;"..S("TA4 Energy Storage")..":]".. "label[5,4.2;"..get("stor").."]".. - "label[0,4.9;"..S("TA4 Electrolyzer")..":]".. "label[5,4.9;"..get("elec").."]".. - "label[0,5.6;"..S("TA4 Fuel Cell")..":]".. "label[5,5.6;"..get("fcel").."]".. - "label[0,6.3;"..S("Other consumers")..":]".. "label[5,6.3;"..get("other").."]".. - "label[0,7;"..S("Number of nodes").." : "..nnodes..alarm.."]".. - "button[3.5,7.5;2,1;update;"..update.."]" -end - -local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - power.generator_alive(pos, mem) - - mem.countdown = mem.countdown or 0 - if mem.countdown > 0 then - mem.countdown = mem.countdown - 1 - M(pos):set_string("formspec", formspec(pos, mem)) - end - - return true -end - -minetest.register_node("techage:ta3_power_terminal", { - description = S("TA3 Power Terminal"), - inventory_image = "techage_power_terminal_front.png", - tiles = { - "techage_power_terminal_top.png", - "techage_power_terminal_top.png", - "techage_power_terminal_side.png", - "techage_power_terminal_side.png", - "techage_power_terminal_back.png", - "techage_power_terminal_front.png", - }, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -8/16, -8/16, 0/16, 8/16, 8/16, 8/16}, - }, - }, - - on_receive_fields = function(pos, formname, fields, player) - local mem = tubelib2.get_mem(pos) - mem.countdown = COUNTDOWN - end, - - on_rightclick = function(pos, node, clicker) - local mem = tubelib2.get_mem(pos) - minetest.get_node_timer(pos):start(CYCLE_TIME) - power.generator_start(pos, mem, PWR_CAPA) - mem.countdown = COUNTDOWN - end, - - on_timer = node_timer, - paramtype2 = "facedir", - paramtype = "light", - on_rotate = screwdriver.disallow, - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky = 1, level = 2}, - sounds = default.node_sound_metal_defaults(), -}) - -techage.power.register_node({"techage:ta3_power_terminal"}, { - power_network = Cable, - conn_sides = {"B"}, - after_place_node = function(pos) - local mem = tubelib2.init_mem(pos) - minetest.get_node_timer(pos):start(CYCLE_TIME) - power.generator_start(pos, mem, PWR_CAPA) - local meta = M(pos) - mem.countdown = 0 - meta:set_string("formspec", formspec(pos, mem)) - end, -}) - -minetest.register_craft({ - output = "techage:ta3_power_terminal", - recipe = { - {"", "techage:usmium_nuggets", "default:steel_ingot"}, - {"", "techage:basalt_glass_thin", "default:copper_ingot"}, - {"", "techage:vacuum_tube", "default:steel_ingot"}, - }, -}) - diff --git a/coal_power_station/turbine.lua b/coal_power_station/turbine.lua index c75212c..67f0c63 100644 --- a/coal_power_station/turbine.lua +++ b/coal_power_station/turbine.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -20,12 +20,12 @@ local Pipe = techage.SteamPipe local function transfer_cooler(pos, topic, payload) return techage.transfer(pos, 6, topic, payload, Pipe, - {"techage:cooler", "techage:cooler_on"}) + {"techage:cooler", "techage:cooler_on"}) end local function transfer_generator(pos, topic, payload) return techage.transfer(pos, "R", topic, payload, nil, - {"techage:generator", "techage:generator_on"}) + {"techage:generator", "techage:generator_on"}) end local function swap_node(pos, name) @@ -37,35 +37,41 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end - -local function node_timer(pos) - local mem = tubelib2.get_mem(pos) - if mem.running then - mem.handle = minetest.sound_play("techage_turbine", { - pos = pos, - gain = 1, - max_hear_distance = 15}) - end - return mem.running -end - local function play_sound(pos) - local mem = tubelib2.get_mem(pos) - if mem.running then - node_timer(pos) - minetest.get_node_timer(pos):start(2) + local mem = techage.get_mem(pos) + mem.handle = minetest.sound_play("techage_turbine", { + pos = pos, + gain = 1, + max_hear_distance = 15, + loop = true}) + if mem.handle == -1 then + minetest.after(1, play_sound, pos) end end local function stop_sound(pos) - local mem = tubelib2.get_mem(pos) - if mem.running and mem.handle then + local mem = techage.get_mem(pos) + if mem.handle then minetest.sound_stop(mem.handle) mem.handle = nil - minetest.get_node_timer(pos):stop(2) end end +local function after_place_node(pos) + Pipe:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + stop_sound(pos) + Pipe:after_dig_node(pos) + techage.del_mem(pos) +end + +local function tubelib2_on_update2(pos, outdir, tlib2, node) + swap_node(pos, "techage:turbine") + stop_sound(pos) +end + minetest.register_node("techage:turbine", { description = S("TA3 Turbine"), tiles = { @@ -77,6 +83,11 @@ minetest.register_node("techage:turbine", { "techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_turbine.png^techage_frame_ta3.png", }, + + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -112,7 +123,9 @@ minetest.register_node("techage:turbine_on", { }, }, }, - on_timer = node_timer, + + tubelib2_on_update2 = tubelib2_on_update2, + paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, diggable = false, @@ -121,49 +134,41 @@ minetest.register_node("techage:turbine_on", { sounds = default.node_sound_wood_defaults(), }) --- for mechanical pipe connections -techage.power.register_node({"techage:turbine", "techage:turbine_on"}, { - conn_sides = {"L", "U"}, - power_network = Pipe, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - local mem = tubelib2.get_mem(pos) - transfer_cooler(pos, "stop", nil) - swap_node(pos, "techage:turbine") - mem.running = false - stop_sound(pos) - end -}) +Pipe:add_secondary_node_names({"techage:turbine", "techage:turbine_on"}) --- for logical communication techage.register_node({"techage:turbine", "techage:turbine_on"}, { on_transfer = function(pos, in_dir, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "trigger" then - return transfer_generator(pos, topic, payload) - elseif topic == "start" then - if transfer_cooler(pos, topic, payload) then - swap_node(pos, "techage:turbine_on") - mem.running = true - play_sound(pos) - return true - end - return false - elseif topic == "running" then + local nvm = techage.get_nvm(pos) + if topic == "trigger" then -- used by boiler if not transfer_cooler(pos, topic, payload) then - swap_node(pos, "techage:turbine") - mem.running = false - stop_sound(pos) - return false + return 0 end + local power = transfer_generator(pos, topic, payload) + if not power or power <= 0 and nvm.running then + swap_node(pos, "techage:cylinder") + stop_sound(pos) + nvm.running = false + return 0 + end + return power + elseif topic == "start" then -- used by generator + swap_node(pos, "techage:turbine_on") + play_sound(pos) + nvm.running = true return true - elseif topic == "stop" then - transfer_cooler(pos, topic, payload) + elseif topic == "stop" then -- used by generator swap_node(pos, "techage:turbine") - mem.running = false stop_sound(pos) + nvm.running = false return true end - end + end, + on_node_load = function(pos, node) + --print("on_node_load", node.name) + if node.name == "techage:turbine_on" then + play_sound(pos) + end + end, }) minetest.register_craft({ @@ -175,12 +180,3 @@ minetest.register_craft({ }, }) -minetest.register_lbm({ - label = "[techage] Turbine sound", - name = "techage:power_station", - nodenames = {"techage:turbine_on"}, - run_at_every_load = true, - action = function(pos, node) - play_sound(pos) - end -}) diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index d4e35b4..7a46f6b 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -189,7 +189,7 @@ techage.manual_DE.aText = { "\n", "Erdöl kann nur mit Hilfe des Explorers gefunden und mit Hilfe entsprechender TA3 Maschinen gefördert werden. Siehe TA3.\n".. "\n", - "Bauxit wird nur im Untertagebau gewonnen. Bauxit findet man nur in Stein in einer Höhe zwischen -50 und -150 Meter.\n".. + "Bauxit wird nur im Untertagebau gewonnen. Bauxit findet man nur in Stein in einer Höhe zwischen -50 und -500 Meter.\n".. "Es wird zur Herstellung von Aluminium benötigt\\, was vor allem in TA4 Verwendung findet.\n".. "\n", " - 28.09.2019: Um Solaranlage erweitert\n".. diff --git a/energy_storage/heatexchanger.lua b/energy_storage/heatexchanger.lua index cbd3b45..5a87aa1 100644 --- a/energy_storage/heatexchanger.lua +++ b/energy_storage/heatexchanger.lua @@ -360,8 +360,10 @@ Pipe:add_secondary_node_names({"techage:heatexchanger1", "techage:heatexchanger3 techage.register_node({"techage:heatexchanger1"}, { on_recv_message = function(pos, src, topic, payload) local mem = tubelib2.get_mem(pos) - if topic == "capa" then + if topic == "load" then return techage.power.percent(mem.capa_max, mem.capa) + elseif topic == "size" then + return (mem.capa_max or 0) / GRVL_CAPA else return State:on_receive_message(pos, topic, payload) end diff --git a/fermenter/gasflare.lua b/fermenter/gasflare.lua index cb5b0bb..f914a9b 100644 --- a/fermenter/gasflare.lua +++ b/fermenter/gasflare.lua @@ -104,7 +104,7 @@ local function start_flarestack(pos, playername) max_hear_distance = 20, gain = 1, loop = true}) - print("handle", handle) + --print("handle", handle) meta:set_int("handle", handle) end @@ -140,7 +140,7 @@ minetest.register_node("techage:gasflare", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - print(dump(oldmetadata)) + --print(dump(oldmetadata)) stop_flarestack(pos, oldmetadata.fields.handle) local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) if node.name == "techage:gasflare2" then diff --git a/furnace/cooking.lua b/furnace/cooking.lua index 1235e29..3667c8a 100644 --- a/furnace/cooking.lua +++ b/furnace/cooking.lua @@ -17,7 +17,7 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S -local range = techage.range +local range = techage.in_range local Recipes = {} -- registered recipes {output = {recipe, ...},} local Ingredients = {} -- {{input = output}, diff --git a/furnace/furnace_top.lua b/furnace/furnace_top.lua index b7be461..65a6f21 100644 --- a/furnace/furnace_top.lua +++ b/furnace/furnace_top.lua @@ -30,7 +30,7 @@ local num_recipes = techage.furnace.get_num_recipes local reset_cooking = techage.furnace.reset_cooking local get_ingredients = techage.furnace.get_ingredients local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup -local range = techage.range +local range = techage.in_range local function update_recipe_menu(pos, mem) diff --git a/hydrogen/electrolyzer.lua b/hydrogen/electrolyzer.lua index 8c829ed..dd7cb68 100644 --- a/hydrogen/electrolyzer.lua +++ b/hydrogen/electrolyzer.lua @@ -8,7 +8,7 @@ GPL v3 See LICENSE.txt for more information - TA4 Electrolyzer + TA4 Electrolyzer v2 ]]-- @@ -18,27 +18,29 @@ local S = techage.S local Power = techage.ElectricCable local power = techage.power +local Pipe = techage.LiquidPipe +local liquid = techage.liquid local CYCLE_TIME = 2 local STANDBY_TICKS = 5 local PWR_NEEDED = 40 local PWR_UNITS_PER_HYDROGEN_ITEM = 320 +local CAPACITY = 400 local function formspec(self, pos, mem) + local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") return "size[8,6.6]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "image[0.5,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]".. - "label[0.7,1.9;"..S("\\[ku\\]").."]".. - "image[3,0;1,1;techage_form_arrow_fg.png^[transformR270]".. - "image_button[4,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[2.1,1;1.8,1;update;"..S("Update").."]".. - "list[context;dst;5.5,0;2,2;]".. + "image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]".. + "label[0.2,1.9;"..S("\\[ku\\]").."]".. + "image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]".. + "image_button[3.5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. + "tooltip[3.5,1;1,1;"..self:get_state_tooltip(mem).."]".. + "button[1.6,1;1.8,1;update;"..update.."]".. "list[current_player;main;0,2.8;8,4;]" .. - "listring[current_player;main]".. - "listring[context;dst]" .. - "listring[current_player;main]".. + liquid.formspec_liquid(5, 0, mem).. default.get_hotbar_bg(0, 2.8) end @@ -55,8 +57,8 @@ local function stop_node(pos, mem, state) end local State = techage.NodeStates:new({ - node_name_passive = "techage:ta4_electrolyzer", - node_name_active = "techage:ta4_electrolyzer_on", + node_name_passive = "techage:ta4_electrolyzer2", + node_name_active = "techage:ta4_electrolyzer2_on", cycle_time = CYCLE_TIME, standby_ticks = STANDBY_TICKS, formspec_func = formspec, @@ -65,47 +67,45 @@ local State = techage.NodeStates:new({ stop_node = stop_node, }) -local function add_hydrogen(pos) - local inv = M(pos):get_inventory() - local leftover = inv:add_item("dst", ItemStack("techage:hydrogen")) - return leftover:get_count() == 0 -end - -local function room_for_hydrogen(pos) - local inv = M(pos):get_inventory() - return inv:room_for_item("dst", ItemStack("techage:hydrogen")) -end - -- converts power into hydrogen local function node_timer(pos, elapsed) local mem = tubelib2.get_mem(pos) mem.num_pwr_units = mem.num_pwr_units or 0 - --print("electrolyzer", mem.running, mem.consumed, mem.num_pwr_units, techage.get_state_string(mem)) + mem.countdown = mem.countdown or 0 + mem.liquid = mem.liquid or {} + mem.liquid.amount = mem.liquid.amount or 0 + print("electrolyzer", mem.running, mem.consumed, mem.num_pwr_units, mem.liquid.amount) if mem.running then if techage.needs_power(mem) then mem.consumed = -power.secondary_alive(pos, mem, 0, 1) --print("mem.consumed", mem.consumed) if mem.consumed > 0 then - mem.num_pwr_units = mem.num_pwr_units + mem.consumed - if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then - if add_hydrogen(pos) then + if mem.liquid.amount < CAPACITY then + mem.num_pwr_units = mem.num_pwr_units + mem.consumed + if mem.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then + mem.liquid.amount = mem.liquid.amount + 1 + mem.liquid.name = "techage:hydrogen" mem.num_pwr_units = mem.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM State:keep_running(pos, mem, 1, 0) -- count items - else - State:blocked(pos, mem) - power.secondary_stop(pos, mem) end + else + State:blocked(pos, mem) + power.secondary_stop(pos, mem) end end else mem.consumed = -power.secondary_alive(pos, mem, 1, 1) - if room_for_hydrogen(pos) then + if mem.liquid.amount < CAPACITY then State:start(pos, mem) power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED) end end end - return mem.running + if mem.countdown > 0 then + mem.countdown = mem.countdown - 1 + M(pos):set_string("formspec", formspec(State, pos, mem)) + end + return mem.running or mem.countdown > 0 end local function on_receive_fields(pos, formname, fields, player) @@ -115,9 +115,9 @@ local function on_receive_fields(pos, formname, fields, player) local mem = tubelib2.get_mem(pos) State:state_button_event(pos, mem, fields) - if fields.update then - M(pos):set_string("formspec", formspec(State, pos, mem)) - end + mem.countdown = 10 + M(pos):set_string("formspec", formspec(State, pos, mem)) + minetest.get_node_timer(pos):start(CYCLE_TIME) end local function allow_metadata_inventory(pos, listname, index, stack, player) @@ -132,10 +132,12 @@ end local function on_rightclick(pos) local mem = tubelib2.get_mem(pos) + mem.countdown = 10 M(pos):set_string("formspec", formspec(State, pos, mem)) + minetest.get_node_timer(pos):start(CYCLE_TIME) end -minetest.register_node("techage:ta4_electrolyzer", { +minetest.register_node("techage:ta4_electrolyzer2", { description = S("TA4 Electrolyzer"), tiles = { -- up, down, right, left, back, front @@ -149,21 +151,46 @@ minetest.register_node("techage:ta4_electrolyzer", { on_construct = function(pos) local mem = tubelib2.init_mem(pos) - local number = techage.add_node(pos, "techage:ta4_electrolyzer") + local number = techage.add_node(pos, "techage:ta4_electrolyzer2") mem.running = false mem.num_pwr_units = 0 State:node_init(pos, mem, number) local meta = M(pos) meta:set_string("formspec", formspec(State, pos, mem)) local inv = meta:get_inventory() - inv:set_size('dst', 4) + inv:set_size('src', 1) + inv:set_size('dst', 1) end, + tubelib2_on_update2 = function(pos, outdir, tlib2, node) + liquid.update_network(pos, outdir) + end, + can_dig = function(pos, player) local inv = M(pos):get_inventory() return inv:is_empty("dst") end, + liquid = { + capa = CAPACITY, + peek = liquid.srv_peek, + put = function(pos, indir, name, amount) + local leftover = liquid.srv_put(pos, indir, name, amount) + local inv = M(pos):get_inventory() + if not inv:is_empty("src") and inv:is_empty("dst") then + liquid.fill_container(pos, inv) + end + return leftover + end, + take = liquid.srv_take, + }, + networks = { + pipe = { + sides = {R = 1}, -- Pipe connection sides + ntype = "tank", + }, + }, + allow_metadata_inventory_put = allow_metadata_inventory, allow_metadata_inventory_take = allow_metadata_inventory, on_receive_fields = on_receive_fields, @@ -176,7 +203,7 @@ minetest.register_node("techage:ta4_electrolyzer", { is_ground_content = false, }) -minetest.register_node("techage:ta4_electrolyzer_on", { +minetest.register_node("techage:ta4_electrolyzer2_on", { description = S("TA4 Electrolyzer"), tiles = { -- up, down, right, left, back, front @@ -206,6 +233,30 @@ minetest.register_node("techage:ta4_electrolyzer_on", { }, }, + tubelib2_on_update2 = function(pos, outdir, tlib2, node) + liquid.update_network(pos, outdir) + end, + + liquid = { + capa = CAPACITY, + peek = liquid.srv_peek, + put = function(pos, indir, name, amount) + local leftover = liquid.srv_put(pos, indir, name, amount) + local inv = M(pos):get_inventory() + if not inv:is_empty("src") and inv:is_empty("dst") then + liquid.fill_container(pos, inv) + end + return leftover + end, + take = liquid.srv_take, + }, + networks = { + pipe = { + sides = {R = 1}, -- Pipe connection sides + ntype = "tank", + }, + }, + allow_metadata_inventory_put = allow_metadata_inventory, allow_metadata_inventory_take = allow_metadata_inventory, on_receive_fields = on_receive_fields, @@ -221,46 +272,29 @@ minetest.register_node("techage:ta4_electrolyzer_on", { light_source = 6, }) -techage.power.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, { +-- Register for power +techage.power.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, { conn_sides = {"L"}, power_network = Power, after_place_node = function(pos) local node = minetest.get_node(pos) local indir = techage.side_to_indir("R", node.param2) M(pos):set_int("in_dir", indir) + Pipe:after_place_node(pos) end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Pipe:after_dig_node(pos) + end, }) -techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, { - on_pull_item = function(pos, in_dir, num) - local meta = minetest.get_meta(pos) - if meta:get_int("in_dir") == in_dir then - local inv = M(pos):get_inventory() - return techage.get_items(inv, "dst", num) - end - end, - on_push_item = function(pos, in_dir, stack) - local meta = minetest.get_meta(pos) - if meta:get_int("in_dir") == in_dir then - local inv = M(pos):get_inventory() - State:start_if_standby(pos) - return techage.put_items(inv, "dst", stack) - end - end, - on_unpull_item = function(pos, in_dir, stack) - local meta = minetest.get_meta(pos) - if meta:get_int("in_dir") == in_dir then - local inv = M(pos):get_inventory() - return techage.put_items(inv, "dst", stack) - end - end, - on_recv_message = function(pos, src, topic, payload) - return State:on_receive_message(pos, topic, payload) - end, -}) +-- Register for tubes +techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.tubing) + +-- Register for pipes +Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}) minetest.register_craft({ - output = "techage:ta4_electrolyzer", + output = "techage:ta4_electrolyzer2", recipe = { {'default:steel_ingot', 'dye:blue', 'default:steel_ingot'}, {'techage:electric_cableS', 'default:glass', 'techage:tubeS'}, diff --git a/hydrogen/hydrogen.lua b/hydrogen/hydrogen.lua deleted file mode 100644 index 2b7a456..0000000 --- a/hydrogen/hydrogen.lua +++ /dev/null @@ -1,34 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA4 Hydrogen - -]]-- - -local S = techage.S - -minetest.register_craftitem("techage:hydrogen", { - description = S("TA4 Hydrogen"), - inventory_image = "techage_hydrogen_inv.png", -}) - -minetest.register_craftitem("techage:ta4_fuelcellstack", { - description = S("TA4 Fuel Cell Stack"), - inventory_image = "techage_fc_stack_inv.png", -}) - -minetest.register_craft({ - output = "techage:ta4_fuelcellstack", - recipe = { - {'techage:baborium_ingot', 'techage:ta4_carbon_fiber', 'default:copper_ingot'}, - {'default:gold_ingot', 'techage:ta4_carbon_fiber', 'default:tin_ingot'}, - {"techage:baborium_ingot", 'techage:ta4_carbon_fiber', 'default:copper_ingot'}, - }, -}) diff --git a/init.lua b/init.lua index 5abd3f3..1ce5ffc 100644 --- a/init.lua +++ b/init.lua @@ -11,45 +11,31 @@ else techage = { NodeDef = {}, -- node registration info } - techage.max_num_forceload_blocks = tonumber(minetest.setting_get("techage_max_num_forceload_blocks")) or 24 - techage.basalt_stone_enabled = minetest.setting_get("techage_basalt_stone_enabled") == "true" - techage.ore_rarity = tonumber(minetest.setting_get("techage_ore_rarity")) or 1 - techage.modified_recipes_enabled = minetest.setting_get("techage_modified_recipes_enabled") == "true" + techage.max_num_forceload_blocks = tonumber(minetest.settings:get("techage_max_num_forceload_blocks")) or 24 + + techage.basalt_stone_enabled = minetest.settings:get_bool("techage_basalt_stone_enabled") ~= false + techage.ore_rarity = tonumber(minetest.settings:get("techage_ore_rarity")) or 1 + techage.modified_recipes_enabled = minetest.settings:get_bool("techage_modified_recipes_enabled") ~= false -- Load support for I18n. techage.S = minetest.get_translator("techage") - -- Debugging via "techage.Debug.dbg(text)" - techage.Debug = { - dbg = function(text, ...) - local t = string.format("%.4f: ", minetest.get_us_time() / 1000000.0) - if type(text) ~= "string" then - text = dump(text) - end - print(t..text, unpack({...})) - end, - --con = true, -- consumer modell - --pwr = true, -- power distribution - --sts = true, -- status plots - --dbg2 = true, - --tst = true, - --bot = true -- Signs Bot - --slr = true, - } - -- Basis features local MP = minetest.get_modpath("techage") dofile(MP.."/basis/lib.lua") -- helper functions dofile(MP.."/basis/gravel_lib.lua") -- ore probability dofile(MP.."/basis/node_states.lua") -- state model - dofile(MP.."/basis/tubes.lua") -- tubelib replacement - dofile(MP.."/basis/command.lua") -- tubelib replacement + dofile(MP.."/basis/tubes.lua") -- tubes for item transport + dofile(MP.."/basis/command.lua") -- command API dofile(MP.."/basis/firebox_lib.lua") -- common firebox functions + dofile(MP.."/basis/boiler_lib.lua") -- common boiler functions dofile(MP.."/basis/mark.lua") dofile(MP.."/basis/mark2.lua") dofile(MP.."/basis/assemble.lua") dofile(MP.."/basis/networks.lua") dofile(MP.."/basis/recipe_lib.lua") + dofile(MP.."/basis/formspec_update.lua") + dofile(MP.."/basis/storage.lua") -- Main doc dofile(MP.."/doc/manual_DE.lua") @@ -59,20 +45,30 @@ else dofile(MP.."/doc/guide.lua") -- construction guides -- Power networks - dofile(MP.."/power/schedule.lua") - --dofile(MP.."/power/distribute.lua") - --dofile(MP.."/power/test.lua") - dofile(MP.."/power/power.lua") - dofile(MP.."/power/power2.lua") + dofile(MP.."/power/node_api.lua") dofile(MP.."/power/junction.lua") + dofile(MP.."/power/distribution.lua") + dofile(MP.."/power/schedule.lua") + dofile(MP.."/power/formspecs.lua") dofile(MP.."/power/drive_axle.lua") + dofile(MP.."/power/gearbox.lua") dofile(MP.."/power/steam_pipe.lua") dofile(MP.."/power/electric_cable.lua") - dofile(MP.."/power/power_line.lua") dofile(MP.."/power/junctionbox.lua") - dofile(MP.."/power/powerswitch.lua") + dofile(MP.."/power/power_terminal.lua") + dofile(MP.."/power/powerswitchbox.lua") dofile(MP.."/power/protection.lua") - dofile(MP.."/power/ta4_cable.lua") + dofile(MP.."/power/power_line.lua") + + + + --dofile(MP.."/power/test.lua") + --dofile(MP.."/power/power.lua") + --dofile(MP.."/power/power2.lua") + --dofile(MP.."/power/junction.lua") + --dofile(MP.."/power/junctionbox.lua") + --dofile(MP.."/power/powerswitch.lua") + --dofile(MP.."/power/ta4_cable.lua") -- Iron Age dofile(MP.."/iron_age/main.lua") @@ -96,10 +92,9 @@ else dofile(MP.."/steam_engine/boiler.lua") dofile(MP.."/steam_engine/cylinder.lua") dofile(MP.."/steam_engine/flywheel.lua") - dofile(MP.."/steam_engine/gearbox.lua") -- Basic Machines - dofile(MP.."/basis/consumer.lua") -- consumer base model + dofile(MP.."/basic_machines/consumer.lua") -- consumer base model dofile(MP.."/basic_machines/source.lua") dofile(MP.."/basic_machines/pusher.lua") dofile(MP.."/basic_machines/legacy_nodes.lua") @@ -113,13 +108,14 @@ else dofile(MP.."/basic_machines/funnel.lua") dofile(MP.."/basic_machines/liquidsampler.lua") - -- Liquids - dofile(MP.."/liquids/liquid_pipe.lua") - dofile(MP.."/liquids/liquid.lua") - dofile(MP.."/liquids/tank.lua") - dofile(MP.."/liquids/silo.lua") - dofile(MP.."/liquids/pump.lua") - dofile(MP.."/liquids/fuel_lib.lua") +-- -- Liquids +-- dofile(MP.."/liquids/liquid_pipe.lua") +-- dofile(MP.."/liquids/liquid.lua") +-- dofile(MP.."/liquids/liquid_lib.lua") +-- dofile(MP.."/liquids/tank.lua") +-- dofile(MP.."/liquids/silo.lua") +-- dofile(MP.."/liquids/pump.lua") +-- dofile(MP.."/liquids/fuel_lib.lua") -- Coal power station dofile(MP.."/coal_power_station/firebox.lua") @@ -128,16 +124,14 @@ else dofile(MP.."/coal_power_station/generator.lua") dofile(MP.."/coal_power_station/turbine.lua") dofile(MP.."/coal_power_station/cooler.lua") - dofile(MP.."/coal_power_station/akkubox.lua") - dofile(MP.."/coal_power_station/power_terminal.lua") - -- Industrial Furnace - dofile(MP.."/furnace/firebox.lua") - dofile(MP.."/furnace/cooking.lua") - dofile(MP.."/furnace/furnace_top.lua") - dofile(MP.."/furnace/booster.lua") - dofile(MP.."/furnace/heater.lua") - dofile(MP.."/furnace/recipes.lua") +-- -- Industrial Furnace +-- dofile(MP.."/furnace/firebox.lua") +-- dofile(MP.."/furnace/cooking.lua") +-- dofile(MP.."/furnace/furnace_top.lua") +-- dofile(MP.."/furnace/booster.lua") +-- dofile(MP.."/furnace/heater.lua") +-- dofile(MP.."/furnace/recipes.lua") -- Tools dofile(MP.."/tools/trowel.lua") @@ -145,24 +139,27 @@ else dofile(MP.."/basic_machines/blackhole.lua") dofile(MP.."/basic_machines/forceload.lua") - -- Lamps - dofile(MP.."/lamps/lib.lua") - dofile(MP.."/lamps/simplelamp.lua") - dofile(MP.."/lamps/streetlamp.lua") - dofile(MP.."/lamps/ceilinglamp.lua") - dofile(MP.."/lamps/industriallamp1.lua") - dofile(MP.."/lamps/industriallamp2.lua") - dofile(MP.."/lamps/industriallamp3.lua") +-- -- Lamps +-- dofile(MP.."/lamps/lib.lua") +-- dofile(MP.."/lamps/simplelamp.lua") +-- dofile(MP.."/lamps/streetlamp.lua") +-- dofile(MP.."/lamps/ceilinglamp.lua") +-- dofile(MP.."/lamps/industriallamp1.lua") +-- dofile(MP.."/lamps/industriallamp2.lua") +-- dofile(MP.."/lamps/industriallamp3.lua") - -- Oil - dofile(MP.."/oil/explore.lua") - dofile(MP.."/oil/tower.lua") - dofile(MP.."/oil/drillbox.lua") - dofile(MP.."/oil/pumpjack.lua") - dofile(MP.."/oil/generator.lua") - dofile(MP.."/oil/distiller.lua") - dofile(MP.."/oil/reboiler.lua") - dofile(MP.."/oil/gasflare.lua") +-- -- Oil +-- dofile(MP.."/oil/explore.lua") +-- dofile(MP.."/oil/tower.lua") +-- dofile(MP.."/oil/drillbox.lua") +-- dofile(MP.."/oil/pumpjack.lua") +-- dofile(MP.."/oil/distiller.lua") +-- dofile(MP.."/oil/reboiler.lua") +-- dofile(MP.."/oil/gasflare.lua") + +-- TA3 power based + --dofile(MP.."/ta3_power/tiny_generator.lua") + --dofile(MP.."/ta3_power/akkubox.lua") -- Logic dofile(MP.."/logic/lib.lua") @@ -183,54 +180,71 @@ else -- Test dofile(MP.."/recipe_checker.lua") - --dofile(MP.."/.test/sink.lua") - dofile(MP.."/.test/source.lua") - --dofile(MP.."/.test/akku.lua") - --dofile(MP.."/.test/switch.lua") + dofile(MP.."/.test/sink.lua") + --dofile(MP.."/.test/source.lua") + --dofile(MP.."/.test/accu.lua") -- Solar - dofile(MP.."/solar/minicell.lua") - dofile(MP.."/solar/solarcell.lua") - dofile(MP.."/solar/inverter.lua") +-- dofile(MP.."/solar/minicell.lua") +-- dofile(MP.."/solar/solarcell.lua") +-- dofile(MP.."/solar/inverter.lua") - -- Wind - dofile(MP.."/wind_turbine/rotor.lua") - dofile(MP.."/wind_turbine/pillar.lua") - dofile(MP.."/wind_turbine/signallamp.lua") +-- -- Wind +-- dofile(MP.."/wind_turbine/rotor.lua") +-- dofile(MP.."/wind_turbine/pillar.lua") +-- dofile(MP.."/wind_turbine/signallamp.lua") - -- TA4 Energy Storage - dofile(MP.."/energy_storage/heatexchanger.lua") - dofile(MP.."/energy_storage/generator.lua") - dofile(MP.."/energy_storage/turbine.lua") - dofile(MP.."/energy_storage/inlet.lua") - dofile(MP.."/energy_storage/nodes.lua") +-- -- TA4 Energy Storage +-- dofile(MP.."/energy_storage/heatexchanger.lua") +-- dofile(MP.."/energy_storage/generator.lua") +-- dofile(MP.."/energy_storage/turbine.lua") +-- dofile(MP.."/energy_storage/inlet.lua") +-- dofile(MP.."/energy_storage/nodes.lua") - -- Chemistry - dofile(MP.."/chemistry/ta4_reactor.lua") - dofile(MP.."/chemistry/ta4_stand.lua") - dofile(MP.."/chemistry/ta4_doser.lua") +-- -- Chemistry +-- dofile(MP.."/chemistry/ta4_reactor.lua") +-- dofile(MP.."/chemistry/ta4_stand.lua") +-- dofile(MP.."/chemistry/ta4_doser.lua") - -- Hydrogen - dofile(MP.."/hydrogen/hydrogen.lua") - dofile(MP.."/hydrogen/electrolyzer.lua") - dofile(MP.."/hydrogen/fuelcell.lua") +-- -- Hydrogen +-- dofile(MP.."/hydrogen/fuelcellstack.lua") +-- dofile(MP.."/hydrogen/electrolyzer.lua") +-- dofile(MP.."/hydrogen/fuelcell.lua") +-- dofile(MP.."/hydrogen/legacy.lua") -- Items - dofile(MP.."/items/barrel.lua") +-- dofile(MP.."/items/barrel.lua") dofile(MP.."/items/baborium.lua") dofile(MP.."/items/usmium.lua") - dofile(MP.."/items/lye.lua") - dofile(MP.."/items/oil.lua") - dofile(MP.."/items/petroleum.lua") - dofile(MP.."/items/bauxit.lua") - dofile(MP.."/items/silicon.lua") - dofile(MP.."/items/steelmat.lua") - dofile(MP.."/items/powder.lua") - dofile(MP.."/items/epoxy.lua") - dofile(MP.."/items/aluminium.lua") - dofile(MP.."/items/plastic.lua") +-- dofile(MP.."/items/lye.lua") +-- dofile(MP.."/items/oil.lua") +-- dofile(MP.."/items/petroleum.lua") +-- dofile(MP.."/items/bauxit.lua") +-- dofile(MP.."/items/silicon.lua") +-- dofile(MP.."/items/steelmat.lua") +-- dofile(MP.."/items/powder.lua") +-- dofile(MP.."/items/epoxy.lua") +-- dofile(MP.."/items/aluminium.lua") +-- dofile(MP.."/items/plastic.lua") +-- dofile(MP.."/items/hydrogen.lua") - if techage.basalt_stone_enabled then - dofile(MP.."/items/basalt.lua") - end -end \ No newline at end of file +-- if techage.basalt_stone_enabled then +-- dofile(MP.."/items/basalt.lua") +-- end + +-- dofile(MP.."/power3/electric_cable.lua") +-- dofile(MP.."/power3/node_api.lua") +-- dofile(MP.."/power3/distribution.lua") +-- dofile(MP.."/power3/schedule.lua") +-- dofile(MP.."/power3/hud_debug.lua") +-- dofile(MP.."/power3/junctionbox.lua") +-- dofile(MP.."/power3/ele3_sink.lua") +-- dofile(MP.."/power3/ele3_source.lua") +-- dofile(MP.."/power3/accu.lua") +-- dofile(MP.."/power3/power_terminal.lua") +-- dofile(MP.."/power3/powerswitchbox.lua") +-- dofile(MP.."/power3/drive_axle.lua") +-- dofile(MP.."/power3/gearbox.lua") +-- dofile(MP.."/power3/axle_sink.lua") +-- dofile(MP.."/power3/axle_source.lua") +end diff --git a/iron_age/coalburner.lua b/iron_age/coalburner.lua index f7fbd45..dc294b1 100644 --- a/iron_age/coalburner.lua +++ b/iron_age/coalburner.lua @@ -234,11 +234,15 @@ function techage.keep_running_burner(pos) else minetest.swap_node(pos, {name="techage:ash"}) remove_coal(pos, height) + local handle = meta:get_int("handle") + minetest.sound_stop(handle) return false end else minetest.swap_node(pos, {name="techage:ash"}) remove_coal(pos, height) + local handle = meta:get_int("handle") + minetest.sound_stop(handle) return false end else diff --git a/iron_age/lighter.lua b/iron_age/lighter.lua index 4af4c9f..27b4f7d 100644 --- a/iron_age/lighter.lua +++ b/iron_age/lighter.lua @@ -32,7 +32,7 @@ minetest.register_node("techage:lighter_burn", { drop = "", light_source = 10, is_ground_content = false, - groups = {crumbly = 1, not_in_creative_inventory=1}, + groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, not_in_creative_inventory=1}, sounds = default.node_sound_dirt_defaults(), }) @@ -56,7 +56,7 @@ minetest.register_node("techage:coal_lighter_burn", { drop = "", light_source = 10, is_ground_content = false, - groups = {crumbly = 1, not_in_creative_inventory=1}, + groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, not_in_creative_inventory=1}, sounds = default.node_sound_dirt_defaults(), }) @@ -75,7 +75,7 @@ minetest.register_node("techage:lighter", { meta:set_string("playername", placer:get_player_name()) end, is_ground_content = false, - groups = {crumbly = 1, flammable = 2}, + groups = {crumbly = 3, snappy = 3, oddly_breakable_by_hand = 1, flammable = 2}, sounds = default.node_sound_dirt_defaults(), }) diff --git a/items/baborium.lua b/items/baborium.lua index a541052..e29dec2 100644 --- a/items/baborium.lua +++ b/items/baborium.lua @@ -40,7 +40,7 @@ minetest.register_ore({ clust_num_ores = 5, clust_size = 3, y_min = -340, - y_max = -260, + y_max = -250, }) minetest.register_craft({ diff --git a/items/barrel.lua b/items/barrel.lua index 053dd7b..ec95a35 100644 --- a/items/barrel.lua +++ b/items/barrel.lua @@ -56,6 +56,16 @@ minetest.register_craftitem("techage:ta3_canister_empty", { inventory_image = "techage_canister_filling.png^[colorize:#BFBFBF:180^techage_canister_frame.png", }) +minetest.register_craftitem("techage:ta3_cylinder_small", { + description = S("Gas Cylinder Small"), + inventory_image = "techage_gas_cylinder_small.png^[colorize:#4D7481:100", +}) + +minetest.register_craftitem("techage:ta3_cylinder_large", { + description = S("Gas Cylinder Large"), + inventory_image = "techage_gas_cylinder_large.png^[colorize:#4D7481:100", +}) + minetest.register_craft({ output = 'techage:ta3_barrel_empty 6', @@ -75,6 +85,26 @@ minetest.register_craft({ } }) +minetest.register_craft({ + output = 'techage:ta3_cylinder_small 8', + recipe = { + {'', 'techage:iron_ingot', ''}, + {'techage:iron_ingot', '', 'techage:iron_ingot'}, + {'techage:iron_ingot', 'techage:iron_ingot', 'techage:iron_ingot'}, + } +}) + +minetest.register_craft({ + output = 'techage:ta3_cylinder_large', + recipe = { + {'', 'techage:ta3_cylinder_small', ''}, + {'', 'techage:ta3_cylinder_small', ''}, + {'', 'techage:ta3_cylinder_small', ''}, + } +}) + + + techage.register_liquid("bucket:bucket_water", "bucket:bucket_empty", 1, "techage:water") techage.register_liquid("bucket:bucket_river_water", "bucket:bucket_empty", 1, "techage:river_water") diff --git a/items/basalt.lua b/items/basalt.lua index cd3045e..1f11b8c 100644 --- a/items/basalt.lua +++ b/items/basalt.lua @@ -33,6 +33,17 @@ minetest.register_node("techage:basalt_stone", { sounds = default.node_sound_stone_defaults(), }) +stairs.register_stair_and_slab( + "basalt_stone", + "techage:basalt_stone", + {cracky = 3, stone = 1}, + {"default_stone.png^[brighten"}, + "Basalt Stone Stair", + "Basalt Stone Slab", + default.node_sound_stone_defaults(), + false +) + minetest.register_node("techage:basalt_cobble", { description = S("Basalt Cobble"), tiles = {"default_cobble.png^[brighten"}, @@ -40,6 +51,17 @@ minetest.register_node("techage:basalt_cobble", { sounds = default.node_sound_stone_defaults(), }) +stairs.register_stair_and_slab( + "basalt_cobble", + "techage:basalt_cobble", + {cracky = 3, stone = 2}, + {"default_cobble.png^[brighten"}, + "Basalt Cobble Stair", + "Basalt Cobble Slab", + default.node_sound_stone_defaults(), + false +) + minetest.register_node("techage:basalt_stone_brick", { description = S("Basalt Stone Brick"), paramtype2 = "facedir", @@ -50,6 +72,17 @@ minetest.register_node("techage:basalt_stone_brick", { sounds = default.node_sound_stone_defaults(), }) +stairs.register_stair_and_slab( + "basalt_stone_brick", + "techage:basalt_stone_brick", + {cracky = 2, stone = 1}, + {"default_stone_brick.png^[brighten"}, + "Basalt Brick Stair", + "Basalt Brick Slab", + default.node_sound_stone_defaults(), + false +) + minetest.register_node("techage:basalt_stone_block", { description = S("Basalt Stone Block"), tiles = {"default_stone_block.png^[brighten"}, @@ -58,6 +91,17 @@ minetest.register_node("techage:basalt_stone_block", { sounds = default.node_sound_stone_defaults(), }) +stairs.register_stair_and_slab( + "basalt_stone_block", + "techage:basalt_stone_block", + {cracky = 2, stone = 1}, + {"default_stone_block.png^[brighten"}, + "Basalt Stone Block Stair", + "Basalt Stone Block Slab", + default.node_sound_stone_defaults(), + false +) + minetest.register_node("techage:basalt_gravel", { description = S("Basalt Gravel"), tiles = {"default_gravel.png^[brighten"}, @@ -65,6 +109,17 @@ minetest.register_node("techage:basalt_gravel", { sounds = default.node_sound_gravel_defaults(), }) +stairs.register_stair_and_slab( + "sieved_basalt_gravel", + "techage:sieved_basalt_gravel", + {crumbly = 2, falling_node = 1}, + {"default_gravel.png^[brighten"}, + "Basalt Gravel Stair", + "Basalt Gravel Slab", + default.node_sound_gravel_defaults(), + false +) + minetest.register_node("techage:sieved_basalt_gravel", { description = S("Sieved Basalt Gravel"), tiles = {"default_gravel.png^[brighten"}, @@ -85,6 +140,17 @@ minetest.register_node("techage:basalt_glass", { sounds = default.node_sound_glass_defaults(), }) +stairs.register_stair_and_slab( + "basalt_glass", + "techage:basalt_glass", + {cracky = 3, oddly_breakable_by_hand = 3}, + {"techage_basalt_glass.png"}, + "Basalt Glass Stair", + "Basalt Glass Slab", + default.node_sound_glass_defaults(), + false +) + minetest.register_node("techage:basalt_glass2", { description = S("Basalt Glass 2"), drawtype = "glasslike_framed_optional", @@ -98,6 +164,17 @@ minetest.register_node("techage:basalt_glass2", { sounds = default.node_sound_glass_defaults(), }) +stairs.register_stair_and_slab( + "basalt_glass2", + "techage:basalt_glass2", + {cracky = 3, oddly_breakable_by_hand = 3}, + {"techage_basalt_glass2.png"}, + "Basalt Glass 2 Stair", + "Basalt Glass 2 Slab", + default.node_sound_glass_defaults(), + false +) + minetest.register_node("techage:basalt_glass_thin", { description = S("Basalt Glass Thin"), drawtype = "nodebox", @@ -174,50 +251,6 @@ minetest.register_node("techage:basalt_glass_thin_xl2", { sounds = default.node_sound_glass_defaults(), }) -stairs.register_stair_and_slab( - "basalt_stone", - "techage:basalt_stone", - {cracky = 3, stone = 1}, - {"default_stone.png^[brighten"}, - "Basalt Stone Stair", - "Basalt Stone Slab", - default.node_sound_stone_defaults(), - false -) - -stairs.register_stair_and_slab( - "basalt_stone_brick", - "techage:basalt_stone_brick", - {cracky = 2, stone = 1}, - {"default_stone_brick.png^[brighten"}, - "Basalt Brick Stair", - "Basalt Brick Slab", - default.node_sound_stone_defaults(), - false -) - -stairs.register_stair_and_slab( - "basalt_stone_block", - "techage:basalt_stone_block", - {cracky = 2, stone = 1}, - {"default_stone_block.png^[brighten"}, - "Basalt Block Stair", - "Basalt Block Slab", - default.node_sound_stone_defaults(), - false -) - -stairs.register_stair_and_slab( - "sieved_basalt_gravel", - "techage:sieved_basalt_gravel", - {crumbly = 2, falling_node = 1}, - {"default_gravel.png^[brighten"}, - "Basalt Gravel Stair", - "Basalt Gravel Slab", - default.node_sound_gravel_defaults(), - false -) - minetest.register_craft({ output = "techage:basalt_stone_brick 4", recipe = { diff --git a/items/petroleum.lua b/items/petroleum.lua index 6202313..e2b04fd 100644 --- a/items/petroleum.lua +++ b/items/petroleum.lua @@ -38,9 +38,19 @@ minetest.register_craftitem("techage:gasoline", { minetest.register_craftitem("techage:gas", { description = S("TA3 Gas"), inventory_image = "techage_gas_inv.png", - groups = {not_in_creative_inventory=1}, }) +minetest.register_craftitem("techage:ta3_cylinder_small_gas", { + description = S("Gas Cylinder Small"), + inventory_image = "techage_gas_cylinder_small.png^[colorize:#e51818:120", + stack_max = 1, +}) + +minetest.register_craftitem("techage:ta3_cylinder_large_gas", { + description = S("Gas Cylinder Large"), + inventory_image = "techage_gas_cylinder_large.png^[colorize:#e51818:120", + stack_max = 1, +}) minetest.register_craftitem("techage:ta3_barrel_bitumen", { description = S("TA3 Bitumen Barrel"), @@ -122,10 +132,12 @@ techage.register_liquid("techage:ta3_barrel_bitumen", "techage:ta3_barrel_empty" techage.register_liquid("techage:ta3_barrel_fueloil", "techage:ta3_barrel_empty", 10, "techage:fueloil") techage.register_liquid("techage:ta3_barrel_naphtha", "techage:ta3_barrel_empty", 10, "techage:naphtha") techage.register_liquid("techage:ta3_barrel_gasoline", "techage:ta3_barrel_empty", 10, "techage:gasoline") +techage.register_liquid("techage:ta3_cylinder_large_gas", "techage:ta3_cylinder_large", 6, "techage:gas") techage.register_liquid("techage:ta3_canister_oil", "techage:ta3_canister_empty", 1, "techage:oil_source") techage.register_liquid("techage:ta3_canister_bitumen", "techage:ta3_canister_empty", 1, "techage:bitumen") techage.register_liquid("techage:ta3_canister_fueloil", "techage:ta3_canister_empty", 1, "techage:fueloil") techage.register_liquid("techage:ta3_canister_naphtha", "techage:ta3_canister_empty", 1, "techage:naphtha") techage.register_liquid("techage:ta3_canister_gasoline", "techage:ta3_canister_empty", 1, "techage:gasoline") +techage.register_liquid("techage:ta3_cylinder_small_gas", "techage:ta3_cylinder_small", 1, "techage:gas") diff --git a/liquids/liquid.lua b/liquids/liquid.lua index 9669c88..fcec176 100644 --- a/liquids/liquid.lua +++ b/liquids/liquid.lua @@ -89,10 +89,10 @@ end local function get_network_table(pos, outdir, ntype) local netID = get_netID(pos, outdir) if netID then - local netw = networks.get_network(netID, Pipe) + local netw = networks.get_network("pipe", netID) if not netw then netw = networks.collect_network_nodes(pos, outdir, Pipe) - networks.set_network(netID, Pipe, netw) + networks.set_network("pipe", netID, netw) end local s = minetest.pos_to_string(minetest.get_position_from_hash(netID)) --print("netw", string.format("%012X", netID), s, dump(netw)) diff --git a/liquids/tank.lua b/liquids/tank.lua index b079cd0..01b39ff 100644 --- a/liquids/tank.lua +++ b/liquids/tank.lua @@ -16,93 +16,22 @@ local S2P = minetest.string_to_pos local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end local Pipe = techage.LiquidPipe local liquid = techage.liquid local CAPACITY = 500 - -local function formspec_tank(x, y, mem) - local itemname = "techage:liquid" - if mem.liquid and mem.liquid.amount and mem.liquid.amount > 0 and mem.liquid.name then - itemname = mem.liquid.name.." "..mem.liquid.amount - end - return "container["..x..","..y.."]".. - "background[0,0;3,2.05;techage_form_grey.png]".. - "image[0,0;1,1;techage_form_input_arrow.png]".. - techage.item_image(1, 0, itemname).. - "image[2,0;1,1;techage_form_output_arrow.png]".. - "image[1,1;1,1;techage_form_arrow.png]".. - "list[context;src;0,1;1,1;]".. - "list[context;dst;2,1;1,1;]".. - --"listring[]".. - "container_end[]" -end - -local function formspec(mem) +local function formspec(pos, mem) local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update") return "size[8,6]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - formspec_tank(2, 0, mem).. + liquid.formspec_liquid(2, 0, mem).. "button[5.5,0.5;2,1;update;"..update.."]".. "list[current_player;main;0,2.3;8,4;]" end -local function fill_container(pos, inv) - local mem = tubelib2.get_mem(pos) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - local empty_container = inv:get_stack("src", 1):get_name() - local full_container = liquid.get_full_container(empty_container, mem.liquid.name) - if empty_container and full_container then - local ldef = liquid.get_liquid_def(full_container) - if ldef and mem.liquid.amount - ldef.size >= 0 then - if inv:room_for_item("dst", ItemStack(full_container)) then - inv:remove_item("src", ItemStack(empty_container)) - inv:add_item("dst", ItemStack(full_container)) - mem.liquid.amount = mem.liquid.amount - ldef.size - if mem.liquid.amount == 0 then - mem.liquid.name = nil - end - end - end - end -end - -local function empty_container(pos, inv) - local mem = tubelib2.get_mem(pos) - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - local stack = inv:get_stack("src", 1) - local ldef = liquid.get_liquid_def(stack:get_name()) - if ldef and (not mem.liquid.name or ldef.inv_item == mem.liquid.name) then - local capa = LQD(pos).capa - local amount = stack:get_count() * ldef.size - if mem.liquid.amount + amount <= capa then - if inv:room_for_item("dst", ItemStack(ldef.container)) then - inv:remove_item("src", stack) - inv:add_item("dst", ItemStack(ldef.container)) - mem.liquid.amount = mem.liquid.amount + amount - mem.liquid.name = ldef.inv_item - end - end - end -end - -local function move_item(pos, stack) - local mem = tubelib2.get_mem(pos) - local inv = M(pos):get_inventory() - if liquid.is_container_empty(stack:get_name()) then - fill_container(pos, inv) - else - empty_container(pos, inv) - end - M(pos):set_string("formspec", formspec(mem)) -end - local function allow_metadata_inventory_put(pos, listname, index, stack, player) if minetest.is_protected(pos, player:get_player_name()) then return 0 @@ -122,13 +51,13 @@ local function allow_metadata_inventory_move() end local function on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.after(0.5, move_item, pos, stack) + minetest.after(0.5, liquid.move_item, pos, stack, CAPACITY, formspec) end local function on_rightclick(pos) local mem = tubelib2.get_mem(pos) mem.countdown = 10 - M(pos):set_string("formspec", formspec(mem)) + M(pos):set_string("formspec", formspec(pos, mem)) minetest.get_node_timer(pos):start(2) end @@ -138,7 +67,7 @@ local function on_receive_fields(pos, formname, fields, player) end local mem = tubelib2.get_mem(pos) mem.countdown = 10 - M(pos):set_string("formspec", formspec(mem)) + M(pos):set_string("formspec", formspec(pos, mem)) minetest.get_node_timer(pos):start(2) end @@ -146,9 +75,7 @@ local function can_dig(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end - local mem = tubelib2.get_mem(pos) - local inv = minetest.get_meta(pos):get_inventory() - return inv:is_empty("src") and inv:is_empty("dst") and (not mem.liquid or (mem.liquid.amount or 0) == 0) + return liquid.is_empty(pos) end @@ -176,7 +103,7 @@ minetest.register_node("techage:ta3_tank", { local number = techage.add_node(pos, "techage:ta3_tank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", formspec(mem)) + meta:set_string("formspec", formspec(pos, mem)) meta:set_string("infotext", S("TA3 Tank").." "..number) Pipe:after_place_node(pos) end, @@ -187,7 +114,7 @@ minetest.register_node("techage:ta3_tank", { local mem = tubelib2.get_mem(pos) if mem.countdown then mem.countdown = mem.countdown - 1 - M(pos):set_string("formspec", formspec(mem)) + M(pos):set_string("formspec", formspec(pos, mem)) return mem.countdown > 0 end end, @@ -202,7 +129,7 @@ minetest.register_node("techage:ta3_tank", { local leftover = liquid.srv_put(pos, indir, name, amount) local inv = M(pos):get_inventory() if not inv:is_empty("src") and inv:is_empty("dst") then - fill_container(pos, inv) + liquid.fill_container(pos, inv) end return leftover end, @@ -263,7 +190,7 @@ minetest.register_node("techage:oiltank", { local number = techage.add_node(pos, "techage:oiltank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", formspec(mem)) + meta:set_string("formspec", formspec(pos, mem)) meta:set_string("infotext", S("Oil Tank").." "..number) Pipe:after_place_node(pos) end, @@ -274,7 +201,7 @@ minetest.register_node("techage:oiltank", { local mem = tubelib2.get_mem(pos) if mem.countdown then mem.countdown = mem.countdown - 1 - M(pos):set_string("formspec", formspec(mem)) + M(pos):set_string("formspec", formspec(pos, mem)) return mem.countdown > 0 end end, @@ -289,7 +216,7 @@ minetest.register_node("techage:oiltank", { local leftover = liquid.srv_put(pos, indir, name, amount) local inv = M(pos):get_inventory() if not inv:is_empty("src") and inv:is_empty("dst") then - fill_container(pos, inv) + liquid.fill_container(pos, inv) end return leftover end, @@ -340,7 +267,7 @@ minetest.register_node("techage:ta4_tank", { local number = techage.add_node(pos, "techage:ta4_tank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", formspec(mem)) + meta:set_string("formspec", formspec(pos, mem)) meta:set_string("infotext", S("TA4 Tank").." "..number) Pipe:after_place_node(pos) end, @@ -351,7 +278,7 @@ minetest.register_node("techage:ta4_tank", { local mem = tubelib2.get_mem(pos) if mem.countdown then mem.countdown = mem.countdown - 1 - M(pos):set_string("formspec", formspec(mem)) + M(pos):set_string("formspec", formspec(pos, mem)) return mem.countdown > 0 end end, @@ -366,7 +293,7 @@ minetest.register_node("techage:ta4_tank", { local leftover = liquid.srv_put(pos, indir, name, amount) local inv = M(pos):get_inventory() if not inv:is_empty("src") and inv:is_empty("dst") then - fill_container(pos, inv) + liquid.fill_container(pos, inv) end return leftover end, @@ -392,45 +319,7 @@ minetest.register_node("techage:ta4_tank", { sounds = default.node_sound_metal_defaults(), }) -techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, { - on_pull_item = function(pos, in_dir, num) - local inv = M(pos):get_inventory() - if not inv:is_empty("dst") then - local taken = techage.get_items(inv, "dst", num) - if not inv:is_empty("src") then - fill_container(pos, inv) - end - return taken - end - end, - on_push_item = function(pos, in_dir, stack) - local inv = M(pos):get_inventory() - if inv:room_for_item("src", stack) then - inv:add_item("src", stack) - if liquid.is_container_empty(stack:get_name()) then - fill_container(pos, inv) - else - empty_container(pos, inv) - end - return true - end - return false - end, - on_unpull_item = function(pos, in_dir, stack) - local meta = M(pos) - local inv = meta:get_inventory() - return techage.put_items(inv, "dst", stack) - end, - on_recv_message = function(pos, src, topic, payload) - if topic == "state" then - local meta = M(pos) - local inv = meta:get_inventory() - return techage.get_inv_state(inv, "main") - else - return "unsupported" - end - end, -}) +techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.tubing) Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}) diff --git a/manuals/manual_ta2_DE.md b/manuals/manual_ta2_DE.md index 96bf32d..f870937 100644 --- a/manuals/manual_ta2_DE.md +++ b/manuals/manual_ta2_DE.md @@ -21,7 +21,7 @@ Bei allen Blöcken beim Setzen immer auch die Ausrichtung achten: Der Boiler muss mit Wasser gefüllt werden. Dazu bis zu 10 Eimer Wasser in den Boiler füllen. Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden. -Wenn das Wasser heiß ist, kann das Ventil am Boiler geöffnet und anschließend die Dampfmaschine am Schwungrad gestartet werden. +Wenn das Wasser heiß ist (Temperaturanzeige ganz oben), kann die Dampfmaschine am Schwungrad gestartet werden. Die Dampfmaschine leistet 25 ku, kann damit mehrere Maschinen gleichzeitig antreiben. @@ -39,7 +39,7 @@ Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden. Die Brenndauer ist a ### TA2 Boiler -Teil der Dampfmaschine. Muss mit Wasser gefüllt werden. Wem kein Wasser mehr vorhanden ist oder die Temperatur zu weit absinkt, schaltet sich der Boiler ab. +Teil der Dampfmaschine. Muss mit Wasser gefüllt werden. Wem kein Wasser mehr vorhanden ist oder die Temperatur zu weit absinkt, schaltet sich die Dampfmaschine ab. [ta2_boiler|image] diff --git a/nodes/test.lua b/nodes/test.lua deleted file mode 100644 index 13651e9..0000000 --- a/nodes/test.lua +++ /dev/null @@ -1,549 +0,0 @@ -minetest.register_node("techage:block1", { - description = "block1", - tiles = {"techage_filling_ta2.png^techage_frame_ta2.png"}, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block2", { - description = "block2", - tiles = {"techage_filling_ta3.png^techage_frame_ta3.png"}, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block3", { - description = "block3", - tiles = { - "techage_top_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png", - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - - - -minetest.register_node("techage:block4", { - description = "block4", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_arrow.png', - 'techage_filling_ta2.png^techage_frame_ta2.png', - 'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_outp.png', - 'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_inp.png', - { - image = "techage_pusher14.png^[transformR180]^techage_frame14_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - { - image = "techage_pusher14.png^techage_frame14_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block5", { - description = "block5", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png', - 'techage_filling_ta3.png^techage_frame_ta3.png', - 'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png', - 'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png', - { - image = "techage_pusher14.png^[transformR180]^techage_frame14_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - { - image = "techage_pusher14.png^techage_frame14_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block6", { - description = "block6", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta4.png^techage_top_ta4.png^techage_appl_arrow.png', - 'techage_filling_ta4.png^techage_frame_ta4.png', - 'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png', - 'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inp.png', - { - image = "tubelib_pusher.png^[transformR180]^techage_frame14_ta4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - { - image = "tubelib_pusher.png^techage_frame14_ta4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - - - - - -minetest.register_node("techage:block7", { - description = "block7", - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta2.png^techage_frame_ta2.png", - "techage_filling_ta2.png^techage_frame_ta2.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_front_ta3.png", - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block8", { - description = "block8", - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta3.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_back_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_chest_front_ta3.png", - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:block9", { - description = "block9", - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta4.png^techage_top_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_back_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_chest_front_ta4.png", - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - - -minetest.register_node("techage:sieve", { - description = "sieve", - drawtype = "nodebox", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_inp.png', - 'techage_filling_ta2.png^techage_frame_ta2.png', - 'techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_outp.png', - 'techage_filling_ta2.png^techage_frame_ta2.png', - { - image = "techage_filling4_ta2.png^techage_appl_sieve4.png^techage_frame4_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - { - image = "techage_filling4_ta2.png^techage_appl_sieve4.png^techage_frame4_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:sieve2", { - description = "sieve", - drawtype = "nodebox", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png', - 'techage_filling_ta3.png^techage_frame_ta3.png', - 'techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_outp.png', - 'techage_filling_ta3.png^techage_frame_ta3.png', - { - image = "techage_filling4_ta3.png^techage_appl_sieve4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - { - image = "techage_filling4_ta3.png^techage_appl_sieve4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - -minetest.register_node("techage:sieve3", { - description = "sieve", - drawtype = "nodebox", - tiles = { - -- up, down, right, left, back, front - 'techage_filling_ta4.png^techage_top_ta4.png^techage_appl_inp.png', - 'techage_filling_ta4.png^techage_frame_ta4.png', - 'techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png', - 'techage_filling_ta4.png^techage_frame_ta4.png', - { - image = "techage_filling4_ta4.png^techage_appl_sieve4.png^techage_frame4_ta4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - { - image = "techage_filling4_ta4.png^techage_appl_sieve4.png^techage_frame4_ta4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - -minetest.register_node("techage:filler", { - description = "filler", - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png", - "techage_filling_ta3.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_inp.png", - --"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_filler.png", - --"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_filler.png", - { - image = "techage_filling4_ta3.png^techage_appl_filler4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - { - image = "techage_filling4_ta3.png^techage_appl_filler4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 2.0, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:compressor", { - description = "compressor", - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_arrow.png", - "techage_filling_ta3.png^techage_frame_ta3.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png", - "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_hole2.png", - --"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_compressor.png", - --"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_compressor.png^[transformFX]", - { - image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.2, - }, - }, - { - image = "techage_filling4_ta3.png^techage_appl_compressor4.png^[transformFX]^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.2, - }, - }, - }, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - -minetest.register_node("techage:fermenter", { - description = "fermenter", - tiles = {"techage_fermenter.png"}, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_node("techage:fermenter_foil", { - description = "fermenter_foil", - tiles = {"techage_fermenter_foil.png"}, - paramtype = "light", - light_source = 0, - sunlight_propagates = true, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - is_ground_content = false, - --sounds = default.node_sound_stone_defaults(), -}) - - -minetest.register_node("techage:biomass", { - description = "biomass", - drawtype = "liquid", - tiles = { - { - name = "techage_biomass.png", - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 4.0, - }, - }, - }, - special_tiles = { - -- New-style water source material (mostly unused) - { - name = "techage_biomass.png", - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 4.0, - }, - backface_culling = false, - }, - }, - - on_timer = function(pos) - minetest.remove_node(pos) - return false - end, - - after_place_node = function(pos, placer) - minetest.get_node_timer(pos):start(5) - end, - - --alpha = 160, - paramtype = "light", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drop = "", - drowning = 1, - liquidtype = "source", - liquid_alternative_flowing = "techage:biomass_flowing", - liquid_alternative_source = "techage:biomass", - liquid_viscosity = 1, - post_effect_color = {a = 103, r = 30, g = 60, b = 90}, - groups = {water = 3, liquid = 3, puts_out_fire = 1, cools_lava = 1}, - sounds = default.node_sound_water_defaults(), -}) - -minetest.register_node("techage:biomass_flowing", { - description = "biomass", - drawtype = "flowingliquid", - tiles = {"default_water.png"}, - special_tiles = { - { - name = "techage_biomass.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 4, - }, - }, - { - name = "techage_biomass.png", - backface_culling = true, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 4, - }, - }, - }, - --alpha = 220, - paramtype = "light", - paramtype2 = "flowingliquid", - walkable = false, - pointable = false, - diggable = false, - buildable_to = true, - is_ground_content = false, - drop = "", - drowning = 1, - liquidtype = "flowing", - liquid_alternative_flowing = "techage:biomass_flowing", - liquid_alternative_source = "techage:biomass", - liquid_viscosity = 1, - post_effect_color = {a = 103, r = 30, g = 60, b = 90}, - groups = {water = 3, liquid = 3, puts_out_fire = 1, - not_in_creative_inventory = 0, cools_lava = 1}, - sounds = default.node_sound_water_defaults(), -}) - diff --git a/oil/gasflare.lua b/oil/gasflare.lua index 1fb4724..58a6ab2 100644 --- a/oil/gasflare.lua +++ b/oil/gasflare.lua @@ -104,7 +104,7 @@ local function start_flarestack(pos, playername) max_hear_distance = 20, gain = 1, loop = true}) - print("handle", handle) + --print("handle", handle) meta:set_int("handle", handle) end @@ -140,7 +140,7 @@ minetest.register_node("techage:gasflare", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - print(dump(oldmetadata)) + --print(dump(oldmetadata)) stop_flarestack(pos, oldmetadata.fields.handle) local node = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) if node.name == "techage:gasflare2" then diff --git a/oil/generator.lua b/oil/generator.lua deleted file mode 100644 index 90b8232..0000000 --- a/oil/generator.lua +++ /dev/null @@ -1,280 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA3 Tiny Oil Power Generator - -]]-- - --- for lazy programmers -local M = minetest.get_meta -local S = techage.S - -local Power = techage.ElectricCable -local firebox = techage.firebox -local power = techage.power -local fuel = techage.fuel -local Pipe = techage.LiquidPipe -local liquid = techage.liquid - -local CYCLE_TIME = 2 -local PWR_CAPA = 12 -local EFFICIENCY = 2.5 - -local function formspec(self, pos, mem) - local fuel_percent = 0 - if mem.running then - fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1) - end - return "size[8,6]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - fuel.formspec_fuel(1, 0, mem).. - "button[1.6,1;1.8,1;update;"..S("Update").."]".. - "image_button[5.5,0.5;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. - "list[current_player;main;0,2.3;8,4;]".. - default.get_hotbar_bg(0, 3) -end - -local function can_start(pos, mem, state) - if mem.burn_cycles > 0 or (mem.liquid and mem.liquid.amount and mem.liquid.amount > 0) then - return true - end - return false -end - -local function start_node(pos, mem, state) - mem.running = true - power.generator_start(pos, mem, PWR_CAPA) - minetest.sound_play("techage_generator", { - pos = pos, - gain = 1, - max_hear_distance = 10}) -end - -local function stop_node(pos, mem, state) - mem.running = false - mem.provided = 0 - power.generator_stop(pos, mem) -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:tiny_generator", - node_name_active = "techage:tiny_generator_on", - cycle_time = CYCLE_TIME, - standby_ticks = 0, - formspec_func = formspec, - infotext_name = "TA3 Tiny Power Generator", - can_start = can_start, - start_node = start_node, - stop_node = stop_node, -}) - -local function burning(pos, mem) - local ratio = math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.02) - - mem.liquid = mem.liquid or {} - mem.liquid.amount = mem.liquid.amount or 0 - mem.burn_cycles = (mem.burn_cycles or 0) - ratio - if mem.burn_cycles <= 0 then - if mem.liquid.amount > 0 then - mem.liquid.amount = mem.liquid.amount - 1 - mem.burn_cycles = fuel.burntime(mem.liquid.name) * EFFICIENCY / CYCLE_TIME - mem.burn_cycles_total = mem.burn_cycles - return true - else - mem.liquid.name = nil - State:fault(pos, mem) - return false - end - else - return true - end -end - -local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.running and burning(pos, mem) then - mem.provided = power.generator_alive(pos, mem) - minetest.sound_play("techage_generator", { - pos = pos, - gain = 1, - max_hear_distance = 10}) - return true - else - mem.provided = 0 - end - return false -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) - State:state_button_event(pos, mem, fields) - - M(pos):set_string("formspec", formspec(State, pos, mem)) -end - - -local function formspec_clbk(pos, mem) - return formspec(State, pos, mem) -end - -local function on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.after(0.5, fuel.move_item, pos, stack, formspec_clbk) -end - -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) -end - -local _liquid = { - fuel_cat = fuel.BT_NAPHTHA, - capa = fuel.CAPACITY, - peek = liquid.srv_peek, - put = function(pos, indir, name, amount) - if fuel.valid_fuel(name, fuel.BT_NAPHTHA) then - return liquid.srv_put(pos, indir, name, amount) - end - return amount - end, - take = liquid.srv_take, -} - -local _networks = { - pipe = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, -} - -minetest.register_node("techage:tiny_generator", { - description = S("TA3 Tiny Power Generator"), - tiles = { - -- up, down, right, left, back, front - "techage_appl_electric_gen_top.png^techage_frame_ta3_top.png", - "techage_appl_electric_gen_top.png^techage_frame_ta3.png", - "techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png", - "techage_appl_electric_gen_side.png^techage_frame_ta3.png", - "techage_appl_electric_gen_front.png^[transformFX]^techage_frame_ta3.png", - "techage_appl_electric_gen_front.png^techage_frame_ta3.png", - }, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - - on_construct = function(pos) - local mem = tubelib2.init_mem(pos) - local number = techage.add_node(pos, "techage:tiny_generator") - mem.running = false - mem.burn_cycles = 0 - State:node_init(pos, mem, number) - local meta = M(pos) - meta:set_string("formspec", formspec(State, pos, mem)) - local inv = meta:get_inventory() - inv:set_size('fuel', 1) - end, - - - allow_metadata_inventory_put = fuel.allow_metadata_inventory_put, - allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, - on_metadata_inventory_put = on_metadata_inventory_put, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, - can_dig = fuel.can_dig, - liquid = _liquid, - networks = _networks, -}) - -minetest.register_node("techage:tiny_generator_on", { - description = S("TA3 Tiny Power Generator"), - tiles = { - -- up, down, right, left, back, front - "techage_appl_electric_gen_top.png^techage_frame_ta3_top.png", - "techage_appl_electric_gen_top.png^techage_frame_ta3.png", - "techage_appl_electric_gen_side.png^techage_appl_hole_electric.png^techage_frame_ta3.png", - "techage_appl_electric_gen_side.png^techage_frame_ta3.png", - { - image = "techage_appl_electric_gen_front4.png^[transformFX]^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.8, - }, - }, - { - image = "techage_appl_electric_gen_front4.png^techage_frame4_ta3.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.8, - }, - }, - }, - - paramtype = "light", - paramtype2 = "facedir", - groups = {not_in_creative_inventory=1}, - diggable = false, - light_source = 4, - on_rotate = screwdriver.disallow, - is_ground_content = false, - - allow_metadata_inventory_put = fuel.allow_metadata_inventory_put, - allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, - on_metadata_inventory_put = on_metadata_inventory_put, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - on_timer = node_timer, - can_dig = fuel.can_dig, - liquid = _liquid, - networks = _networks, -}) - -Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"}) - -techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { - conn_sides = {"R"}, - power_network = Power, -}) - -techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { - on_recv_message = function(pos, src, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "load" then - return power.percent(PWR_CAPA, mem.provided) - else - return State:on_receive_message(pos, topic, payload) - end - end, - on_node_load = function(pos) - State:on_node_load(pos) - end, -}) - -minetest.register_craft({ - output = "techage:tiny_generator", - recipe = { - {'default:steel_ingot', 'techage:usmium_nuggets', 'default:steel_ingot'}, - {'dye:red', 'basic_materials:gear_steel', 'techage:electric_cableS'}, - {'default:steel_ingot', 'techage:vacuum_tube', 'default:steel_ingot'}, - }, -}) - diff --git a/power/api.md b/power/api.md deleted file mode 100644 index 44d5267..0000000 --- a/power/api.md +++ /dev/null @@ -1,65 +0,0 @@ -# Power Distribution API - -The module power supports 3 kinds of devices: -- Generators: Provide power, can be turned on/off -- Consumers: Need power, like machines or lamps, can be turned on/off -- Akkus: Can provide stored power, combination of generator and consumer - -### Possible connection sides -``` - U(p) B(ack) - | / - | / - +--|-----+ - / o /| - +--------+ | - L(eft) ----| |o---- R(ight) - | o | + - | / |/ - +--/-----+ - / | - F(ront) | - | - D(own) -``` - -All 3 kinds of nodes use the same registration function to enrich the nodes functionality for power distribution. - - techage.power.register_nodes(names, definition) - -- names is a list of node names - -- definition is a table according to: - - { - conn_sides = , -- allowed connection sides for power cables - -- one or several of {"L", "R", "U", "D", "F", "B"} - power_network = , - } - -tbd.......... - - - techage.power.power_distribution(pos) - -- Trigger the recalculation or the power distribution in case of - -- a turn on/off request - - - techage.power.formspec_power_bar(max_power, current_power) - -- returns the formspec PGN with a bar according the the ratio `current_power/max_power` - - techage.power.formspec_load_bar(charging) - -- returns the formspec PGN with the charging/uncharging symbol - -- charging can be: - -- true => charging - -- false => uncharging - -- nil => turned off - - -### Internas -The function `techage.power.register_nodes`: -- adds a wrapper to `after_place_node` (needed to maintain tubelib2 data base) -- adds a wrapper to `after_dig_node` (needed to maintain tubelib2 data base) -- adds the function `after_tube_update` (needed to maintain tubelib2 data base) -- adds the table `power` to the node definition with the provided attributes -- adds `power_dirs` to the node meta table with the `conn_sides` information converted to node specific dirs -- adds `mem.connections` for the available power connections with consideration of valid `power_dirs` - diff --git a/power/drive_axle.lua b/power/drive_axle.lua index 3cd5f4a..da823d2 100644 --- a/power/drive_axle.lua +++ b/power/drive_axle.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -33,11 +33,6 @@ local Axle = tubelib2.Tube:new({ end, }) -Axle:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) - minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) -end) - -techage.Axle = Axle minetest.register_node("techage:axle", { description = S("TA2 Drive Axle"), @@ -182,17 +177,4 @@ minetest.register_craft({ }) --- Axles PNG animation -function techage.switch_axles(pos, on) - local s = M(pos):get_string("power_dirs") - if s ~= "" then - for _,indir in ipairs(minetest.deserialize(s)) do - local out_dir = tubelib2.Turn180Deg[indir] - if on then - Axle:switch_tube_line(pos, out_dir, "on") - else - Axle:switch_tube_line(pos, out_dir, "off") - end - end - end -end \ No newline at end of file +techage.Axle = Axle diff --git a/power/electric_cable.lua b/power/electric_cable.lua index 2c51b29..1aeab14 100644 --- a/power/electric_cable.lua +++ b/power/electric_cable.lua @@ -3,12 +3,12 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information - TA3/TA4 Cable for electrical power distribution + TA3 Electric Cables (AC) ]]-- @@ -18,13 +18,16 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S +local ELE1_MAX_CABLE_LENGHT = 1000 + local Cable = tubelib2.Tube:new({ dirs_to_check = {1,2,3,4,5,6}, - max_tube_length = 1000, + max_tube_length = ELE1_MAX_CABLE_LENGHT, show_infotext = false, - tube_type = "electric_cable", - primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", - "techage:power_line", "techage:power_lineS", "techage:power_lineA", "techage:power_pole2"}, + tube_type = "ele1", + primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", + "techage:power_line", "techage:power_lineS", "techage:power_lineA", + "techage:power_pole2"}, secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes) -- Handle "power line" nodes @@ -154,14 +157,6 @@ minetest.register_node("techage:electric_cableA", { drop = "techage:electric_cableS", }) -Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) - if minetest.registered_nodes[node.name].after_tube_update then -- primay/secondary nodes - minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) - else -- all kind of nodes, used as cable filler/grout - techage.power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir, Cable) - end -end) - minetest.register_craft({ output = "techage:electric_cableS 6", recipe = { @@ -171,3 +166,5 @@ minetest.register_craft({ }, }) +techage.ElectricCable = Cable +techage.ELE1_MAX_CABLE_LENGHT = ELE1_MAX_CABLE_LENGHT diff --git a/power/junction.lua b/power/junction.lua index 4d99371..5de3798 100644 --- a/power/junction.lua +++ b/power/junction.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -48,10 +48,10 @@ end -- 'size' is the size of the junction cube without any connection, e.g. 1/8 -- 'boxes' is a table with 6 table elements for the 6 possible connection arms --- 'network' is the power (tubelib2) instance or nil +-- 'tlib2' is the tubelib2 instance -- 'node' is the node definition with tiles, callback functions, and so on -- 'index' number for the inventory node (default 0) -function techage.register_junction(name, size, boxes, network, node, index) +function techage.register_junction(name, size, boxes, tlib2, node, index) for idx = 0,63 do local ndef = table.copy(node) if idx == (index or 0) then @@ -69,21 +69,21 @@ function techage.register_junction(name, size, boxes, network, node, index) ndef.is_ground_content = false ndef.drop = name..(index or "0") minetest.register_node(name..idx, ndef) - -- Register in addition for power distribution - if network then - techage.power.register_node({name..idx}, { - power_network = network, - after_tube_update = ndef.after_tube_update, - }) - end + tlib2:add_secondary_node_names({name..idx}) end end function techage.junction_type(pos, network) local val = 0 for dir = 1,6 do - if network:connected(pos, dir) then - val = setbit(val, bit(dir)) + if network.force_to_use_tubes then + if network:friendly_primary_node(pos, dir) then + val = setbit(val, bit(dir)) + end + else + if network:connected(pos, dir) then + val = setbit(val, bit(dir)) + end end end return val diff --git a/power/junctionbox.lua b/power/junctionbox.lua index c0de294..354ada4 100644 --- a/power/junctionbox.lua +++ b/power/junctionbox.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -16,6 +16,7 @@ local M = minetest.get_meta local S = techage.S +local networks = techage.networks local Cable = techage.ElectricCable local power = techage.power @@ -35,22 +36,23 @@ techage.register_junction("techage:electric_junction", 2/8, Boxes, Cable, { groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1}, sounds = default.node_sound_defaults(), - on_construct = tubelib2.init_mem, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) + after_place_node = function(pos, placer, itemstack, pointed_thing) local name = "techage:electric_junction"..techage.junction_type(pos, Cable) minetest.swap_node(pos, {name = name, param2 = 0}) - power.network_changed(pos, tubelib2.get_mem(pos)) + Cable:after_place_node(pos) end, - is_power_available = function(pos) - return techage.power.power_accounting(pos, tubelib2.get_mem(pos)) + tubelib2_on_update2 = function(pos, dir1, tlib2, node) + local name = "techage:electric_junction"..techage.junction_type(pos, Cable) + minetest.swap_node(pos, {name = name, param2 = 0}) + power.update_network(pos, nil, tlib2) end, -}) - -minetest.register_craft({ - output = "techage:electric_junction0 2", - recipe = { - {"", "basic_materials:plastic_sheet", ""}, - {"basic_materials:plastic_sheet", "default:copper_ingot", "basic_materials:plastic_sheet"}, - {"", "basic_materials:plastic_sheet", ""}, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Cable:after_dig_node(pos) + end, + networks = { + ele1 = { + sides = networks.AllSides, -- connection sides for cables + ntype = "junc", + }, }, -}) \ No newline at end of file +}) diff --git a/power/power.lua b/power/power.lua deleted file mode 100644 index 697bf9d..0000000 --- a/power/power.lua +++ /dev/null @@ -1,678 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - Power distribution and consumption calculation - for any kind of power distribution network - -]]-- - --- 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 N = function(pos) return minetest.get_node(pos).name end -local D = techage.Debug - --- Techage Related Data -local PWR = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).power end - --- Used to determine the already passed nodes while power distribution -local Route = {} -local NumNodes = 0 - -techage.power = {} - -local MAX_NUM_NODES = 1000 -techage.MAX_NUM_NODES = MAX_NUM_NODES - --- Consumer States -local STOPPED = 1 -local NOPOWER = 2 -local RUNNING = 3 - --------------------------------------------------- Migrate -local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end -local Consumer = { - ["techage:streetlamp_off"] = 0, - ["techage:streetlamp_on"] = 0.5, - ["techage:industriallamp1_off"] = 0, - ["techage:industriallamp1_on"] = 0.5, - ["techage:industriallamp2_off"] = 0, - ["techage:industriallamp2_on"] = 0.5, - ["techage:industriallamp3_off"] = 0, - ["techage:industriallamp3_on"] = 0.5, - ["techage:simplelamp_off"] = 0, - ["techage:simplelamp_on"] = 0.5, - ["techage:ceilinglamp_off"] = 0, - ["techage:ceilinglamp_on"] = 0.5, - ["techage:ta2_autocrafter_pas"] = 0, - ["techage:ta2_autocrafter_act"] = 4, - ["techage:ta3_autocrafter_pas"] = 0, - ["techage:ta3_autocrafter_act"] = 6, - ["techage:ta2_electronic_fab_pas"] = 0, - ["techage:ta2_electronic_fab_act"] = 8, - ["techage:ta3_electronic_fab_pas"] = 0, - ["techage:ta3_electronic_fab_act"] = 12, - ["techage:ta2_gravelsieve_pas"] = 0, - ["techage:ta2_gravelsieve_act"] = 3, - ["techage:ta3_gravelsieve_pas"] = 0, - ["techage:ta3_gravelsieve_act"] = 4, - ["techage:ta2_grinder_pas"] = 0, - ["techage:ta2_grinder_act"] = 4, - ["techage:ta3_grinder_pas"] = 0, - ["techage:ta3_grinder_act"] = 6, - ["techage:ta2_rinser_pas"] = 0, - ["techage:ta2_rinser_act"] = 3, - ["techage:ta3_booster"] = 0, - ["techage:ta3_booster_on"] = 3, - ["techage:ta3_drillbox_pas"] = 0, - ["techage:ta3_drillbox_act"] = 16, - ["techage:ta3_pumpjack_pas"] = 0, - ["techage:ta3_pumpjack_act"] = 16, - ["techage:gearbox"] = 0, - ["techage:gearbox_on"] = 1, -} -local Generator = { - ["techage:t2_source"] = 20, - ["techage:t3_source"] = 20, - ["techage:t4_source"] = 20, - ["techage:flywheel"] = 0, - ["techage:flywheel_on"] = 25, - ["techage:generator"] = 0, - ["techage:generator_on"] = 80, - ["techage:tiny_generator"] = 0, - ["techage:tiny_generator_on"] = 12, -} -local Akku = { - ["techage:ta3_akku"] = 10 -} - -local function migrate(pos, mem, node) - if mem.master_pos or mem.is_master ~= nil then - print("migrate", S(pos), node.name) - if mem.master_pos then - mem.pwr_master_pos = table.copy(mem.master_pos) - mem.master_pos = nil - end - mem.pwr_is_master = mem.is_master; mem.is_master = nil - mem.available1 = nil - mem.available2 = nil - mem.supply1 = nil - mem.supply2 = nil - mem.needed1 = nil - mem.needed2 = nil - mem.demand1 = nil - mem.demand2 = nil - mem.reserve = nil - mem.could_be_master = nil - mem.node_loaded = nil - - mem.pwr_power_provided_cnt = 2 - mem.pwr_node_alive_cnt = 4 - - local name = techage.get_node_lvm(pos).name - mem.pwr_needed = Consumer[name] - mem.pwr_available = Generator[name] - mem.pwr_could_provide = Akku[name] - mem.pwr_could_need = Akku[name] - - if Consumer[name] then - if mem.techage_state then - if mem.techage_state == techage.STOPPED then - mem.pwr_state = STOPPED - elseif mem.techage_state == techage.NOPOWER or mem.techage_state == techage.RUNNING then - local crd = CRD(pos) - techage.power.consumer_start(pos, mem, crd.cycle_time, crd.power_consumption) - end - elseif mem.turned_on then - mem.pwr_state = RUNNING - elseif mem.pwr_needed then - mem.pwr_state = RUNNING - else - mem.pwr_state = STOPPED - end - if techage.in_list({"techage:ta2_electronic_fab_pas", "techage:ta2_electronic_fab_act", "techage:ta3_electronic_fab_pas", "techage:ta3_electronic_fab_act"}, name) then - mem.pwr_cycle_time = 6 - elseif techage.in_list({"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"}, name) then - mem.pwr_cycle_time = 16 - elseif techage.in_list({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"}, name) then - mem.pwr_cycle_time = 8 - else - mem.pwr_cycle_time = 4 - end - elseif Generator[name] then - mem.pwr_cycle_time = 2 - if mem.generating then - techage.power.generator_start(pos, mem, Generator[name]) - else - techage.power.generator_stop(pos, mem) - end - elseif Akku[name] then - mem.pwr_cycle_time = 2 - if mem.techage_state and mem.techage_state == techage.RUNNING then - mem.running = true - minetest.get_node_timer(pos):start(2) - techage.power.secondary_start(pos, mem, mem.pwr_could_provide, mem.pwr_could_need) - end - end - end -end - -local Nodenames={} -local n=0 - -for k,v in pairs(Consumer) do - n=n+1 - Nodenames[n]=k -end -for k,v in pairs(Generator) do - n=n+1 - Nodenames[n]=k -end -for k,v in pairs(Akku) do - n=n+1 - Nodenames[n]=k -end - - -minetest.register_lbm({ - label = "[techage] Power Conversion", - name = "techage:power", - nodenames = Nodenames, - run_at_every_load = true, - action = function(pos, node) - local mem = tubelib2.get_mem(pos) - migrate(pos, mem, node) - end -}) - --------------------------------------------------- Migrate - -local function connection_color(t) - local count = 0 - for _ in pairs(t) do count = count + 1 end - if count == 0 then return count, "#FF0000" end - if count == 1 then return count, "#FFFF00" end - return count, "#00FF00" -end - -local function pos_already_reached(pos) - local key = minetest.hash_node_position(pos) - if not Route[key] and NumNodes < MAX_NUM_NODES then - Route[key] = true - NumNodes = NumNodes + 1 - return false - end - return true -end - -local function min(val, max) - if val < 0 then return 0 end - if val > max then return max end - return val -end - -local function accounting(pos, mem) - -- calculate the primary and secondary supply and demand - mem.mst_supply1 = min(mem.mst_needed1 + mem.mst_needed2, mem.mst_available1) - mem.mst_demand1 = min(mem.mst_needed1, mem.mst_available1 + mem.mst_available2) - mem.mst_supply2 = min(mem.mst_demand1 - mem.mst_supply1, mem.mst_available2) - mem.mst_demand2 = min(mem.mst_supply1 - mem.mst_demand1, mem.mst_available1) - mem.mst_reserve = (mem.mst_available1 + mem.mst_available2) - mem.mst_needed1 - if D.sts then D.dbg("needed = "..mem.mst_needed1.."/"..mem.mst_needed2..", available = "..mem.mst_available1.."/"..mem.mst_available2) end - if D.sts then D.dbg("supply = "..mem.mst_supply1.."/"..mem.mst_supply2..", demand = "..mem.mst_demand1.."/"..mem.mst_demand2..", reserve = "..mem.mst_reserve) end -end - -local function connection_walk(pos, clbk) - local mem = tubelib2.get_mem(pos) - mem.interrupted_dirs = mem.interrupted_dirs or {} - if clbk then - clbk(pos, mem) - end - for out_dir,item in pairs(mem.connections or {}) do - if item.pos and not pos_already_reached(item.pos) and - not mem.interrupted_dirs[out_dir] then - connection_walk(item.pos, clbk) - end - end -end - --- Comfort walk with abort condition and additional info --- num_hops is for internal use only --- clbk(pos, node, mem, num_hops, num_nodes) -local function limited_connection_walk(pos, clbk, num_hops) - num_hops = num_hops or 1 - local mem = tubelib2.get_mem(pos) - mem.interrupted_dirs = mem.interrupted_dirs or {} - if clbk then - local node = techage.get_node_lvm(pos) - if clbk(pos, node, mem, num_hops, NumNodes) then return true end - end - num_hops = num_hops + 1 - for out_dir,item in pairs(mem.connections or {}) do - if item.pos and not pos_already_reached(item.pos) and - not mem.interrupted_dirs[out_dir] then - limited_connection_walk(item.pos, clbk, num_hops) - end - end - return false -end - --- if no power available -local function consumer_turn_off(pos, mem) - local pwr = PWR(pos) - if D.pwr then D.dbg("consumer_turn_off") end - if pwr and pwr.on_nopower then - pwr.on_nopower(pos, mem) - end - mem.pwr_state = NOPOWER - mem.pwr_power_provided_cnt = -1 -end - -local function consumer_turn_on(pos, mem) - local pwr = PWR(pos) - if D.pwr then D.dbg("consumer_turn_on") end - if pwr and pwr.on_power then - pwr.on_power(pos, mem) - end - mem.pwr_state = RUNNING - -- to avoid consumer starvation - mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1 -end - --- determine one "generating" node as master (largest hash number) -local function determine_master(pos) - Route = {} - NumNodes = 0 - pos_already_reached(pos) - local hash = 0 - local master = nil - connection_walk(pos, function(pos, mem) - if (mem.pwr_node_alive_cnt or 0) >= 0 and - ((mem.pwr_available or 0) > 0 or - (mem.pwr_available2 or 0) > 0) then -- active generator? - - local new = minetest.hash_node_position(pos) - if hash <= new then - hash = new - master = pos - end - end - end) - return master -end - --- store master position on all network nodes -local function store_master(pos, master_pos) - Route = {} - NumNodes = 0 - pos_already_reached(pos) - connection_walk(pos, function(pos, mem) - mem.pwr_master_pos = master_pos - end) -end - -local function master_mem(mem) - if mem.pwr_master_pos then - local netkey = minetest.hash_node_position(mem.pwr_master_pos) - return techage.schedule.get_network(netkey) - end -end - -local function handle_generator(mst_mem, mem, pos, power_available) - -- for next cycle - mst_mem.mst_available1 = (mst_mem.mst_available1 or 0) + power_available - -- current cycle - mst_mem.mst_supply1 = mst_mem.mst_supply1 or 0 - if mst_mem.mst_supply1 < power_available then - mem.pwr_provided = mst_mem.mst_supply1 - mst_mem.mst_supply1 = 0 - else - mst_mem.mst_supply1 = mst_mem.mst_supply1 - power_available - mem.pwr_provided = power_available - end -end - -local function handle_consumer(mst_mem, mem, pos, power_needed) - if mem.pwr_state == NOPOWER then - -- for next cycle - mst_mem.mst_needed1 = (mst_mem.mst_needed1 or 0) + power_needed - -- current cycle - if (mst_mem.mst_demand1 or 0) >= power_needed then - mst_mem.mst_demand1 = (mst_mem.mst_demand1 or 0) - power_needed - if D.sts then D.dbg("consumer_turn_on: mst_demand = "..mst_mem.mst_demand1..", node = "..minetest.get_node(pos).name) end - consumer_turn_on(pos, mem) - end - elseif mem.pwr_state == RUNNING then - -- for next cycle - mst_mem.mst_needed1 = (mst_mem.mst_needed1 or 0) + power_needed - -- current cycle - if (mst_mem.mst_demand1 or 0) >= power_needed then - mst_mem.mst_demand1 = (mst_mem.mst_demand1 or 0) - power_needed - -- small consumer like lamps are allowed to "use" the reserve - elseif power_needed <= 2 and (mst_mem.mst_reserve or 0) >= power_needed then - mst_mem.mst_reserve = (mst_mem.mst_reserve or 0) - power_needed - else -- no power available - mst_mem.mst_demand1 = 0 - if D.sts then D.dbg("consumer_turn_off: mst_demand = "..mst_mem.mst_demand1..", node = "..minetest.get_node(pos).name) end - consumer_turn_off(pos, mem) - end - end -end - -local function handle_secondary(mst_mem, mem, pos, provides, needed) - -- for next cycle - mst_mem.mst_available2 = (mst_mem.mst_available2 or 0) + provides - mst_mem.mst_needed2 = (mst_mem.mst_needed2 or 0) + needed - -- check as generator - mst_mem.mst_supply2 = mst_mem.mst_supply2 or 0 - mst_mem.mst_demand2 = mst_mem.mst_demand2 or 0 - if mst_mem.mst_supply2 > 0 then - local val = math.min(provides, mst_mem.mst_supply2) - mst_mem.mst_supply2 = mst_mem.mst_supply2 - val - mem.pwr_provided = val - -- check as consumer - elseif mst_mem.mst_demand2 > 0 then - local val = math.min(needed, mst_mem.mst_demand2) - mst_mem.mst_demand2 = mst_mem.mst_demand2 - val - mem.pwr_provided = -val - else - mem.pwr_provided = 0 - end - -end - -local function trigger_nodes(mst_pos, mst_mem, dec) - Route = {} - NumNodes = 0 - pos_already_reached(mst_pos) - connection_walk(mst_pos, function(pos, mem) - mem.pwr_node_alive_cnt = (mem.pwr_node_alive_cnt or 1) - dec - mem.pwr_power_provided_cnt = 2 - if D.pwr then D.dbg("trigger_nodes", minetest.get_node(pos).name, mem.pwr_node_alive_cnt, mem.pwr_available2 or mem.pwr_available or mem.pwr_needed) end - if mem.pwr_node_alive_cnt >= 0 or mem.pwr_state == NOPOWER then - if mem.pwr_available then - handle_generator(mst_mem, mem, pos, mem.pwr_available) - elseif mem.pwr_needed then - handle_consumer(mst_mem, mem, pos, mem.pwr_needed) - elseif mem.pwr_available2 then - handle_secondary(mst_mem, mem, pos, mem.pwr_available2, mem.pwr_needed2) - end - end - end) -end - -local function turn_off_nodes(mst_pos) - Route = {} - NumNodes = 0 - pos_already_reached(mst_pos) - if D.pwr then D.dbg("turn_off_nodes") end - connection_walk(mst_pos, function(pos, mem) - if (mem.pwr_node_alive_cnt or -1) >= 0 then - if mem.pwr_needed then - consumer_turn_off(pos, mem) - end - end - end) -end - -local function determine_new_master(pos, mem) - local mpos = determine_master(pos) - store_master(pos, mpos) - mem.pwr_master_pos = mpos - return true -end - --- called from all nodes -local function trigger_network(pos, mem) - if mem.pwr_master_pos then - local netkey = minetest.hash_node_position(mem.pwr_master_pos) - local network = techage.schedule.get_network(netkey) or - techage.schedule.add_network(netkey, {mst_pos = mem.pwr_master_pos}) - network.alive = 10 - else - print("node without master_pos "..N(pos).." at "..S(pos)) - end -end - --- called from global timer -function techage.power.power_distribution(time, pos, mem) - if D.pwr then D.dbg("power_distribution"..math.floor(time).." "..N(pos)) end - mem.mst_needed1 = 0 - mem.mst_needed2 = 0 - mem.mst_available1 = 0 - mem.mst_available2 = 0 - trigger_nodes(pos, mem, 1) - accounting(pos, mem) -end - --- --- Power API functions --- - --- To be called for each network change from any node -function techage.power.network_changed(pos, mem) - if D.pwr then D.dbg("network_changed") end - mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1 - if determine_new_master(pos, mem) then -- new master - trigger_network(pos, mem) - end -end - --- --- Generator related functions --- -function techage.power.generator_start(pos, mem, available) - mem.pwr_node_alive_cnt = 2 - mem.pwr_cycle_time = 2 - mem.pwr_available = available - if determine_new_master(pos, mem) then -- new master - trigger_network(pos, mem) - end -end - -function techage.power.generator_update(pos, mem, available) - mem.pwr_available = available -end - -function techage.power.generator_stop(pos, mem) - mem.pwr_node_alive_cnt = 0 - mem.pwr_available = 0 - if determine_new_master(pos, mem) then -- last available master - trigger_network(pos, mem) - end -end - -function techage.power.generator_alive(pos, mem) - mem.pwr_node_alive_cnt = 2 - trigger_network(pos, mem) - return mem.pwr_provided or 0 -end - --- --- Consumer related functions --- --- this is more a try to start, the start will be performed by consumer_turn_on() -function techage.power.consumer_start(pos, mem, cycle_time, needed) - mem.pwr_cycle_time = cycle_time - mem.pwr_power_provided_cnt = 0 -- must be zero! - mem.pwr_node_alive_cnt = 2 - mem.pwr_needed = needed - mem.pwr_state = NOPOWER -end - -function techage.power.consumer_stop(pos, mem) - mem.pwr_node_alive_cnt = 0 - mem.pwr_needed = 0 - mem.pwr_state = STOPPED -end - -function techage.power.consumer_alive(pos, mem) - if D.pwr then D.dbg("consumer_alive", mem.pwr_power_provided_cnt, mem.pwr_cycle_time) end - mem.pwr_node_alive_cnt = (mem.pwr_cycle_time or 2)/2 + 1 - mem.pwr_power_provided_cnt = (mem.pwr_power_provided_cnt or 0) - 1 - if mem.pwr_power_provided_cnt < 0 and mem.pwr_state == RUNNING then - consumer_turn_off(pos, mem) - end -end - --- Lamp related function to speed up the turn on -function techage.power.power_available(pos, mem, needed) - if mem.pwr_master_pos and (mem.pwr_power_provided_cnt or 0) > 0 then - mem = master_mem(mem) - if mem and (mem.mst_reserve or 0) >= needed then - mem.mst_reserve = (mem.mst_reserve or 0) - needed - return true - end - end - return false -end - --- Debug info, used by junction boxes -function techage.power.power_accounting(pos, mem) - if mem.pwr_master_pos and (mem.pwr_power_provided_cnt or 0) > 0 then - mem.pwr_power_provided_cnt = (mem.pwr_power_provided_cnt or 0) - 1 - mem = master_mem(mem) - if mem then - return { - prim_available = mem.mst_available1 or 0, - sec_available = mem.mst_available2 or 0, - prim_needed = mem.mst_needed1 or 0, - sec_needed = mem.mst_needed2 or 0, - num_nodes = mem.mst_num_nodes or 0, - } - end - end - return { - prim_available = 0, - sec_available = 0, - prim_needed = 0, - sec_needed = 0, - num_nodes = 0, - } -end - --- --- Akku related functions --- -function techage.power.secondary_start(pos, mem, available, needed) - mem.pwr_node_alive_cnt = 2 - mem.pwr_could_provide = available - mem.pwr_could_need = needed - if determine_new_master(pos, mem) then -- new master - trigger_network(pos, mem) - end -end - -function techage.power.secondary_stop(pos, mem) - mem.pwr_node_alive_cnt = 0 - mem.pwr_could_provide = 0 - mem.pwr_could_need = 0 - mem.pwr_needed2 = 0 - if determine_new_master(pos, mem) then -- last available master - trigger_network(pos, mem) - end -end - -function techage.power.secondary_alive(pos, mem, capa_curr, capa_max) - if D.pwr then D.dbg("secondary_alive") end - if capa_curr >= capa_max then - mem.pwr_available2, mem.pwr_needed2 = mem.pwr_could_provide, 0 -- can provide only - elseif capa_curr <= 0 then - mem.pwr_available2, mem.pwr_needed2 = 0, mem.pwr_could_need -- can deliver only - else - mem.pwr_available2, mem.pwr_needed2 = mem.pwr_could_provide, mem.pwr_could_need - end - - mem.pwr_node_alive_cnt = 2 - if mem.pwr_is_master then - if D.pwr then D.dbg("secondary_alive is master") end - trigger_network(pos, mem) - end - if mem.pwr_master_pos then - return mem.pwr_provided or 0 - end - return 0 -end - --- --- Read the current power value from all connected devices (used for solar cells) --- Only used by the solar inverter to collect the power of all solar cells. --- Only one inverter per network is allowed. Therefore, we have to check, --- if additional inverters are in the network. --- Function returns in addition the number of found inverters. -function techage.power.get_power(start_pos, inverter) - Route = {} - NumNodes = 0 - pos_already_reached(start_pos) - local sum = 0 - local num_inverter = 0 - connection_walk(start_pos, function(pos, mem) - local pwr = PWR(pos) - if pwr and pwr.on_getpower then - sum = sum + pwr.on_getpower(pos, mem) - else - local node = techage.get_node_lvm(pos) - if node.name == inverter then - num_inverter = num_inverter + 1 - end - end - end) - return sum, num_inverter -end - -function techage.power.power_network_available(start_pos) - Route = {} - NumNodes = 0 - pos_already_reached(start_pos) - limited_connection_walk(start_pos, function(pos, node, mem, _, num_nodes) - return num_nodes > 2 - end) - return NumNodes > 2 -end - -function techage.power.mark_nodes(name, start_pos) - Route = {} - NumNodes = 0 - pos_already_reached(start_pos) - techage.unmark_position(name) - limited_connection_walk(start_pos, function(pos, node, mem, num_hops, num_nodes) - local num, color = connection_color(mem.connections or {}) - techage.mark_position(name, pos, S(pos).." : "..num, color) - return num_hops >= 3 or num_nodes >= 100 - end) -end - --- Network walk with callback for each node: --- --- limited_connection_walk(pos, clbk) --> num_hops, num_nodes --- --- called function: clbk(pos, node, mem, num_hops, num_nodes) --- walk will be arborted if function returns true -function techage.power.limited_connection_walk(pos, clbk) - Route = {} - NumNodes = 0 - pos_already_reached(pos) - limited_connection_walk(pos, clbk) - return NumNodes -end - ---local function test() --- print("test") --- local cnt = 0 --- tubelib2.walk_over_all(function(pos, mem) --- local node = techage.get_node_lvm(pos) --- print(S(pos), node.name) --- cnt = cnt + 1 --- end) --- print("cnt = "..cnt) ---end - ---minetest.after(1, test) diff --git a/power/power2.lua b/power/power2.lua deleted file mode 100644 index 347e2cc..0000000 --- a/power/power2.lua +++ /dev/null @@ -1,270 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - Power helper functions -]]-- - --- 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 N = function(pos) return minetest.get_node(pos).name end --- Techage Related Data -local PWR = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).power end -local PWRN = function(node) return (minetest.registered_nodes[node.name] or {}).power end - -local network_changed = techage.power.network_changed - -local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6} - -local function side_to_dir(param2, side) - local dir = SideToDir[side] - if dir < 5 then - dir = (((dir - 1) + (param2 % 4)) % 4) + 1 - end - return dir -end - -local function set_conn_dirs(pos, sides) - local tbl = {} - local node = minetest.get_node(pos) - if type(sides) == "function" then - tbl = sides(pos, node) - else - for _,side in ipairs(sides) do - tbl[#tbl+1] = tubelib2.Turn180Deg[side_to_dir(node.param2, side)] - end - end - M(pos):set_string("power_dirs", minetest.serialize(tbl)) -end - -techage.power.side_to_dir = side_to_dir -techage.power.set_conn_dirs = set_conn_dirs - -local function valid_indir(pos, in_dir) - local s = M(pos):get_string("power_dirs") - if s == "" then - local pwr = PWR(pos) - if pwr then - set_conn_dirs(pos, pwr.conn_sides) - end - end - if s ~= "" then - for _,dir in ipairs(minetest.deserialize(s)) do - if dir == in_dir then - return true - end - end - end - return false -end - -local function valid_outdir(pos, out_dir) - return valid_indir(pos, tubelib2.Turn180Deg[out_dir]) -end - --- Both nodes are from the same power network type? -local function matching_nodes(pos, peer_pos) - local tube_type1 = pos and PWR(pos) and PWR(pos).power_network.tube_type - local tube_type2 = peer_pos and PWR(peer_pos) and PWR(peer_pos).power_network.tube_type - return not tube_type1 or not tube_type2 or tube_type1 == tube_type2 -end - -function techage.get_pos(pos, side) - local node = techage.get_node_lvm(pos) - local dir = nil - if node.name ~= "air" and node.name ~= "ignore" then - dir = side_to_dir(node.param2, side) - end - return tubelib2.get_pos(pos, dir) -end - --- only for nodes with own 'conn_sides' and rotate function -function techage.power.after_rotate_node(pos, cable) - cable:after_dig_node(pos) - set_conn_dirs(pos, PWR(pos).conn_sides) - cable:after_place_node(pos) -end - -local function add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, power) - mem.connections = mem.connections or {} - if not peer_pos or not valid_indir(peer_pos, peer_in_dir) - or not valid_outdir(pos, out_dir) - or not matching_nodes(pos, peer_pos) then - mem.connections[out_dir] = nil -- del connection - else - mem.connections[out_dir] = {pos = peer_pos, in_dir = peer_in_dir} - end - -- update network for power scheduling - techage.power.network_changed(pos, mem) -end - -function techage.power.register_node(names, pwr_def) - for _,name in ipairs(names) do - local ndef = minetest.registered_nodes[name] - if ndef then - minetest.override_item(name, { - power = { - conn_sides = pwr_def.conn_sides or {"L", "R", "U", "D", "F", "B"}, - on_power = pwr_def.on_power, - on_nopower = pwr_def.on_nopower, - on_getpower = pwr_def.on_getpower, - power_network = pwr_def.power_network, - after_place_node = pwr_def.after_place_node, - after_dig_node = pwr_def.after_dig_node, - after_tube_update = pwr_def.after_tube_update, - }, - -- after_place_node decorator - after_place_node = function(pos, placer, itemstack, pointed_thing) - local res - local pwr = PWR(pos) - set_conn_dirs(pos, pwr.conn_sides) - if pwr.after_place_node then - res = pwr.after_place_node(pos, placer, itemstack, pointed_thing) - end - pwr.power_network:after_place_node(pos) - return res - end, - -- after_dig_node decorator - after_dig_node = function(pos, oldnode, oldmetadata, digger) - local pwr = PWRN(oldnode) - pwr.power_network:after_dig_node(pos) - minetest.after(0.1, tubelib2.del_mem, pos) -- At latest... - if pwr.after_dig_node then - return pwr.after_dig_node(pos, oldnode, oldmetadata, digger) - end - end, - -- tubelib2->Cable:register_on_tube_update callback, called after any connection change - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - local pwr = PWR(pos) - local mem = tubelib2.get_mem(pos) - add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, pwr) - if pwr.after_tube_update then - return pwr.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) - end - end, - }) - pwr_def.power_network:add_secondary_node_names({name}) - end - end -end - - --- --- API function set for nodes, which don't (what to) call techage.power.register_node() --- -function techage.power.enrich_node(names, pwr_def) - for _,name in ipairs(names) do - minetest.override_item(name, { - power = { - conn_sides = pwr_def.conn_sides or {"L", "R", "U", "D", "F", "B"}, - on_power = pwr_def.on_power, - on_nopower = pwr_def.on_nopower, - on_getpower = pwr_def.on_getpower, - power_network = pwr_def.power_network, - } - }) - pwr_def.power_network:add_secondary_node_names({name}) - end -end - -function techage.power.after_place_node(pos) - local pwr = PWR(pos) - set_conn_dirs(pos, pwr.conn_sides) - pwr.power_network:after_place_node(pos) -end - -function techage.power.after_dig_node(pos, oldnode) - local pwr = PWRN(oldnode) - pwr.power_network:after_dig_node(pos) -end - -function techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) - local pwr = PWR(pos) - local mem = tubelib2.get_mem(pos) - add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, pwr) -end - --- --- Further helper functions --- - --- Called from tubelib2 via Cable:register_on_tube_update() --- For all kind of nodes, used as cable filler/grout -function techage.power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir, power) - local mem = tubelib2.get_mem(pos) - add_connection(mem, pos, out_dir, peer_pos, peer_in_dir, power) - if power.after_tube_update then - return power.after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) - end -end - -function techage.power.percent(max_val, curr_val) - return math.min(math.ceil(((curr_val or 0) * 100.0) / (max_val or 1.0)), 100) -end - -function techage.power.formspec_load_bar(charging, max_val) - local percent - charging = charging or 0 - max_val = max_val or 1 - if charging ~= 0 then - percent = 50 + math.ceil((charging * 50.0) / max_val) - end - - if charging > 0 then - return "techage_form_level_off.png^[lowpart:"..percent..":techage_form_level_charge.png" - elseif charging < 0 then - return "techage_form_level_unload.png^[lowpart:"..percent..":techage_form_level_off.png" - else - return "techage_form_level_off.png" - end -end - -function techage.power.formspec_power_bar(max_power, current_power) - if (current_power or 0) == 0 then - return "techage_form_level_bg.png" - end - local percent = techage.power.percent(max_power, current_power) - percent = (percent + 5) / 1.22 -- texture correction - return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png" -end - - -function techage.power.side_to_outdir(pos, side) - local node = techage.get_node_lvm(pos) - return side_to_dir(node.param2, side) -end - --- Used to turn on/off the power by means of a power switch -function techage.power.power_cut(pos, dir, cable, cut) - local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0]) - - local node = techage.get_node_lvm(npos) - if node.name ~= "techage:powerswitch_box" and - M(npos):get_string("techage_hidden_nodename") ~= "techage:powerswitch_box" then - return - end - - local mem = tubelib2.get_mem(npos) - mem.interrupted_dirs = mem.interrupted_dirs or {} - - if cut then - mem.interrupted_dirs = {true, true, true, true, true, true} - for dir,_ in pairs(mem.connections) do - mem.interrupted_dirs[dir] = false -- open the port - techage.power.network_changed(npos, mem) - mem.interrupted_dirs[dir] = true - end - else - mem.interrupted_dirs = {} - techage.power.network_changed(npos, mem) - end -end - diff --git a/power/power_line.lua b/power/power_line.lua index 248c7b0..ae14588 100644 --- a/power/power_line.lua +++ b/power/power_line.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -16,7 +16,9 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S +local networks = techage.networks local Cable = techage.ElectricCable +local power = techage.power -- Primary techage.ElectricCable node minetest.register_node("techage:power_line", { @@ -162,81 +164,6 @@ minetest.register_node("techage:power_lineA", { sounds = default.node_sound_defaults(), }) -minetest.register_node("techage:power_pole", { - description = S("TA Power Pole Top (for up to 6 connections)"), - tiles = { - "default_wood.png^techage_power_pole_top.png", - "default_wood.png^techage_power_pole_top.png", - "default_wood.png^techage_power_pole.png" - }, - - paramtype2 = "facedir", -- important! - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}, - {-16/32, -6/32, -1/32, 16/32, -4/32, 1/32}, - { -1/32, -6/32, -16/32, 1/32, -4/32, 16/32}, - {-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}, - { 12/32, -4/32, -2/32, 16/32, 4/32, 2/32}, - { -2/32, -4/32, -16/32, 2/32, 4/32, -12/32}, - { -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, - }, - }, - - on_rotate = screwdriver.disallow, -- important! - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky=2, crumbly=2, choppy=2}, -}) - -minetest.register_node("techage:power_pole_conn", { - description = "TA Power Pole Top (for up to 6 connections)", - tiles = { - "default_wood.png^techage_power_pole_top.png", - "default_wood.png^techage_power_pole_top.png", - "default_wood.png^techage_power_pole.png" - }, - - paramtype2 = "facedir", -- important! - drawtype = "nodebox", - node_box = { - type = "connected", - fixed = {{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}}, - - connect_left = {{-16/32, -6/32, -1/32, 1/32, -4/32, 1/32}, - {-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}}, - connect_right = {{ -1/32, -6/32, -1/32, 16/32, -4/32, 1/32}, - {12/32, -4/32, -2/32, 16/32, 4/32, 2/32}}, - connect_back = {{-1/32, -6/32, -1/32, 1/32, -4/32, 16/32}, - {-2/32, -4/32, 12/32, 2/32, 4/32, 16/32}}, - connect_front = {{-1/32, -6/32, -16/32, 1/32, -4/32, 1/32}, - {-2/32, -4/32, -16/32, 2/32, 4/32, -12/32}}, - }, - connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"}, - - can_dig = function(pos, digger) - local meta = minetest.get_meta(pos) - if meta:get_string("owner") == digger:get_player_name() then - return true - end - if minetest.check_player_privs(digger:get_player_name(), "powerline") then - return true - end - return false - end, - - drop = "techage:power_pole", - on_rotate = screwdriver.disallow, -- important! - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1}, - sounds = default.node_sound_defaults(), -}) - minetest.register_node("techage:power_pole2", { description = S("TA Power Pole Top 2 (for landlines)"), tiles = { @@ -256,8 +183,6 @@ minetest.register_node("techage:power_pole2", { { -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, }, }, - after_place_node = function(pos, placer, itemstack, pointed_thing) - end, after_place_node = function(pos, placer, itemstack, pointed_thing) M(pos):set_string("owner", placer:get_player_name()) @@ -296,9 +221,113 @@ minetest.register_node("techage:power_pole2", { sounds = default.node_sound_defaults(), }) +-- dummy node for the inventory and to be placed and imediately replaced +minetest.register_node("techage:power_pole", { + description = S("TA Power Pole Top (for up to 6 connections)"), + tiles = { + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole.png" + }, + + paramtype2 = "facedir", -- important! + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}, + {-16/32, -6/32, -1/32, 16/32, -4/32, 1/32}, + { -1/32, -6/32, -16/32, 1/32, -4/32, 16/32}, + {-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}, + { 12/32, -4/32, -2/32, 16/32, 4/32, 2/32}, + { -2/32, -4/32, -16/32, 2/32, 4/32, -12/32}, + { -2/32, -4/32, 12/32, 2/32, 4/32, 16/32}, + }, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + M(pos):set_string("owner", placer:get_player_name()) + if techage.is_protected(pos, placer:get_player_name()) then + minetest.remove_node(pos) + return true + end + local node = minetest.get_node(pos) + node.name = "techage:power_pole_conn" + minetest.swap_node(pos, node) + Cable:after_place_node(pos) + end, + + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky=2, crumbly=2, choppy=2}, +}) + + +-- secondary node like a junction +minetest.register_node("techage:power_pole_conn", { + description = "TA Power Pole Top (for up to 6 connections)", + tiles = { + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole_top.png", + "default_wood.png^techage_power_pole.png" + }, + + paramtype2 = "facedir", -- important! + drawtype = "nodebox", + node_box = { + type = "connected", + fixed = {{ -4/32, -16/32, -4/32, 4/32, 16/32, 4/32}}, + + connect_left = {{-16/32, -6/32, -1/32, 1/32, -4/32, 1/32}, + {-16/32, -4/32, -2/32, -12/32, 4/32, 2/32}}, + connect_right = {{ -1/32, -6/32, -1/32, 16/32, -4/32, 1/32}, + {12/32, -4/32, -2/32, 16/32, 4/32, 2/32}}, + connect_back = {{-1/32, -6/32, -1/32, 1/32, -4/32, 16/32}, + {-2/32, -4/32, 12/32, 2/32, 4/32, 16/32}}, + connect_front = {{-1/32, -6/32, -16/32, 1/32, -4/32, 1/32}, + {-2/32, -4/32, -16/32, 2/32, 4/32, -12/32}}, + }, + connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"}, + + tubelib2_on_update2 = function(pos, dir1, tlib2, node) + power.update_network(pos, nil, tlib2) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Cable:after_dig_node(pos) + end, + can_dig = function(pos, digger) + local meta = minetest.get_meta(pos) + if meta:get_string("owner") == digger:get_player_name() then + return true + end + if minetest.check_player_privs(digger:get_player_name(), "powerline") then + return true + end + return false + end, + networks = { + ele1 = { + sides = networks.AllSides, -- connection sides for cables + ntype = "junc", + }, + }, + + drop = "techage:power_pole", + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1}, + sounds = default.node_sound_defaults(), +}) + +Cable:add_secondary_node_names({"techage:power_pole_conn"}) + + minetest.register_node("techage:power_pole3", { description = S("TA Power Pole"), - --tiles = {"techage_power_pole.png"}, tiles = { "default_wood.png", "default_wood.png", @@ -321,24 +350,6 @@ minetest.register_node("techage:power_pole3", { sounds = default.node_sound_defaults(), }) -techage.power.register_node({"techage:power_pole"}, { - power_network = Cable, - after_place_node = function(pos, placer, itemstack, pointed_thing) - M(pos):set_string("owner", placer:get_player_name()) - if techage.is_protected(pos, placer:get_player_name()) then - minetest.remove_node(pos) - return true - end - local node = minetest.get_node(pos) - node.name = "techage:power_pole_conn" - minetest.swap_node(pos, node) - end, -}) - -techage.power.register_node({"techage:power_pole_conn"}, { - power_network = Cable, -}) - minetest.register_craft({ output = "techage:power_lineS 24", recipe = { diff --git a/power/powerswitch.lua b/power/powerswitch.lua deleted file mode 100644 index b3f6433..0000000 --- a/power/powerswitch.lua +++ /dev/null @@ -1,323 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA3 Power Switch (large and small) - -]]-- - --- for lazy programmers -local P = minetest.string_to_pos -local M = minetest.get_meta -local S = techage.S - - -local Cable = techage.ElectricCable -local power_cut = techage.power.power_cut -local after_rotate_node = techage.power.after_rotate_node - -local Param2ToDir = { - [0] = 6, - [1] = 5, - [2] = 2, - [3] = 4, - [4] = 1, - [5] = 3, -} - -local function switch_on(pos, node, clicker, name) - if clicker and minetest.is_protected(pos, clicker:get_player_name()) then - return - end - node.name = name - minetest.swap_node(pos, node) - minetest.sound_play("techage_button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local dir = Param2ToDir[node.param2] - power_cut(pos, dir, Cable, false) -end - -local function switch_off(pos, node, clicker, name) - if clicker and minetest.is_protected(pos, clicker:get_player_name()) then - return - end - node.name = name - minetest.swap_node(pos, node) - minetest.get_node_timer(pos):stop() - minetest.sound_play("techage_button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5, - }) - local dir = Param2ToDir[node.param2] - power_cut(pos, dir, Cable, true) -end - - -minetest.register_node("techage:powerswitch", { - description = S("TA Power Switch"), - inventory_image = "techage_appl_switch_inv.png", - tiles = { - 'techage_appl_switch_off.png', - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -1/4, -8/16, -1/4, 1/4, -7/16, 1/4}, - { -1/6, -12/16, -1/6, 1/6, -8/16, 1/6}, - }, - }, - - after_place_node = function(pos, placer) - local meta = M(pos) - local number = techage.add_node(pos, "techage:powerswitch") - meta:set_string("node_number", number) - meta:set_string("owner", placer:get_player_name()) - meta:set_string("infotext", S("TA Power Switch").." "..number) - end, - - on_rightclick = function(pos, node, clicker) - switch_on(pos, node, clicker, "techage:powerswitch_on") - end, - - on_rotate = screwdriver.disallow, - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "wallmounted", - groups = {choppy=2, cracky=2, crumbly=2}, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - - -minetest.register_node("techage:powerswitch_on", { - description = S("TA Power Switch"), - inventory_image = "techage_appl_switch_inv.png", - tiles = { - 'techage_appl_switch_on.png', - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -1/4, -8/16, -1/4, 1/4, -7/16, 1/4}, - { -1/6, -12/16, -1/6, 1/6, -8/16, 1/6}, - }, - }, - - on_rightclick = function(pos, node, clicker) - switch_off(pos, node, clicker, "techage:powerswitch") - end, - - drop = "techage:powerswitch", - on_rotate = screwdriver.disallow, - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "wallmounted", - groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1}, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - -minetest.register_node("techage:powerswitchsmall", { - description = S("TA Power Switch Small"), - inventory_image = "techage_smart_button_inventory.png", - tiles = { - 'techage_smart_button_off.png', - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -5/32, -16/32, -5/32, 5/32, -15/32, 5/32}, - { -2/16, -12/16, -2/16, 2/16, -8/16, 2/16}, - }, - }, - - after_place_node = function(pos, placer) - local meta = M(pos) - local number = techage.add_node(pos, "techage:powerswitchsmall") - meta:set_string("node_number", number) - meta:set_string("owner", placer:get_player_name()) - meta:set_string("infotext", S("TA Power Switch Small").." "..number) - end, - - on_rightclick = function(pos, node, clicker) - switch_on(pos, node, clicker, "techage:powerswitchsmall_on") - end, - - on_rotate = screwdriver.disallow, - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "wallmounted", - groups = {choppy=2, cracky=2, crumbly=2}, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - - -minetest.register_node("techage:powerswitchsmall_on", { - description = S("TA Power Switch Small"), - inventory_image = "techage_appl_switch_inv.png", - tiles = { - 'techage_smart_button_on.png', - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -5/32, -16/32, -5/32, 5/32, -15/32, 5/32}, - { -2/16, -12/16, -2/16, 2/16, -8/16, 2/16}, - }, - }, - - on_rightclick = function(pos, node, clicker) - switch_off(pos, node, clicker, "techage:powerswitchsmall") - end, - - drop = "techage:powerswitchsmall", - on_rotate = screwdriver.disallow, - paramtype = "light", - sunlight_propagates = true, - paramtype2 = "wallmounted", - groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory = 1}, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - - -local function get_conn_dirs(pos, node) - local tbl = {[0]= - {2,4}, {1,3}, {2,4}, {1,3}, - {2,4}, {5,6}, {2,4}, {5,6}, - {2,4}, {5,6}, {2,4}, {5,6}, - {5,6}, {1,3}, {5,6}, {1,3}, - {5,6}, {1,3}, {5,6}, {1,3}, - {2,4}, {1,3}, {2,4}, {1,3}, - } - return tbl[node.param2] -end - -local function on_place(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then - return itemstack - end - return minetest.rotate_and_place(itemstack, placer, pointed_thing) -end - -local function on_rotate(pos, node, user, mode, new_param2) - if minetest.is_protected(pos, user:get_player_name()) then - return false - end - node.param2 = techage.rotate_wallmounted(node.param2) - minetest.swap_node(pos, node) - after_rotate_node(pos, Cable) - return true -end - -minetest.register_node("techage:powerswitch_box", { - description = S("TA Power Switch Box"), - tiles = { - -- up, down, right, left, back, front - 'techage_electric_switch.png', - 'techage_electric_switch.png', - 'techage_electric_junction.png', - 'techage_electric_junction.png', - 'techage_electric_switch.png', - 'techage_electric_switch.png', - }, - - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -2/4, -1/4, -1/4, 2/4, 1/4, 1/4}, - }, - }, - - paramtype = "light", - sunlight_propagates = true, - on_place = on_place, - on_rotate = on_rotate, - paramtype2 = "facedir", - groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1}, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - -techage.power.register_node({"techage:powerswitch_box"}, { - power_network = Cable, - conn_sides = get_conn_dirs, -}) - -techage.register_node({"techage:powerswitch", "techage:powerswitch_on"}, { - on_recv_message = function(pos, src, topic, payload) - local node = techage.get_node_lvm(pos) - if topic == "on" and node.name == "techage:powerswitch" then - switch_on(pos, node, nil, "techage:powerswitch_on") - return true - elseif topic == "on" and node.name == "techage:powerswitchsmall" then - switch_on(pos, node, nil, "techage:powerswitchsmall_on") - return true - elseif topic == "off" and node.name == "techage:powerswitch_on" then - switch_off(pos, node, nil, "techage:powerswitch") - return true - elseif topic == "off" and node.name == "techage:powerswitchsmall_on" then - switch_off(pos, node, nil, "techage:powerswitchsmall") - return true - elseif topic == "state" then - if node.name == "techage:powerswitch_on" or node.name == "techage:powerswitchsmall_on"then - return "on" - end - return "off" - else - return "unsupported" - end - end, - on_node_load = function(pos) - local meta = M(pos) - local number = meta:get_string("number") or "" - if number ~= "" then - meta:set_string("node_number", number) - meta:set_string("number", nil) - end - end, -}) - -minetest.register_craft({ - output = "techage:powerswitch 2", - recipe = { - {"", "", ""}, - {"dye:yellow", "dye:red", "dye:yellow"}, - {"basic_materials:plastic_sheet", "basic_materials:copper_wire", "basic_materials:plastic_sheet"}, - }, -}) - -minetest.register_craft({ - type = "shapeless", - output = "techage:powerswitchsmall", - recipe = {"techage:powerswitch"}, -}) - -minetest.register_craft({ - output = "techage:powerswitch_box", - recipe = { - {"", "basic_materials:plastic_sheet", ""}, - {"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"}, - {"", "basic_materials:plastic_sheet", ""}, - }, -}) diff --git a/power/schedule.lua b/power/schedule.lua index b399264..d08d145 100644 --- a/power/schedule.lua +++ b/power/schedule.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -18,70 +18,64 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local M = minetest.get_meta local N = function(pos) return minetest.get_node(pos).name end -local CYCLE_TIME = 2.0 +local power = techage.power +local networks = techage.networks + +local CYCLE_TIME = 2 techage.schedule = {} -local NetList = {} +local JobTable = {} local JobQueue = {} local first = 0 local last = -1 -local LocalTime = 0 + +techage.SystemTime = 0 local function push(item) last = last + 1 - item.time = LocalTime + CYCLE_TIME + item.time = techage.SystemTime + CYCLE_TIME JobQueue[last] = item end local function pop() if first > last then return end local item = JobQueue[first] - if item.time <= LocalTime then + if item.time <= techage.SystemTime then JobQueue[first] = nil -- to allow garbage collection first = first + 1 return item end end +local function power_distribution(network, tlib_type) + local t = minetest.get_us_time() + power.power_distribution(network, tlib_type, techage.SystemTime) + t = minetest.get_us_time() - t + --print("t = "..t..", #jobs = "..(last + 1 - first)) +end + -- Scheduler minetest.register_globalstep(function(dtime) - LocalTime = LocalTime + dtime + techage.SystemTime = techage.SystemTime + dtime local item = pop() while item do - local network = NetList[item.netkey] + local network = networks.get_network(item.tube_type, item.netID) if network and network.alive and network.alive >= 0 then - --techage.distribute.power_distribution(LocalTime, network) - techage.power.power_distribution(LocalTime, network.mst_pos, network) + power_distribution(network, item.tube_type) network.alive = network.alive - 1 push(item) else - NetList[item.netkey] = nil + JobTable[item.netID] = nil + networks.delete_network(item.tube_type, item.netID) end item = pop() end end) -function techage.schedule.add_network(netkey, network) - if netkey then - if NetList[netkey] then -- already scheduled - NetList[netkey] = network - else - NetList[netkey] = network - push({netkey = netkey}) - end - return NetList[netkey] - end -end - -function techage.schedule.has_network(netkey) - if netkey then - return NetList[netkey] ~= nil - end -end - -function techage.schedule.get_network(netkey) - if netkey then - return NetList[netkey] +function techage.schedule.start(tube_type, netID) + if not JobTable[netID] then + push({tube_type = tube_type, netID = netID}) + JobTable[netID] = true end end diff --git a/power/steam_pipe.lua b/power/steam_pipe.lua index e491abf..6d92845 100644 --- a/power/steam_pipe.lua +++ b/power/steam_pipe.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -22,7 +22,7 @@ local Pipe = tubelib2.Tube:new({ max_tube_length = 12, show_infotext = false, force_to_use_tubes = true, - tube_type = "steam_pipe", + tube_type = "pipe1", primary_node_names = {"techage:steam_pipeS", "techage:steam_pipeA"}, secondary_node_names = {"techage:cylinder", "techage:cylinder_on", "techage:boiler2"}, after_place_tube = function(pos, param2, tube_type, num_tubes) @@ -30,13 +30,6 @@ local Pipe = tubelib2.Tube:new({ end, }) -Pipe:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) - minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) -end) - -techage.SteamPipe = Pipe - - minetest.register_node("techage:steam_pipeS", { description = S("TA2 Steam Pipe"), tiles = { @@ -57,7 +50,7 @@ minetest.register_node("techage:steam_pipeS", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - Pipe:after_dig_tube(pos, oldnode) + Pipe:after_dig_tube(pos, oldnode, oldmetadata) end, paramtype2 = "facedir", -- important! @@ -88,7 +81,7 @@ minetest.register_node("techage:steam_pipeA", { }, after_dig_node = function(pos, oldnode, oldmetadata, digger) - Pipe:after_dig_tube(pos, oldnode) + Pipe:after_dig_tube(pos, oldnode, oldmetadata) end, paramtype2 = "facedir", -- important! @@ -117,3 +110,5 @@ minetest.register_craft({ {"default:bronze_ingot", '', ''}, }, }) + +techage.SteamPipe = Pipe diff --git a/power/ta4_cable.lua b/power/ta4_cable.lua deleted file mode 100644 index 57df374..0000000 --- a/power/ta4_cable.lua +++ /dev/null @@ -1,170 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA4 Low Power Cable for solar plants - -]]-- - --- for lazy programmers -local S2P = minetest.string_to_pos -local P2S = minetest.pos_to_string -local M = minetest.get_meta -local S = techage.S - -local Cable = tubelib2.Tube:new({ - dirs_to_check = {1,2,3,4,5,6}, - max_tube_length = 200, - show_infotext = false, - tube_type = "ta4_power_cable", - primary_node_names = {"techage:ta4_power_cableS", "techage:ta4_power_cableA"}, - secondary_node_names = {}, - after_place_tube = function(pos, param2, tube_type, num_tubes) - minetest.swap_node(pos, {name = "techage:ta4_power_cable"..tube_type, param2 = param2}) - end, -}) - -Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) - local ndef = minetest.registered_nodes[node.name] - if ndef and ndef.after_tube_update then - minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) - end -end) - -techage.TA4_Cable = Cable - -minetest.register_node("techage:ta4_power_cableS", { - description = S("TA4 Low Power Cable"), - tiles = { - -- up, down, right, left, back, front - "techage_ta4_cable.png", - "techage_ta4_cable.png", - "techage_ta4_cable.png", - "techage_ta4_cable.png", - "techage_ta4_cable_end.png", - "techage_ta4_cable_end.png", - }, - - after_place_node = function(pos, placer, itemstack, pointed_thing) - if not Cable:after_place_tube(pos, placer, pointed_thing) then - minetest.remove_node(pos) - return true - end - return false - end, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - Cable:after_dig_tube(pos, oldnode) - end, - - paramtype2 = "facedir", -- important! - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-1/16, -1/16, -4/8, 1/16, 1/16, 4/8}, - }, - }, - on_rotate = screwdriver.disallow, -- important! - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3}, - sounds = default.node_sound_defaults(), -}) - -minetest.register_node("techage:ta4_power_cableA", { - description = S("TA4 Low Power Cable"), - tiles = { - -- up, down, right, left, back, front - "techage_ta4_cable.png", - "techage_ta4_cable_end.png", - "techage_ta4_cable.png", - "techage_ta4_cable.png", - "techage_ta4_cable.png", - "techage_ta4_cable_end.png", - }, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - Cable:after_dig_tube(pos, oldnode) - end, - - paramtype2 = "facedir", -- important! - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-1/16, -4/8, -1/16, 1/16, 1/16, 1/16}, - {-1/16, -1/16, -4/8, 1/16, 1/16, -1/16}, - }, - }, - on_rotate = screwdriver.disallow, -- important! - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1}, - sounds = default.node_sound_defaults(), - drop = "techage:ta4_power_cableS", -}) - -minetest.register_node("techage:ta4_power_box", { - description = S("TA4 Low Power Box"), - tiles = { - "techage_ta4_junctionbox_top.png", - "techage_ta4_junctionbox_top.png", - "techage_ta4_junctionbox_side.png^techage_appl_ta4_cable.png", - }, - - paramtype2 = "facedir", -- important! - drawtype = "nodebox", - node_box = { - type = "connected", - fixed = { - { -3/16, -3/16, -3/16, 3/16, 3/16, 3/16}, -- box - { -1/16, -7/16, -1/16, 1/16, -4/16, 1/16}, -- post - { -3/16, -8/16, -3/16, 3/16, -7/16, 3/16}, -- base - }, - - connect_left = {{ -1/2, -1/16, -1/16, 0, 1/16, 1/16}}, - connect_right = {{ 0, -1/16, -1/16, 1/2, 1/16, 1/16}}, - connect_back = {{-1/16, -1/16, 0, 1/16, 1/16, 1/2}}, - connect_front = {{-1/16, -1/16, -1/2, 1/16, 1/16, 0}}, - }, - connects_to = {"techage:ta4_power_cableA", "techage:ta4_power_cableS"}, - - on_rotate = screwdriver.disallow, -- important! - paramtype = "light", - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky=2, crumbly=2, choppy=2}, - sounds = default.node_sound_defaults(), -}) - -techage.power.register_node({"techage:ta4_power_box"}, { - power_network = Cable, - conn_sides ={"L", "R", "F", "B"}, -}) - - -minetest.register_craft({ - output = "techage:ta4_power_cableS 8", - recipe = { - {"basic_materials:plastic_sheet", "dye:red", ""}, - {"", "default:copper_ingot", ""}, - {"", "dye:red", "basic_materials:plastic_sheet"}, - }, -}) - -minetest.register_craft({ - output = "techage:ta4_power_box 2", - recipe = { - {"techage:ta4_power_cableS", "basic_materials:plastic_sheet", "techage:ta4_power_cableS"}, - {"basic_materials:plastic_sheet", "default:copper_ingot", "basic_materials:plastic_sheet"}, - {"techage:ta4_power_cableS", "basic_materials:plastic_sheet", "techage:ta4_power_cableS"}, - },}) diff --git a/sounds/techage_turbine.ogg b/sounds/techage_turbine.ogg index 2f2c70d7834f0244b48ac7a67eadf1a69dbb06c7..37dcce5850eabf2bf86ae8aad3a4df06e1871604 100644 GIT binary patch delta 5985 zcmV-n7oO;+f3`{*PiJRS00IC200000007y=-53A>007MAXV8%vE)3bl-53D?001>p zD4elW;|+h=#oZVJ0001C-&Ii|ARmr{e~W^OgnWR4gM^2FeuRjHhl7B6frop3fP{gD ze_Z1S?0vv`0I;l=v@Gy1OvhE;XZ!Aom7PcWy_!k|0Bqxn2>a7Tpk=haGfI3ZzKAPw zWsP#%{XVX$Z#Q5Vdh3quXr#9b%>ehw087zf$|8T%ir(v$$PS(SC)I0aXf{3gN9n_4 zUc7oVu0xhXdHl=P=ZCW`B&wdtA~tKTLgzSt89M)IIuCe z2H(@y^9w&mY{sE0W;KbNYie$!hnR!iIk^$}uTm57o5wbg}QH4Hl z7Bgq>XPj^Kdi=Kwaa-3_#fV5XH9PlXHLI!fvBll$o%16zyXPk&l|nl4pWD2zRC^t@ zDPDWEFIjrvC@VpG=R|*xG4FMd;7IawAb4pw>PbUMzMMIfHi;{&ksH9P0I1GC%#?os z{)=vIZnPiWrU}8pcrVP)SwrnumK2GMP{g~r>DQ?HOyT{#;?4c$Ir^GyBZxwi9amVG zj(e7!a4Ylx+13!N_bc`h@IGpmS=c*(CKAc|S66LTVfzu_=KH9aU z%-WcQS*Yu$j~)5g^clW>Zl;4`WOiY5xZAP%jkCRTCtAct3^y6;c||UpdQo~y+LxF^ zg0dYL>{zji4thIsn)3{77`h%yxZ9_N5yBu9Ilo%35|jzCr-m5@KWwCXUQd54&@dU` za%d{Vx=84_KL-UqjBa%g>wqSiaem&}Je`Xr770KtmV%KgBtnwWd(G(ns-|bkt>5U1 zr4cWgzS7ml(KLF>zhLrAZHa}Xf*xN7t%)X*k4ktjiI=3NciEeqdF>1PB@ZfU0RUK%Br24;R}Trj zrPZZ<&ue0WS_4&PoSs$!yE7vUwq~#b#gjsz9R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Xnr;Jo@oBFjdrN%LA34$*gH)11Yzxo`k$nv%^+ld|kKIuZ&3B&K(zw zbj%ZM24K+mK0l%{iV?XQ$CwF`n7{_casLHCcsl_8n{IBOMIBma2u3(xOHa-T49k)v zs8H5s+PP=lZ}qm;*}HVPzFhalshAnS=85J#u^4~5%}P=s?0a3sxq7 zU9*e}UBt%A*>`MBTFuBKqz_)dhzq z+L$guy|d5&&~*t%g+#%7Q_eFxBhUPZ60Cn_)mR#;YrOBC%LB#Nr~6K;ecvJ}&Zvt{ z$|N zzH`30eW%!|&%eh8t=)SmGkjRs1v{wAL}Bg*LP)s^d>>{;Nnp>c=j>$r8WxRD%1YJ; zv5?4oRk!9gTpu8L=^}_y7xAPd#of6Ic8ka|1N9j5scRk7j z{yU!Q8tQ@}8oLF5H>+OTcoGxlH z$HCuPmwAiJ(PjNEowwZQl_FRi#*I-msHzJ;ElYV)>&*(Ub79_(I~USQ>JR!nMU z=^J-L*3jX!!Ff599mi$n+ zsbO@hELqXcQ~;itt$K;aWYd3uTYd2Usm{zn9Y9gLXp$?oFd0w z7N@ZGQs<2NyYpJ@UTit?81%wRIY9Ac?fG4SWzk2l+oqxC>{5>Hl2gK~*ZK;{!sR(> zwo+3;xh=uOi1$zioZWu-(?5_b#XvX#_H^elBrwNH9WVqw$o<;KyEszuq;@7n#x?f>z2g~bnytQX#SA(admRzhnOHwRh Z?X`3O%U#K--DS61xgBjl0u%s9BmkH=8TSAH diff --git a/steam_engine/boiler.lua b/steam_engine/boiler.lua index 172a56e..d971381 100644 --- a/steam_engine/boiler.lua +++ b/steam_engine/boiler.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -13,202 +13,91 @@ ]]-- -- for lazy programmers -local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S local CYCLE_TIME = 4 -local STANDBY_TICKS = 2 -local COUNTDOWN_TICKS = 2 -local HEAT_STEP = 10 local WATER_CONSUMPTION = 0.5 -local MAX_WATER = 10 local Pipe = techage.SteamPipe +local boiler = techage.boiler -local Water = { - ["bucket:bucket_river_water"] = true, - ["bucket:bucket_water"] = true, - ["bucket:bucket_empty"] = true, -} - -local function formspec(self, pos, mem) - local temp = mem.temperature or 20 - local ratio = mem.power_ratio or 0 - return "size[8,7]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "image_button[0,0.2;1,1;techage_form_inventory.png;storage;;true;false;]".. - "list[context;water;1,0.2;1,1;]".. - "image_button[0,1.6;1,1;techage_form_input.png;input;;true;false;]".. - "list[context;input;1,1.6;1,1;]".. - "image[1,1.6;1,1;bucket_water.png]".. - "image[1,1.6;1,1;techage_form_mask.png]".. - "image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:".. - temp..":techage_form_temp_fg.png]".. - "image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]".. - "image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[3,1.5;2,1;update;"..S("Update").."]".. - "list[current_player;main;0,3;8,4;]".. - "listring[current_name;water]".. - "listring[current_player;main]".. - default.get_hotbar_bg(0, 3) -end - -local function can_start(pos, mem, state) - return mem.temperature and mem.temperature > 80 -end - -local function start_node(pos, mem, state) - mem.running = true - mem.power_ratio = 0 -end - -local function stop_node(pos, mem, state) - mem.running = false - mem.power_ratio = 0 -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:boiler2", - cycle_time = CYCLE_TIME, - standby_ticks = STANDBY_TICKS, - has_item_meter = false, - formspec_func = formspec, - can_start = can_start, - start_node = start_node, - stop_node = stop_node, -}) - -local function get_water(pos) - local inv = M(pos):get_inventory() - local items = inv:get_stack("water", 1) - if items:get_count() > 0 then - local taken = items:take_item(1) - inv:set_stack("water", 1, items) - return true - end - return false -end - -local function water_temperature(pos, mem) - mem.temperature = mem.temperature or 20 - if mem.fire_trigger then - mem.temperature = math.min(mem.temperature + HEAT_STEP, 100) - else - mem.temperature = math.max(mem.temperature - HEAT_STEP, 20) - end - mem.fire_trigger = false - - if mem.water_level == 0 then - if get_water(pos) then - mem.water_level = 100 - else - mem.temperature = 20 - end - end - return mem.temperature -end - -local function steaming(pos, mem, temp) - local wc = WATER_CONSUMPTION * (mem.power_ratio or 1) - mem.water_level = math.max((mem.water_level or 0) - wc, 0) +local function steaming(pos, nvm, temp) if temp >= 80 then - if mem.running then - State:keep_running(pos, mem, COUNTDOWN_TICKS) - else - State:fault(pos, mem) - end - else - State:stop(pos, mem) - minetest.get_node_timer(pos):start(CYCLE_TIME) + local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1) + nvm.water_level = math.max((nvm.water_level or 0) - wc, 0) end end local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - local temp = water_temperature(pos, mem) - if State:is_active(mem) then - steaming(pos, mem, temp) + local nvm = techage.get_nvm(pos) + local temp = boiler.water_temperature(pos, nvm) + steaming(pos, nvm, temp) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", boiler.formspec(pos, nvm)) end - return mem.temperature > 20 + return temp > 20 end -local function on_receive_fields(pos, formname, fields, player) - if minetest.is_protected(pos, player:get_player_name()) then - return +local function after_place_node(pos) + local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) + if node.name == "techage:boiler1" then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", boiler.formspec(pos, nvm)) + Pipe:after_place_node(pos) end - local mem = tubelib2.get_mem(pos) - mem.temperature = mem.temperature or 20 - State:state_button_event(pos, mem, fields) +end + +local function after_dig_node(pos, oldnode) + Pipe:after_dig_node(pos) + techage.del_mem(pos) +end + +-- boiler2: Main part, needed as generator +minetest.register_node("techage:boiler2", { + description = S("TA2 Boiler Top"), + tiles = {"techage_boiler2.png"}, + drawtype = "mesh", + mesh = "techage_cylinder_09.obj", + selection_box = { + type = "fixed", + fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32}, + }, - if fields.update then - if mem.temperature > 20 then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end - M(pos):set_string("formspec", formspec(State, pos, mem)) - end -end - - -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) -end - -local function can_dig(pos, player) - local inv = M(pos):get_inventory() - local mem = tubelib2.get_mem(pos) - return inv:is_empty("input") and not mem.running -end - -local function move_to_water(pos) - local inv = M(pos):get_inventory() - local water_stack = inv:get_stack("water", 1) - local input_stack = inv:get_stack("input", 1) + can_dig = boiler.can_dig, + on_timer = node_timer, + on_rightclick = boiler.on_rightclick, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + on_punch = boiler.on_punch, - if input_stack:get_name() == "bucket:bucket_empty" then - if input_stack:get_count() == 1 then - if water_stack:get_count() > 0 then - water_stack:set_count(water_stack:get_count() - 1) - input_stack = ItemStack("bucket:bucket_water") - inv:set_stack("water", 1, water_stack) - inv:set_stack("input", 1, input_stack) + paramtype = "light", + groups = {cracky=1}, + on_rotate = screwdriver.disallow, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), +}) + +Pipe:add_secondary_node_names({"techage:boiler2"}) + +techage.register_node({"techage:boiler2"}, { + on_transfer = function(pos, in_dir, topic, payload) + if topic == "trigger" then + local nvm = techage.get_nvm(pos) + nvm.fire_trigger = true + if not minetest.get_node_timer(pos):is_started() then + minetest.get_node_timer(pos):start(CYCLE_TIME) + end + if (nvm.temperature or 20) > 80 then + nvm.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, { + "techage:cylinder", "techage:cylinder_on"}) or 0 + return nvm.power_ratio + else + return 0 end end - elseif water_stack:get_count() < MAX_WATER then - if water_stack:get_count() == 0 then - water_stack = ItemStack("default:water_source") - else - water_stack:set_count(water_stack:get_count() + 1) - end - input_stack = ItemStack("bucket:bucket_empty") - inv:set_stack("water", 1, water_stack) - inv:set_stack("input", 1, input_stack) - end -end - - -local function allow_metadata_inventory_put(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - if listname == "input" and Water[stack:get_name()] then - return stack:get_count() - end - return 0 -end - -local function allow_metadata_inventory_take(pos, listname, index, stack, player) - if minetest.is_protected(pos, player:get_player_name()) then - return 0 - end - if listname == "input" then - return stack:get_count() - end - return 0 -end + end, +}) minetest.register_node("techage:boiler1", { description = S("TA2 Boiler Base"), @@ -227,73 +116,7 @@ minetest.register_node("techage:boiler1", { sounds = default.node_sound_metal_defaults(), }) --- boiler2: Main part, needed as generator -minetest.register_node("techage:boiler2", { - description = S("TA2 Boiler Top"), - tiles = {"techage_boiler2.png"}, - drawtype = "mesh", - mesh = "techage_cylinder_09.obj", - selection_box = { - type = "fixed", - fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32}, - }, - - can_dig = can_dig, - on_timer = node_timer, - allow_metadata_inventory_put = allow_metadata_inventory_put, - allow_metadata_inventory_take = allow_metadata_inventory_take, - allow_metadata_inventory_move = function(pos) return 0 end, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - - on_construct = function(pos) - local inv = M(pos):get_inventory() - inv:set_size('water', 1) - inv:set_size('input', 1) - end, - - on_metadata_inventory_put = function(pos) - minetest.after(0.5, move_to_water, pos) - end, - - paramtype = "light", - groups = {cracky=1}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - sounds = default.node_sound_metal_defaults(), -}) -techage.power.register_node({"techage:boiler2"}, { - conn_sides = {"U"}, - power_network = Pipe, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State:node_init(pos, mem, "") - local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) - if node.name == "techage:boiler1" then - on_rightclick(pos) - end - end, -}) - -techage.register_node({"techage:boiler2"}, { - on_transfer = function(pos, in_dir, topic, payload) - if topic == "trigger" then - local mem = tubelib2.get_mem(pos) - mem.fire_trigger = true - if not minetest.get_node_timer(pos):is_started() then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end - if mem.running then - mem.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, { - "techage:cylinder", "techage:cylinder_on"}) or 0 - return mem.power_ratio - else - return 0 - end - end - end -}) minetest.register_craft({ output = "techage:boiler1", diff --git a/steam_engine/cylinder.lua b/steam_engine/cylinder.lua index ee5d10a..e31c0b4 100644 --- a/steam_engine/cylinder.lua +++ b/steam_engine/cylinder.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -13,12 +13,16 @@ ]]-- -- for lazy programmers -local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S local Pipe = techage.SteamPipe +local function transfer_flywheel(pos, topic, payload) + return techage.transfer(pos, "R", topic, payload, nil, + {"techage:flywheel", "techage:flywheel_on"}) +end + local function swap_node(pos, name) local node = techage.get_node_lvm(pos) if node.name == name then @@ -28,6 +32,41 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end +local function play_sound(pos) + local mem = techage.get_mem(pos) + mem.handle = minetest.sound_play("techage_steamengine", { + pos = pos, + gain = 0.5, + max_hear_distance = 10, + loop = true}) + if mem.handle == -1 then + minetest.after(1, play_sound, pos) + end +end + +local function stop_sound(pos) + local mem = techage.get_mem(pos) + if mem.handle then + minetest.sound_stop(mem.handle) + mem.handle = nil + end +end + +local function after_place_node(pos) + Pipe:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + stop_sound(pos) + Pipe:after_dig_node(pos) + techage.del_mem(pos) +end + +local function tubelib2_on_update2(pos, outdir, tlib2, node) + swap_node(pos, "techage:cylinder") + stop_sound(pos) +end + minetest.register_node("techage:cylinder", { description = S("TA2 Cylinder"), tiles = { @@ -40,6 +79,10 @@ minetest.register_node("techage:cylinder", { "techage_filling_ta2.png^techage_cylinder.png^techage_frame_ta2.png", }, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -77,6 +120,8 @@ minetest.register_node("techage:cylinder_on", { }, }, + tubelib2_on_update2 = tubelib2_on_update2, + paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, diggable = false, @@ -85,42 +130,38 @@ minetest.register_node("techage:cylinder_on", { sounds = default.node_sound_wood_defaults(), }) -techage.power.register_node({"techage:cylinder", "techage:cylinder_on"}, { - conn_sides = {"L"}, - power_network = Pipe, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - local mem = tubelib2.get_mem(pos) - mem.running = false - swap_node(pos, "techage:cylinder") - end, -}) +Pipe:add_secondary_node_names({"techage:cylinder", "techage:cylinder_on"}) --- used by firebox techage.register_node({"techage:cylinder", "techage:cylinder_on"}, { on_transfer = function(pos, in_dir, topic, payload) - local mem = tubelib2.get_mem(pos) - if topic == "trigger" then - local power = techage.transfer(pos, "R", "trigger", nil, nil, { - "techage:flywheel", "techage:flywheel_on"}) or 0 - - if not power then - return 0 - elseif power > 0 and not mem.running then - swap_node(pos, "techage:cylinder_on") - mem.running = true - return power - elseif power <= 0 and mem.running then + local nvm = techage.get_nvm(pos) + if topic == "trigger" then -- used by firebox + local power = transfer_flywheel(pos, topic, payload) + if not power or power <= 0 and nvm.running then swap_node(pos, "techage:cylinder") - mem.running = false + stop_sound(pos) + nvm.running = false return 0 - else - return power end - elseif topic == "stop" then + return power + elseif topic == "start" then -- used by flywheel + swap_node(pos, "techage:cylinder_on") + play_sound(pos) + nvm.running = true + return true + elseif topic == "stop" then -- used by flywheel swap_node(pos, "techage:cylinder") - mem.running = false + stop_sound(pos) + nvm.running = false + return true end - end + end, + on_node_load = function(pos, node) + --print("on_node_load", node.name) + if node.name == "techage:cylinder_on" then + play_sound(pos) + end + end, }) minetest.register_craft({ diff --git a/steam_engine/firebox.lua b/steam_engine/firebox.lua index 48c436d..a516828 100644 --- a/steam_engine/firebox.lua +++ b/steam_engine/firebox.lua @@ -23,8 +23,8 @@ local CYCLE_TIME = 2 local BURN_CYCLE_FACTOR = 0.8 local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.running then + local nvm = techage.get_nvm(pos) + if nvm.running then local power = techage.transfer( {x=pos.x, y=pos.y+2, z=pos.z}, nil, -- outdir @@ -33,19 +33,22 @@ local function node_timer(pos, elapsed) nil, -- network {"techage:boiler2"} -- nodenames ) - mem.burn_cycles = (mem.burn_cycles or 0) - math.max((power or 0.1), 0.1) - if mem.burn_cycles <= 0 then + nvm.burn_cycles = (nvm.burn_cycles or 0) - math.max((power or 0.1), 0.1) + if nvm.burn_cycles <= 0 then local taken = firebox.get_fuel(pos) if taken then - mem.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR - mem.burn_cycles_total = mem.burn_cycles + nvm.burn_cycles = (firebox.Burntime[taken:get_name()] or 1) / CYCLE_TIME * BURN_CYCLE_FACTOR + nvm.burn_cycles_total = nvm.burn_cycles else - mem.running = false + nvm.running = false firebox.swap_node(pos, "techage:firebox") - M(pos):set_string("formspec", firebox.formspec(mem)) + M(pos):set_string("formspec", firebox.formspec(nvm)) return false end end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", firebox.formspec(nvm)) + end return true end end @@ -71,27 +74,26 @@ minetest.register_node("techage:firebox", { can_dig = firebox.can_dig, allow_metadata_inventory_put = firebox.allow_metadata_inventory_put, allow_metadata_inventory_take = firebox.allow_metadata_inventory_take, - on_receive_fields = firebox.on_receive_fields, on_rightclick = firebox.on_rightclick, on_construct = function(pos) - local mem = tubelib2.init_mem(pos) - mem.running = false - mem.burn_cycles = 0 + local nvm = techage.get_nvm(pos) + nvm.running = false + nvm.burn_cycles = 0 local meta = M(pos) - meta:set_string("formspec", firebox.formspec(mem)) + meta:set_string("formspec", firebox.formspec(nvm)) local inv = meta:get_inventory() inv:set_size('fuel', 1) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - local mem = tubelib2.init_mem(pos) - mem.running = true + local nvm = techage.get_nvm(pos) + nvm.running = true -- activate the formspec fire temporarily - mem.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME - mem.burn_cycles_total = mem.burn_cycles - M(pos):set_string("formspec", firebox.formspec(mem)) - mem.burn_cycles = 0 + nvm.burn_cycles = firebox.Burntime[stack:get_name()] / CYCLE_TIME + nvm.burn_cycles_total = nvm.burn_cycles + M(pos):set_string("formspec", firebox.formspec(nvm)) + nvm.burn_cycles = 0 firebox.swap_node(pos, "techage:firebox_on") minetest.get_node_timer(pos):start(CYCLE_TIME) end, @@ -163,9 +165,9 @@ minetest.register_lbm({ nodenames = {"techage:firebox_on"}, run_at_every_load = true, action = function(pos, node) + local nvm = techage.get_nvm(pos) + nvm.running = true minetest.get_node_timer(pos):start(CYCLE_TIME) - local mem = tubelib2.get_mem(pos) - mem.power_level = nil end }) diff --git a/steam_engine/flywheel.lua b/steam_engine/flywheel.lua index b6b342a..33b5f44 100644 --- a/steam_engine/flywheel.lua +++ b/steam_engine/flywheel.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2020 Joachim Stolberg GPL v3 See LICENSE.txt for more information @@ -13,7 +13,6 @@ ]]-- -- for lazy programmers -local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S @@ -24,42 +23,50 @@ local PWR_CAPA = 25 local Axle = techage.Axle local power = techage.power +local networks = techage.networks -local function formspec(self, pos, mem) - return "size[8,7]".. +-- Axles texture animation +local function switch_axles(pos, on) + local outdir = M(pos):get_int("outdir") + Axle:switch_tube_line(pos, outdir, on and "on" or "off") +end + +local function formspec(self, pos, nvm) + return "size[4,4]".. + "box[0,-0.1;3.8,0.5;#c6e8ff]".. + "label[1,-0.1;"..minetest.colorize( "#000000", S("Flywheel")).."]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "image[6,0.5;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]".. - "image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]".. - "button[2,1.5;2,1;update;"..S("Update").."]".. - "list[current_player;main;0,3;8,4;]".. - default.get_hotbar_bg(0, 3) + power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. + "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. + "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" end -local function can_start(pos, mem, state) - return (mem.firebox_trigger or 0) > 0 -- by means of firebox +local function transfer_cylinder(pos, topic, payload) + return techage.transfer(pos, "L", topic, payload, nil, + {"techage:cylinder", "techage:cylinder_on"}) end -local function start_node(pos, mem, state) - mem.generating = true -- needed for power distribution - techage.switch_axles(pos, true) - mem.handle = minetest.sound_play("techage_steamengine", { - pos = pos, - gain = 0.5, - max_hear_distance = 10}) - power.generator_start(pos, mem, PWR_CAPA) +local function can_start(pos, nvm, state) + return (nvm.firebox_trigger or 0) > 0 -- by means of firebox end -local function stop_node(pos, mem, state) - mem.generating = false - techage.switch_axles(pos, false) - if mem.handle then - minetest.sound_stop(mem.handle) - mem.handle = nil - end - power.generator_stop(pos, mem) - mem.provided = 0 +local function start_node(pos, nvm, state) + switch_axles(pos, true) + local outdir = M(pos):get_int("outdir") + power.generator_start(pos, Axle, CYCLE_TIME, outdir) + transfer_cylinder(pos, "start") + nvm.running = true +end + +local function stop_node(pos, nvm, state) + switch_axles(pos, false) + local outdir = M(pos):get_int("outdir") + power.generator_stop(pos, Axle, outdir) + nvm.provided = 0 + transfer_cylinder(pos, "stop") + nvm.running = false end local State = techage.NodeStates:new({ @@ -74,48 +81,62 @@ local State = techage.NodeStates:new({ }) local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - if mem.generating then - mem.firebox_trigger = (mem.firebox_trigger or 0) - 1 - if mem.firebox_trigger <= 0 then - State:nopower(pos, mem) - mem.generating = false - techage.switch_axles(pos, false) - power.generator_stop(pos, mem) - mem.provided = 0 - techage.transfer(pos, "L", "stop", nil, nil, {"techage:cylinder_on"}) - else - mem.provided = power.generator_alive(pos, mem) - State:keep_running(pos, mem, COUNTDOWN_TICKS) - mem.handle = minetest.sound_play("techage_steamengine", { - pos = pos, - gain = 0.5, - max_hear_distance = 10}) - end + local nvm = techage.get_nvm(pos) + nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1 + if nvm.firebox_trigger <= 0 then + State:nopower(pos, nvm) + stop_node(pos, nvm, State) + transfer_cylinder(pos, "stop") + else + local outdir = M(pos):get_int("outdir") + nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir) + State:keep_running(pos, nvm, COUNTDOWN_TICKS) end - return State:is_active(mem) + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return State:is_active(nvm) 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) - State:state_button_event(pos, mem, fields) - - if fields.update then - M(pos):set_string("formspec", formspec(State, pos, mem)) - end + local nvm,_ = techage.get_nvm(pos, true) + State:state_button_event(pos, nvm, fields) end -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - M(pos):set_string("formspec", formspec(State, pos, mem)) - if mem.generating then - minetest.get_node_timer(pos):start(CYCLE_TIME) - end +local function on_rightclick(pos, node, clicker) + local nvm = techage.get_nvm(pos) + techage.set_activeformspec(pos, clicker) + M(pos):set_string("formspec", formspec(State, pos, nvm)) end +local function after_place_node(pos) + local nvm = techage.get_nvm(pos) + State:node_init(pos, nvm, "") + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + Axle:after_place_node(pos) +end + +local function after_dig_node(pos, oldnode) + Axle:after_dig_node(pos) + techage.del_mem(pos) +end + +local function tubelib2_on_update2(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2) +end + +local net_def = { + axle = { + sides = {R = 1}, + ntype = "gen1", + nominal = PWR_CAPA, + }, +} + minetest.register_node("techage:flywheel", { description = S("TA2 Flywheel"), tiles = { @@ -131,6 +152,10 @@ minetest.register_node("techage:flywheel", { on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_timer = node_timer, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -161,8 +186,8 @@ minetest.register_node("techage:flywheel_on", { backface_culling = false, animation = { type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, + aspect_w = 64, + aspect_h = 64, length = 1.2, }, }, @@ -171,8 +196,8 @@ minetest.register_node("techage:flywheel_on", { backface_culling = false, animation = { type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, + aspect_w = 64, + aspect_h = 64, length = 1.2, }, }, @@ -181,6 +206,10 @@ minetest.register_node("techage:flywheel_on", { on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_timer = node_timer, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + tubelib2_on_update2 = tubelib2_on_update2, + networks = net_def, drop = "", paramtype2 = "facedir", @@ -191,29 +220,24 @@ minetest.register_node("techage:flywheel_on", { sounds = default.node_sound_wood_defaults(), }) -techage.power.register_node({"techage:flywheel", "techage:flywheel_on"}, { - conn_sides = {"R"}, - power_network = Axle, - after_place_node = function(pos, placer) - local mem = tubelib2.init_mem(pos) - State:node_init(pos, mem, "") - on_rightclick(pos) - end, - -}) +Axle:add_secondary_node_names({"techage:flywheel", "techage:flywheel_on"}) techage.register_node({"techage:flywheel", "techage:flywheel_on"}, { on_transfer = function(pos, in_dir, topic, payload) - local mem = tubelib2.get_mem(pos) + local nvm = techage.get_nvm(pos) if topic == "trigger" then - mem.firebox_trigger = 3 - if mem.generating then - return math.max((mem.provided or PWR_CAPA) / PWR_CAPA, 0.1) + nvm.firebox_trigger = 3 + if nvm.running then + return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.1) else return 0 end end - end + end, + on_node_load = function(pos, node) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + State:on_node_load(pos) + end, }) minetest.register_craft({ @@ -225,3 +249,4 @@ minetest.register_craft({ }, }) + diff --git a/steam_engine/gearbox.lua b/steam_engine/gearbox.lua deleted file mode 100644 index 88663bf..0000000 --- a/steam_engine/gearbox.lua +++ /dev/null @@ -1,117 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - TA2 Gearbox - -]]-- - --- for lazy programmers -local P = minetest.string_to_pos -local M = minetest.get_meta -local S = techage.S - -local PWR_NEEDED = 1 -local CYCLE_TIME = 4 - -local Axle = techage.Axle -local power = techage.power - -local function swap_node(pos, name) - local node = techage.get_node_lvm(pos) - if node.name == name then - return - end - node.name = name - minetest.swap_node(pos, node) -end - -local function on_power(pos, mem) - swap_node(pos, "techage:gearbox_on") - techage.switch_axles(pos, true) -end - -local function on_nopower(pos, mem) - swap_node(pos, "techage:gearbox") - techage.switch_axles(pos, false) -end - -local function node_timer(pos, elapsed) - local mem = tubelib2.get_mem(pos) - power.consumer_alive(pos, mem) - return true -end - --- to be able to restart the node after server crashes -local function on_rightclick(pos) - local mem = tubelib2.get_mem(pos) - minetest.get_node_timer(pos):start(CYCLE_TIME) - power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) -end - -minetest.register_node("techage:gearbox", { - description = S("TA2 Gearbox"), - tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"}, - - on_rightclick = on_rightclick, - on_timer = node_timer, - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - - -minetest.register_node("techage:gearbox_on", { - tiles = { - -- up, down, right, left, back, front - { - image = "techage_filling4_ta2.png^techage_axle_gearbox4.png^techage_frame4_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.6, - }, - }, - }, - - on_rightclick = on_rightclick, - on_timer = node_timer, - paramtype2 = "facedir", - groups = {not_in_creative_inventory=1}, - diggable = false, - drop = "", - on_rotate = screwdriver.disallow, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), -}) - -techage.power.register_node({"techage:gearbox", "techage:gearbox_on"}, { - power_network = Axle, - on_power = on_power, - on_nopower = on_nopower, - after_place_node = function(pos, placer, itemstack, pointed_thing) - on_rightclick(pos) - end, - after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) - techage.switch_axles(pos, node.name == "techage:gearbox_on") - end, -}) - -minetest.register_craft({ - output = "techage:gearbox 2", - recipe = { - {"default:junglewood", "techage:axle", "default:wood"}, - {"techage:axle", "techage:iron_ingot", "techage:axle"}, - {"default:wood", "techage:axle", "default:junglewood"}, - }, -}) diff --git a/textures/techage_flywheel.png b/textures/techage_flywheel.png index ccaa876fb71947c0423048e60bdb0acd9678dc84..19e8c407444b01b73bef1c820edbbd19a430a6be 100644 GIT binary patch literal 1621 zcmV-b2CDgqP)Px#32;bRa{vGf6951U69E94oEQKA0Hsh&R7Ff_abI9! zSp@}900|KW827v(qF*G$M4-X0h112ILwgUrd2nTBd0ssI2c?Jhz zWM(A+0d_(VQ&m{3v9>@$L}&s6kpTg#0|UOq$*%$e1q1}34GqJ|&d1HthZ`G|5Dya( z5uT%`vj+stf-@v0Cx}uRCp1rkX_ zK~zY`jhAbGvOElj>ljdx=`HFu2b3xW3j&HeeE*O3Bn6a{KIVn{4Y>YI(o;gnsC}$H zrC^K+^<#amKFIU-@hO=oPEp2pU_6UXg<$gYNr{!ktlZmqZR5M_B$>5(f|l%(@rv1b z5ts)qsQGb@4Y?q@qv~ zS;_9ZV2KC@-{mq5k!+jq?^BtB0?(N>PEUk|QASdyegpY&>^D+=pi9)xq?nB0@9YdO zd65R{dw)LF*S5`=VXyV+ym}U<1%6Yq_YwR8uOi{7FX!8}v7Eh6%wYeIyv;OYy`3wC zg@|yFfxrZDo{Ip#qP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#@FAZ+6#av6l|K~yLskAz@DG1`{_r{fu)5(N{zU%J z$OkYG&H2Oh)ot_-2HBAOWw7KQ_Ut?sJdZ?W=2iaCSC~C86{90~ui#h1dBz7!`CuqC zp1bX!v00Hn*oGnTBdwG_L|OizP=jDu%pQ>R!F8ARC4X4DE^`>nU=V)+tvY|mEQ(|p zW4MKw?3(Wa(rOR002ovPDHLkV1h-r@*e;I diff --git a/textures/techage_form_level_bg.png b/textures/techage_form_level_bg.png index 30c42f6b87267b1b293260e1ea0bf79846fc7063..83aea90b3d75d0540b3e825acc1361e8660f568e 100644 GIT binary patch delta 59 zcmcc3c$IO&LKAsU7sn8d^T`Pf%*#R@E;P*DXkucLHO26g#E!`CTzgV4H|cmW O0D-5gpUXO@geCx{#1&!y delta 65 zcmcc0c$;y;LMv5I7sn8d^T`Pf%*#R@E;P*D*wEO>&7Pc@k#R*Md4^GeI;RE$!{Qg6 U86k6~pI`t2Pgg&ebxsLQ07Y~dSpWb4 diff --git a/textures/techage_form_level_fg.png b/textures/techage_form_level_fg.png index cd31c5b4b1afad82d48ea9dbfb96ec26761c4247..d7eacfc70d76adf231a5d9007008f8271afd39b4 100644 GIT binary patch delta 59 zcmcc3c$IO&LKAsU7sn8d^T`Pf%*O&03J#p>h}xRYN%34D)7A Vek#2`?g|4Cc)I$ztaD0e0svsB88`p{ diff --git a/textures/techage_gas_inv.png b/textures/techage_gas_inv.png index b528306acec4bae645002f38f915b8fe91a81766..54e611ecd1e338638c478b73dcbcc482763c3113 100644 GIT binary patch delta 1684 zcmV;F25b4^2AK_z8Gi-<002d+8sGo`00v@9M??Ss00000`9r&Z00009a7bBm000XU z000XU0RWnu7ytkO2XskIMF-;x77{rWRa(>s000IiNklyuDVyFo=?Ka7aV3bxAVuN5<#DA2P77~Qy!Bk5WsYIe_ zl|slSHnj1#eXulD@j=m9q1#%lb;C;RL%Vi%_uiR%XYL)Pc%F85?w!5ooAdLXbMF9b z%eDXj81(+bjH*^!@XwGX^8ML5*aZX3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;q(9P2MPf`K51BAvH$=807*qoM6N<$f?vIcy8r+H diff --git a/tools/repairkit.lua b/tools/repairkit.lua index 7234a39..7b22ed2 100644 --- a/tools/repairkit.lua +++ b/tools/repairkit.lua @@ -88,10 +88,10 @@ local function read_state(itemstack, user, pointed_thing) load = dump(load) minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": load = "..load.." % ") end - local capa = techage.send_single("0", number, "capa", nil) - if capa and capa ~= "" and capa ~= "unsupported" then - capa = dump(capa) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": capa = "..capa.." % ") + local size = techage.send_single("0", number, "size", nil) + if size and size ~= "" and size ~= "unsupported" then + size = dump(size) + minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": size = "..size.." units ") end local owner = M(pos):get_string("owner") or "" if owner ~= "" then diff --git a/tools/trowel.lua b/tools/trowel.lua index 1bfdf4e..8425016 100644 --- a/tools/trowel.lua +++ b/tools/trowel.lua @@ -100,7 +100,7 @@ minetest.register_on_dignode(function(pos, oldnode, digger) if other_hidden_nodes(pos, "techage_hidden_nodename") then -- test both hidden networks techage.ElectricCable:after_dig_node(pos, oldnode, digger) - techage.BiogasPipe:after_dig_node(pos, oldnode, digger) + --techage.BiogasPipe:after_dig_node(pos, oldnode, digger) -- probably a hidden node with mem data tubelib2.del_mem(pos) else