Adapt chemistry, electrolyser and fuel cell to networks

This commit is contained in:
Joachim Stolberg 2021-06-20 22:21:56 +02:00
parent 1d7db7943b
commit 104b1f179d
8 changed files with 336 additions and 462 deletions

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
Copyright (C) 2019-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -17,8 +17,7 @@ local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local Pipe = techage.LiquidPipe
local networks = techage.networks
local liquid = techage.liquid
local liquid = networks.liquid
local recipes = techage.recipes
local Liquids = {} -- {hash(pos) = {name = outdir},...}
@ -27,26 +26,6 @@ local STANDBY_TICKS = 2
local COUNTDOWN_TICKS = 3
local CYCLE_TIME = 10
-- to mark the pump source and destinstion node
local DebugCache = {}
local function set_starter_name(pos, clicker)
local key = minetest.hash_node_position(pos)
DebugCache[key] = {starter = clicker:get_player_name(), count = 10}
end
local function get_starter_name(pos)
local key = minetest.hash_node_position(pos)
local def = DebugCache[key]
if def then
def.count = (def.count or 0) - 1
if def.count > 0 then
return def.starter
end
DebugCache[key] = nil
end
end
local function formspec(self, pos, nvm)
return "size[6,3.6]"..
default.gui_bg..
@ -199,8 +178,10 @@ local function dosing(pos, nvm, elapsed)
end
end
-- inputs
local starter = get_starter_name(pos)
local taken = {}
local mem = techage.get_mem(pos)
mem.dbg_cycles = (mem.dbg_cycles or 0) - 1
for _,item in pairs(recipe.input) do
if item.name ~= "" then
local outdir = liquids[item.name] or reload_liquids(pos)[item.name]
@ -210,7 +191,7 @@ local function dosing(pos, nvm, elapsed)
untake(pos, taken)
return
end
local num = liquid.take(pos, Pipe, outdir, item.name, item.num, starter)
local num = liquid.take(pos, Pipe, outdir, item.name, item.num, mem.dbg_cycles > 0)
if num < item.num then
taken[#taken + 1] = {outdir = outdir, name = item.name, num = num}
State:standby(pos, nvm)
@ -267,19 +248,12 @@ local function on_receive_fields(pos, formname, fields, player)
if not nvm.running then
recipes.on_receive_fields(pos, formname, fields, player)
end
set_starter_name(pos, player)
local mem = techage.get_mem(pos)
mem.dbg_cycles = 5
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local nworks = {
pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "pump",
},
}
minetest.register_node("techage:ta4_doser", {
description = S("TA4 Doser"),
tiles = {
@ -301,7 +275,7 @@ minetest.register_node("techage:ta4_doser", {
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos, dir)
liquid.update_network(pos, dir, tlib2, node)
del_liquids(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
@ -312,7 +286,6 @@ minetest.register_node("techage:ta4_doser", {
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
networks = nworks,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
@ -340,13 +313,12 @@ minetest.register_node("techage:ta4_doser_on", {
},
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos, dir)
liquid.update_network(pos, dir, tlib2, node)
del_liquids(pos)
end,
on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick,
on_timer = node_timer,
networks = nworks,
paramtype2 = "facedir",
on_rotate = screwdriver.disallow,
@ -356,15 +328,14 @@ minetest.register_node("techage:ta4_doser_on", {
sounds = default.node_sound_metal_defaults(),
})
liquid.register_nodes({"techage:ta4_doser", "techage:ta4_doser_on"}, Pipe, "pump", nil, {})
techage.register_node({"techage:ta4_doser", "techage:ta4_doser_on"}, {
on_recv_message = function(pos, src, topic, payload)
return State:on_receive_message(pos, topic, payload)
end,
})
Pipe:add_secondary_node_names({"techage:ta4_doser", "techage:ta4_doser_on"})
if minetest.global_exists("unified_inventory") then
unified_inventory.register_craft_type("ta4_doser", {
description = S("TA4 Reactor"),

View File

@ -15,8 +15,8 @@
local S = techage.S
local M = minetest.get_meta
local Pipe = techage.LiquidPipe
local networks = techage.networks
local liquid = techage.liquid
local Cable = techage.ElectricCable
local liquid = networks.liquid
minetest.register_node("techage:ta4_reactor_fillerpipe", {
description = S("TA4 Reactor Filler Pipe"),
@ -48,9 +48,9 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
Pipe:after_place_node(pos1)
end
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos)
end,
-- tubelib2_on_update2 = function(pos, dir, tlib2, node)
-- liquid.update_network(pos, dir, tlib2, node)
-- end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
@ -63,13 +63,6 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
networks = {
pipe2 = {
sides = {U = 1}, -- Pipe connection sides
ntype = "tank",
},
},
})
local function stand_cmnd(pos, cmnd, payload)
@ -117,6 +110,8 @@ techage.register_node({"techage:ta4_reactor_fillerpipe"}, {
end,
})
liquid.register_nodes({"techage:ta4_reactor_fillerpipe"}, Pipe, "tank", {"U"}, {})
local function formspec()
local title = S("TA4 Reactor")
return "size[8,6]"..
@ -176,8 +171,6 @@ minetest.register_node("techage:ta4_reactor", {
sounds = default.node_sound_metal_defaults(),
})
Pipe:add_secondary_node_names({"techage:ta4_reactor_fillerpipe"})
minetest.register_craft({
output = 'techage:ta4_reactor',
recipe = {

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
Copyright (C) 2019-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -15,13 +15,12 @@
local S = techage.S
local M = minetest.get_meta
local Cable = techage.ElectricCable
local power = techage.power
local Pipe = techage.LiquidPipe
local networks = techage.networks
local liquid = techage.liquid
local power = networks.power
local liquid = networks.liquid
local PWR_NEEDED = 8
local CYCLE_TIME = 4
local CYCLE_TIME = 2
local function play_sound(pos)
local mem = techage.get_mem(pos)
@ -49,18 +48,18 @@ local function on_power(pos)
M(pos):set_string("infotext", S("on"))
play_sound(pos)
local nvm = techage.get_nvm(pos)
nvm.has_power = true
nvm.running = true
end
local function on_nopower(pos)
M(pos):set_string("infotext", S("no power"))
stop_sound(pos)
local nvm = techage.get_nvm(pos)
nvm.has_power = false
nvm.running = false
end
local function is_running(pos, nvm)
return nvm.has_power
return nvm.running
end
minetest.register_node("techage:ta4_reactor_stand", {
@ -103,15 +102,21 @@ minetest.register_node("techage:ta4_reactor_stand", {
Pipe:after_place_node(pos)
Cable:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
if tlib2.tube_type == "ele1" then
power.update_network(pos, dir, tlib2)
else
liquid.update_network(pos, dir, tlib2)
end
end,
-- tubelib2_on_update2 = function(pos, dir, tlib2, node)
-- if tlib2.tube_type == "ele1" then
-- power.update_network(pos, dir, tlib2, node)
-- else
-- liquid.update_network(pos, dir, tlib2, node)
-- end
-- end,
on_timer = function(pos, elapsed)
power.consumer_alive(pos, Cable, CYCLE_TIME)
local nvm = techage.get_nvm(pos)
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
if not nvm.running and consumed == PWR_NEEDED then
on_power(pos)
elseif nvm.running and consumed < PWR_NEEDED then
on_nopower(pos)
end
return true
end,
after_dig_node = function(pos, oldnode)
@ -127,21 +132,6 @@ minetest.register_node("techage:ta4_reactor_stand", {
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
networks = {
pipe2 = {
sides = {R=1},
ntype = "pump",
},
ele1 = {
sides = {L=1},
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
is_running = is_running,
},
},
})
-- controlled by the fillerpipe
@ -149,21 +139,19 @@ techage.register_node({"techage:ta4_reactor_stand"}, {
on_transfer = function(pos, in_dir, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "power" then
return nvm.has_power or power.power_available(pos, Cable)
return nvm.running or power.power_available(pos, Cable)
elseif topic == "output" then
local outdir = M(pos):get_int("outdir")
return liquid.put(pos, Pipe, outdir, payload.name, payload.amount, payload.player_name)
elseif topic == "can_start" then
return power.power_available(pos, Cable)
elseif topic == "start" then
nvm.has_power = false
power.consumer_start(pos, Cable, CYCLE_TIME)
nvm.running = false
minetest.get_node_timer(pos):start(CYCLE_TIME)
M(pos):set_string("infotext", "...")
return true
elseif topic == "stop" then
nvm.has_power = false
power.consumer_stop(pos, Cable)
stop_sound(pos)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
@ -194,9 +182,9 @@ minetest.register_node("techage:ta4_reactor_base", {
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
end,
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos, dir, tlib2)
end,
-- tubelib2_on_update2 = function(pos, dir, tlib2, node)
-- liquid.update_network(pos, dir, tlib2, node)
-- end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
@ -206,21 +194,11 @@ minetest.register_node("techage:ta4_reactor_base", {
groups = {cracky=2},
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
networks = {
pipe2 = {
sides = {R=1}, -- Pipe connection sides
ntype = "pump",
},
},
})
Pipe:add_secondary_node_names({
"techage:ta4_reactor_base",
"techage:ta4_reactor_stand",
})
Cable:add_secondary_node_names({"techage:ta4_reactor_stand"})
liquid.register_nodes({"techage:ta4_reactor_base"}, Pipe, "pump", {"R"}, {})
liquid.register_nodes({"techage:ta4_reactor_stand"}, Pipe, "pump", {"R"}, {})
power.register_nodes({"techage:ta4_reactor_stand"}, Cable, "con", {"L"})
minetest.register_craft({
output = 'techage:ta4_reactor_stand',

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
Copyright (C) 2019-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -17,10 +17,9 @@ local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
local power = techage.power
local power = networks.power
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local networks = techage.networks
local liquid = networks.liquid
local CYCLE_TIME = 2
local STANDBY_TICKS = 3
@ -28,6 +27,10 @@ local PWR_NEEDED = 35
local PWR_UNITS_PER_HYDROGEN_ITEM = 80
local CAPACITY = 200
local function evaluate_percent(s)
return (tonumber(s:sub(1, -2)) or 0) / 100
end
local function formspec(self, pos, nvm)
local amount = (nvm.liquid and nvm.liquid.amount) or 0
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
@ -36,31 +39,41 @@ local function formspec(self, pos, nvm)
arrow = "image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
end
if amount > 0 then
lqd_name = lqd_name.." "..amount
lqd_name = lqd_name .. " " .. amount
end
return "size[6,4]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]"..
techage.power.formspec_label_bar(pos, 0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken)..
arrow..
"image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
return "size[6,4]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"box[0,-0.1;5.8,0.5;#c6e8ff]" ..
"label[0.2,-0.1;" .. minetest.colorize( "#000000", S("Electrolyzer")) .. "]" ..
techage.formspec_power_bar(pos, 0.1, 0.8, S("Electricity"), nvm.taken, PWR_NEEDED) ..
arrow ..
"image_button[3,2.5;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" ..
"tooltip[3,2.5;1,1;" .. self:get_state_tooltip(nvm) .. "]" ..
techage.item_image(4.5,2, lqd_name)
end
local function can_start(pos, nvm, state)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.liquid.amount < CAPACITY then
return true
end
return S("Storage full")
end
local function start_node(pos, nvm, state)
nvm.running = true
nvm.taken = 0
power.consumer_start(pos, Cable, CYCLE_TIME)
nvm.taken = 0
nvm.reduction = evaluate_percent(M(pos):get_string("reduction"))
nvm.turnoff = evaluate_percent(M(pos):get_string("turnoff"))
end
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.taken = 0
power.consumer_stop(pos, Cable)
end
local State = techage.NodeStates:new({
@ -70,26 +83,11 @@ local State = techage.NodeStates:new({
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
infotext_name = S("TA4 Electrolyzer"),
can_start = can_start,
start_node = start_node,
stop_node = stop_node,
})
local function on_power(pos)
local nvm = techage.get_nvm(pos)
State:start(pos, nvm)
nvm.running = true
end
local function on_nopower(pos)
local nvm = techage.get_nvm(pos)
State:stop(pos, nvm)
nvm.running = false
end
local function is_running(pos, nvm)
return nvm.running
end
local function generating(pos, nvm)
nvm.num_pwr_units = nvm.num_pwr_units or 0
nvm.countdown = nvm.countdown or 0
@ -106,16 +104,32 @@ end
-- converts power into hydrogen
local function node_timer(pos, elapsed)
local meta = M(pos)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
if nvm.liquid.amount < CAPACITY then
nvm.taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
generating(pos, nvm)
State:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS?
local in_dir = meta:get_int("in_dir")
local curr_load = power.get_storage_load(pos, Cable, in_dir, 1)
if curr_load > (nvm.turnoff or 0) then
local to_be_taken = PWR_NEEDED * (nvm.reduction or 1)
nvm.taken = power.consume_power(pos, Cable, in_dir, to_be_taken) or 0
generating(pos, nvm)
if not nvm.running and nvm.taken == to_be_taken then
State:start(pos, nvm)
elseif nvm.running and nvm.taken < to_be_taken then
State:nopower(pos, nvm)
else
State:keep_running(pos, nvm, 1)
end
elseif curr_load == 0 then
State:nopower(pos, nvm)
else
State:standby(pos, nvm, S("Turnoff point reached"))
end
else
State:blocked(pos, nvm, S("full"))
State:blocked(pos, nvm, S("Storage full"))
power.consumer_stop(pos, Cable)
end
if techage.is_activeformspec(pos) then
@ -129,6 +143,7 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, player)
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
@ -165,44 +180,30 @@ local function put(pos, indir, name, amount)
return leftover
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2)
else
power.update_network(pos, outdir, tlib2)
end
end
local netw_def = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
local tool_config = {
{
type = "const",
name = "needed",
label = S("Needed power [ku]"),
tooltip = S("The maximum amount of power\nthe consumer can consume"),
value = PWR_NEEDED,
},
ele1 = {
sides = {L = 1}, -- Cable connection sides
ntype = "con2",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
is_running = is_running,
{
type = "dropdown",
choices = "20%,40%,60%,80%,100%",
name = "reduction",
label = S("Power reduction"),
tooltip = S("The reduced amount of power\nthe consumer should consume"),
},
{
type = "dropdown",
choices = "0%,20%,40%,60%,80%",
name = "turnoff",
label = S("Turnoff point"),
tooltip = S("If the load of the storage system\nreaches the configured value,\nthe consumer will be switched off"),
},
}
local liquid_def = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = put,
untake = put,
take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return amount, name
end
}
minetest.register_node("techage:ta4_electrolyzer", {
description = S("TA4 Electrolyzer"),
tiles = {
@ -224,10 +225,7 @@ minetest.register_node("techage:ta4_electrolyzer", {
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
on_punch = liquid.on_punch,
networks = netw_def,
liquid = liquid_def,
on_receive_fields = on_receive_fields,
on_timer = node_timer,
on_rightclick = on_rightclick,
@ -236,6 +234,7 @@ minetest.register_node("techage:ta4_electrolyzer", {
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
ta3_formspec = tool_config,
})
minetest.register_node("techage:ta4_electrolyzer_on", {
@ -268,9 +267,6 @@ minetest.register_node("techage:ta4_electrolyzer_on", {
},
},
tubelib2_on_update2 = tubelib2_on_update2,
networks = netw_def,
liquid = liquid_def,
on_receive_fields = on_receive_fields,
on_punch = liquid.on_punch,
on_timer = node_timer,
@ -283,10 +279,47 @@ minetest.register_node("techage:ta4_electrolyzer_on", {
diggable = false,
paramtype = "light",
light_source = 6,
ta3_formspec = tool_config,
})
Cable:add_secondary_node_names({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"})
Pipe:add_secondary_node_names({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"})
local liquid_def = {
capa = CAPACITY,
peek = function(pos)
local nvm = techage.get_nvm(pos)
return liquid.srv_peek(nvm)
end,
put = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return leftover
end,
take = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
amount, name = liquid.srv_take(nvm, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return amount, name
end,
untake = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return leftover
end,
}
liquid.register_nodes({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, Pipe, "tank", {"R"}, liquid_def)
power.register_nodes({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, Cable, "con", {"L"})
techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, {
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
@ -298,6 +331,13 @@ techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"
return State:on_receive_message(pos, topic, payload)
end
end,
on_node_load = function(pos, node)
local meta = M(pos)
if not meta:contains("reduction") then
meta:set_string("reduction", "100%")
meta:set_string("turnoff", "0%")
end
end,
})
minetest.register_craft({

View File

@ -3,7 +3,7 @@
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
Copyright (C) 2019-2021 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
@ -17,33 +17,17 @@ local M = minetest.get_meta
local S = techage.S
local Cable = techage.ElectricCable
local power = techage.power
local power = networks.power
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local networks = techage.networks
local liquid = networks.liquid
local control = networks.control
local CYCLE_TIME = 2
local STANDBY_TICKS = 4
local PWR_CAPA = 34
local PWR_PERF = 34
local PWR_UNITS_PER_HYDROGEN_ITEM = 75
local CAPACITY = 100
local States = {}
local STATE = function(pos) return States[techage.get_node_lvm(pos).name] end
local function is_gen1(nvm)
if not nvm.running then
local is_gen1 = dump(nvm.is_gen1 or false)
return "checkbox[0.3,0.5;is_gen1;"..S("Cat. 1 generator")..";"..is_gen1.."]"..
"tooltip[0.3,0.5;1,1;"..S("If set, fuelcell will work\nas cat. 1 generator")..";#0C3D32;#FFFFFF]"
end
if nvm.is_gen1 then
return "label[0.5,0.7;"..S("Cat. 1 generator").."]"
else
return "label[0.5,0.7;"..S("Cat. 2 generator").."]"
end
end
local function formspec(self, pos, nvm)
local amount = (nvm.liquid and nvm.liquid.amount) or 0
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
@ -59,40 +43,28 @@ local function formspec(self, pos, nvm)
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]"..
"label[0.2,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]"..
techage.item_image(0.5,2, lqd_name)..
arrow..
is_gen1(nvm)..
"image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
techage.power.formspec_label_bar(pos, 3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given)
techage.formspec_power_bar(pos, 3.5, 0.8, S("Electricity"), nvm.provided, PWR_PERF)
end
local function start_node(pos, nvm, state)
nvm.running = true
nvm.given = 0
nvm.provided = 0
local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
power.start_storage_calc(pos, Cable, outdir)
end
local function stop_node(pos, nvm, state)
nvm.running = false
nvm.given = 0
nvm.provided = 0
local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
power.start_storage_calc(pos, Cable, outdir)
end
local State = techage.NodeStates:new({
node_name_passive = "techage:ta4_fuelcell",
node_name_active = "techage:ta4_fuelcell_on",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
infotext_name = S("TA4 Fuel Cell Gen2"),
start_node = start_node,
stop_node = stop_node,
})
local function has_hydrogen(nvm)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
@ -100,30 +72,53 @@ local function has_hydrogen(nvm)
return nvm.num_pwr_units > 0 or (nvm.liquid.amount > 0 and nvm.liquid.name == "techage:hydrogen")
end
local function can_start(pos, nvm, state)
if has_hydrogen(nvm) then
return true
end
return S("no hydrogen")
end
local State = techage.NodeStates:new({
node_name_passive = "techage:ta4_fuelcell",
node_name_active = "techage:ta4_fuelcell_on",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
infotext_name = S("TA4 Fuel Cell"),
can_start = can_start,
start_node = start_node,
stop_node = stop_node,
})
local function consuming(pos, nvm)
if nvm.num_pwr_units <= 0 then
nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
nvm.liquid.amount = nvm.liquid.amount - 1
end
nvm.num_pwr_units = nvm.num_pwr_units - nvm.given
nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided
end
-- converts hydrogen into power
local function node_timer(pos, elapsed)
local meta = M(pos)
local nvm = techage.get_nvm(pos)
local state = STATE(pos)
--print("fuelcell", nvm.running, nvm.given, nvm.num_pwr_units)
--print("fuelcell", nvm.running, nvm.provided, nvm.num_pwr_units)
if has_hydrogen(nvm) then
local outdir = M(pos):get_int("outdir")
nvm.given = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
local tp1 = tonumber(meta:get_string("termpoint1"))
local tp2 = tonumber(meta:get_string("termpoint2"))
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
consuming(pos, nvm)
state:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS?
State:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS?
else
state:standby(pos, nvm)
nvm.given = 0
State:standby(pos, nvm)
nvm.provided = 0
end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(state, pos, nvm))
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return true
end
@ -133,26 +128,14 @@ local function on_receive_fields(pos, formname, fields, player)
return
end
local nvm = techage.get_nvm(pos)
if fields.is_gen1 then
nvm.is_gen1 = fields.is_gen1 == "true"
local node = minetest.get_node(pos)
if nvm.is_gen1 then
node.name = "techage:ta4_fuelcell2"
else
node.name = "techage:ta4_fuelcell"
end
minetest.swap_node(pos, node)
local outdir = M(pos):get_int("outdir")
techage.power.update_network(pos, outdir, Cable)
end
STATE(pos):state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm))
State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm))
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
local function after_place_node(pos)
@ -160,7 +143,7 @@ local function after_place_node(pos)
nvm.running = false
nvm.num_pwr_units = 0
local number = techage.add_node(pos, "techage:ta4_fuelcell")
STATE(pos):node_init(pos, nvm, number)
State:node_init(pos, nvm, number)
local node = minetest.get_node(pos)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
@ -176,47 +159,13 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
Cable:after_dig_node(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2)
else
power.update_network(pos, outdir, tlib2)
local function get_generator_data(pos, tlib2)
local nvm = techage.get_nvm(pos)
if nvm.running then
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
end
end
local netw_def = {
pipe2 = {
sides = {L = 1}, -- Pipe connection sides
ntype = "tank",
},
ele1 = {
sides = {R = 1}, -- Cable connection sides
ntype = "gen2",
nominal = PWR_CAPA,
},
}
local liquid_def = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local leftover = liquid.srv_put(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm))
end
return leftover
end,
take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm))
end
return amount, name
end
}
minetest.register_node("techage:ta4_fuelcell", {
description = S("TA4 Fuel Cell"),
tiles = {
@ -238,13 +187,12 @@ minetest.register_node("techage:ta4_fuelcell", {
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
get_generator_data = get_generator_data,
on_punch = liquid.on_punch,
networks = netw_def,
liquid = liquid_def,
on_receive_fields = on_receive_fields,
on_timer = node_timer,
on_rightclick = on_rightclick,
ta4_formspec = techage.generator_settings("ta4", PWR_PERF),
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
@ -282,13 +230,12 @@ minetest.register_node("techage:ta4_fuelcell_on", {
},
},
tubelib2_on_update2 = tubelib2_on_update2,
networks = netw_def,
liquid = liquid_def,
get_generator_data = get_generator_data,
on_receive_fields = on_receive_fields,
on_punch = liquid.on_punch,
on_timer = node_timer,
on_rightclick = on_rightclick,
ta4_formspec = techage.generator_settings("ta4", PWR_PERF),
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
@ -299,138 +246,81 @@ minetest.register_node("techage:ta4_fuelcell_on", {
light_source = 6,
})
-------------------------------------------------------------------------------
-- Gen1 fuellcell
-------------------------------------------------------------------------------
local State2 = techage.NodeStates:new({
node_name_passive = "techage:ta4_fuelcell2",
node_name_active = "techage:ta4_fuelcell2_on",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
formspec_func = formspec,
infotext_name = S("TA4 Fuel Cell Gen1"),
start_node = start_node,
stop_node = stop_node,
})
local netw_def2 = {
pipe2 = {
sides = {L = 1}, -- Pipe connection sides
ntype = "tank",
},
ele1 = {
sides = {R = 1}, -- Cable connection sides
ntype = "gen1",
nominal = PWR_CAPA - 1, -- to be able to distiguish between cat1 and 2
},
local liquid_def = {
capa = CAPACITY,
peek = function(pos)
local nvm = techage.get_nvm(pos)
return liquid.srv_peek(nvm)
end,
put = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return leftover
end,
take = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
amount, name = liquid.srv_take(nvm, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return amount, name
end,
untake = function(pos, indir, name, amount)
local nvm = techage.get_nvm(pos)
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return leftover
end,
}
minetest.register_node("techage:ta4_fuelcell2", {
description = S("TA4 Fuel Cell"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png^[transformFX",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png",
},
liquid.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, Pipe, "tank", {"L"}, liquid_def)
power.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, Cable, "gen", {"R"})
can_dig = function(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
return liquid.is_empty(pos)
end,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
on_punch = liquid.on_punch,
networks = netw_def2,
liquid = liquid_def,
on_receive_fields = on_receive_fields,
on_timer = node_timer,
on_rightclick = on_rightclick,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
drop = "techage:ta4_fuelcell",
})
minetest.register_alias_force("techage:ta4_fuelcell2", "techage:ta4_fuelcell")
minetest.register_alias_force("techage:ta4_fuelcell2_on", "techage:ta4_fuelcell_on")
minetest.register_node("techage:ta4_fuelcell2_on", {
description = S("TA4 Fuel Cell"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png",
"techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.png",
{
image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_fuelcell4.png^techage_appl_ctrl_unit4.png^[transformFX",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.8,
},
},
{
image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_fuelcell4.png^techage_appl_ctrl_unit4.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 0.8,
},
},
},
tubelib2_on_update2 = tubelib2_on_update2,
networks = netw_def2,
liquid = liquid_def,
on_receive_fields = on_receive_fields,
on_punch = liquid.on_punch,
on_timer = node_timer,
on_rightclick = on_rightclick,
paramtype2 = "facedir",
groups = {not_in_creative_inventory=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
diggable = false,
paramtype = "light",
light_source = 6,
})
States["techage:ta4_fuelcell"] = State
States["techage:ta4_fuelcell_on"] = State
States["techage:ta4_fuelcell2"] = State2
States["techage:ta4_fuelcell2_on"] = State2
Cable:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on",
"techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"})
Pipe:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on",
"techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"})
techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on",
"techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"}, {
techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, {
on_recv_message = function(pos, src, topic, payload)
local nvm = techage.get_nvm(pos)
if topic == "load" then
return techage.power.percent(CAPACITY, (nvm.liquid and nvm.liquid.amount) or 0)
elseif topic == "delivered" then
return math.floor((nvm.given or 0) + 0.5)
return math.floor((nvm.provided or 0) + 0.5)
else
return STATE(pos):on_receive_message(pos, topic, payload)
return State:on_receive_message(pos, topic, payload)
end
end,
})
control.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, {
on_receive = function(pos, tlib2, topic, payload)
end,
on_request = function(pos, tlib2, topic)
if topic == "info" then
local nvm = techage.get_nvm(pos)
local meta = M(pos)
return {
type = S("TA4 Fuel Cell"),
number = meta:get_string("node_number") or "",
running = nvm.running or false,
available = PWR_PERF,
provided = nvm.provided or 0,
termpoint = meta:get_string("termpoint"),
}
end
return false
end,
}
)
minetest.register_craft({
output = "techage:ta4_fuelcell",
recipe = {

View File

@ -286,15 +286,15 @@ dofile(MP.."/energy_storage/inlet.lua")
dofile(MP.."/energy_storage/nodes.lua")
-- Chemistry
--dofile(MP.."/chemistry/ta4_reactor.lua")
--dofile(MP.."/chemistry/ta4_stand.lua")
--dofile(MP.."/chemistry/ta4_doser.lua")
--dofile(MP.."/chemistry/ta4_liquid_filter.lua")
dofile(MP.."/chemistry/ta4_reactor.lua")
dofile(MP.."/chemistry/ta4_stand.lua")
dofile(MP.."/chemistry/ta4_doser.lua")
dofile(MP.."/chemistry/ta4_liquid_filter.lua")
-- Hydrogen
--dofile(MP.."/hydrogen/fuelcellstack.lua")
--dofile(MP.."/hydrogen/electrolyzer.lua")
--dofile(MP.."/hydrogen/fuelcell.lua")
dofile(MP.."/hydrogen/fuelcellstack.lua")
dofile(MP.."/hydrogen/electrolyzer.lua")
dofile(MP.."/hydrogen/fuelcell.lua")
-- ICTA Controller
--dofile(MP.."/icta_controller/submenu.lua")
@ -324,20 +324,20 @@ 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/electronic.lua")
--dofile(MP.."/items/redstone.lua")
--dofile(MP.."/items/cement.lua")
--dofile(MP.."/items/cracking.lua")
--dofile(MP.."/items/ceramic.lua")
--dofile(MP.."/items/basalt.lua")
--dofile(MP.."/items/moreblocks.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/electronic.lua")
dofile(MP.."/items/redstone.lua")
dofile(MP.."/items/cement.lua")
dofile(MP.."/items/cracking.lua")
dofile(MP.."/items/ceramic.lua")
dofile(MP.."/items/basalt.lua")
dofile(MP.."/items/moreblocks.lua")
-- Carts
--dofile(MP.."/carts/tank_cart.lua")

View File

@ -129,13 +129,13 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.del_mem(pos)
end
local function tubelib2_on_update2(pos, outdir, tlib2, node)
if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2)
else
power.update_network(pos, outdir, tlib2)
end
end
--local function tubelib2_on_update2(pos, outdir, tlib2, node)
-- if tlib2.tube_type == "pipe2" then
-- liquid.update_network(pos, outdir, tlib2)
-- else
-- power.update_network(pos, outdir, tlib2)
-- end
--end
local netw_def = {
pipe2 = {
@ -165,7 +165,7 @@ minetest.register_node("techage:t4_waterpump", {
after_place_node = after_place_node,
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
--tubelib2_on_update2 = tubelib2_on_update2,
networks = netw_def,
on_receive_fields = on_receive_fields,
on_timer = node_timer,

View File

@ -233,6 +233,29 @@ function techage.generator_settings(tier, available)
end
end
function techage.evaluate_charge_termination(nvm, meta)
local termpoint = meta:get_string("termpoint")
if termpoint == "40% - 60%" then
meta:set_string("termpoint1", 0.4)
meta:set_string("termpoint2", 0.6)
elseif termpoint == "60% - 80%" then
meta:set_string("termpoint1", 0.6)
meta:set_string("termpoint2", 0.8)
elseif termpoint == "80% - 100%" then
meta:set_string("termpoint1", 0.8)
meta:set_string("termpoint2", 1.0)
else
meta:set_string("termpoint", "80% - 100%")
meta:set_string("termpoint1", 0.8)
meta:set_string("termpoint2", 1.0)
end
end
techage.power.percent = calc_percent
techage.CYCLES_PER_DAY = CYCLES_PER_DAY
techage.round = round
-------------------------------------------------------------------------------
-- Still used legacy functions
-------------------------------------------------------------------------------
@ -268,24 +291,3 @@ function techage.formspec_label_bar(pos, x, y, label, max_power, current_power,
end
function techage.evaluate_charge_termination(nvm, meta)
local termpoint = meta:get_string("termpoint")
if termpoint == "40% - 60%" then
meta:set_string("termpoint1", 0.4)
meta:set_string("termpoint2", 0.6)
elseif termpoint == "60% - 80%" then
meta:set_string("termpoint1", 0.6)
meta:set_string("termpoint2", 0.8)
elseif termpoint == "80% - 100%" then
meta:set_string("termpoint1", 0.8)
meta:set_string("termpoint2", 1.0)
else
meta:set_string("termpoint", "80% - 100%")
meta:set_string("termpoint1", 0.8)
meta:set_string("termpoint2", 1.0)
end
end
techage.power.percent = calc_percent
techage.CYCLES_PER_DAY = CYCLES_PER_DAY
techage.round = round