diff --git a/.test/sink.lua b/.test/sink.lua index 08a47a7..cb737ea 100644 --- a/.test/sink.lua +++ b/.test/sink.lua @@ -42,10 +42,8 @@ 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 - --swap_node(pos, "techage:sink_on") power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) - minetest.get_node_timer(pos):start(CYCLE_TIME) - M(pos):set_string("infotext", "on") + M(pos):set_string("infotext", "...") else mem.running = false swap_node(pos, "techage:sink") diff --git a/chemistry/ta4_doser.lua b/chemistry/ta4_doser.lua index 9e6a285..bab6f94 100644 --- a/chemistry/ta4_doser.lua +++ b/chemistry/ta4_doser.lua @@ -21,10 +21,9 @@ local recipes = techage.recipes local Liquids = {} -- {hash(pos) = {name = outdir},...} -local STANDBY_TICKS = 0 -local COUNTDOWN_TICKS = 6 -local CYCLE_TIME = 2 -local POWER_NEED = 10 +local STANDBY_TICKS = 4 +local COUNTDOWN_TICKS = 4 +local CYCLE_TIME = 4 local function formspec(self, pos, mem) return "size[8,7]".. @@ -73,20 +72,24 @@ end local function can_start(pos, mem, state) -- check reactor - local res = reactor_cmnd(pos, "can_start") + local res = reactor_cmnd(pos, "check") if not res then return S("reactor defect") end + res = reactor_cmnd(pos, "can_start") + if not res then + return S("reactor defect or no power") + end return true end local function start_node(pos, mem, state) - reactor_cmnd(pos, "start", {cycle_time = CYCLE_TIME, pwr_needed = POWER_NEED}) + reactor_cmnd(pos, "start") mem.running = true end local function stop_node(pos, mem, state) - reactor_cmnd(pos, "stop", nil) + reactor_cmnd(pos, "stop") mem.running = false end @@ -108,35 +111,43 @@ end local function dosing(pos, mem, elapsed) -- trigger reactor (power) - if not reactor_cmnd(pos, "power", POWER_NEED) then - State:nopower(pos, mem, S("reactor has no power")) + if not reactor_cmnd(pos, "power") then + if not mem.techage_countdown or mem.techage_countdown < 2 then + State:nopower(pos, mem, S("reactor has no power")) + end + State:idle(pos, mem) return end - -- available liquids - local liquids = get_liquids(pos) - local recipe = recipes.get(mem, "ta4_doser") - if not liquids or not recipe then return end - -- inputs - for _,item in pairs(recipe.input) do - if item.name ~= "" then - print("dosing", item.name, dump(liquids)) - local outdir = liquids[item.name] - if not outdir then - State:fault(pos, mem, S("input missing")) - return - end - if liquid.take(pos, outdir, item.name, item.num) < item.num then - State:fault(pos, mem, S("input missing")) - return - end - end - end +-- -- available liquids +-- local liquids = get_liquids(pos) +-- local recipe = recipes.get(mem, "ta4_doser") +-- if not liquids or not recipe then return end +-- -- inputs +-- for _,item in pairs(recipe.input) do +-- if item.name ~= "" then +-- print("dosing", item.name, dump(liquids)) +-- local outdir = liquids[item.name] +-- if not outdir then +-- State:fault(pos, mem, S("input missing")) +-- return +-- end +-- if liquid.take(pos, outdir, item.name, item.num) < item.num then +-- State:fault(pos, mem, S("input missing")) +-- return +-- end +-- end +-- end -- output - if not reactor_cmnd(pos, "output", recipe.output.name) then + --if not reactor_cmnd(pos, "output", recipe.output.name) then + local leftover + leftover = reactor_cmnd(pos, "output", {name = "techage:gasoline", amount = 1, player_name = "singleplayer"}) + if not leftover or leftover > 0 then State:fault(pos, mem, S("output blocked")) return end - if not reactor_cmnd(pos, "waste", recipe.waste.name) then + --if not reactor_cmnd(pos, "waste", recipe.waste.name) then + leftover = reactor_cmnd(pos, "waste", {name = "techage:bitumen", amount = 1, player_name = "singleplayer"}) + if not leftover or leftover > 0 then State:fault(pos, mem, S("output blocked")) return end diff --git a/chemistry/ta4_reactor.lua b/chemistry/ta4_reactor.lua index 4dc1675..6a12927 100644 --- a/chemistry/ta4_reactor.lua +++ b/chemistry/ta4_reactor.lua @@ -13,100 +13,13 @@ ]]-- local S = techage.S +local M = minetest.get_meta local Cable = techage.ElectricCable local power = techage.power local Pipe = techage.LiquidPipe local networks = techage.networks local liquid = techage.liquid --- pos of the reactor stand -local function on_power(pos, mem) - mem.running = true -end - -local function on_nopower(pos, mem) - mem.running = false -end - -minetest.register_node("techage:ta4_reactor", { - description = S("TA4 Reactor"), - tiles = {"techage_reactor_side.png"}, - drawtype = "mesh", - mesh = "techage_cylinder_12h.obj", - selection_box = { - type = "fixed", - fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2}, - }, - collision_box = { - type = "fixed", - fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2}, - }, - - paramtype = "light", - paramtype2 = "facedir", - on_rotate = screwdriver.disallow, - groups = {cracky=2}, - is_ground_content = false, - sounds = default.node_sound_metal_defaults(), -}) - -minetest.register_node("techage:ta4_reactor_stand", { - description = S("TA4 Reactor"), - tiles = { - -- up, down, right, left, back, front - "techage_reactor_stand_top.png^[transformR90", - "techage_reactor_stand_bottom.png^[transformFY^[transformR270", - "techage_reactor_stand_front.png", - "techage_reactor_stand_back.png", - "techage_reactor_stand_side.png^[transformFX", - "techage_reactor_stand_side.png", - }, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -8/16, 2/16, -8/16, 8/16, 4/16, 8/16 }, - - { -8/16, -8/16, -8/16, -6/16, 8/16, -6/16 }, - { 6/16, -8/16, -8/16, 8/16, 8/16, -6/16 }, - { -8/16, -8/16, 6/16, -6/16, 8/16, 8/16 }, - { 6/16, -8/16, 6/16, 8/16, 8/16, 8/16 }, - - {-1/8, -4/8, -1/8, 1/8, 4/8, 1/8}, - - {-4/8, -1/8, -1/8, 4/8, 1/8, 1/8}, --- {-3/8, -1/8, -4/8, 3/8, 1/8, -3/8}, - {-4/8, -1/8, -3/8, -3/8, 1/8, 3/8}, - --- {-3/8, -1/8, 3/8, 3/8, 1/8, 4/8}, - { 3/8, -1/8, -3/8, 4/8, 1/8, 3/8}, -}, - }, - selection_box = { - type = "fixed", - fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2}, - }, - paramtype = "light", - paramtype2 = "facedir", - on_rotate = screwdriver.disallow, - groups = {cracky=2}, - is_ground_content = false, - sounds = default.node_sound_metal_defaults(), - - networks = { - pipe = { - sides = {R=1}, -- Pipe connection sides - ntype = "pump", - }, - }, -}) - --- for electrical connections -techage.power.register_node({"techage:ta4_reactor_stand"}, { - conn_sides = {"L"}, - power_network = Cable, -}) - minetest.register_node("techage:ta4_reactor_fillerpipe", { description = S("TA4 Reactor Filler Pipe"), tiles = { @@ -130,7 +43,6 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", { }, after_place_node = function(pos) local pos1 = {x = pos.x, y = pos.y-1, z = pos.z} - print(minetest.get_node(pos1).name) if minetest.get_node(pos1).name == "air" then local node = minetest.get_node(pos) minetest.remove_node(pos) @@ -161,70 +73,63 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", { }, }) +local function stand_cmnd(pos, cmnd, payload) + return techage.transfer( + {x = pos.x, y = pos.y-1, z = pos.z}, + 5, -- outdir + cmnd, -- topic + payload, -- payload + nil, -- network + {"techage:ta4_reactor_stand"}) +end + +local function base_waste(pos, payload) + local pos2 = {x = pos.x, y = pos.y-3, z = pos.z} + local outdir = M(pos2):get_int("outdir") + return liquid.put(pos2, outdir, payload.name, payload.amount, payload.player_name) +end + -- controlled by the doser techage.register_node({"techage:ta4_reactor_fillerpipe"}, { on_transfer = function(pos, in_dir, topic, payload) - -- pos of the reactor stand - local pos2 = {x = pos.x, y = pos.y-2, z = pos.z} - local mem = tubelib2.get_mem(pos2) - if topic == "power" then - power.consumer_alive(pos2, mem) - return mem.running - elseif topic == "can_start" then - local pos1 = {x = pos.x, y = pos.y-1, z = pos.z} - if minetest.get_node(pos1).name ~= "techage:ta4_reactor" then return false end - if minetest.get_node(pos2).name ~= "techage:ta4_reactor_stand" then return false end - return true - elseif topic == "start" and payload then - mem.running = true - power.consumer_start(pos2, mem, payload.cycle_time or 0, payload.pwr_needed or 0) - return true - elseif topic == "stop" then - mem.running = false - power.consumer_stop(pos2, mem) + if topic == "check" then + local pos2,node = Pipe:get_node(pos, 5) + if not node or node.name ~= "techage:ta4_reactor" then + return false + end + pos2,node = Pipe:get_node(pos2, 5) + if not node or node.name ~= "techage:ta4_reactor_stand" then + return false + end return true + elseif topic == "waste" then + return base_waste(pos, payload or {}) + else + return stand_cmnd(pos, topic, payload or {}) end end, }) -minetest.register_node("techage:ta4_reactor_base", { - description = S("TA4 Reactor Base"), - tiles = { - -- up, down, right, left, back, front - "techage_concrete.png^techage_appl_arrowXL.png^techage_appl_hole_pipe.png^[transformR270", - "techage_concrete.png", - "techage_concrete.png^techage_appl_hole_pipe.png", - "techage_concrete.png", - "techage_concrete.png", - "techage_concrete.png", +minetest.register_node("techage:ta4_reactor", { + description = S("TA4 Reactor"), + tiles = {"techage_reactor_side.png"}, + drawtype = "mesh", + mesh = "techage_cylinder_12h.obj", + selection_box = { + type = "fixed", + fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2}, }, - - after_place_node = function(pos, placer) - Pipe:after_place_node(pos) - end, - tubelib2_on_update2 = function(pos, dir, tlib2, node) - liquid.update_network(pos) - end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - Pipe:after_dig_node(pos) - end, - + collision_box = { + type = "fixed", + fixed = {-1/2, -23/32, -1/2, 1/2, 32/32, 1/2}, + }, + + paramtype = "light", paramtype2 = "facedir", on_rotate = screwdriver.disallow, groups = {cracky=2}, is_ground_content = false, - sounds = default.node_sound_stone_defaults(), - - networks = { - pipe = { - sides = {R=1}, -- Pipe connection sides - ntype = "pump", - }, - }, + sounds = default.node_sound_metal_defaults(), }) -Pipe:add_secondary_node_names({ - "techage:ta4_reactor_base", - "techage:ta4_reactor_fillerpipe", - "techage:ta4_reactor_stand", -}) +Pipe:add_secondary_node_names({"techage:ta4_reactor_fillerpipe"}) diff --git a/chemistry/ta4_stand.lua b/chemistry/ta4_stand.lua new file mode 100644 index 0000000..740ad04 --- /dev/null +++ b/chemistry/ta4_stand.lua @@ -0,0 +1,201 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + TA4 Reactor Stand and Base + +]]-- + +local S = techage.S +local M = minetest.get_meta +local Cable = techage.ElectricCable +local power = techage.power +local Pipe = techage.LiquidPipe +local networks = techage.networks +local liquid = techage.liquid + +local PWR_NEEDED = 8 +local CYCLE_TIME = 4 + +local function on_power(pos, mem) + if mem.running then + minetest.get_node_timer(pos):start(CYCLE_TIME) + M(pos):set_string("infotext", S("on")) + mem.has_power = true + end +end + +local function on_nopower(pos, mem) + M(pos):set_string("infotext", S("no power")) + mem.has_power = false +end + +minetest.register_node("techage:ta4_reactor_stand", { + description = S("TA4 Reactor"), + tiles = { + -- up, down, right, left, back, front + "techage_reactor_stand_top.png^[transformR90", + "techage_reactor_stand_bottom.png^[transformFY^[transformR270", + "techage_reactor_stand_front.png", + "techage_reactor_stand_back.png", + "techage_reactor_stand_side.png^[transformFX", + "techage_reactor_stand_side.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, 2/16, -8/16, 8/16, 4/16, 8/16 }, + + { -8/16, -8/16, -8/16, -6/16, 8/16, -6/16 }, + { 6/16, -8/16, -8/16, 8/16, 8/16, -6/16 }, + { -8/16, -8/16, 6/16, -6/16, 8/16, 8/16 }, + { 6/16, -8/16, 6/16, 8/16, 8/16, 8/16 }, + + {-1/8, -4/8, -1/8, 1/8, 4/8, 1/8}, + {-4/8, -1/8, -1/8, 4/8, 1/8, 1/8}, + {-4/8, -1/8, -3/8, -3/8, 1/8, 3/8}, + { 3/8, -1/8, -3/8, 4/8, 1/8, 3/8}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2}, + }, + + after_place_node = function(pos, placer) + local mem = tubelib2.init_mem(pos) + techage.power.after_place_node(pos) + M(pos):set_string("infotext", S("off")) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + Pipe:after_place_node(pos) + end, + tubelib2_on_update2 = function(pos, dir, tlib2, node) + liquid.update_network(pos) + end, + after_tube_update = function(node, pos, out_dir, peer_pos, peer_in_dir) + techage.power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir) + end, + on_timer = function(pos, elapsed) + local mem = tubelib2.get_mem(pos) + power.consumer_alive(pos, mem) + return mem.running + end, + on_rightclick = function(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) + M(pos):set_string("infotext", "...") + else + mem.running = false + power.consumer_stop(pos, mem) + minetest.get_node_timer(pos):stop() + M(pos):set_string("infotext", S("off")) + end + end, + after_dig_node = function(pos, oldnode) + techage.power.after_dig_node(pos, oldnode) + Pipe:after_dig_node(pos) + tubelib2.del_mem(pos) + end, + + paramtype = "light", + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + groups = {cracky=2}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + -- Pipe connection + networks = { + pipe = { + sides = {R=1}, + ntype = "pump", + }, + }, +}) + +-- for electrical connections +techage.power.enrich_node({"techage:ta4_reactor_stand"}, { + conn_sides = {"L"}, + power_network = Cable, + on_power = on_power, + on_nopower = on_nopower, +}) + +-- controlled by the fillerpipe +techage.register_node({"techage:ta4_reactor_stand"}, { + on_transfer = function(pos, in_dir, topic, payload) + print(topic, payload) + local mem = tubelib2.get_mem(pos) + if topic == "power" then + return mem.has_power + elseif topic == "output" then + local outdir = M(pos):get_int("outdir") + return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name) + elseif topic == "can_start" then + return power.power_available(pos, mem, 0) + elseif topic == "start" and payload then + mem.running = true + mem.has_power = false + power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED) + M(pos):set_string("infotext", "...") + return true + elseif topic == "stop" then + mem.running = false + mem.has_power = false + power.consumer_stop(pos, mem) + minetest.get_node_timer(pos):stop() + M(pos):set_string("infotext", S("off")) + return true + end + end, +}) + +minetest.register_node("techage:ta4_reactor_base", { + description = S("TA4 Reactor Base"), + tiles = { + -- up, down, right, left, back, front + "techage_concrete.png^techage_appl_arrowXL.png^techage_appl_hole_pipe.png^[transformR270", + "techage_concrete.png", + "techage_concrete.png^techage_appl_hole_pipe.png", + "techage_concrete.png", + "techage_concrete.png", + "techage_concrete.png", + }, + + after_place_node = function(pos, placer) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + Pipe:after_place_node(pos) + end, + tubelib2_on_update2 = function(pos, dir, tlib2, node) + liquid.update_network(pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Pipe:after_dig_node(pos) + end, + + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + groups = {cracky=2}, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), + + networks = { + pipe = { + sides = {R=1}, -- Pipe connection sides + ntype = "pump", + }, + }, +}) + +Pipe:add_secondary_node_names({ + "techage:ta4_reactor_base", + "techage:ta4_reactor_stand", +}) diff --git a/coal_power_station/turbine.lua b/coal_power_station/turbine.lua index 320d244..c75212c 100644 --- a/coal_power_station/turbine.lua +++ b/coal_power_station/turbine.lua @@ -37,14 +37,23 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function play_sound(pos) + +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}) - minetest.after(2, play_sound, pos) + 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) end end @@ -53,6 +62,7 @@ local function stop_sound(pos) if mem.running and mem.handle then minetest.sound_stop(mem.handle) mem.handle = nil + minetest.get_node_timer(pos):stop(2) end end @@ -102,6 +112,7 @@ minetest.register_node("techage:turbine_on", { }, }, }, + on_timer = node_timer, paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, diggable = false, diff --git a/init.lua b/init.lua index 0276536..58d1551 100644 --- a/init.lua +++ b/init.lua @@ -195,7 +195,7 @@ else -- Test dofile(MP.."/recipe_checker.lua") - --dofile(MP.."/.test/sink.lua") + dofile(MP.."/.test/sink.lua") dofile(MP.."/.test/source.lua") --dofile(MP.."/.test/akku.lua") --dofile(MP.."/.test/switch.lua") @@ -219,8 +219,9 @@ else dofile(MP.."/energy_storage/nodes.lua") -- Chemistry - --dofile(MP.."/chemistry/ta4_reactor.lua") - --dofile(MP.."/chemistry/ta4_doser.lua") + dofile(MP.."/chemistry/ta4_reactor.lua") + dofile(MP.."/chemistry/ta4_stand.lua") + dofile(MP.."/chemistry/ta4_doser.lua") -- Hydrogen dofile(MP.."/hydrogen/hydrogen.lua") diff --git a/liquids/liquid.lua b/liquids/liquid.lua index 742522a..429b169 100644 --- a/liquids/liquid.lua +++ b/liquids/liquid.lua @@ -119,7 +119,7 @@ function techage.liquid.put(pos, outdir, name, amount, player_name) local peek = liquid.peek(item.pos, item.indir) if peek and peek ~= name then return amount or 0 end if player_name then - local num = techage.get_node_number(pos) + local num = techage.get_node_number(pos) or "000" techage.mark_position(player_name, item.pos, "("..num..") put", "", 1) end amount = liquid.put(item.pos, item.indir, name, amount) diff --git a/liquids/tank.lua b/liquids/tank.lua index 08f0d6c..5188f33 100644 --- a/liquids/tank.lua +++ b/liquids/tank.lua @@ -148,7 +148,7 @@ local function can_dig(pos, player) 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 (mem.liquid.amount or 0) == 0 + return inv:is_empty("src") and inv:is_empty("dst") and (not mem.liquid or (mem.liquid.amount or 0) == 0) end diff --git a/locale/techage.de.tr b/locale/techage.de.tr index 7cd6d74..8f65703 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -76,7 +76,7 @@ Power=Energie Primary available=Primär verfügbar Primary needed=Primär benötigt Pusher=Schieber -Recipe=Rezepte +Recipe=Rezept Remove derrick=Entferne Ölturm Rinsing=Waschen River Water Barrel=Flusswasserfass diff --git a/logic/terminal.lua b/logic/terminal.lua index e8e7f53..074b7e0 100644 --- a/logic/terminal.lua +++ b/logic/terminal.lua @@ -156,7 +156,7 @@ local function command(pos, command, player) return end - local cmnd, payload = command:match('^pipe%s+(%w+)%s*(.*)$') + local cmnd, payload = command:match('^pipe%s+([%w_]+)%s*(.*)$') if cmnd then if not minetest.check_player_privs(player, "server") then output(pos, "server privs missing")