pipe2 addded

This commit is contained in:
Joachim Stolberg 2020-01-31 19:55:10 +01:00
parent 859587713d
commit f049f7b18c
60 changed files with 1815 additions and 1419 deletions

View File

@ -1,62 +0,0 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local CYCLE_TIME = 2
local PWR_CAPA = 15
local Cable = techage.ElectricCable
local power = techage.power
local function node_timer(pos, elapsed)
--print("node_timer source "..S(pos))
local mem = tubelib2.get_mem(pos)
if mem.generating then
local provided = power.generator_alive(pos, mem)
--print("provided", provided)
end
return mem.generating
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
if not mem.generating then
mem.generating = true
power.generator_start(pos, mem, PWR_CAPA)
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "on")
else
mem.generating = false
power.generator_stop(pos, mem)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", "off")
end
end
minetest.register_node("techage:source", {
description = "Source",
tiles = {
-- up, down, right, left, back, front
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png^techage_electric_plug.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
'techage_electric_button.png^techage_appl_electronic_fab.png',
},
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
is_ground_content = false,
on_rightclick = on_rightclick,
on_timer = node_timer,
})
techage.power.register_node({"techage:source"}, {
power_network = Cable,
after_place_node = function(pos)
local mem = tubelib2.init_mem(pos)
M(pos):set_string("infotext", "off")
end,
})

View File

@ -1,46 +0,0 @@
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local Cable = techage.ElectricCable
local power_switched = techage.power.power_switched
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
mem.interrupted_dirs = mem.interrupted_dirs or {}
mem.interrupted = not mem.interrupted
--print("switch", mem.interrupted)
if mem.interrupted then
mem.interrupted_dirs = {true, true, true, true, true, true}
for dir,_ in pairs(mem.connections) do
mem.interrupted_dirs[dir] = false
power_switched(pos)
mem.interrupted_dirs[dir] = true
end
else
mem.interrupted_dirs = {}
power_switched(pos)
end
end
minetest.register_node("techage:switch", {
description = "Switch",
tiles = {'techage_appl_switch_inv.png'},
--on_timer = node_timer,
on_rightclick = on_rightclick,
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
techage.power2.register_node({"techage:switch"}, {
power_network = Cable,
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -51,7 +51,7 @@ local function build(pos, param2, AssemblyPlan, idx)
minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4})
minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1)
else
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
mem.assemble_locked = false
end
end
@ -65,7 +65,7 @@ local function remove(pos, param2, AssemblyPlan, idx)
minetest.remove_node(pos1)
minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1)
else
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
mem.assemble_locked = false
end
end
@ -98,7 +98,7 @@ function techage.assemble.build(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then
return
end
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
if mem.assemble_locked then
return
end
@ -115,7 +115,7 @@ function techage.assemble.remove(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then
return
end
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
if mem.assemble_locked then
return
end

View File

@ -18,22 +18,47 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
local function deserialize(s)
local tbl = {}
for line in s:gmatch("[^;]+") do
local num, spos = unpack(string.split(line, "="))
tbl[num] = {pos = minetest.string_to_pos(spos)}
end
return tbl
end
local function serialize(data)
local tbl = {}
for k,v in pairs(data) do
tbl[#tbl+1] = k.."="..minetest.pos_to_string(v.pos)
end
return table.concat(tbl, ";")
end
------------------------------------------------------------------
-- Data base storage
-------------------------------------------------------------------
local storage = minetest.get_mod_storage()
local NextNumber = minetest.deserialize(storage:get_string("NextNumber")) or 1
local Version = minetest.deserialize(storage:get_string("Version")) or 1
local Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
local Version = minetest.deserialize(storage:get_string("Version")) or 2
local Number2Pos
if Version == 1 then
Version = 2
Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
else
Number2Pos = deserialize(storage:get_string("Number2Pos"))
end
local function update_mod_storage()
local t = minetest.get_us_time()
minetest.log("action", "[TechAge] Store data...")
storage:set_string("NextNumber", minetest.serialize(NextNumber))
storage:set_string("Version", minetest.serialize(Version))
storage:set_string("Number2Pos", minetest.serialize(Number2Pos))
storage:set_string("Number2Pos", serialize(Number2Pos))
-- store data each hour
minetest.after(60*59, update_mod_storage)
minetest.log("action", "[TechAge] Data stored")
t = minetest.get_us_time() - t
minetest.log("action", "[TechAge] Data stored. t="..t.."us")
end
minetest.register_on_shutdown(function()
@ -232,11 +257,7 @@ function techage.remove_node(pos)
local name
if Number2Pos[number] then
name = Number2Pos[number].name
Number2Pos[number] = {
pos = pos,
name = nil,
time = minetest.get_day_count() -- used for reservation timeout
}
Number2Pos[number].name = nil
end
if item_handling_node(name) then
Tube:after_dig_node(pos)
@ -485,18 +506,15 @@ end
-------------------------------------------------------------------------------
local function data_maintenance()
minetest.log("info", "[TechAge] Data maintenance started")
-- Remove old unused positions
local Tbl = table.copy(Number2Pos)
-- Remove unused positions
local tbl = table.copy(Number2Pos)
Number2Pos = {}
local day_cnt = minetest.get_day_count()
for num,item in pairs(Tbl) do
if item.name then
for num,item in pairs(tbl) do
local name = techage.get_node_lvm(item.pos).name
if NodeDef[name] then
Number2Pos[num] = item
-- data not older than 5 real days
elseif item.time and (item.time + (72*5)) > day_cnt then
Number2Pos[num] = item
else
minetest.log("info", "Position deleted", num)
-- add node names which are not stored as file
Number2Pos[num].name = name
end
end
minetest.log("info", "[TechAge] Data maintenance finished")
@ -504,8 +522,6 @@ end
generate_Key2Number()
-- maintain data after 5 seconds
-- (minetest.get_day_count() will not be valid at start time)
minetest.after(5, data_maintenance)
minetest.after(2, data_maintenance)

View File

@ -491,6 +491,7 @@ function NodeStates:on_node_load(pos, not_start_timer)
elseif not info.pos then
minetest.log("warning", "[TA] Node at "..S(pos).." has no info.pos")
elseif not vector.equals(pos, info.pos) then
print(S(pos), S(info.pos))
minetest.log("warning", "[TA] Node at "..S(pos).." is pos ~= info.pos")
end
swap_node(pos, "techage:defect_dummy")

View File

@ -45,10 +45,10 @@ local function input_string(recipe)
return table.concat(tbl, "")
end
function techage.recipes.get(mem, rtype)
function techage.recipes.get(nvm, rtype)
local recipes = Recipes[rtype] or {}
local recipe_list = RecipeList[rtype] or {}
return recipes[recipe_list[mem.recipe_idx or 1]]
return recipes[recipe_list[nvm.recipe_idx or 1]]
end
-- Add 4 input/output/waste recipe
@ -95,11 +95,11 @@ function techage.recipes.add(rtype, recipe)
end
end
function techage.recipes.formspec(x, y, rtype, mem)
function techage.recipes.formspec(x, y, rtype, nvm)
local recipes = Recipes[rtype] or {}
local recipe_list = RecipeList[rtype] or {}
mem.recipe_idx = range(mem.recipe_idx or 1, 1, #recipe_list)
local idx = mem.recipe_idx
nvm.recipe_idx = range(nvm.recipe_idx or 1, 1, #recipe_list)
local idx = nvm.recipe_idx
local recipe = recipes[recipe_list[idx]] or RECIPE
local output = recipe.output.name.." "..recipe.output.num
local waste = recipe.waste.name.." "..recipe.waste.num
@ -119,14 +119,14 @@ function techage.recipes.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)
local nvm = techage.get_nvm(pos)
mem.recipe_idx = mem.recipe_idx or 1
if not mem.running then
nvm.recipe_idx = nvm.recipe_idx or 1
if not nvm.running then
if fields.next == ">>" then
mem.recipe_idx = mem.recipe_idx + 1
nvm.recipe_idx = nvm.recipe_idx + 1
elseif fields.priv == "<<" then
mem.recipe_idx = mem.recipe_idx - 1
nvm.recipe_idx = nvm.recipe_idx - 1
end
end
end

View File

@ -14,14 +14,46 @@
]]--
local NUM_NODES_PER_MIN = 100
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
-- Node data will be stored every NUM_SLOTS * CYCLE_TIME seconds
local NUM_SLOTS = 50
local CYCLE_TIME = 30
local NvmStore = {}
local MemStore = {}
local NumNodes = 0
local StoredNodes = 0
local NextNum = 0
local Timeslot = 0
local FNAME = minetest.get_worldpath()..DIR_DELIM.."techage_metadata.txt"
local function read_file()
local f = io.open(FNAME, "r")
if f ~= nil then
local s = f:read("*all")
io.close(f)
return minetest.deserialize(s) or {}
end
return {}
end
local function write_file(tbl)
local s = minetest.serialize(tbl)
local f = io.open(FNAME, "w")
f:write(s)
f:close()
end
NvmStore = read_file()
minetest.register_on_shutdown(function()
write_file(NvmStore)
end)
local function set_metadata(hash, tbl)
local pos = minetest.get_position_from_hash(hash)
tbl.USED = nil
local data = minetest.serialize(tbl)
local meta = minetest.get_meta(pos)
meta:set_string("ta_data", data)
@ -37,68 +69,46 @@ local function get_metadata(hash)
end
end
local function storage_loop()
local cnt = 0
while true do
NumNodes = 0
StoredNodes = 0
for hash,tbl in pairs(NvmStore) do
NumNodes = NumNodes + 1
if tbl.__used__ then
tbl.__used__ = nil
local function nvm_storage()
local ToBeDeleted = {}
for hash,tbl in pairs(NvmStore) do
NumNodes = NumNodes + 1
if tbl.USED then
if not tbl.SLOT then
tbl.SLOT = NextNum % NUM_SLOTS
NextNum = NextNum + 1
end
if tbl.SLOT == Timeslot then
set_metadata(hash, tbl)
StoredNodes = StoredNodes + 1
cnt = cnt + 1
if cnt > NUM_NODES_PER_MIN then
cnt = 0
coroutine.yield()
end
else
-- remove from memory if node is unloaded
local pos = minetest.get_position_from_hash(hash)
if minetest.get_node(pos).name == "ignore" then
NvmStore[hash] = nil
MemStore[hash] = nil
end
end
else
ToBeDeleted[#ToBeDeleted+1] = hash
end
coroutine.yield()
end
for _,hash in ipairs(ToBeDeleted) do
NvmStore[hash] = nil
end
return #ToBeDeleted
end
local co = coroutine.create(storage_loop)
local function cyclic_task()
local t = minetest.get_us_time()
coroutine.resume(co)
t = minetest.get_us_time() - t
print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes)
-- run every minutes
minetest.after(60, cyclic_task)
end
minetest.register_on_shutdown(function()
Timeslot = (Timeslot + 1) % NUM_SLOTS
NumNodes = 0
StoredNodes = 0
local t = minetest.get_us_time()
for k,v in pairs(NvmStore) do
NumNodes = NumNodes + 1
if v.__used__ then
v.__used__ = nil
set_metadata(k, v)
StoredNodes = StoredNodes + 1
end
end
local deleted = nvm_storage()
t = minetest.get_us_time() - t
print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes)
end)
print("[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes..", deleted="..deleted)
minetest.after(CYCLE_TIME, cyclic_task)
end
minetest.after(CYCLE_TIME, cyclic_task)
minetest.after(60, cyclic_task)
-- To get the volatile node data as table
function techage.get_mem(pos, will_change)
function techage.get_mem(pos)
local hash = minetest.hash_node_position(pos)
if not MemStore[hash] then
MemStore[hash] = {}
@ -112,10 +122,15 @@ function techage.get_nvm(pos)
if not NvmStore[hash] then
NvmStore[hash] = get_metadata(hash) or {}
end
NvmStore[hash].__used__ = true
NvmStore[hash].USED = true
return NvmStore[hash]
end
function techage.peek_nvm(pos)
local hash = minetest.hash_node_position(pos)
return NvmStore[hash] or {}
end
-- To be called when a node is removed
function techage.del_mem(pos)
local meta = minetest.get_meta(pos)

View File

@ -47,14 +47,14 @@ local function get_starter_name(pos)
end
end
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
recipes.formspec(0, 0, "ta4_doser", mem)..
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"tooltip[6,1;1,1;"..self:get_state_tooltip(mem).."]"..
recipes.formspec(0, 0, "ta4_doser", nvm)..
"image_button[6,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[6,1;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[current_player;main;0,3.3;8,4;]" ..
default.get_hotbar_bg(0, 3.5)
end
@ -92,7 +92,7 @@ local function reactor_cmnd(pos, cmnd, payload)
end
local function can_start(pos, mem, state)
local function can_start(pos, nvm, state)
-- check reactor
local res = reactor_cmnd(pos, "check")
if not res then
@ -105,15 +105,15 @@ local function can_start(pos, mem, state)
return true
end
local function start_node(pos, mem, state)
local function start_node(pos, nvm, state)
reactor_cmnd(pos, "start")
del_liquids(pos)
mem.running = true
nvm.running = true
end
local function stop_node(pos, mem, state)
local function stop_node(pos, nvm, state)
reactor_cmnd(pos, "stop")
mem.running = false
nvm.running = false
end
local State = techage.NodeStates:new({
@ -128,30 +128,30 @@ local State = techage.NodeStates:new({
stop_node = stop_node,
})
local function dosing(pos, mem, elapsed)
local function dosing(pos, nvm, elapsed)
-- trigger reactor (power)
if not reactor_cmnd(pos, "power") then
if not mem.techage_countdown or mem.techage_countdown < 3 then
if not nvm.techage_countdown or nvm.techage_countdown < 3 then
reactor_cmnd(pos, "stop")
State:nopower(pos, mem, S("reactor has no power"))
State:nopower(pos, nvm, S("reactor has no power"))
end
State:idle(pos, mem)
State:idle(pos, nvm)
return
end
-- check from time to time
mem.check_cnt = (mem.check_cnt or 0) + 1
if mem.check_cnt >= 4 then
mem.check_cnt = 0
nvm.check_cnt = (nvm.check_cnt or 0) + 1
if nvm.check_cnt >= 4 then
nvm.check_cnt = 0
local res = reactor_cmnd(pos, "check")
if not res then
State:fault(pos, mem, S("reactor defect"))
State:fault(pos, nvm, S("reactor defect"))
reactor_cmnd(pos, "stop")
return
end
end
-- available liquids
local liquids = get_liquids(pos)
local recipe = recipes.get(mem, "ta4_doser")
local recipe = recipes.get(nvm, "ta4_doser")
if not liquids or not recipe then return end
-- inputs
local starter = get_starter_name(pos)
@ -159,12 +159,12 @@ local function dosing(pos, mem, elapsed)
if item.name ~= "" then
local outdir = liquids[item.name]
if not outdir then
State:standby(pos, mem)
State:standby(pos, nvm)
reactor_cmnd(pos, "stop")
return
end
if liquid.take(pos, outdir, item.name, item.num, starter) < item.num then
State:standby(pos, mem)
State:standby(pos, nvm)
reactor_cmnd(pos, "stop")
return
end
@ -176,7 +176,7 @@ local function dosing(pos, mem, elapsed)
name = recipe.output.name,
amount = recipe.output.num})
if not leftover or (tonumber(leftover) or 1) > 0 then
State:blocked(pos, mem)
State:blocked(pos, nvm)
reactor_cmnd(pos, "stop")
return
end
@ -185,23 +185,23 @@ local function dosing(pos, mem, elapsed)
name = recipe.waste.name,
amount = recipe.waste.num})
if not leftover or (tonumber(leftover) or 1) > 0 then
State:blocked(pos, mem)
State:blocked(pos, nvm)
reactor_cmnd(pos, "stop")
return
end
end
State:keep_running(pos, mem, COUNTDOWN_TICKS)
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
dosing(pos, mem, elapsed)
return State:is_active(mem)
local nvm = techage.get_nvm(pos)
dosing(pos, nvm, elapsed)
return State:is_active(nvm)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function on_receive_fields(pos, formname, fields, player)
@ -209,17 +209,17 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
local mem = tubelib2.get_mem(pos)
if not mem.running then
local nvm = techage.get_nvm(pos)
if not nvm.running then
recipes.on_receive_fields(pos, formname, fields, player)
end
set_starter_name(pos, player)
State:state_button_event(pos, mem, fields)
M(pos):set_string("formspec", formspec(State, pos, mem))
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local nworks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "pump",
},
@ -237,13 +237,13 @@ minetest.register_node("techage:ta4_doser", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_doser")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec(State, pos, mem))
meta:set_string("formspec", formspec(State, pos, nvm))
meta:set_string("infotext", S("TA4 Doser").." "..number)
State:node_init(pos, mem, number)
State:node_init(pos, nvm, number)
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
@ -253,7 +253,7 @@ minetest.register_node("techage:ta4_doser", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
Pipe:after_dig_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,

View File

@ -66,7 +66,7 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {U=1}, -- Pipe connection sides
ntype = "tank",
},

View File

@ -23,17 +23,17 @@ local liquid = techage.liquid
local PWR_NEEDED = 8
local CYCLE_TIME = 4
local function on_power(pos, mem)
if mem.running then
local function on_power(pos, nvm)
if nvm.running then
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", S("on"))
mem.has_power = true
nvm.has_power = true
end
end
local function on_nopower(pos, mem)
local function on_nopower(pos, nvm)
M(pos):set_string("infotext", S("no power"))
mem.has_power = false
nvm.has_power = false
end
minetest.register_node("techage:ta4_reactor_stand", {
@ -70,7 +70,7 @@ minetest.register_node("techage:ta4_reactor_stand", {
},
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(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"))
@ -83,18 +83,18 @@ minetest.register_node("techage:ta4_reactor_stand", {
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)
local nvm = techage.get_nvm(pos)
power.consumer_alive(pos, nvm)
minetest.sound_play("techage_reactor", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
return mem.running
return nvm.running
end,
after_dig_node = function(pos, oldnode)
techage.power.after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype = "light",
@ -105,7 +105,7 @@ minetest.register_node("techage:ta4_reactor_stand", {
sounds = default.node_sound_metal_defaults(),
-- Pipe connection
networks = {
pipe = {
pipe2 = {
sides = {R=1},
ntype = "pump",
},
@ -124,25 +124,25 @@ techage.power.enrich_node({"techage:ta4_reactor_stand"}, {
techage.register_node({"techage:ta4_reactor_stand"}, {
on_transfer = function(pos, in_dir, topic, payload)
--print(topic, dump(payload))
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "power" then
--print("power", mem.has_power)
return mem.has_power or power.power_available(pos, mem, 0)
--print("power", nvm.has_power)
return nvm.has_power or power.power_available(pos, Cable)
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)
return power.power_available(pos, Cable)
elseif topic == "start" and payload then
mem.running = true
mem.has_power = false
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
nvm.running = true
nvm.has_power = false
power.consumer_start(pos, Cable, CYCLE_TIME)
M(pos):set_string("infotext", "...")
return true
elseif topic == "stop" then
mem.running = false
mem.has_power = false
power.consumer_stop(pos, mem)
nvm.running = false
nvm.has_power = false
power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
return true
@ -180,7 +180,7 @@ minetest.register_node("techage:ta4_reactor_base", {
sounds = default.node_sound_stone_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {R=1}, -- Pipe connection sides
ntype = "pump",
},

View File

@ -220,9 +220,9 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
end
end,
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return techage.power.percent(PWR_CAPA, mem.provided)
return techage.power.percent(PWR_CAPA, nvm.provided)
else
return State:on_receive_message(pos, topic, payload)
end

View File

@ -38,28 +38,28 @@ local function firehole(pos, on)
end
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
-- 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
(nvm.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
if mem.burn_cycles <= 0 then
nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
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) * EFFICIENCY / CYCLE_TIME
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
@ -67,9 +67,9 @@ local function node_timer(pos, elapsed)
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)
@ -102,13 +102,13 @@ minetest.register_node("techage:coalfirebox", {
on_rightclick = firebox.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:coalfirebox")
mem.running = false
mem.burn_cycles = 0
mem.power_level = 4
nvm.running = false
nvm.burn_cycles = 0
nvm.power_level = 4
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 +119,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,
})
@ -189,32 +189,32 @@ minetest.register_node("techage:coalfirehole_on", {
})
local function on_timer2(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
fuel.formspec_update(pos, mem)
local nvm = techage.get_nvm(pos)
if nvm.running then
fuel.formspec_update(pos, nvm)
-- 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
(nvm.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
nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.burn_cycles <= 0 then
if nvm.liquid.amount > 0 then
nvm.liquid.amount = nvm.liquid.amount - 1
nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
nvm.burn_cycles_total = nvm.burn_cycles
else
mem.running = false
mem.liquid.name = nil
nvm.running = false
nvm.liquid.name = nil
firehole(pos, false)
M(pos):set_string("formspec", fuel.formspec(mem))
M(pos):set_string("formspec", fuel.formspec(nvm))
return false
end
end
@ -222,13 +222,13 @@ local function on_timer2(pos, elapsed)
end
end
local function start_firebox2(pos, mem)
if not mem.running and mem.liquid.amount > 0 then
mem.running = true
local function start_firebox2(pos, nvm)
if not nvm.running and nvm.liquid.amount > 0 then
nvm.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))
M(pos):set_string("formspec", fuel.formspec(nvm))
end
end
@ -258,14 +258,14 @@ minetest.register_node("techage:oilfirebox", {
on_rightclick = fuel.on_rightclick,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:oilfirebox")
mem.running = false
mem.burn_cycles = 0
mem.liquid = {}
mem.liquid.amount = 0
nvm.running = false
nvm.burn_cycles = 0
nvm.liquid = {}
nvm.liquid.amount = 0
local meta = M(pos)
meta:set_string("formspec", fuel.formspec(mem))
meta:set_string("formspec", fuel.formspec(nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
firehole(pos, false)
@ -276,10 +276,10 @@ minetest.register_node("techage:oilfirebox", {
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)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
minetest.after(1, start_firebox2, pos, nvm)
fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
end,
@ -290,10 +290,10 @@ minetest.register_node("techage:oilfirebox", {
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)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
start_firebox2(pos, nvm)
return leftover
end
return amount
@ -321,8 +321,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 +333,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"
@ -352,15 +352,15 @@ techage.register_node({"techage:coalfirebox"}, {
techage.register_node({"techage:oilfirebox"}, {
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 == "fuel" then
return mem.liquid and mem.liquid.amount and mem.liquid.amount
return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
else
return "unsupported"
end

View File

@ -32,11 +32,11 @@ end
-- to detect the missing turbine
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.remote_trigger = (mem.remote_trigger or 0) - 1
if mem.remote_trigger <= 0 then
local nvm = techage.get_nvm(pos)
nvm.remote_trigger = (nvm.remote_trigger or 0) - 1
if nvm.remote_trigger <= 0 then
swap_node(pos, "techage:ta4_generator")
mem.running = false
nvm.running = false
end
return true
end
@ -118,9 +118,9 @@ techage.power.register_node({"techage:ta4_generator", "techage:ta4_generator_on"
conn_sides = {"R"},
power_network = Cable,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.remote_trigger = 0
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.remote_trigger = 0
end,
})
@ -128,24 +128,24 @@ techage.power.register_node({"techage:ta4_generator", "techage:ta4_generator_on"
-- controlled by the turbine
techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "power" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
return techage.power.power_network_available(pos)
elseif topic == "start" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
swap_node(pos, "techage:ta4_generator_on")
mem.running = true
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
return true
elseif topic == "stop" then
swap_node(pos, "techage:ta4_generator")
mem.running = false
mem.remote_trigger = 0
nvm.running = false
nvm.remote_trigger = 0
minetest.get_node_timer(pos):stop()
return true
elseif topic == "trigger" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
return true
end
end,

View File

@ -28,7 +28,7 @@ local PWR_CAPA = {
}
local Cable = techage.ElectricCable
local Pipe = techage.BiogasPipe
local Pipe = techage.LiquidPipe
local power = techage.power
local function in_range(val, min, max)
@ -69,9 +69,9 @@ local function inlet_cmnd(pos, cmnd, payload)
end
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.handle = minetest.sound_play("techage_booster", {
local nvm = techage.get_nvm(pos)
if nvm.running then
nvm.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
@ -79,10 +79,10 @@ local function play_sound(pos)
end
local function stop_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running and mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
local nvm = techage.get_nvm(pos)
if nvm.running and nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
end
end
@ -95,12 +95,12 @@ local function swap_node(pos, name)
minetest.swap_node(pos, node)
end
local function charging(pos, mem, is_charging)
if mem.capa >= mem.capa_max then
local function charging(pos, nvm, is_charging)
if nvm.capa >= nvm.capa_max then
return
end
if is_charging ~= mem.was_charging then
mem.was_charging = is_charging
if is_charging ~= nvm.was_charging then
nvm.was_charging = is_charging
if is_charging then
turbine_cmnd(pos, "stop")
play_sound(pos)
@ -113,12 +113,12 @@ local function charging(pos, mem, is_charging)
end
end
local function delivering(pos, mem, delivered)
if mem.capa <= 0 then
local function delivering(pos, nvm, delivered)
if nvm.capa <= 0 then
return
end
if delivered ~= mem.had_delivered then
mem.had_delivered = delivered
if delivered ~= nvm.had_delivered then
nvm.had_delivered = delivered
if delivered > 0 then
turbine_cmnd(pos, "start")
elseif delivered == 0 then
@ -127,26 +127,26 @@ local function delivering(pos, mem, delivered)
end
end
local function glowing(pos, mem, should_glow)
if mem.win_pos then
local function glowing(pos, nvm, should_glow)
if nvm.win_pos then
if should_glow then
swap_node(mem.win_pos, "techage:glow_gravel")
swap_node(nvm.win_pos, "techage:glow_gravel")
else
swap_node(mem.win_pos, "default:gravel")
swap_node(nvm.win_pos, "default:gravel")
end
end
end
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
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(mem.capa_max, mem.capa).."]"..
"image[0,0.5;1,2;"..techage.power.formspec_power_bar(nvm.capa_max, nvm.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).."]"..
"image_button[3,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"image[4,0.5;1,2;"..techage.power.formspec_load_bar(-(nvm.delivered or 0), PWR_PERF).."]"..
"label[4.2,2.5;Flow]"
end
@ -156,12 +156,12 @@ local function error_info(pos, err)
M(pos1):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num.." : "..err)
end
local function can_start(pos, mem, state)
local function can_start(pos, nvm, state)
if turbine_cmnd(pos, "power") then
local diameter = inlet_cmnd(pos, "diameter")
if diameter then
mem.capa_max = PWR_CAPA[tonumber(diameter)] or 0
if mem.capa_max ~= 0 then
nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0
if nvm.capa_max ~= 0 then
local owner = M(pos):get_string("owner") or ""
if inlet_cmnd(pos, "volume", owner) then
error_info(pos, "")
@ -185,21 +185,21 @@ local function can_start(pos, mem, state)
return false
end
local function start_node(pos, mem, state)
mem.running = true
mem.delivered = 0
mem.was_charging = true
mem.had_delivered = nil
local function start_node(pos, nvm, state)
nvm.running = true
nvm.delivered = 0
nvm.was_charging = true
nvm.had_delivered = nil
play_sound(pos)
mem.win_pos = inlet_cmnd(pos, "window")
power.secondary_start(pos, mem, PWR_PERF, PWR_PERF)
nvm.win_pos = inlet_cmnd(pos, "window")
power.secondary_start(pos, nvm, PWR_PERF, PWR_PERF)
end
local function stop_node(pos, mem, state)
mem.running = false
mem.delivered = 0
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.delivered = 0
turbine_cmnd(pos, "stop")
power.secondary_stop(pos, mem)
power.secondary_stop(pos, nvm)
end
local State = techage.NodeStates:new({
@ -212,24 +212,24 @@ local State = techage.NodeStates:new({
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running and turbine_cmnd(pos, "power") then
mem.capa = mem.capa or 0
mem.capa_max = mem.capa_max or 0
mem.delivered = mem.delivered or 0
mem.delivered = power.secondary_alive(pos, mem, mem.capa, mem.capa_max)
mem.capa = mem.capa - mem.delivered
mem.capa = in_range(mem.capa, 0, mem.capa_max)
glowing(pos, mem, mem.capa > mem.capa_max * 0.8)
charging(pos, mem, mem.delivered < 0)
delivering(pos, mem, mem.delivered)
local nvm = techage.get_nvm(pos)
if nvm.running and turbine_cmnd(pos, "power") then
nvm.capa = nvm.capa or 0
nvm.capa_max = nvm.capa_max or 0
nvm.delivered = nvm.delivered or 0
nvm.delivered = power.secondary_alive(pos, nvm, nvm.capa, nvm.capa_max)
nvm.capa = nvm.capa - nvm.delivered
nvm.capa = in_range(nvm.capa, 0, nvm.capa_max)
glowing(pos, nvm, nvm.capa > nvm.capa_max * 0.8)
charging(pos, nvm, nvm.delivered < 0)
delivering(pos, nvm, nvm.delivered)
end
return mem.running
return nvm.running
end
local function can_dig(pos, player)
local mem = tubelib2.get_mem(pos)
return not mem.running
local nvm = techage.get_nvm(pos)
return not nvm.running
end
local function orientate_node(pos, name)
@ -292,16 +292,16 @@ minetest.register_node("techage:heatexchanger2", {
return true
end
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1)
local nvm = techage.get_nvm(pos1)
local own_num = M(pos1):get_string("node_number")
M(pos):set_string("formspec", formspec(State, pos1, mem))
M(pos):set_string("formspec", formspec(State, pos1, nvm))
M(pos):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num)
end,
on_rightclick = function(pos)
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1)
M(pos):set_string("formspec", formspec(State, pos1, mem))
local nvm = techage.get_nvm(pos1)
M(pos):set_string("formspec", formspec(State, pos1, nvm))
end,
on_receive_fields = function(pos, formname, fields, player)
@ -309,9 +309,9 @@ minetest.register_node("techage:heatexchanger2", {
return
end
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
local mem = tubelib2.get_mem(pos1)
State:state_button_event(pos1, mem, fields)
M(pos):set_string("formspec", formspec(State, pos1, mem))
local nvm = techage.get_nvm(pos1)
State:state_button_event(pos1, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos1, nvm))
end,
paramtype2 = "facedir",
@ -345,12 +345,12 @@ techage.power.register_node({"techage:heatexchanger1"}, {
conn_sides = {"F", "B"},
power_network = Cable,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = M(pos)
local own_num = techage.add_node(pos, "techage:heatexchanger1")
meta:set_string("owner", placer:get_player_name())
State:node_init(pos, mem, own_num)
mem.capa = 0
State:node_init(pos, nvm, own_num)
nvm.capa = 0
end,
})
@ -359,11 +359,11 @@ Pipe:add_secondary_node_names({"techage:heatexchanger1", "techage:heatexchanger3
-- for logical communication
techage.register_node({"techage:heatexchanger1"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return techage.power.percent(mem.capa_max, mem.capa)
return techage.power.percent(nvm.capa_max, nvm.capa)
elseif topic == "size" then
return (mem.capa_max or 0) / GRVL_CAPA
return (nvm.capa_max or 0) / GRVL_CAPA
else
return State:on_receive_message(pos, topic, payload)
end

View File

@ -19,7 +19,7 @@ local D = techage.Debug
local M = minetest.get_meta
local S = techage.S
local Pipe = techage.BiogasPipe
local Pipe = techage.LiquidPipe
minetest.register_node("techage:ta4_pipe_inlet", {
description = S("TA4 Pipe Inlet"),

View File

@ -18,7 +18,7 @@ local S = techage.S
local CYCLE_TIME = 2
local Pipe = techage.BiogasPipe
local Pipe = techage.LiquidPipe
local function swap_node(pos, name)
local node = techage.get_node_lvm(pos)
@ -30,9 +30,9 @@ local function swap_node(pos, name)
end
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then
mem.handle = minetest.sound_play("techage_turbine", {
local nvm = techage.get_nvm(pos)
if nvm.running then
nvm.handle = minetest.sound_play("techage_turbine", {
pos = pos,
gain = 0.5,
max_hear_distance = 10})
@ -40,10 +40,10 @@ local function play_sound(pos)
end
local function stop_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.running and mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
local nvm = techage.get_nvm(pos)
if nvm.running and nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
end
end
@ -59,12 +59,12 @@ end
-- to detect the missing "steam pressure"
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.remote_trigger = (mem.remote_trigger or 0) - 1
if mem.remote_trigger <= 0 then
local nvm = techage.get_nvm(pos)
nvm.remote_trigger = (nvm.remote_trigger or 0) - 1
if nvm.remote_trigger <= 0 then
swap_node(pos, "techage:ta4_turbine")
stop_sound(pos)
mem.running = false
nvm.running = false
end
play_sound(pos)
return true
@ -138,35 +138,35 @@ techage.power.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, {
conn_sides = {"L", "U"},
power_network = Pipe,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
mem.running = false
mem.remote_trigger = 0
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.remote_trigger = 0
end,
})
-- for logical communication
techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "power" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
return generator_cmnd(pos, topic)
elseif topic == "start" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
swap_node(pos, "techage:ta4_turbine_on")
mem.running = true
nvm.running = true
minetest.get_node_timer(pos):start(CYCLE_TIME)
play_sound(pos)
return generator_cmnd(pos, topic)
elseif topic == "stop" then
swap_node(pos, "techage:ta4_turbine")
mem.running = false
mem.remote_trigger = 0
nvm.running = false
nvm.remote_trigger = 0
minetest.get_node_timer(pos):stop()
stop_sound(pos)
return generator_cmnd(pos, topic)
elseif topic == "trigger" then
mem.remote_trigger = 2
nvm.remote_trigger = 2
return generator_cmnd(pos, topic)
end
end

View File

@ -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,8 +20,9 @@ local D = techage.Debug
local PWR_NEEDED = 3
local CYCLE_TIME = 2
local Power = techage.ElectricCable
local Cable = techage.ElectricCable
local power = techage.power
--local networks = techage.networks
local function infotext(pos, state)
M(pos):set_string("infotext", S("TA3 Booster")..": "..state)
@ -36,36 +37,71 @@ 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:ta3_booster_on")
infotext(pos, "running")
local function play_sound(pos)
local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
if D.dbg2 then D.dbg("booster on_power") end
mem.is_powered = true
end
local function on_nopower(pos, mem)
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 on_power(pos)
swap_node(pos, "techage:ta3_booster_on")
infotext(pos, "running")
play_sound(pos)
end
local function on_nopower(pos)
swap_node(pos, "techage:ta3_booster")
infotext(pos, "no power")
if D.dbg2 then D.dbg("booster on_nopower") end
mem.is_powered = false
stop_sound(pos)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running and mem.is_powered then
minetest.sound_play("techage_booster", {
pos = pos,
gain = 1,
max_hear_distance = 7})
end
if mem.running then
power.consumer_alive(pos, mem)
end
return mem.running
power.consumer_alive(pos, Cable, CYCLE_TIME)
return true
end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
Cable:after_place_node(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("indir", indir)
infotext(pos, "stopped")
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 = {B = true, F = true, L = true, D = true, U = true},
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:ta3_booster", {
description = S("TA3 Booster"),
tiles = {
@ -77,7 +113,13 @@ minetest.register_node("techage:ta3_booster", {
"techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png",
},
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,
@ -116,6 +158,11 @@ minetest.register_node("techage:ta3_booster_on", {
},
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 = {not_in_creative_inventory = 1},
diggable = false,
@ -124,46 +171,30 @@ minetest.register_node("techage:ta3_booster_on", {
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
power_network = Power,
conn_sides = {"F", "B", "U", "D", "L"},
on_power = on_power,
on_nopower = on_nopower,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("indir", indir)
infotext(pos, "stopped")
end,
})
Cable:add_secondary_node_names({"techage:ta3_booster", "techage:ta3_booster_on"})
-- for intra machine communication
techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
on_transfer = function(pos, in_dir, topic, payload)
if M(pos):get_int("indir") == in_dir then
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "power" then
if D.dbg2 then D.dbg("booster power") end
return power.power_available(pos, mem, 0)
elseif topic == "start" and not mem.running then
if D.dbg2 then D.dbg("booster try start", mem.pwr_master_pos, mem.pwr_power_provided_cnt) end
if power.power_available(pos, mem, 0) then
mem.running = true
if D.dbg2 then D.dbg("booster start") end
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
return techage.get_node_lvm(pos).name == "techage:ta3_booster_on"
elseif topic == "start" and not nvm.running then
if power.power_available(pos, Cable) then
nvm.running = true
power.consumer_start(pos, Cable, CYCLE_TIME)
minetest.get_node_timer(pos):start(CYCLE_TIME)
else
if D.dbg2 then D.dbg("booster no power") end
infotext(pos, "no power")
end
elseif topic == "stop" then
mem.running = false
if D.dbg2 then D.dbg("booster stop") end
nvm.running = false
swap_node(pos, "techage:ta3_booster")
power.consumer_stop(pos, mem)
power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
infotext(pos, "stopped")
stop_sound(pos)
end
end
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -104,17 +104,17 @@ local function process(inv, recipe, output)
return techage.RUNNING
end
function techage.furnace.check_if_worth_to_wakeup(pos, mem)
function techage.furnace.check_if_worth_to_wakeup(pos, nvm)
local inv = M(pos):get_inventory()
if not mem.output or not mem.num_recipe then
if not nvm.output or not nvm.num_recipe then
return false
end
local recipe = Recipes[mem.output] and Recipes[mem.output][mem.num_recipe]
local recipe = Recipes[nvm.output] and Recipes[nvm.output][nvm.num_recipe]
if not recipe then
return false
end
-- check dst inv
local stack = ItemStack(mem.output)
local stack = ItemStack(nvm.output)
stack:set_count(recipe.number)
if not inv:room_for_item("dst", stack) then
return false
@ -129,52 +129,52 @@ function techage.furnace.check_if_worth_to_wakeup(pos, mem)
return true
end
function techage.furnace.smelting(pos, mem, elapsed)
function techage.furnace.smelting(pos, nvm, elapsed)
local inv = M(pos):get_inventory()
local state = techage.RUNNING
if inv and not inv:is_empty("src") then
if not mem.output or not mem.num_recipe then
if not nvm.output or not nvm.num_recipe then
return techage.FAULT, "recipe error"
end
local recipe = Recipes[mem.output] and Recipes[mem.output][mem.num_recipe]
local recipe = Recipes[nvm.output] and Recipes[nvm.output][nvm.num_recipe]
if not recipe then
return techage.FAULT, "recipe error"
end
elapsed = elapsed + (mem.leftover or 0)
elapsed = elapsed + (nvm.leftover or 0)
while elapsed >= recipe.time do
state = process(inv, recipe, mem.output)
state = process(inv, recipe, nvm.output)
if state ~= techage.RUNNING then
return state
end
elapsed = elapsed - recipe.time
end
mem.leftover = elapsed
nvm.leftover = elapsed
if recipe.time >= 10 then
mem.item_percent = math.min(math.floor((mem.leftover * 100.0) / recipe.time), 100)
nvm.item_percent = math.min(math.floor((nvm.leftover * 100.0) / recipe.time), 100)
else
mem.item_percent = 100
nvm.item_percent = 100
end
return state
end
return techage.STANDBY
end
function techage.furnace.get_output(mem, ingr, idx)
function techage.furnace.get_output(nvm, ingr, idx)
local tbl = get_recipes(ingr)
idx = range(idx, 1, #tbl)
mem.output = tbl[idx] or tbl[1]
mem.num_recipe = all_ingredients_available(mem.output, ingr)
return mem.output
nvm.output = tbl[idx] or tbl[1]
nvm.num_recipe = all_ingredients_available(nvm.output, ingr)
return nvm.output
end
function techage.furnace.get_num_recipes(ingr)
return #get_recipes(ingr)
end
function techage.furnace.reset_cooking(mem)
mem.leftover = 0
mem.item_percent = 0
function techage.furnace.reset_cooking(nvm)
nvm.leftover = 0
nvm.item_percent = 0
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -25,32 +25,33 @@ local CYCLE_TIME = 2
local EFFICIENCY = 2 -- burn cycles
local CATEGORY = 3
local function has_fuel(pos, mem)
return mem.burn_cycles > 0 or (mem.liquid and mem.liquid.amount and mem.liquid.amount > 0)
local function has_fuel(pos, nvm)
print("has_fuel", nvm.burn_cycles, topic, payload)
return nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
end
local function stop_firebox(pos, mem)
mem.running = false
local function stop_firebox(pos, nvm)
nvm.running = false
firebox.swap_node(pos, "techage:furnace_firebox")
minetest.get_node_timer(pos):stop()
M(pos):set_string("formspec", fuel.formspec(mem))
M(pos):set_string("formspec", fuel.formspec(nvm))
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
if mem.running then
fuel.formspec_update(pos, mem)
mem.burn_cycles = (mem.burn_cycles or 0) - 1
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
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.running then
fuel.formspec_update(pos, nvm)
nvm.burn_cycles = (nvm.burn_cycles or 0) - 1
if nvm.burn_cycles <= 0 then
if nvm.liquid.amount > 0 then
nvm.liquid.amount = nvm.liquid.amount - 1
nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
nvm.burn_cycles_total = nvm.burn_cycles
else
mem.liquid.name = nil
stop_firebox(pos, mem)
nvm.liquid.name = nil
stop_firebox(pos, nvm)
return false
end
end
@ -58,13 +59,13 @@ local function node_timer(pos, elapsed)
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)
firebox.swap_node(pos, "techage:furnace_firebox_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("formspec", fuel.formspec(mem))
M(pos):set_string("formspec", fuel.formspec(nvm))
end
end
@ -92,7 +93,7 @@ local _liquid = {
}
local _networks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
@ -126,14 +127,14 @@ minetest.register_node("techage:furnace_firebox", {
networks = _networks,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
techage.add_node(pos, "techage:furnace_firebox")
mem.running = false
mem.burn_cycles = 0
mem.liquid = {}
mem.liquid.amount = 0
nvm.running = false
nvm.burn_cycles = 0
nvm.liquid = {}
nvm.liquid.amount = 0
local meta = M(pos)
meta:set_string("formspec", fuel.formspec(mem))
meta:set_string("formspec", fuel.formspec(nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
@ -178,10 +179,10 @@ minetest.register_node("techage:furnace_firebox_on", {
networks = _networks,
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
start_firebox(pos, mem)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
start_firebox(pos, nvm)
fuel.on_metadata_inventory_put(pos, listname, index, stack, player)
end,
})
@ -197,31 +198,32 @@ minetest.register_craft({
techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, {
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 == "fuel" then
return mem.liquid and mem.liquid.amount and mem.liquid.amount
return nvm.liquid and nvm.liquid.amount and nvm.liquid.amount
else
return "unsupported"
end
end,
-- called from furnace_top
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "fuel" then
return has_fuel(pos, mem) and booster_cmnd(pos, "power")
print(dump(nvm))
return has_fuel(pos, nvm) and booster_cmnd(pos, "power")
elseif topic == "running" then
return mem.running and booster_cmnd(pos, "power")
return nvm.running and booster_cmnd(pos, "power")
elseif topic == "start" then
start_firebox(pos, mem)
start_firebox(pos, nvm)
booster_cmnd(pos, "start")
elseif topic == "stop" then
stop_firebox(pos, mem)
stop_firebox(pos, nvm)
booster_cmnd(pos, "stop")
end
end

View File

@ -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,26 +33,26 @@ local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup
local range = techage.in_range
local function update_recipe_menu(pos, mem)
local function update_recipe_menu(pos, nvm)
local ingr = get_ingredients(pos)
mem.rp_num = num_recipes(ingr)
mem.rp_idx = range(mem.rp_idx or 1, 0, mem.rp_num)
mem.rp_outp = get_output(mem, ingr, mem.rp_idx)
nvm.rp_num = num_recipes(ingr)
nvm.rp_idx = range(nvm.rp_idx or 1, 0, nvm.rp_num)
nvm.rp_outp = get_output(nvm, ingr, nvm.rp_idx)
end
local function formspec(self, pos, mem)
local idx = mem.rp_idx or 1
local num = mem.rp_num or 1
local outp = mem.rp_outp or ""
local function formspec(self, pos, nvm)
local idx = nvm.rp_idx or 1
local num = nvm.rp_num or 1
local outp = nvm.rp_outp or ""
return "size[8,7.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0,0;2,2;]"..
"image[2,0.5;1,1;techage_form_arrow_bg.png^[lowpart:"..
(mem.item_percent or 0)..":techage_form_arrow_fg.png^[transformR270]"..
"image_button[2,2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"tooltip[2,2;1,1;"..self:get_state_tooltip(mem).."]"..
(nvm.item_percent or 0)..":techage_form_arrow_fg.png^[transformR270]"..
"image_button[2,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[context;dst;3,0;2,2;]"..
@ -71,8 +71,8 @@ local function formspec(self, pos, mem)
end
local function on_rightclick(pos, node, clicker)
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
local function firebox_cmnd(pos, cmnd)
@ -86,34 +86,34 @@ local function firebox_cmnd(pos, cmnd)
"techage:furnace_heater", "techage:furnace_heater_on"})
end
local function cooking(pos, crd, mem, elapsed)
if mem.techage_state == techage.RUNNING or check_if_worth_to_wakeup(pos, mem) then
local function cooking(pos, crd, nvm, elapsed)
if nvm.techage_state == techage.RUNNING or check_if_worth_to_wakeup(pos, nvm) then
if firebox_cmnd(pos, "fuel") then
local state, err = smelting(pos, mem, elapsed)
local state, err = smelting(pos, nvm, elapsed)
if state == techage.RUNNING then
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif state == techage.BLOCKED then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
elseif state == techage.FAULT then
crd.State:fault(pos, mem, err)
crd.State:fault(pos, nvm, err)
elseif state == techage.STANDBY then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
else
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
end
end
end
local function keep_running(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
cooking(pos, crd, mem, elapsed)
mem.toggle = not mem.toggle
if mem.toggle then -- progress bar/arrow
M(pos):set_string("formspec", formspec(crd.State, pos, mem))
cooking(pos, crd, nvm, elapsed)
nvm.toggle = not nvm.toggle
if nvm.toggle then -- progress bar/arrow
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
return crd.State:is_active(mem)
return crd.State:is_active(nvm)
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -121,7 +121,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
return 0
end
if listname == "src" then
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
return stack:get_count()
elseif listname == "dst" then
return 0
@ -143,31 +143,31 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
end
local function on_metadata_inventory(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
M(pos):set_string("formspec", formspec(crd.State, pos, mem))
M(pos):set_string("formspec", formspec(crd.State, pos, 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)
mem.rp_idx = mem.rp_idx or 1
local nvm = techage.get_nvm(pos)
nvm.rp_idx = nvm.rp_idx or 1
if fields.next == ">>" then
local ingr = get_ingredients(pos)
mem.rp_idx = math.min(mem.rp_idx + 1, num_recipes(ingr))
update_recipe_menu(pos, mem)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
reset_cooking(mem)
nvm.rp_idx = math.min(nvm.rp_idx + 1, num_recipes(ingr))
update_recipe_menu(pos, nvm)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
reset_cooking(nvm)
elseif fields.priv == "<<" then
local ingr = get_ingredients(pos)
mem.rp_idx = range(mem.rp_idx - 1, 1, num_recipes(ingr))
update_recipe_menu(pos, mem)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
reset_cooking(mem)
nvm.rp_idx = range(nvm.rp_idx - 1, 1, num_recipes(ingr))
update_recipe_menu(pos, nvm)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
reset_cooking(nvm)
end
CRD(pos).State:state_button_event(pos, mem, fields)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
local function can_dig(pos, player)
@ -178,8 +178,7 @@ local function can_dig(pos, player)
return inv:is_empty("dst") and inv:is_empty("src")
end
local function can_start(pos, mem, state)
if D.dbg2 then D.dbg("can_start", state, firebox_cmnd(pos, "fuel")) end
local function can_start(pos, nvm, state)
if not firebox_cmnd(pos, "fuel") then
return S("no fuel or no power")
end
@ -187,7 +186,6 @@ local function can_start(pos, mem, state)
end
local function on_node_state_change(pos, old_state, new_state)
if D.dbg2 then D.dbg("on_node_state_change", new_state) end
local pwr1 = techage.needs_power2(old_state)
local pwr2 = techage.needs_power2(new_state)
if pwr1 ~= pwr2 then
@ -197,8 +195,8 @@ local function on_node_state_change(pos, old_state, new_state)
firebox_cmnd(pos, "stop")
end
end
local mem = tubelib2.get_mem(pos)
reset_cooking(mem)
local nvm = techage.get_nvm(pos)
reset_cooking(nvm)
end
local tiles = {}

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -24,7 +24,7 @@ local liquid = techage.liquid
local CYCLE_TIME = 2
local PWR_NEEDED = 14
local Power = techage.ElectricCable
local Cable = techage.ElectricCable
local power = techage.power
local function swap_node(pos, name)
@ -36,25 +36,42 @@ 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:furnace_heater_on")
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
mem.has_power = true
local function on_power(pos)
swap_node(pos, "techage:furnace_heater_on")
end
local function on_nopower(pos, mem)
local function on_nopower(pos)
swap_node(pos, "techage:furnace_heater")
mem.has_power = false
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
power.consumer_alive(pos, mem)
return mem.running
power.consumer_alive(pos, Cable, CYCLE_TIME)
return true
end
local function after_place_node(pos)
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 = {B = true, F = true, L = true, D = true, U = true},
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
minetest.register_node("techage:furnace_heater", {
description = S("TA4 Furnace Heater"),
tiles = {
@ -66,7 +83,13 @@ minetest.register_node("techage:furnace_heater", {
"techage_concrete.png^techage_frame_ta3.png",
"techage_concrete.png^techage_appl_heater.png^techage_frame_ta3.png",
},
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,
@ -86,8 +109,13 @@ minetest.register_node("techage:furnace_heater_on", {
"techage_concrete.png^techage_appl_heater_on.png^techage_frame_ta3.png",
},
light_source = 8,
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,
light_source = 8,
paramtype2 = "facedir",
groups = {not_in_creative_inventory = 1},
diggable = false,
@ -96,15 +124,7 @@ minetest.register_node("techage:furnace_heater_on", {
sounds = default.node_sound_wood_defaults(),
})
techage.power.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, {
power_network = Power,
conn_sides = {"F", "B", "U", "D", "L"},
on_power = on_power,
on_nopower = on_nopower,
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
end,
})
Cable:add_secondary_node_names({"techage:furnace_heater", "techage:furnace_heater_on"})
minetest.register_craft({
output = "techage:furnace_heater",
@ -118,22 +138,22 @@ minetest.register_craft({
techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, {
-- called from furnace_top
on_transfer = function(pos, in_dir, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "fuel" then
return mem.has_power or power.power_available(pos, mem, 0)
return power.power_available(pos, Cable)
elseif topic == "running" then
return mem.running and (mem.has_power or power.power_available(pos, mem, 0))
elseif topic == "start" and not mem.running then
if power.power_available(pos, mem, 0) then
mem.running = true
mem.has_power = false
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
return techage.get_node_lvm(pos).name == "techage:furnace_heater_on"
elseif topic == "start" and not nvm.running then
if power.power_available(pos, Cable) then
nvm.running = true
power.consumer_start(pos, Cable, CYCLE_TIME)
minetest.get_node_timer(pos):start(CYCLE_TIME)
return true
end
elseif topic == "stop" and mem.running then
mem.running = false
elseif topic == "stop" and nvm.running then
nvm.running = false
swap_node(pos, "techage:furnace_heater")
power.consumer_stop(pos, mem)
power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
return true
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information

View File

@ -27,33 +27,33 @@ 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")
local function formspec(self, pos, nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,6.6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, mem.consumed).."]"..
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, nvm.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).."]"..
"image_button[3.5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.5,1;1,1;"..self:get_state_tooltip(nvm).."]"..
"button[1.6,1;1.8,1;update;"..update.."]"..
"list[current_player;main;0,2.8;8,4;]" ..
liquid.formspec_liquid(5, 0, mem)..
liquid.formspec_liquid(5, 0, nvm)..
default.get_hotbar_bg(0, 2.8)
end
local function start_node(pos, mem, state)
mem.running = true
mem.consumed = 0
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED)
local function start_node(pos, nvm, state)
nvm.running = true
nvm.consumed = 0
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
end
local function stop_node(pos, mem, state)
mem.running = false
mem.consumed = 0
power.secondary_stop(pos, mem)
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.consumed = 0
power.secondary_stop(pos, nvm)
end
local State = techage.NodeStates:new({
@ -69,54 +69,54 @@ local State = techage.NodeStates:new({
-- 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
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
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
local nvm = techage.get_nvm(pos)
nvm.num_pwr_units = nvm.num_pwr_units or 0
nvm.countdown = nvm.countdown or 0
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
print("electrolyzer", nvm.running, nvm.consumed, nvm.num_pwr_units, nvm.liquid.amount)
if nvm.running then
if techage.needs_power(nvm) then
nvm.consumed = -power.secondary_alive(pos, nvm, 0, 1)
--print("nvm.consumed", nvm.consumed)
if nvm.consumed > 0 then
if nvm.liquid.amount < CAPACITY then
nvm.num_pwr_units = nvm.num_pwr_units + nvm.consumed
if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
nvm.liquid.amount = nvm.liquid.amount + 1
nvm.liquid.name = "techage:hydrogen"
nvm.num_pwr_units = nvm.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM
State:keep_running(pos, nvm, 1, 0) -- count items
end
else
State:blocked(pos, mem)
power.secondary_stop(pos, mem)
State:blocked(pos, nvm)
power.secondary_stop(pos, nvm)
end
end
else
mem.consumed = -power.secondary_alive(pos, mem, 1, 1)
if mem.liquid.amount < CAPACITY then
State:start(pos, mem)
power.secondary_start(pos, mem, PWR_NEEDED, PWR_NEEDED)
nvm.consumed = -power.secondary_alive(pos, nvm, 1, 1)
if nvm.liquid.amount < CAPACITY then
State:start(pos, nvm)
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED)
end
end
end
if mem.countdown > 0 then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(State, pos, mem))
if nvm.countdown > 0 then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return mem.running or mem.countdown > 0
return nvm.running or nvm.countdown > 0
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)
local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields)
mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem))
nvm.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
@ -131,9 +131,9 @@ local function allow_metadata_inventory(pos, listname, index, stack, player)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
@ -150,13 +150,13 @@ minetest.register_node("techage:ta4_electrolyzer2", {
},
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
mem.running = false
mem.num_pwr_units = 0
State:node_init(pos, mem, number)
nvm.running = false
nvm.num_pwr_units = 0
State:node_init(pos, nvm, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem))
meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory()
inv:set_size('src', 1)
inv:set_size('dst', 1)
@ -185,7 +185,7 @@ minetest.register_node("techage:ta4_electrolyzer2", {
take = liquid.srv_take,
},
networks = {
pipe = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
@ -251,7 +251,7 @@ minetest.register_node("techage:ta4_electrolyzer2_on", {
take = liquid.srv_take,
},
networks = {
pipe = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},

View File

@ -24,16 +24,16 @@ local STANDBY_TICKS = 5
local PWR_CAPA = 40
local PWR_UNITS_PER_HYDROGEN_ITEM = 240
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
return "size[8,6.6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0.5,0;2,2;]"..
"image[4,0;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image_button[5,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
"image_button[5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"button[3.1,1;1.8,1;update;"..S("Update").."]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, mem.provided).."]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]"..
"label[6.7,1.9;"..S("\\[ku\\]").."]"..
"list[current_player;main;0,2.8;8,4;]" ..
"listring[current_player;main]"..
@ -42,16 +42,16 @@ local function formspec(self, pos, mem)
default.get_hotbar_bg(0, 2.8)
end
local function start_node(pos, mem, state)
mem.running = true
mem.provided = 0
power.generator_start(pos, mem, PWR_CAPA)
local function start_node(pos, nvm, state)
nvm.running = true
nvm.provided = 0
power.generator_start(pos, nvm, PWR_CAPA)
end
local function stop_node(pos, mem, state)
mem.running = false
mem.provided = 0
power.generator_stop(pos, mem)
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.provided = 0
power.generator_stop(pos, nvm)
end
local State = techage.NodeStates:new({
@ -78,46 +78,46 @@ end
-- converts hydrogen into power
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.num_pwr_units = mem.num_pwr_units or 0
--print("fuelcell", mem.running, mem.provided, mem.num_pwr_units, techage.get_state_string(mem))
if mem.running then
if techage.needs_power(mem) then
if mem.num_pwr_units <= 0 then
local nvm = techage.get_nvm(pos)
nvm.num_pwr_units = nvm.num_pwr_units or 0
--print("fuelcell", nvm.running, nvm.provided, nvm.num_pwr_units, techage.get_state_string(nvm))
if nvm.running then
if techage.needs_power(nvm) then
if nvm.num_pwr_units <= 0 then
if get_hydrogen(pos) then
State:keep_running(pos, mem, 1, 0) -- count items
mem.num_pwr_units = mem.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
State:keep_running(pos, nvm, 1, 0) -- count items
nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
else
State:standby(pos, mem)
mem.provided = 0
power.generator_stop(pos, mem)
M(pos):set_string("formspec", formspec(State, pos, mem))
State:standby(pos, nvm)
nvm.provided = 0
power.generator_stop(pos, nvm)
M(pos):set_string("formspec", formspec(State, pos, nvm))
return true
end
end
mem.provided = power.generator_alive(pos, mem)
mem.num_pwr_units = mem.num_pwr_units - mem.provided
nvm.provided = power.generator_alive(pos, nvm)
nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided
else
if contains_hydrogen(pos) then
State:start(pos, mem)
mem.provided = 0
power.generator_start(pos, mem, PWR_CAPA)
M(pos):set_string("formspec", formspec(State, pos, mem))
State:start(pos, nvm)
nvm.provided = 0
power.generator_start(pos, nvm, PWR_CAPA)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
end
end
return mem.running
return nvm.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)
local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
end
@ -132,8 +132,8 @@ local function allow_metadata_inventory(pos, listname, index, stack, player)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
minetest.register_node("techage:ta4_fuelcell", {
@ -149,13 +149,13 @@ minetest.register_node("techage:ta4_fuelcell", {
},
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_fuelcell")
mem.running = false
mem.num_pwr_units = 0
State:node_init(pos, mem, number)
nvm.running = false
nvm.num_pwr_units = 0
State:node_init(pos, nvm, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem))
meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory()
inv:set_size('src', 4)
end,

View File

@ -60,15 +60,7 @@ else
dofile(MP.."/power/powerswitch.lua")
dofile(MP.."/power/protection.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/ta4_cable.lua")
dofile(MP.."/power/ta4_cable.lua")
-- Iron Age
dofile(MP.."/iron_age/main.lua")
@ -109,13 +101,13 @@ else
dofile(MP.."/basic_machines/liquidsampler.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")
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")
@ -126,12 +118,12 @@ else
dofile(MP.."/coal_power_station/cooler.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")
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")
@ -139,14 +131,14 @@ 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")
@ -181,6 +173,7 @@ else
-- Test
dofile(MP.."/recipe_checker.lua")
dofile(MP.."/.test/sink.lua")
dofile(MP.."/.test/meta_node.lua")
--dofile(MP.."/.test/source.lua")
--dofile(MP.."/.test/accu.lua")
@ -213,24 +206,24 @@ else
-- 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/hydrogen.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
if techage.basalt_stone_enabled then
dofile(MP.."/items/basalt.lua")
end
-- dofile(MP.."/power3/electric_cable.lua")
-- dofile(MP.."/power3/node_api.lua")

View File

@ -18,7 +18,7 @@ local P = minetest.string_to_pos
local M = minetest.get_meta
local PWR_NEEDED = 0.5
local CYCLE_TIME = 4
local CYCLE_TIME = 2
local Cable = techage.ElectricCable
local power = techage.power
@ -33,22 +33,17 @@ local function swap_node(pos, postfix)
minetest.swap_node(pos, node)
end
local function on_power(pos, mem)
if mem.turned_on then
swap_node(pos, "on")
end
local function on_power(pos)
swap_node(pos, "on")
end
local function on_nopower(pos, mem)
local function on_nopower(pos)
swap_node(pos, "off")
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.turned_on then
power.consumer_alive(pos, mem)
end
return mem.turned_on
power.consumer_alive(pos, Cable, CYCLE_TIME)
return true
end
local function lamp_on_rightclick(pos, node, clicker)
@ -56,16 +51,16 @@ local function lamp_on_rightclick(pos, node, clicker)
return
end
local mem = tubelib2.get_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
if not mem.turned_on and power.power_available(pos, mem, PWR_NEEDED) then
mem.turned_on = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
local nvm = techage.get_nvm(pos)
if not nvm.turned_on and power.power_available(pos, Cable) then
nvm.turned_on = true
power.consumer_start(pos, Cable, CYCLE_TIME)
minetest.get_node_timer(pos):start(CYCLE_TIME)
swap_node(pos, "on")
else
mem.turned_on = false
power.consumer_stop(pos, mem)
nvm.turned_on = false
power.consumer_stop(pos, Cable)
minetest.get_node_timer(pos):stop()
swap_node(pos, "off")
end
end
@ -86,12 +81,35 @@ local function on_place(itemstack, placer, pointed_thing)
return minetest.rotate_and_place(itemstack, placer, pointed_thing)
end
local function determine_power_side(pos, node)
return {techage.determine_node_bottom_as_dir(node)}
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
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 = {U=1, D=1}, -- Cable connection sides
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.on_construct = tubelib2.init_mem
ndef_off.after_place_node = after_place_node
ndef_off.after_dig_node = after_dig_node
ndef_off.tubelib2_on_update2 = tubelib2_on_update2
ndef_off.networks = net_def
ndef_off.on_rightclick = lamp_on_rightclick
if not ndef_off.on_rotate then
ndef_off.on_place = on_place
@ -106,7 +124,10 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
ndef_off.is_ground_content = false
ndef_off.sounds = default.node_sound_glass_defaults()
ndef_on.on_construct = tubelib2.init_mem
ndef_on.after_place_node = after_place_node
ndef_on.after_dig_node = after_dig_node
ndef_on.tubelib2_on_update2 = tubelib2_on_update2
ndef_on.networks = net_def
ndef_on.on_rightclick = lamp_on_rightclick
ndef_on.on_rotate = ndef_on.on_rotate or on_rotate
ndef_on.on_timer = node_timer
@ -121,23 +142,7 @@ function techage.register_lamp(basename, ndef_off, ndef_on)
minetest.register_node(basename.."_off", ndef_off)
minetest.register_node(basename.."_on", ndef_on)
techage.power.register_node({basename.."_off", basename.."_on"}, {
power_network = Cable,
conn_sides = ndef_off.conn_sides or determine_power_side, -- will be handled by clbk function
on_power = on_power,
on_nopower = on_nopower,
})
minetest.register_lbm({
label = "[techage] Start lamp",
name = "techage:start_lamp",
nodenames = {basename.."_on"},
run_at_every_load = true,
action = function(pos, node)
local mem = tubelib2.get_mem(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
end
})
Cable:add_secondary_node_names({basename.."_off", basename.."_on"})
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -35,14 +35,14 @@ techage.fuel.BT_FUELOIL = 2
techage.fuel.BT_NAPHTHA = 1
local function formspec_fuel(x, y, mem)
local function formspec_fuel(x, y, nvm)
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
if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then
itemname = nvm.liquid.name.." "..nvm.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)
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
return "container["..x..","..y.."]"..
"background[0,0;3,1.05;techage_form_grey.png]"..
@ -56,48 +56,48 @@ 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")
function techage.fuel.formspec(nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
formspec_fuel(1, 0, mem)..
formspec_fuel(1, 0, nvm)..
"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 function fill_container(pos, inv, nvm)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.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)
local full_container = liquid.get_full_container(empty_container, nvm.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 ldef and nvm.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
if mem.liquid.amount == 0 then
mem.liquid.name = nil
nvm.liquid.amount = nvm.liquid.amount - ldef.size
if nvm.liquid.amount == 0 then
nvm.liquid.name = nil
end
end
end
end
local function empty_container(pos, inv, mem)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local function empty_container(pos, inv, nvm)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.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
if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then
if nvm.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
nvm.liquid.amount = nvm.liquid.amount + ldef.size
nvm.liquid.name = ldef.inv_item
end
end
end
@ -105,25 +105,25 @@ local function empty_container(pos, inv, mem)
end
local function move_item(pos, stack)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem)
fill_container(pos, inv, nvm)
else
empty_container(pos, inv, mem)
empty_container(pos, inv, nvm)
end
M(pos):set_string("formspec", techage.fuel.formspec(mem))
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end
function techage.fuel.move_item(pos, stack, formspec)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
if liquid.is_container_empty(stack:get_name()) then
fill_container(pos, inv, mem)
fill_container(pos, inv, nvm)
else
empty_container(pos, inv, mem)
empty_container(pos, inv, nvm)
end
M(pos):set_string("formspec", formspec(pos, mem))
M(pos):set_string("formspec", formspec(pos, nvm))
end
function techage.fuel.allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -156,32 +156,32 @@ 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 nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local inv = M(pos):get_inventory()
return inv:is_empty("fuel") and mem.liquid.amount == 0
return inv:is_empty("fuel") and nvm.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))
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
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))
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
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))
function techage.fuel.formspec_update(pos, nvm)
if nvm.countdown and nvm.countdown > 0 then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -35,7 +35,7 @@ local ContainerDef = {}
local function determine_netID(pos, outdir)
local netID = 0
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype
local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then
local new = minetest.hash_node_position(pos) * 8 + outdir
if netID <= new then
@ -49,13 +49,13 @@ end
-- store network ID on each pump like node
local function store_netID(pos, outdir, netID)
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype
local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local outdir = networks.Flip[indir]
mem.pipe = mem.pipe or {}
mem.pipe.netIDs = mem.pipe.netIDs or {}
mem.pipe.netIDs[outdir] = netID
nvm.pipe2 = nvm.pipe2 or {}
nvm.pipe2.netIDs = nvm.pipe2.netIDs or {}
nvm.pipe2.netIDs[outdir] = netID
end
end)
end
@ -64,13 +64,13 @@ end
local function delete_netID(pos, outdir)
local netID = 0
networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node)
local ntype = net_def(pos, "pipe").ntype
local ntype = net_def(pos, "pipe2").ntype
if ntype and ntype == "pump" then
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local outdir = networks.Flip[indir]
if mem.pipe and mem.pipe.netIDs and mem.pipe.netIDs[outdir] then
netID = mem.pipe.netIDs[outdir]
mem.pipe.netIDs[outdir] = nil
if nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir] then
netID = nvm.pipe2.netIDs[outdir]
nvm.pipe2.netIDs[outdir] = nil
end
end
end)
@ -78,21 +78,21 @@ local function delete_netID(pos, outdir)
end
local function get_netID(pos, outdir)
local mem = tubelib2.get_mem(pos)
if not mem.pipe or not mem.pipe.netIDs or not mem.pipe.netIDs[outdir] then
local nvm = techage.get_nvm(pos)
if not nvm.pipe2 or not nvm.pipe2.netIDs or not nvm.pipe2.netIDs[outdir] then
local netID = determine_netID(pos, outdir)
store_netID(pos, outdir, netID)
end
return mem.pipe and mem.pipe.netIDs and mem.pipe.netIDs[outdir]
return nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir]
end
local function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir)
if netID then
local netw = networks.get_network("pipe", netID)
local netw = networks.get_network("pipe2", netID)
if not netw then
netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network("pipe", netID, netw)
networks.set_network("pipe2", netID, netw)
end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID))
--print("netw", string.format("%012X", netID), s, dump(netw))
@ -165,28 +165,28 @@ end
--
function techage.liquid.srv_peek(pos, indir)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
return mem.liquid.name
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
return nvm.liquid.name
end
function techage.liquid.srv_put(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
amount = amount or 0
if not mem.liquid.name then
mem.liquid.name = name
mem.liquid.amount = amount
if not nvm.liquid.name then
nvm.liquid.name = name
nvm.liquid.amount = amount
return 0
elseif mem.liquid.name == name then
mem.liquid.amount = mem.liquid.amount or 0
elseif nvm.liquid.name == name then
nvm.liquid.amount = nvm.liquid.amount or 0
local capa = LQD(pos).capa
if mem.liquid.amount + amount <= capa then
mem.liquid.amount = mem.liquid.amount + amount
if nvm.liquid.amount + amount <= capa then
nvm.liquid.amount = nvm.liquid.amount + amount
return 0
else
local rest = mem.liquid.amount + amount - capa
mem.liquid.amount = capa
local rest = nvm.liquid.amount + amount - capa
nvm.liquid.amount = capa
return rest
end
end
@ -194,20 +194,20 @@ function techage.liquid.srv_put(pos, indir, name, amount)
end
function techage.liquid.srv_take(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
amount = amount or 0
if not name or mem.liquid.name == name then
name = mem.liquid.name
mem.liquid.amount = mem.liquid.amount or 0
if mem.liquid.amount > amount then
mem.liquid.amount = mem.liquid.amount - amount
if not name or nvm.liquid.name == name then
name = nvm.liquid.name
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.liquid.amount > amount then
nvm.liquid.amount = nvm.liquid.amount - amount
return amount, name
else
local rest = mem.liquid.amount
local name = mem.liquid.name
mem.liquid.amount = 0
mem.liquid.name = nil
local rest = nvm.liquid.amount
local name = nvm.liquid.name
nvm.liquid.amount = 0
nvm.liquid.name = nil
return rest, name
end
end

View File

@ -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,10 +18,10 @@ local liquid = techage.liquid
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
function techage.liquid.formspec_liquid(x, y, mem)
function techage.liquid.formspec_liquid(x, y, nvm)
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
if nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0 and nvm.liquid.name then
itemname = nvm.liquid.name.." "..nvm.liquid.amount
end
return "container["..x..","..y.."]"..
"background[0,0;3,2.05;techage_form_grey.png]"..
@ -40,20 +40,20 @@ function techage.liquid.formspec_liquid(x, y, mem)
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 nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.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)
local full_container = liquid.get_full_container(empty_container, nvm.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 ldef and nvm.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
nvm.liquid.amount = nvm.liquid.amount - ldef.size
if nvm.liquid.amount == 0 then
nvm.liquid.name = nil
end
end
end
@ -61,39 +61,39 @@ local function fill_container(pos, inv)
end
local function empty_container(pos, inv, size)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.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
if ldef and (not nvm.liquid.name or ldef.inv_item == nvm.liquid.name) then
local amount = stack:get_count() * ldef.size
if mem.liquid.amount + amount <= size then
if nvm.liquid.amount + amount <= size 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
nvm.liquid.amount = nvm.liquid.amount + amount
nvm.liquid.name = ldef.inv_item
end
end
end
end
function techage.liquid.move_item(pos, stack, size, formspec)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(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, size)
end
M(pos):set_string("formspec", formspec(pos, mem))
M(pos):set_string("formspec", formspec(pos, nvm))
end
function techage.liquid.is_empty(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(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 inv:is_empty("src") and inv:is_empty("dst") and (not nvm.liquid or (nvm.liquid.amount or 0) == 0)
end
techage.liquid.tubing = {
@ -127,8 +127,8 @@ techage.liquid.tubing = {
end,
on_recv_message = function(pos, src, topic, payload)
if topic == "load" then
local mem = tubelib2.get_mem(pos)
return techage.power.percent(LQD(pos).capa, (mem.liquid and mem.liquid.amount) or 0)
local nvm = techage.get_nvm(pos)
return techage.power.percent(LQD(pos).capa, (nvm.liquid and nvm.liquid.amount) or 0)
elseif topic == "size" then
return LQD(pos).capa
else

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -26,7 +26,7 @@ local Pipe = tubelib2.Tube:new({
max_tube_length = MAX_PIPE_LENGHT,
show_infotext = false,
force_to_use_tubes = true,
tube_type = "pipe",
tube_type = "pipe2",
primary_node_names = {"techage:ta3_pipeS", "techage:ta3_pipeA"},
secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes)
@ -54,7 +54,7 @@ minetest.register_node("techage:ta3_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!
@ -85,7 +85,7 @@ minetest.register_node("techage:ta3_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!
@ -138,7 +138,7 @@ local Boxes = {
}
}
techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, nil, {
techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, {
description = S("TA Junction Pipe"),
tiles = {"techage_gaspipe_junction.png"},
groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1},
@ -158,18 +158,13 @@ techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, nil, {
Pipe:after_dig_node(pos)
end,
networks = {
pipe = {
pipe2 = {
sides = networks.AllSides, -- connection sides for pipes
ntype = "junc",
},
},
}, 25)
-- register by hand, as there is no power support
for idx = 0,63 do
Pipe:add_secondary_node_names({"techage:ta3_junctionpipe"..idx})
end
minetest.register_craft({
output = "techage:ta3_junctionpipe25 2",
recipe = {
@ -191,6 +186,5 @@ minetest.register_craft({
minetest.register_alias("techage:ta4_pipeA", "techage:ta3_pipeA")
minetest.register_alias("techage:ta4_pipeS", "techage:ta3_pipeS")
techage.BiogasPipe = Pipe
techage.LiquidPipe = Pipe

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -62,7 +62,7 @@ local State4 = techage.NodeStates:new({
standby_ticks = STANDBY_TICKS,
})
local function pumping(pos, mem, state, capa)
local function pumping(pos, nvm, state, capa)
local outdir = M(pos):get_int("outdir")
local starter = get_starter_name(pos)
local taken, name = liquid.take(pos, Flip[outdir], nil, capa, starter)
@ -70,55 +70,55 @@ local function pumping(pos, mem, state, capa)
local leftover = liquid.put(pos, outdir, name, taken, starter)
if leftover and leftover > 0 then
liquid.put(pos, Flip[outdir], name, leftover)
state:blocked(pos, mem)
state:blocked(pos, nvm)
return
end
state:keep_running(pos, mem, COUNTDOWN_TICKS)
state:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
state:idle(pos, mem)
state:idle(pos, nvm)
end
local function after_place_node3(pos, placer)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:t3_pump")
State3:node_init(pos, mem, number)
State3:node_init(pos, nvm, number)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end
local function after_place_node4(pos, placer)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:t4_pump")
State4:node_init(pos, mem, number)
State4:node_init(pos, nvm, number)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end
local function node_timer3(pos, elapsed)
local mem = tubelib2.get_mem(pos)
pumping(pos, mem, State3, CAPA)
return State3:is_active(mem)
local nvm = techage.get_nvm(pos)
pumping(pos, nvm, State3, CAPA)
return State3:is_active(nvm)
end
local function node_timer4(pos, elapsed)
local mem = tubelib2.get_mem(pos)
pumping(pos, mem, State4, CAPA * 2)
return State4:is_active(mem)
local nvm = techage.get_nvm(pos)
pumping(pos, nvm, State4, CAPA * 2)
return State4:is_active(nvm)
end
local function on_rightclick(pos, node, clicker)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if node.name == "techage:t3_pump" then
set_starter_name(pos, clicker)
State3:start(pos, mem)
State3:start(pos, nvm)
elseif node.name == "techage:t3_pump_on" then
State3:stop(pos, mem)
State3:stop(pos, nvm)
elseif node.name == "techage:t4_pump" then
set_starter_name(pos, clicker)
State4:start(pos, mem)
State4:start(pos, nvm)
elseif node.name == "techage:t4_pump_on" then
State4:stop(pos, mem)
State4:stop(pos, nvm)
end
end
@ -128,7 +128,7 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end
local ta3_tiles_pas = {
@ -208,7 +208,7 @@ local ta4_tiles_act = {
}
local nworks = {
pipe = {
pipe2 = {
sides = {L = 1, R = 1}, -- Pipe connection side
ntype = "pump",
},

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -26,8 +26,8 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local mem = tubelib2.get_mem(pos)
mem.item_name = nil
local nvm = techage.get_nvm(pos)
nvm.item_name = nil
local inv = minetest.get_meta(pos):get_inventory()
if inv:is_empty(listname) then
return stack:get_count()
@ -42,8 +42,8 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
local mem = tubelib2.get_mem(pos)
mem.item_name = nil
local nvm = techage.get_nvm(pos)
nvm.item_name = nil
return stack:get_count()
end
@ -55,12 +55,12 @@ local function can_dig(pos, player)
return inv:is_empty("main")
end
local function get_item_name(mem, inv)
local function get_item_name(nvm, inv)
for idx = 1, inv:get_size("main") do
local stack = inv:get_stack("main", idx)
if stack:get_count() > 0 then
mem.item_name = stack:get_name()
return mem.item_name
nvm.item_name = stack:get_name()
return nvm.item_name
end
end
end
@ -90,10 +90,10 @@ end
local tLiquid = {
capa = 0,
peek = function(pos, indir)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
if not inv:is_empty("main") then
return mem.item_name or get_item_name(mem, inv)
return nvm.item_name or get_item_name(nvm, inv)
end
end,
put = function(pos, indir, name, amount)
@ -106,10 +106,10 @@ local tLiquid = {
return amount
end,
take = function(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
if not name then
name = mem.item_name or get_item_name(mem, inv)
name = nvm.item_name or get_item_name(nvm, inv)
end
if name then
local stack = ItemStack(name.." "..amount)
@ -120,7 +120,7 @@ local tLiquid = {
}
local tNetworks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
@ -143,12 +143,12 @@ minetest.register_node("techage:ta3_silo", {
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta3_silo")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec3(mem))
meta:set_string("formspec", formspec3(nvm))
meta:set_string("infotext", S("TA3 Silo").." "..number)
Pipe:after_place_node(pos)
end,
@ -188,12 +188,12 @@ minetest.register_node("techage:ta4_silo", {
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
local number = techage.add_node(pos, "techage:ta4_silo")
meta:set_string("node_number", number)
meta:set_string("owner", placer:get_player_name())
meta:set_string("formspec", formspec4(mem))
meta:set_string("formspec", formspec4(nvm))
meta:set_string("infotext", S("TA4 Silo").." "..number)
Pipe:after_place_node(pos)
end,

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -21,13 +21,13 @@ local liquid = techage.liquid
local CAPACITY = 500
local function formspec(pos, mem)
local update = ((mem.countdown or 0) > 0 and mem.countdown) or S("Update")
local function formspec(pos, nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update")
return "size[8,6]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
liquid.formspec_liquid(2, 0, mem)..
liquid.formspec_liquid(2, 0, nvm)..
"button[5.5,0.5;2,1;update;"..update.."]"..
"list[current_player;main;0,2.3;8,4;]"
end
@ -55,9 +55,9 @@ local function on_metadata_inventory_put(pos, listname, index, stack, player)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
mem.countdown = 10
M(pos):set_string("formspec", formspec(pos, mem))
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", formspec(pos, nvm))
minetest.get_node_timer(pos):start(2)
end
@ -65,9 +65,9 @@ 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.countdown = 10
M(pos):set_string("formspec", formspec(pos, mem))
local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", formspec(pos, nvm))
minetest.get_node_timer(pos):start(2)
end
@ -98,12 +98,12 @@ minetest.register_node("techage:ta3_tank", {
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
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(pos, mem))
meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("TA3 Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -111,11 +111,11 @@ minetest.register_node("techage:ta3_tank", {
liquid.update_network(pos, outdir)
end,
on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
local nvm = techage.get_nvm(pos)
if nvm.countdown then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, nvm))
return nvm.countdown > 0
end
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -136,7 +136,7 @@ minetest.register_node("techage:ta3_tank", {
take = liquid.srv_take,
},
networks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
@ -185,12 +185,12 @@ minetest.register_node("techage:oiltank", {
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
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(pos, mem))
meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("Oil Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -198,11 +198,11 @@ minetest.register_node("techage:oiltank", {
liquid.update_network(pos, outdir)
end,
on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
local nvm = techage.get_nvm(pos)
if nvm.countdown then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, nvm))
return nvm.countdown > 0
end
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -223,7 +223,7 @@ minetest.register_node("techage:oiltank", {
take = liquid.srv_take,
},
networks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},
@ -262,12 +262,12 @@ minetest.register_node("techage:ta4_tank", {
end,
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
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(pos, mem))
meta:set_string("formspec", formspec(pos, nvm))
meta:set_string("infotext", S("TA4 Tank").." "..number)
Pipe:after_place_node(pos)
end,
@ -275,11 +275,11 @@ minetest.register_node("techage:ta4_tank", {
liquid.update_network(pos, outdir)
end,
on_timer = function(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.countdown then
mem.countdown = mem.countdown - 1
M(pos):set_string("formspec", formspec(pos, mem))
return mem.countdown > 0
local nvm = techage.get_nvm(pos)
if nvm.countdown then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(pos, nvm))
return nvm.countdown > 0
end
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -300,7 +300,7 @@ minetest.register_node("techage:ta4_tank", {
take = liquid.srv_take,
},
networks = {
pipe = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank",
},

View File

@ -278,7 +278,7 @@ Water Barrel=Wasserfass
[TechAge Programmer] Error: programmer not supported!=[TechAge Programmer] Fehler: Programmer wird nicht unterstützt!
[TechAge Programmer] Unknown node on=[TechAge Programmer] Unbekannter Block bei
[TechAge Programmer] foreign or unknown node!=[TechAge Programmer] Fremder oder unbekannter Block!
[TechAge Programmer] node programmed!=[TechAge Programmer] Nicht programmiert!
[TechAge Programmer] node programmed!=[TechAge Programmer] Nummer(n) programmiert!
[TechAge Programmer] number=[TechAge Programmer] Nummer=
[TechAge Programmer] programmer reset=[TechAge Programmer] Programmer zurück gesetzt
\\[ku\\]=\\[ku\\]

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -140,7 +140,6 @@ minetest.register_node("techage:ta3_button_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
end,
on_rotate = screwdriver.disallow,
@ -186,7 +185,6 @@ minetest.register_node("techage:ta3_button_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
end,
paramtype2 = "facedir",

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -95,7 +95,6 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
end
minetest.register_node("techage:ta3_cartdetector_off", {

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -20,7 +20,7 @@ local logic = techage.logic
local BLOCKING_TIME = 8 -- seconds
local function switch_on(pos)
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
local t = minetest.get_gametime()
if t > (mem.time or 0) then
logic.swap_node(pos, "techage:ta3_detector_on")
@ -55,7 +55,6 @@ minetest.register_node("techage:ta3_detector_off", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
logic.after_place_node(pos, placer, "techage:ta3_detector_off", S("TA3 Detector"))
logic.infotext(meta, S("TA3 Detector"))
meta:set_string("formspec", formspec(meta))
@ -79,7 +78,7 @@ minetest.register_node("techage:ta3_detector_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
on_rotate = screwdriver.disallow,
@ -116,7 +115,7 @@ minetest.register_node("techage:ta3_detector_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype2 = "facedir",

View File

@ -57,11 +57,11 @@ for idx,pgn in ipairs(tPgns) do
},
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local number = techage.add_node(pos, "techage:doorblock"..idx)
mem.facedir = node.param2
nvm.facedir = node.param2
meta:set_string("node_number", number)
meta:set_string("infotext", S("TechAge Door Block").." "..number)
meta:set_string("formspec", "size[3,2]"..
@ -73,11 +73,11 @@ for idx,pgn in ipairs(tPgns) do
on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if fields.type then
node.name = "techage:doorblock"..tTextures[fields.type]
minetest.swap_node(pos, node)
mem.name = node.name
nvm.name = node.name
end
if fields.exit then
meta:set_string("formspec", nil)
@ -86,7 +86,7 @@ for idx,pgn in ipairs(tPgns) do
after_dig_node = function(pos, oldnode, oldmetadata)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
--drawtype = "glasslike",
@ -104,10 +104,10 @@ for idx,pgn in ipairs(tPgns) do
if topic == "on" then
minetest.remove_node(pos)
elseif topic == "off" then
local mem = tubelib2.get_mem(pos)
mem.facedir = mem.facedir or 0
mem.name = mem.name or "techage:doorblock"..NUM_TEXTURES
minetest.add_node(pos, {name = mem.name, paramtype2 = "facedir", param2 = mem.facedir})
local nvm = techage.get_nvm(pos)
nvm.facedir = nvm.facedir or 0
nvm.name = nvm.name or "techage:doorblock"..NUM_TEXTURES
minetest.add_node(pos, {name = nvm.name, paramtype2 = "facedir", param2 = nvm.facedir})
end
end,
})

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -52,56 +52,56 @@ local function check(expression)
return true, "ok"
end
local function compile(mem, expression)
local function compile(nvm, expression)
local res, err = check(expression)
if res then
local code, err = loadstring(expression, "")
if code then
mem.code = code
mem.error = "ok"
nvm.code = code
nvm.error = "ok"
else
mem.code = nil
mem.error = err
nvm.code = nil
nvm.error = err
end
else
mem.code = nil
mem.error = err
nvm.code = nil
nvm.error = err
end
end
local function get_code(pos, mem)
local function get_code(pos, nvm)
local meta = M(pos)
local if_expr = meta:get_string("if_expr") or ""
local then_expr = meta:get_string("then_expr") or ""
local else_expr = meta:get_string("else_expr") or ""
local expr = "if "..if_expr.." then return "..then_expr.." else return "..else_expr.." end"
compile(mem, expr)
return mem.code
compile(nvm, expr)
return nvm.code
end
local function eval(pos, mem)
mem.code = mem.code or get_code(pos, mem)
if mem.code then
setfenv(mem.code, mem.inp_tbl)
local res, sts = pcall(mem.code)
local function eval(pos, nvm)
nvm.code = nvm.code or get_code(pos, nvm)
if nvm.code then
setfenv(nvm.code, nvm.inp_tbl)
local res, sts = pcall(nvm.code)
if res then
mem.error = "ok"
if sts == true and mem.inp_tbl.outp ~= true then
mem.inp_tbl.outp = sts
nvm.error = "ok"
if sts == true and nvm.inp_tbl.outp ~= true then
nvm.inp_tbl.outp = sts
return "on"
elseif sts == false and mem.inp_tbl.outp ~= false then
mem.inp_tbl.outp = sts
elseif sts == false and nvm.inp_tbl.outp ~= false then
nvm.inp_tbl.outp = sts
return "off"
end
else
mem.error = "Error: "..sts
nvm.error = "Error: "..sts
end
end
end
local function data(mem)
local tbl = {"inp = "..dump(mem.inp_tbl.inp), "outp = "..dump(mem.inp_tbl.outp)}
for k,v in pairs(mem.inp_tbl) do
local function data(nvm)
local tbl = {"inp = "..dump(nvm.inp_tbl.inp), "outp = "..dump(nvm.inp_tbl.outp)}
for k,v in pairs(nvm.inp_tbl) do
if k ~= "inp" and k ~= "outp" then
tbl[#tbl+1] = k.." = "..dump(v)
end
@ -110,18 +110,18 @@ local function data(mem)
end
local function formspec(pos, meta)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local numbers = meta:get_string("numbers") or ""
local if_expr = meta:get_string("if_expr") or ""
local then_expr = meta:get_string("then_expr") or ""
local else_expr = meta:get_string("else_expr") or ""
local err = mem.error or "ok"
local err = nvm.error or "ok"
if err ~= "ok" then
err = string.sub(err, 15)
end
err = minetest.formspec_escape(err)
mem.inp_tbl = mem.inp_tbl or {inp = false, outp = false}
local data = data(mem)
nvm.inp_tbl = nvm.inp_tbl or {inp = false, outp = false}
local data = data(nvm)
return "size[9,8]"..
"background[0,0;9,1.3;techage_formspec_bg.png]"..
"field[0.5,0.2;8.5,2;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
@ -153,8 +153,8 @@ minetest.register_node("techage:ta3_logic", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
mem.inp_tbl = {inp = false, outp = false}
local nvm = techage.get_nvm(pos)
nvm.inp_tbl = {inp = false, outp = false}
logic.after_place_node(pos, placer, "techage:ta3_logic", S("TA3 Logic Block"))
logic.infotext(meta, S("TA3 Logic Block"))
meta:set_string("formspec", formspec(pos, meta))
@ -166,7 +166,7 @@ minetest.register_node("techage:ta3_logic", {
end
local meta = M(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if fields.numbers and fields.numbers ~= "" then
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
@ -183,14 +183,14 @@ minetest.register_node("techage:ta3_logic", {
meta:set_string("else_expr", fields.else_expr)
end
if fields.store then
get_code(pos, mem)
get_code(pos, nvm)
end
meta:set_string("formspec", formspec(pos, meta))
end,
on_timer = function(pos,elapsed)
local mem = tubelib2.get_mem(pos)
local topic = eval(pos, mem)
local nvm = techage.get_nvm(pos)
local topic = eval(pos, nvm)
if topic then
local meta = M(pos)
local own_num = meta:get_string("node_number") or ""
@ -209,7 +209,7 @@ minetest.register_node("techage:ta3_logic", {
after_dig_node = function(pos)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype2 = "facedir",
@ -230,15 +230,15 @@ minetest.register_craft({
techage.register_node({"techage:ta3_logic"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
mem.inp_tbl = mem.inp_tbl or {outp = false}
local nvm = techage.get_nvm(pos)
nvm.inp_tbl = nvm.inp_tbl or {outp = false}
if topic == "on" then
mem.inp_tbl.inp = true
mem.inp_tbl["n"..src] = true
nvm.inp_tbl.inp = true
nvm.inp_tbl["n"..src] = true
elseif topic == "off" then
mem.inp_tbl.inp = false
mem.inp_tbl["n"..src] = false
nvm.inp_tbl.inp = false
nvm.inp_tbl["n"..src] = false
else
return "unsupported"
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -37,7 +37,7 @@ local DropdownValues = {
[S("added or removed")] = 3,
}
local function formspec(meta, mem)
local function formspec(meta, nvm)
local numbers = meta:get_string("numbers") or ""
local label = S("added")..","..S("removed")..","..S("added or removed")
return "size[7.5,4]"..
@ -46,34 +46,34 @@ local function formspec(meta, mem)
default.gui_slots..
"field[0.5,0.6;7,1;numbers;"..S("Insert destination node number(s)")..";"..numbers.."]" ..
"label[0.2,1.6;"..S("Send signal if nodes have been:").."]"..
"dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(mem.mode or 3).."]"..
"dropdown[0.2,2.1;7.3,1;mode;"..label..";"..(nvm.mode or 3).."]"..
"button_exit[2,3.2;3,1;accept;"..S("accept").."]"
end
local function any_node_changed(pos)
local mem = tubelib2.get_mem(pos)
if not mem.pos1 or not mem.pos2 or not mem.num then
local nvm = techage.get_nvm(pos)
if not nvm.pos1 or not nvm.pos2 or not nvm.num then
local node = minetest.get_node(pos)
local param2 = (node.param2 + 2) % 4
mem.pos1 = logic.dest_pos(pos, param2, {0})
mem.pos2 = logic.dest_pos(pos, param2, {0,0,0})
mem.num = #minetest.find_nodes_in_area(mem.pos1, mem.pos2, {"air"})
nvm.pos1 = logic.dest_pos(pos, param2, {0})
nvm.pos2 = logic.dest_pos(pos, param2, {0,0,0})
nvm.num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"})
return false
end
local num = #minetest.find_nodes_in_area(mem.pos1, mem.pos2, {"air"})
local num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"})
if mem.num ~= num then
if mem.mode == 1 and num < mem.num then
mem.num = num
if nvm.num ~= num then
if nvm.mode == 1 and num < nvm.num then
nvm.num = num
return true
elseif mem.mode == 2 and num > mem.num then
mem.num = num
elseif nvm.mode == 2 and num > nvm.num then
nvm.num = num
return true
elseif mem.mode == 3 then
mem.num = num
elseif nvm.mode == 3 then
nvm.num = num
return true
end
mem.num = num
nvm.num = num
end
return false
end
@ -83,16 +83,16 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = M(pos)
if fields.accept then
mem.mode = DropdownValues[fields.mode] or 3
nvm.mode = DropdownValues[fields.mode] or 3
if techage.check_numbers(fields.numbers, player:get_player_name()) then
meta:set_string("numbers", fields.numbers)
logic.infotext(M(pos), S("TA3 Node Detector"))
end
end
meta:set_string("formspec", formspec(meta, mem))
meta:set_string("formspec", formspec(meta, nvm))
end
local function node_timer(pos)
@ -115,11 +115,11 @@ minetest.register_node("techage:ta3_nodedetector_off", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Node Detector"))
logic.infotext(meta, S("TA3 Node Detector"))
mem.mode = 3 -- default mode
meta:set_string("formspec", formspec(meta, mem))
nvm.mode = 3 -- default mode
meta:set_string("formspec", formspec(meta, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
any_node_changed(pos)
end,
@ -130,13 +130,13 @@ minetest.register_node("techage:ta3_nodedetector_off", {
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector"))
meta:set_string("formspec", formspec(meta, tubelib2.get_mem(pos)))
meta:set_string("formspec", formspec(meta, techage.get_nvm(pos)))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
on_rotate = screwdriver.disallow,
@ -160,13 +160,13 @@ minetest.register_node("techage:ta3_nodedetector_on", {
techage_set_numbers = function(pos, numbers, player_name)
local meta = M(pos)
local res = logic.set_numbers(pos, numbers, player_name, S("TA3 Node Detector"))
meta:set_string("formspec", formspec(meta, tubelib2.get_mem(pos)))
meta:set_string("formspec", formspec(meta, techage.get_nvm(pos)))
return res
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
on_rotate = screwdriver.disallow,

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -32,24 +32,24 @@ local function switch_off(pos)
end
local function scan_for_player(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = minetest.get_meta(pos)
local names = meta:get_string("names") or ""
for _, object in pairs(minetest.get_objects_inside_radius(pos, 4)) do
if object:is_player() then
if names == "" then
mem.player_name = object:get_player_name()
nvm.player_name = object:get_player_name()
return true
end
for _,name in ipairs(string.split(names, " ")) do
if object:get_player_name() == name then
mem.player_name = name
nvm.player_name = name
return true
end
end
end
end
mem.player_name = nil
nvm.player_name = nil
return false
end
@ -133,7 +133,7 @@ minetest.register_node("techage:ta3_playerdetector_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype2 = "facedir",
@ -168,7 +168,7 @@ minetest.register_node("techage:ta3_playerdetector_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype2 = "facedir",
@ -190,8 +190,8 @@ minetest.register_craft({
techage.register_node({"techage:ta3_playerdetector_off", "techage:ta3_playerdetector_on"}, {
on_recv_message = function(pos, topic, payload)
if topic == "name" then
local mem = tubelib2.get_mem(pos)
return mem.player_name or ""
local nvm = techage.get_nvm(pos)
return nvm.player_name or ""
else
return "unsupported"
end

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -38,7 +38,7 @@ minetest.register_node("techage:ta3_repeater", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local mem = techage.get_mem(pos)
logic.after_place_node(pos, placer, "techage:ta3_repeater", S("TA3 Repeater"))
logic.infotext(meta, S("TA3 Repeater"))
meta:set_string("formspec", formspec(meta))
@ -60,7 +60,7 @@ minetest.register_node("techage:ta3_repeater", {
end,
on_timer = function(pos,elapsed)
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
mem.overload_cnt = 0
return true
end,
@ -74,7 +74,7 @@ minetest.register_node("techage:ta3_repeater", {
after_dig_node = function(pos)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype2 = "facedir",
@ -95,7 +95,7 @@ minetest.register_craft({
techage.register_node({"techage:ta3_repeater"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local mem = techage.get_mem(pos)
mem.overload_cnt = (mem.overload_cnt or 0) + 1
if mem.overload_cnt > OVER_LOAD_MAX then
logic.infotext(M(pos), S("TA3 Repeater"), "fault (overloaded)")

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2017-2019 Joachim Stolberg
Copyright (C) 2017-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -66,13 +66,13 @@ local function formspec_help()
end
local function stop_the_sequencer(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = M(pos)
mem.running = false
mem.endless = mem.endless or false
mem.rules = mem.rules or new_rules()
nvm.running = false
nvm.endless = nvm.endless or false
nvm.rules = nvm.rules or new_rules()
logic.infotext(meta, S("TA3 Sequencer"), "stopped")
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless))
meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
minetest.get_node_timer(pos):stop()
return false
end
@ -98,20 +98,20 @@ local function restart_timer(pos, time)
end
local function check_rules(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local own_num = M(pos):get_string("node_number")
mem.rules = mem.rules or new_rules()
mem.running = mem.running or false
mem.index = mem.index or 1
mem.endless = mem.endless or false
nvm.rules = nvm.rules or new_rules()
nvm.running = nvm.running or false
nvm.index = nvm.index or 1
nvm.endless = nvm.endless or false
while true do -- process all rules as long as offs == 0
local rule = mem.rules[mem.index]
local offs = tonumber(mem.rules[mem.index].offs or 1)
local rule = nvm.rules[nvm.index]
local offs = tonumber(nvm.rules[nvm.index].offs or 1)
techage.send_multi(own_num, rule.num, tAction[rule.act])
mem.index = get_next_slot(mem.index, mem.rules, mem.endless)
if mem.index ~= nil and offs ~= nil and mem.running then
nvm.index = get_next_slot(nvm.index, nvm.rules, nvm.endless)
if nvm.index ~= nil and offs ~= nil and nvm.running then
-- after the last rule a pause with 1 or more sec is required
if mem.index == 1 and offs < 1 then
if nvm.index == 1 and offs < 1 then
offs = 1
end
if offs > 0 then
@ -126,13 +126,13 @@ local function check_rules(pos, elapsed)
end
local function start_the_sequencer(pos)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
local meta = M(pos)
mem.running = true
mem.endless = mem.endless or false
mem.rules = mem.rules or new_rules()
nvm.running = true
nvm.endless = nvm.endless or false
nvm.rules = nvm.rules or new_rules()
logic.infotext(meta, S("TA3 Sequencer"), "running")
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless))
meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
minetest.get_node_timer(pos):start(0.1)
return false
end
@ -143,10 +143,10 @@ local function on_receive_fields(pos, formname, fields, player)
end
local meta = M(pos)
local mem = tubelib2.get_mem(pos)
mem.running = mem.running or false
mem.endless = mem.endless or false
mem.rules = mem.rules or new_rules()
local nvm = techage.get_nvm(pos)
nvm.running = nvm.running or false
nvm.endless = nvm.endless or false
nvm.rules = nvm.rules or new_rules()
if fields.help ~= nil then
meta:set_string("formspec", formspec_help())
@ -154,34 +154,34 @@ local function on_receive_fields(pos, formname, fields, player)
end
if fields.endless ~= nil then
mem.endless = fields.endless == "true"
mem.index = 1
nvm.endless = fields.endless == "true"
nvm.index = 1
end
if fields.exit ~= nil then
if mem.running then
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless))
if nvm.running then
meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
else
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless))
meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end
return
end
for idx = 1,NUM_SLOTS do
if fields["offs"..idx] ~= nil then
mem.rules[idx].offs = tonumber(fields["offs"..idx]) or ""
nvm.rules[idx].offs = tonumber(fields["offs"..idx]) or ""
end
if fields["num"..idx] ~= nil and
techage.check_numbers(fields["num"..idx], player:get_player_name()) then
mem.rules[idx].num = fields["num"..idx]
nvm.rules[idx].num = fields["num"..idx]
end
if fields["act"..idx] ~= nil then
mem.rules[idx].act = kvAction[fields["act"..idx]]
nvm.rules[idx].act = kvAction[fields["act"..idx]]
end
end
if fields.button ~= nil then
if mem.running then
if nvm.running then
stop_the_sequencer(pos)
else
start_the_sequencer(pos)
@ -189,10 +189,10 @@ local function on_receive_fields(pos, formname, fields, player)
elseif fields.num1 ~= nil then -- any other change?
stop_the_sequencer(pos)
else
if mem.running then
meta:set_string("formspec", formspec(techage.RUNNING, mem.rules, mem.endless))
if nvm.running then
meta:set_string("formspec", formspec(techage.RUNNING, nvm.rules, nvm.endless))
else
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless))
meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end
end
end
@ -208,14 +208,14 @@ minetest.register_node("techage:ta3_sequencer", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_sequencer", S("TA3 Sequencer"))
logic.infotext(meta, S("TA3 Sequencer"), S("stopped"))
mem.rules = new_rules()
mem.index = 1
mem.running = false
mem.endless = false
meta:set_string("formspec", formspec(techage.STOPPED, mem.rules, mem.endless))
nvm.rules = new_rules()
nvm.index = 1
nvm.running = false
nvm.endless = false
meta:set_string("formspec", formspec(techage.STOPPED, nvm.rules, nvm.endless))
end,
on_receive_fields = on_receive_fields,
@ -224,11 +224,11 @@ minetest.register_node("techage:ta3_sequencer", {
if minetest.is_protected(pos, puncher:get_player_name()) then
return
end
local mem = tubelib2.get_mem(pos)
if not mem.running then
local nvm = techage.get_nvm(pos)
if not nvm.running then
minetest.node_dig(pos, node, puncher, pointed_thing)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end
end,
@ -256,15 +256,15 @@ techage.register_node({"techage:ta3_sequencer"}, {
start_the_sequencer(pos)
elseif topic == "off" then
-- do not stop immediately
local mem = tubelib2.get_mem(pos)
mem.endless = false
local nvm = techage.get_nvm(pos)
nvm.endless = false
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(1)
end
end,

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
Copyright (C) 2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -55,7 +55,6 @@ minetest.register_node("techage:signal_lamp_off", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end
@ -99,7 +98,6 @@ minetest.register_node("techage:signal_lamp_on", {
after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos)
tubelib2.del_mem(pos)
if COLORED then
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
end

View File

@ -3,7 +3,7 @@
Terminal
========
Copyright (C) 2018-2019 Joachim Stolberg
Copyright (C) 2018-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
@ -167,7 +167,7 @@ local function command(pos, command, player)
"B", -- outdir
cmnd, -- topic
payload, -- payload
techage.BiogasPipe, -- network
techage.LiquidPipe, -- network
nil) -- valid nodes
output(pos, dump(resp))
return
@ -228,7 +228,6 @@ local function register_terminal(num, tiles, node_box, selection_box)
after_dig_node = function(pos)
techage.remove_node(pos)
tubelib2.del_mem(pos)
end,
paramtype = "light",

View File

@ -79,8 +79,8 @@ end
local function check_rules(pos,elapsed)
local mem = tubelib2.get_mem(pos)
mem.done = mem.done or {false,false,false,false,false,false}
local nvm = techage.get_nvm(pos)
nvm.done = nvm.done or {false,false,false,false,false,false}
local hour = math.floor(minetest.get_timeofday() * 24)
local meta = minetest.get_meta(pos)
local events = deserialize(meta, "events")
@ -94,19 +94,19 @@ local function check_rules(pos,elapsed)
if act ~= "" and numbers[idx] ~= "" then
local hr = (events[idx] - 1) * 2
if ((hour - hr) % 24) <= 4 then -- last 4 hours?
if mem.done[idx] == false then -- not already executed?
if nvm.done[idx] == false then -- not already executed?
techage.send_multi(number, numbers[idx], act)
mem.done[idx] = true
nvm.done[idx] = true
end
else
mem.done[idx] = false
nvm.done[idx] = false
end
end
end
-- prepare for the next day
if hour == 23 then
mem.done = {false,false,false,false,false,false}
nvm.done = {false,false,false,false,false,false}
end
return true
end
@ -125,13 +125,13 @@ minetest.register_node("techage:ta3_timer", {
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
logic.after_place_node(pos, placer, "techage:ta3_timer", S("TA3 Timer"))
logic.infotext(meta, S("TA3 Timer"))
local events = {1,1,1,1,1,1}
local numbers = {"0000","","","","",""}
local actions = {"","","","","",""}
mem.done = {false,false,false,false,false,false}
nvm.done = {false,false,false,false,false,false}
meta:set_string("events", minetest.serialize(events))
meta:set_string("numbers", minetest.serialize(numbers))
meta:set_string("actions", minetest.serialize(actions))
@ -169,15 +169,15 @@ minetest.register_node("techage:ta3_timer", {
end
meta:set_string("actions", minetest.serialize(actions))
meta:set_string("formspec", formspec(events, numbers, actions))
local mem = tubelib2.get_mem(pos)
mem.done = {false,false,false,false,false,false}
local nvm = techage.get_nvm(pos)
nvm.done = {false,false,false,false,false,false}
end,
on_timer = check_rules,
after_dig_node = function(pos)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
paramtype = "light",
@ -202,8 +202,8 @@ techage.register_node({"techage:ta3_timer"}, {
on_node_load = function(pos)
minetest.get_node_timer(pos):start(CYCLE_TIME)
-- check rules for just loaded areas
local mem = tubelib2.get_mem(pos)
mem.done = {false,false,false,false,false,false}
local nvm = techage.get_nvm(pos)
nvm.done = {false,false,false,false,false,false}
check_rules(pos,0)
end,
})

View File

@ -85,7 +85,7 @@ minetest.register_node("techage:ta3_distiller_base", {
sounds = default.node_sound_stone_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {B=1}, -- Pipe connection sides
ntype = "pump",
},
@ -124,7 +124,7 @@ minetest.register_node("techage:ta3_distiller1", {
sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {F=1}, -- Pipe connection sides
ntype = "tank",
},
@ -187,7 +187,7 @@ minetest.register_node("techage:ta3_distiller3", {
sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {B=1}, -- Pipe connection sides
ntype = "pump",
},
@ -225,7 +225,7 @@ minetest.register_node("techage:ta3_distiller4", {
sounds = default.node_sound_metal_defaults(),
networks = {
pipe = {
pipe2 = {
sides = {U=1}, -- Pipe connection sides
ntype = "pump",
},

View File

@ -31,9 +31,9 @@ local formspec0 = "size[5,4]"..
"button_exit[1,3.2;3,1;build;"..S("Build derrick").."]"
local function play_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.techage_state == techage.RUNNING then
mem.handle = minetest.sound_play("techage_oildrill", {
local nvm = techage.get_nvm(pos)
if nvm.techage_state == techage.RUNNING then
nvm.handle = minetest.sound_play("techage_oildrill", {
pos = pos,
gain = 1,
max_hear_distance = 15})
@ -42,19 +42,19 @@ local function play_sound(pos)
end
local function stop_sound(pos)
local mem = tubelib2.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
local nvm = techage.get_nvm(pos)
if nvm.handle then
minetest.sound_stop(nvm.handle)
nvm.handle = nil
end
end
local function formspec(self, pos, mem)
if not mem.assemble_build then
local function formspec(self, pos, nvm)
if not nvm.assemble_build then
return formspec0
end
local depth = M(pos):get_int("depth")
local curr_depth = pos.y - (mem.drill_pos or pos).y
local curr_depth = pos.y - (nvm.drill_pos or pos).y
return "size[8,8]"..
default.gui_bg..
default.gui_bg_img..
@ -64,9 +64,9 @@ local function formspec(self, pos, mem)
"item_image[1,1;1,1;techage:oil_drillbit]"..
"label[1,2;"..S("Drill Bit").."]"..
"label[0.5,3;"..S("Depth")..": "..curr_depth.."/"..depth.."]"..
"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;]"..
"label[6.2,0.5;OUT]"..
"list[context;dst;6,1;1,1;]"..
"button_exit[5,3;3,1;remove;"..S("Remove derrick").."]"..
@ -105,8 +105,8 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
end
local function on_rightclick(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
local function on_node_state_change(pos, old_state, new_state)
@ -117,65 +117,65 @@ local function on_node_state_change(pos, old_state, new_state)
end
end
local function drilling(pos, crd, mem, inv)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem))
mem.drill_pos = mem.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
local function drilling(pos, crd, nvm, inv)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
local owner = M(pos):get_string("owner")
local depth = M(pos):get_int("depth")
local curr_depth = pos.y - (mem.drill_pos or pos).y
local node = techage.get_node_lvm(mem.drill_pos)
local curr_depth = pos.y - (nvm.drill_pos or pos).y
local node = techage.get_node_lvm(nvm.drill_pos)
local ndef = minetest.registered_nodes[node.name]
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
crd.State:idle(pos, mem)
crd.State:idle(pos, nvm)
elseif curr_depth >= depth then
M(pos):set_string("oil_found", "true")
crd.State:stop(pos, mem)
elseif minetest.is_protected(mem.drill_pos, owner) then
crd.State:fault(pos, mem)
crd.State:stop(pos, nvm)
elseif minetest.is_protected(nvm.drill_pos, owner) then
crd.State:fault(pos, nvm)
elseif node.name == "techage:oil_drillbit2" then
mem.drill_pos.y = mem.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif minetest.get_item_group(node.name, "lava") >= 1 then
minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"})
minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
inv:remove_item("src", ItemStack("techage:oil_drillbit"))
mem.drill_pos.y = mem.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif techage.can_node_dig(node, ndef) then
local drop_name = techage.dropped_node(node, ndef)
if drop_name then
local item = ItemStack(drop_name)
if not inv:room_for_item("dst", item) then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
return
end
inv:add_item("dst", item)
end
minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"})
minetest.swap_node(nvm.drill_pos, {name = "techage:oil_drillbit2"})
inv:remove_item("src", ItemStack("techage:oil_drillbit"))
mem.drill_pos.y = mem.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else
crd.State:fault(pos, mem)
crd.State:fault(pos, nvm)
end
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
drilling(pos, crd, mem, inv)
drilling(pos, crd, nvm, inv)
end
return crd.State:is_active(mem)
return crd.State:is_active(nvm)
end
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)
if mem.assemble_locked or mem.assemble_build then
local nvm = techage.get_nvm(pos)
if nvm.assemble_locked or nvm.assemble_build then
return false
end
local inv = M(pos):get_inventory()
@ -194,9 +194,9 @@ local function on_receive_fields(pos, formname, fields, player)
techage.oiltower.remove(pos, player:get_player_name())
end
else
local mem = tubelib2.get_mem(pos)
if not mem.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
CRD(pos).State:state_button_event(pos, mem, fields)
local nvm = techage.get_nvm(pos)
if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
CRD(pos).State:state_button_event(pos, nvm, fields)
end
end
end
@ -302,9 +302,9 @@ minetest.register_lbm({
nodenames = {"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"},
run_at_every_load = true,
action = function(pos, node)
local mem = tubelib2.get_mem(pos)
mem.assemble_locked = false
if mem.techage_state == techage.RUNNING then
local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
if nvm.techage_state == techage.RUNNING then
play_sound(pos)
end
end

View File

@ -45,7 +45,7 @@ local function dec_oil_item(pos, meta)
end
end
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
local amount = 0
local storage_pos = M(pos):get_string("storage_pos")
if storage_pos ~= "" then
@ -56,36 +56,36 @@ local function formspec(self, pos, mem)
default.gui_bg_img..
default.gui_slots..
"image[0.5,0;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
"image[2,0;1,1;"..techage.get_power_image(pos, mem).."]"..
"image[2,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"label[0,1.3;"..S("Oil amount:")..": "..amount.."]"..
"button[3,1.1;2,1;update;"..S("Update").."]"..
"image_button[2,2.2;1,1;".. self:get_state_button_image(mem) ..";state_button;]"
"image_button[2,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"
end
local function on_rightclick(pos, node, clicker)
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
local function pumping(pos, crd, meta, mem)
local function pumping(pos, crd, meta, nvm)
if has_oil(pos, meta) then
local leftover = liquid.put(pos, 6, "techage:oil_source", 1)
if leftover and leftover > 0 then
crd.State:blocked(pos, mem)
crd.State:blocked(pos, nvm)
return
end
dec_oil_item(pos, meta)
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return
end
crd.State:fault(pos, mem)
crd.State:fault(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)
pumping(pos, crd, M(pos), mem)
return crd.State:is_active(mem)
pumping(pos, crd, M(pos), nvm)
return crd.State:is_active(nvm)
end
local function on_receive_fields(pos, formname, fields, player)
@ -93,11 +93,11 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
if fields.update then
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))
else
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
end
@ -171,7 +171,7 @@ local _, node_name_ta3, _ =
Pipe:after_place_node(pos)
end,
networks = {
pipe = {
pipe2 = {
sides = {U = 1}, -- Pipe connection side
ntype = "pump",
},

View File

@ -28,7 +28,7 @@ local CAPA = 12
local PWR_NEEDED = 14
local function swap_node(pos, on)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if on then
local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler_on"
@ -38,23 +38,23 @@ local function swap_node(pos, on)
pos = pos,
gain = 1,
max_hear_distance = 10})
elseif not on and mem.running then
elseif not on and nvm.running then
local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):stop()
mem.running = false
power.consumer_stop(pos, mem)
nvm.running = false
power.consumer_stop(pos, Cable)
end
end
local function on_power(pos, mem)
if mem.running then
local function on_power(pos, nvm)
if nvm.running then
swap_node(pos, true)
end
end
local function on_nopower(pos, mem)
local function on_nopower(pos, nvm)
swap_node(pos, false)
end
@ -69,32 +69,32 @@ local function pump_cmnd(pos, cmnd, payload)
end
local function start_node(pos)
local mem = tubelib2.get_mem(pos)
if mem.running then return end
local nvm = techage.get_nvm(pos)
if nvm.running then return end
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
if mem.liquid.amount >= 5 and mem.liquid.name == "techage:oil_source" then
if power.power_available(pos, mem, PWR_NEEDED) then
mem.running = true
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
if power.power_available(pos, Cable) then
nvm.running = true
power.consumer_start(pos, Cable, CYCLE_TIME)
end
end
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.liquid = mem.liquid or {}
mem.liquid.amount = mem.liquid.amount or 0
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
power.consumer_alive(pos, mem)
power.consumer_alive(pos, nvm)
if mem.liquid.amount >= 5 and mem.liquid.name == "techage:oil_source" then
mem.liquid.amount = mem.liquid.amount - 5
if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then
nvm.liquid.amount = nvm.liquid.amount - 5
local leftover = pump_cmnd(pos, "put")
if (tonumber(leftover) or 1) > 0 then
mem.liquid.amount = mem.liquid.amount + 5
mem.error = 25 -- = 5 pump cycles
nvm.liquid.amount = nvm.liquid.amount + 5
nvm.error = 25 -- = 5 pump cycles
M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked"))
swap_node(pos, false)
return false
@ -123,17 +123,17 @@ end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
power.after_dig_node(pos, oldnode)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end
local _liquid = {
capa = CAPA,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local mem = tubelib2.get_mem(pos)
if mem.error and mem.error > 0 then
mem.error = mem.error - 1
if mem.error <= 0 then
local nvm = techage.get_nvm(pos)
if nvm.error and nvm.error > 0 then
nvm.error = nvm.error - 1
if nvm.error <= 0 then
M(pos):set_string("infotext", S("TA3 Oil Reboiler"))
start_node(pos)
return liquid.srv_put(pos, indir, name, amount)
@ -149,7 +149,7 @@ local _liquid = {
}
local _networks = {
pipe = {
pipe2 = {
sides = {L = true, R = true}, -- Pipe connection sides
ntype = "tank",
},
@ -168,8 +168,8 @@ minetest.register_node("techage:ta3_reboiler", {
},
after_place_node = function(pos, placer)
local mem = tubelib2.init_mem(pos)
mem.liquid = {}
local nvm = techage.get_nvm(pos)
nvm.liquid = {}
local meta = M(pos)
meta:set_string("infotext", S("TA3 Oil Reboiler"))
meta:set_int("outdir", networks.side_to_outdir(pos, "R"))

View File

@ -54,8 +54,6 @@ local Cable = tubelib2.Tube:new({
end,
})
techage.ElectricCable = Cable
-- Overridden method of tubelib2!
function Cable:get_primary_node_param2(pos, dir)

246
power/powerswitch.lua Normal file
View File

@ -0,0 +1,246 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 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 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]
local pos2 = tubelib2.get_pos(pos, dir)
M(pos2):set_int("tl2_param2", M(pos2):get_int("techage_hidden_param2"))
Cable:after_place_tube(pos2, clicker)
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]
local pos2 = tubelib2.get_pos(pos, dir)
local node2 = techage.get_node_lvm(pos2)
node2.param2 = Cable:get_primary_node_param2(pos2)
M(pos2):set_int("tl2_param2", 0)
Cable:after_dig_tube(pos2, node2)
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(),
})
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,
})
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"},
})

189
power/ta4_cable.lua Normal file
View File

@ -0,0 +1,189 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 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 power = techage.power
local ELE2_MAX_CABLE_LENGHT = 200
local Cable = tubelib2.Tube:new({
dirs_to_check = {1,2,3,4,5,6},
max_tube_length = ELE2_MAX_CABLE_LENGHT,
show_infotext = false,
tube_type = "ele2",
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)
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"},
after_place_node = function(pos, placer, itemstack, pointed_thing)
Cable:after_place_node(pos)
end,
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,
networks = {
ele2 = {
sides = {L=1, R=1, F=1, B=1},
ntype = "junc",
},
},
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(),
})
Cable:add_secondary_node_names({"techage:ta4_power_box"})
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"},
},})
techage.TA4_Cable = Cable

View File

@ -25,41 +25,41 @@ local power = techage.power
local CYCLE_TIME = 2
local PWR_PERF = 100
local function determine_power(pos, mem)
local function determine_power(pos, nvm)
-- determine DC node position
local dir = M(pos):get_int("left_dir")
local pos1 = tubelib2.get_pos(pos, dir)
local pos1 = techage.get_pos(pos, dir)
local max_power, num_inverter = power.get_power(pos1, "techage:ta4_solar_inverterDC")
if num_inverter == 1 then
mem.max_power = math.min(PWR_PERF, max_power)
nvm.max_power = math.min(PWR_PERF, max_power)
else
mem.max_power = 0
nvm.max_power = 0
end
return max_power, num_inverter
end
local function determine_power_from_time_to_time(pos, mem)
local function determine_power_from_time_to_time(pos, nvm)
local time = minetest.get_timeofday() or 0
if time < 6.00/24.00 or time > 18.00/24.00 then
mem.ticks = 0
mem.max_power = 0
power.generator_update(pos, mem, mem.max_power)
nvm.ticks = 0
nvm.max_power = 0
power.generator_update(pos, nvm, nvm.max_power)
return
end
mem.ticks = mem.ticks or 0
if (mem.ticks % 10) == 0 then -- calculate max_power not to often
determine_power(pos, mem)
power.generator_update(pos, mem, mem.max_power)
nvm.ticks = nvm.ticks or 0
if (nvm.ticks % 10) == 0 then -- calculate max_power not to often
determine_power(pos, nvm)
power.generator_update(pos, nvm, nvm.max_power)
else
mem.max_power = mem.max_power or 0
nvm.max_power = nvm.max_power or 0
end
mem.ticks = mem.ticks + 1
nvm.ticks = nvm.ticks + 1
end
local function formspec(self, pos, mem)
determine_power(pos, mem)
local max_power = mem.max_power or 0
local delivered = mem.delivered or 0
local function formspec(self, pos, nvm)
determine_power(pos, nvm)
local max_power = nvm.max_power or 0
local delivered = nvm.delivered or 0
local bar_in = techage.power.formspec_power_bar(max_power, max_power)
local bar_out = techage.power.formspec_power_bar(max_power, delivered)
return "size[5,3]"..
@ -70,30 +70,30 @@ local function formspec(self, pos, mem)
"image[0,0.5;1,2;"..bar_in.."]"..
"label[0,2.5;"..max_power.." ku]"..
"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_button[3,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"label[4.2,0;AC]"..
"image[4,0.5;1,2;"..bar_out.."]"..
"label[4,2.5;"..delivered.." ku]"
end
local function can_start(pos, mem, state)
local max_power, num_inverter = determine_power(pos, mem)
local function can_start(pos, nvm, state)
local max_power, num_inverter = determine_power(pos, nvm)
if num_inverter > 1 then return "solar network error" end
if max_power == 0 then return "no solar power" end
return true
end
local function start_node(pos, mem, state)
mem.running = true
mem.delivered = 0
mem.ticks = 0
power.generator_start(pos, mem, mem.max_power)
local function start_node(pos, nvm, state)
nvm.running = true
nvm.delivered = 0
nvm.ticks = 0
power.generator_start(pos, nvm, nvm.max_power)
end
local function stop_node(pos, mem, state)
mem.running = false
mem.delivered = 0
power.generator_stop(pos, mem)
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.delivered = 0
power.generator_stop(pos, nvm)
end
local State = techage.NodeStates:new({
@ -108,33 +108,33 @@ local State = techage.NodeStates:new({
})
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
if mem.running then
determine_power(pos, mem)
if mem.max_power > 0 then
mem.delivered = power.generator_alive(pos, mem)
local nvm = techage.get_nvm(pos)
if nvm.running then
determine_power(pos, nvm)
if nvm.max_power > 0 then
nvm.delivered = power.generator_alive(pos, nvm)
else
mem.delivered = 0
nvm.delivered = 0
end
end
return mem.running
return nvm.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)
local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, mem))
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
minetest.register_node("techage:ta4_solar_inverter", {
@ -182,9 +182,9 @@ techage.power.register_node({"techage:ta4_solar_inverter"}, {
-- DC block direction
M(pos):set_int("left_dir", techage.power.side_to_outdir(pos, "L"))
local number = techage.add_node(pos, "techage:ta4_solar_inverter")
local mem = tubelib2.init_mem(pos)
State:node_init(pos, mem, number)
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
State:node_init(pos, nvm, number)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end,
})

View File

@ -30,32 +30,32 @@ local Cable = techage.ElectricCable
local power = techage.power
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
mem.capa = mem.capa or 0
local nvm = techage.get_nvm(pos)
nvm.capa = nvm.capa or 0
pos.y = pos.y + 1
local light = minetest.get_node_light(pos) or 0
pos.y = pos.y - 1
if light >= (minetest.LIGHT_MAX - 1) then
if mem.providing then
power.generator_stop(pos, mem)
mem.providing = false
mem.provided = 0
if nvm.providing then
power.generator_stop(pos, nvm)
nvm.providing = false
nvm.provided = 0
end
mem.capa = math.min(mem.capa + PWR_PERF * 1.2, PWR_CAPA)
nvm.capa = math.min(nvm.capa + PWR_PERF * 1.2, PWR_CAPA)
else
if mem.capa > 0 then
if not mem.providing then
power.generator_start(pos, mem, PWR_PERF)
mem.providing = true
if nvm.capa > 0 then
if not nvm.providing then
power.generator_start(pos, nvm, PWR_PERF)
nvm.providing = true
end
mem.provided = power.generator_alive(pos, mem)
mem.capa = mem.capa - mem.provided
nvm.provided = power.generator_alive(pos, nvm)
nvm.capa = nvm.capa - nvm.provided
else
power.generator_stop(pos, mem)
mem.providing = false
mem.provided = 0
mem.capa = 0
power.generator_stop(pos, nvm)
nvm.providing = false
nvm.provided = 0
nvm.capa = 0
end
end
return true
@ -91,25 +91,25 @@ techage.power.register_node({"techage:ta4_solar_minicell"}, {
local number = techage.add_node(pos, "techage:ta4_solar_minicell")
meta:set_string("node_number", number)
meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number)
local mem = tubelib2.init_mem(pos)
mem.capa = 0
mem.providing = false
local nvm = techage.get_nvm(pos)
nvm.capa = 0
nvm.providing = false
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
after_dig_node = function(pos)
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
})
techage.register_node({"techage:ta4_solar_minicell"}, {
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.providing then
if nvm.providing then
return "discharging"
elseif (mem.capa or 0) > 0 then
elseif (nvm.capa or 0) > 0 then
return "charging"
else
return "unused"

View File

@ -49,7 +49,7 @@ local function start_node(pos, nvm, state)
nvm.needed = 0
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
power.consumer_start(pos, Cable, CYCLE_TIME, outdir)
power.consumer_start(pos, Cable, CYCLE_TIME)
end
local function stop_node(pos, nvm, state)
@ -57,7 +57,7 @@ local function stop_node(pos, nvm, state)
nvm.needed = 0
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
power.consumer_stop(pos, Cable, outdir)
power.consumer_stop(pos, Cable)
end
local State = techage.NodeStates:new({

View File

@ -16,54 +16,58 @@
local M = minetest.get_meta
local S = techage.S
local Power = techage.ElectricCable
local Cable = techage.ElectricCable
local firebox = techage.firebox
local power = techage.power
local fuel = techage.fuel
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local networks = techage.networks
local CYCLE_TIME = 2
local PWR_CAPA = 12
local EFFICIENCY = 2.5
local function formspec(self, pos, mem)
local function formspec(self, pos, nvm)
local fuel_percent = 0
if mem.running then
fuel_percent = ((mem.burn_cycles or 1) * 100) / (mem.burn_cycles_total or 1)
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
return "size[8,6]"..
--"box[0,-0.1;3.8,0.5;#c6e8ff]"..
--"label[1,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
--power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
fuel.formspec_fuel(1, 0, mem)..
fuel.formspec_fuel(1, 0, nvm)..
"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).."]"..
"image_button[5.5,0.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.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
local function can_start(pos, nvm, state)
if nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.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)
local function start_node(pos, nvm, state)
nvm.running = true
power.generator_start(pos, nvm, 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)
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.provided = 0
power.generator_stop(pos, nvm)
end
local State = techage.NodeStates:new({
@ -72,27 +76,27 @@ local State = techage.NodeStates:new({
cycle_time = CYCLE_TIME,
standby_ticks = 0,
formspec_func = formspec,
infotext_name = "TA3 Tiny Power Generator",
infotext_name = S("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)
local function burning(pos, nvm)
local ratio = math.max((nvm.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
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
nvm.burn_cycles = (nvm.burn_cycles or 0) - ratio
if nvm.burn_cycles <= 0 then
if nvm.liquid.amount > 0 then
nvm.liquid.amount = nvm.liquid.amount - 1
nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
nvm.burn_cycles_total = nvm.burn_cycles
return true
else
mem.liquid.name = nil
State:fault(pos, mem)
nvm.liquid.name = nil
State:fault(pos, nvm)
return false
end
else
@ -101,16 +105,16 @@ local function burning(pos, mem)
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)
local nvm = techage.get_nvm(pos)
if nvm.running and burning(pos, nvm) then
nvm.provided = power.generator_alive(pos, nvm)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true
else
mem.provided = 0
nvm.provided = 0
end
return false
end
@ -119,15 +123,15 @@ 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)
local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, mem))
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function formspec_clbk(pos, mem)
return formspec(State, pos, mem)
local function formspec_clbk(pos, nvm)
return formspec(State, pos, nvm)
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
@ -135,8 +139,8 @@ local function on_metadata_inventory_put(pos, listname, index, stack, player)
end
local function on_rightclick(pos)
local mem = tubelib2.get_mem(pos)
M(pos):set_string("formspec", formspec(State, pos, mem))
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local _liquid = {
@ -176,13 +180,13 @@ minetest.register_node("techage:tiny_generator", {
is_ground_content = false,
on_construct = function(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:tiny_generator")
mem.running = false
mem.burn_cycles = 0
State:node_init(pos, mem, number)
nvm.running = false
nvm.burn_cycles = 0
State:node_init(pos, nvm, number)
local meta = M(pos)
meta:set_string("formspec", formspec(State, pos, mem))
meta:set_string("formspec", formspec(State, pos, nvm))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
@ -257,9 +261,9 @@ techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_o
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return power.percent(PWR_CAPA, mem.provided)
return power.percent(PWR_CAPA, nvm.provided)
else
return State:on_receive_message(pos, topic, payload)
end

View File

@ -100,7 +100,6 @@ 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)
-- probably a hidden node with mem data
techage.del_mem(pos)
else

View File

@ -48,8 +48,8 @@ local function pos_and_yaw(pos, param2)
return pos, {x=0, y=yaw, z=0}
end
local function add_rotor(pos, mem, player_name)
mem.error = false
local function add_rotor(pos, nvm, player_name)
nvm.error = false
-- Check for next wind turbine
local pos1 = {x=pos.x-13, y=pos.y-9, z=pos.z-13}
@ -62,7 +62,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("The wind turbines are too close together!"))
end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true
nvm.error = true
return
end
@ -77,7 +77,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("More water expected (2 m deep)!"))
end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true
nvm.error = true
return
end
@ -90,7 +90,7 @@ local function add_rotor(pos, mem, player_name)
" "..S("No wind at this altitude!"))
end
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true
nvm.error = true
return
end
@ -108,28 +108,28 @@ local function add_rotor(pos, mem, player_name)
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
end
local function start_rotor(pos, mem)
local function start_rotor(pos, nvm)
local npos = techage.get_pos(pos, "F")
local node = minetest.get_node(npos)
if node.name ~= "techage:ta4_wind_turbine_nacelle" then
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Error"))
mem.error = true
nvm.error = true
return
end
mem.providing = true
mem.delivered = 0
power.generator_start(pos, mem, PWR_PERF)
nvm.providing = true
nvm.delivered = 0
power.generator_start(pos, nvm, PWR_PERF)
local hash = minetest.hash_node_position(pos)
if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(50)
end
end
local function stop_rotor(pos, mem)
mem.providing = false
mem.delivered = 0
power.generator_stop(pos, mem)
local function stop_rotor(pos, nvm)
nvm.providing = false
nvm.delivered = 0
power.generator_stop(pos, nvm)
local hash = minetest.hash_node_position(pos)
if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(0)
@ -137,24 +137,24 @@ local function stop_rotor(pos, mem)
end
local function node_timer(pos, elapsed)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if not mem.running then
if not nvm.running then
return false
end
local time = minetest.get_timeofday() or 0
if (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) then
if not mem.providing then
start_rotor(pos, mem)
if not nvm.providing then
start_rotor(pos, nvm)
end
else
if mem.providing then
stop_rotor(pos, mem)
if nvm.providing then
stop_rotor(pos, nvm)
end
end
if mem.providing then
mem.delivered = power.generator_alive(pos, mem)
if nvm.providing then
nvm.delivered = power.generator_alive(pos, nvm)
end
return true
end
@ -212,14 +212,14 @@ techage.power.register_node({"techage:ta4_wind_turbine"}, {
conn_sides = {"D"},
after_place_node = function(pos, placer)
local meta = M(pos)
local mem = tubelib2.init_mem(pos)
local nvm = techage.get_nvm(pos)
local own_num = techage.add_node(pos, "techage:ta4_wind_turbine")
meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
mem.providing = false
mem.running = true
add_rotor(pos, mem, placer:get_player_name())
nvm.providing = false
nvm.running = true
add_rotor(pos, nvm, placer:get_player_name())
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
@ -230,37 +230,37 @@ techage.power.register_node({"techage:ta4_wind_turbine"}, {
end
Rotors[hash] = nil
techage.remove_node(pos)
tubelib2.del_mem(pos)
techage.del_mem(pos)
end,
})
techage.register_node({"techage:ta4_wind_turbine"}, {
on_recv_message = function(pos, src, topic, payload)
local mem = tubelib2.get_mem(pos)
local nvm = techage.get_nvm(pos)
if topic == "state" then
local node = minetest.get_node(pos)
if node.name == "ignore" then -- unloaded node?
return "unloaded"
end
if mem.error then
if nvm.error then
return "error"
elseif mem.running and mem.providing then
elseif nvm.running and nvm.providing then
return "running"
else
return "stopped"
end
elseif topic == "on" then
mem.running = true
nvm.running = true
elseif topic == "off" then
mem.running = false
nvm.running = false
else
return "unsupported"
end
end,
on_node_load = function(pos)
local mem = tubelib2.get_mem(pos)
add_rotor(pos, mem)
mem.providing = false -- to force the rotor start
local nvm = techage.get_nvm(pos)
add_rotor(pos, nvm)
nvm.providing = false -- to force the rotor start
minetest.get_node_timer(pos):start(CYCLE_TIME)
end,
})