fuelcell and electrolyzer reactivated

This commit is contained in:
Joachim Stolberg 2020-02-10 21:20:54 +01:00
parent 762347521c
commit 54c7267af7
13 changed files with 339 additions and 531 deletions

View File

@ -45,52 +45,13 @@ function techage.liquid.formspec(pos, nvm)
techage.item_image(1.5, 1, itemname) techage.item_image(1.5, 1, itemname)
end end
--function techage.liquid.move_item(pos, stack, size, formspec)
-- 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, nvm))
--end
function techage.liquid.is_empty(pos) function techage.liquid.is_empty(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("src") and inv:is_empty("dst") and (not nvm.liquid or (nvm.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 end
techage.liquid.tubing = { techage.liquid.recv_message = {
-- on_pull_item = function(pos, in_dir, num)
-- local inv = M(pos):get_inventory()
-- if not inv:is_empty("dst") then
-- local taken = techage.get_items(inv, "dst", num)
-- if not inv:is_empty("src") then
-- fill_container(pos, inv)
-- end
-- return taken
-- end
-- end,
-- on_push_item = function(pos, in_dir, stack)
-- local inv = M(pos):get_inventory()
-- if inv:room_for_item("src", stack) then
-- inv:add_item("src", stack)
-- if liquid.is_container_empty(stack:get_name()) then
-- fill_container(pos, inv)
-- else
-- empty_container(pos, inv)
-- end
-- return true
-- end
-- return false
-- end,
-- on_unpull_item = function(pos, in_dir, stack)
-- local meta = M(pos)
-- local inv = meta:get_inventory()
-- return techage.put_items(inv, "dst", stack)
-- end,
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
if topic == "load" then if topic == "load" then
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
@ -153,7 +114,8 @@ local function empty_container(pos, inv, full_container)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {} nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local tank_size = LQD(pos).capa or 0 local ndef_lqd = LQD(pos)
local tank_size = (ndef_lqd and ndef_lqd.capa) or 0
local ldef = get_liquid_def(full_container) local ldef = get_liquid_def(full_container)
--print("ldef", dump(ldef), "tank_size", tank_size) --print("ldef", dump(ldef), "tank_size", tank_size)
if ldef and (not nvm.liquid.name or ldef.inv_item == nvm.liquid.name) then if ldef and (not nvm.liquid.name or ldef.inv_item == nvm.liquid.name) then
@ -205,14 +167,15 @@ end
local function empty_on_punch(pos, nvm, full_container) local function empty_on_punch(pos, nvm, full_container)
nvm.liquid = nvm.liquid or {} nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0 nvm.liquid.amount = nvm.liquid.amount or 0
local ldef = get_liquid_def(full_container) local lqd_def = get_liquid_def(full_container)
if ldef then local ndef_lqd = LQD(pos)
local tank_size = LQD(pos).capa or 0 if lqd_def and ndef_lqd then
if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then local tank_size = ndef_lqd.capa or 0
if nvm.liquid.amount + ldef.size <= tank_size then if not nvm.liquid.name or lqd_def.inv_item == nvm.liquid.name then
nvm.liquid.amount = nvm.liquid.amount + ldef.size if nvm.liquid.amount + lqd_def.size <= tank_size then
nvm.liquid.name = ldef.inv_item nvm.liquid.amount = nvm.liquid.amount + lqd_def.size
return {name = ldef.container} nvm.liquid.name = lqd_def.inv_item
return {name = lqd_def.container}
end end
end end
end end

View File

@ -298,7 +298,7 @@ function NodeStates:standby(pos, nvm, err_string)
end end
-- special case of standby for pushing nodes -- special case of standby for pushing nodes
function NodeStates:blocked(pos, nvm) function NodeStates:blocked(pos, nvm, err_string)
local state = nvm.techage_state or STOPPED local state = nvm.techage_state or STOPPED
if state == RUNNING then if state == RUNNING then
nvm.techage_state = BLOCKED nvm.techage_state = BLOCKED
@ -307,10 +307,10 @@ function NodeStates:blocked(pos, nvm)
end end
if self.infotext_name then if self.infotext_name then
local number = M(pos):get_string("node_number") local number = M(pos):get_string("node_number")
M(pos):set_string("infotext", self.infotext_name.." "..number..": blocked") M(pos):set_string("infotext", self.infotext_name.." "..number..": "..(err_string or "blocked"))
end end
if self.formspec_func then if self.formspec_func then
nvm.ta_state_tooltip = "blocked" nvm.ta_state_tooltip = err_string or "blocked"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then

View File

@ -32,7 +32,7 @@ local function formspec(self, pos, nvm)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided).. power.formspec_label_bar(0, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)..
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
end end

View File

@ -30,9 +30,9 @@ end
local function formspec(self, pos, nvm) local function formspec(self, pos, nvm)
local capa_max, capa, needed_max, needed = he1_cmnd(pos, "state") local capa_max, capa, needed_max, needed = he1_cmnd(pos, "state")
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR90]" local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
if needed > 0 then if needed > 0 then
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR90]" arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
end end
return "size[6,4]".. return "size[6,4]"..
default.gui_bg.. default.gui_bg..
@ -40,8 +40,8 @@ local function formspec(self, pos, nvm)
default.gui_slots.. default.gui_slots..
"box[0,-0.1;5.8,0.5;#c6e8ff]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]".. "label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]"..
power.formspec_label_bar(0, 0.8, S("Thermal"), capa_max, capa, "").. power.formspec_label_bar(0, 0.8, S("Electricity"), needed_max, needed)..
power.formspec_label_bar(3.5, 0.8, S("Input"), needed_max, needed).. power.formspec_label_bar(3.5, 0.8, S("Thermal"), capa_max, capa, "")..
arrow.. arrow..
"image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]"

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -16,44 +16,51 @@
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local Power = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local liquid = techage.liquid local liquid = techage.liquid
local networks = techage.networks
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local STANDBY_TICKS = 5 local STANDBY_TICKS = 5
local PWR_NEEDED = 40 local PWR_NEEDED = 30
local PWR_UNITS_PER_HYDROGEN_ITEM = 320 local PWR_UNITS_PER_HYDROGEN_ITEM = 80
local CAPACITY = 400 local CAPACITY = 200
local function formspec(self, pos, nvm) local function formspec(self, pos, nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update") local amount = (nvm.liquid and nvm.liquid.amount) or 0
return "size[8,6.6]".. local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
local arrow = "image[3,1;1,1;techage_form_arrow_bg.png^[transformR270]"
if nvm.running then
arrow = "image[3,1;1,1;techage_form_arrow_fg.png^[transformR270]"
end
if amount > 0 then
lqd_name = lqd_name.." "..amount
end
return "size[6,4]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0.0,0;1,2;"..power.formspec_power_bar(PWR_NEEDED, nvm.consumed).."]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[0.2,1.9;"..S("\\[ku\\]").."]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]"..
"image[2.5,0;1,1;techage_form_arrow_fg.png^[transformR270]".. techage.power.formspec_label_bar(0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken)..
"image_button[3.5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"..
"tooltip[3.5,1;1,1;"..self:get_state_tooltip(nvm).."]".. "image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"button[1.6,1;1.8,1;update;"..update.."]".. "tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[current_player;main;0,2.8;8,4;]" .. techage.item_image(4.5,2, lqd_name)
liquid.formspec_liquid(5, 0, nvm)..
default.get_hotbar_bg(0, 2.8)
end end
local function start_node(pos, nvm, state) local function start_node(pos, nvm, state)
nvm.running = true nvm.running = true
nvm.consumed = 0 nvm.taken = 0
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED) power.consumer_start(pos, Cable, CYCLE_TIME)
end end
local function stop_node(pos, nvm, state) local function stop_node(pos, nvm, state)
nvm.running = false nvm.running = false
nvm.consumed = 0 nvm.taken = 0
power.secondary_stop(pos, nvm) power.consumer_stop(pos, Cable)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -62,50 +69,56 @@ local State = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
infotext_name = "TA4 Electrolyzer", infotext_name = S("TA4 Electrolyzer"),
start_node = start_node, start_node = start_node,
stop_node = stop_node, stop_node = stop_node,
}) })
-- converts power into hydrogen local function on_power(pos)
local function node_timer(pos, elapsed)
local nvm = techage.get_nvm(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 generating(pos, nvm)
nvm.num_pwr_units = nvm.num_pwr_units or 0 nvm.num_pwr_units = nvm.num_pwr_units or 0
nvm.countdown = nvm.countdown or 0 nvm.countdown = nvm.countdown or 0
nvm.liquid = nvm.liquid or {} print("electrolyzer", nvm.running, nvm.taken, nvm.num_pwr_units, nvm.liquid.amount)
nvm.liquid.amount = nvm.liquid.amount or 0 if nvm.taken > 0 then
print("electrolyzer", nvm.running, nvm.consumed, nvm.num_pwr_units, nvm.liquid.amount) nvm.num_pwr_units = nvm.num_pwr_units + (nvm.taken or 0)
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 if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
nvm.liquid.amount = nvm.liquid.amount + 1 nvm.liquid.amount = nvm.liquid.amount + 1
nvm.liquid.name = "techage:hydrogen" nvm.liquid.name = "techage:hydrogen"
nvm.num_pwr_units = nvm.num_pwr_units - PWR_UNITS_PER_HYDROGEN_ITEM 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, nvm)
power.secondary_stop(pos, nvm)
end end
end end
else end
nvm.consumed = -power.secondary_alive(pos, nvm, 1, 1)
-- converts power into hydrogen
local function node_timer(pos, elapsed)
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 if nvm.liquid.amount < CAPACITY then
State:start(pos, nvm) nvm.taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
power.secondary_start(pos, nvm, PWR_NEEDED, PWR_NEEDED) generating(pos, nvm)
State:keep_running(pos, nvm, 1, 0) -- count items
else
State:blocked(pos, nvm, S("full"))
power.consumer_stop(pos, Cable)
end end
end if techage.is_activeformspec(pos) then
end
if nvm.countdown > 0 then
nvm.countdown = nvm.countdown - 1
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
return nvm.running or nvm.countdown > 0 return true
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -114,85 +127,100 @@ local function on_receive_fields(pos, formname, fields, player)
end end
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields) State:state_button_event(pos, nvm, fields)
nvm.countdown = 10
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
local function allow_metadata_inventory(pos, listname, index, stack, player) local function on_rightclick(pos, node, clicker)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if stack:get_name() == "techage:hydrogen" then
return stack:get_count()
end
return 0
end
local function on_rightclick(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.countdown = 10 techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
minetest.get_node_timer(pos):start(CYCLE_TIME)
end end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.num_pwr_units = 0
local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
State:node_init(pos, nvm, number)
local node = minetest.get_node(pos)
M(pos):set_int("in_dir", techage.side_to_indir("R", node.param2))
Pipe:after_place_node(pos)
Cable:after_place_node(pos)
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
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)
end
end
local netw_def = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
ele1 = {
sides = {L = 1}, -- Cable connection sides
ntype = "con2",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
}
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, 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, nvm))
end
return amount, name
end
}
minetest.register_node("techage:ta4_electrolyzer2", { minetest.register_node("techage:ta4_electrolyzer2", {
description = S("TA4 Electrolyzer"), description = S("TA4 Electrolyzer"),
tiles = { tiles = {
-- up, down, right, left, back, front -- 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_top.png^techage_appl_arrow.png",
"techage_filling_ta4.png^techage_frame_ta4.png", "techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.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_electric.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png^[transformFX", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png^[transformFX",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_electrolyzer.png^techage_appl_ctrl_unit.png",
}, },
on_construct = function(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_electrolyzer2")
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, nvm))
local inv = meta:get_inventory()
inv:set_size('src', 1)
inv:set_size('dst', 1)
end,
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
liquid.update_network(pos, outdir)
end,
can_dig = function(pos, player) can_dig = function(pos, player)
local inv = M(pos):get_inventory() if minetest.is_protected(pos, player:get_player_name()) then
return inv:is_empty("dst") return false
end,
liquid = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
liquid.fill_container(pos, inv)
end end
return leftover return liquid.is_empty(pos)
end, end,
take = liquid.srv_take,
},
networks = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
},
allow_metadata_inventory_put = allow_metadata_inventory, after_place_node = after_place_node,
allow_metadata_inventory_take = allow_metadata_inventory, 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_receive_fields = on_receive_fields,
on_timer = node_timer, on_timer = node_timer,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
@ -209,7 +237,7 @@ minetest.register_node("techage:ta4_electrolyzer2_on", {
-- up, down, right, left, back, front -- 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_top.png^techage_appl_arrow.png",
"techage_filling_ta4.png^techage_frame_ta4.png", "techage_filling_ta4.png^techage_frame_ta4.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_outp.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.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_electric.png",
{ {
image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_electrolyzer4.png^techage_appl_ctrl_unit4.png^[transformFX", image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_electrolyzer4.png^techage_appl_ctrl_unit4.png^[transformFX",
@ -233,33 +261,11 @@ minetest.register_node("techage:ta4_electrolyzer2_on", {
}, },
}, },
tubelib2_on_update2 = function(pos, outdir, tlib2, node) tubelib2_on_update2 = tubelib2_on_update2,
liquid.update_network(pos, outdir) networks = netw_def,
end, liquid = liquid_def,
liquid = {
capa = CAPACITY,
peek = liquid.srv_peek,
put = function(pos, indir, name, amount)
local leftover = liquid.srv_put(pos, indir, name, amount)
local inv = M(pos):get_inventory()
if not inv:is_empty("src") and inv:is_empty("dst") then
liquid.fill_container(pos, inv)
end
return leftover
end,
take = liquid.srv_take,
},
networks = {
pipe2 = {
sides = {R = 1}, -- Pipe connection sides
ntype = "tank",
},
},
allow_metadata_inventory_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_punch = liquid.on_punch,
on_timer = node_timer, on_timer = node_timer,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
@ -272,26 +278,9 @@ minetest.register_node("techage:ta4_electrolyzer2_on", {
light_source = 6, light_source = 6,
}) })
-- Register for power Cable:add_secondary_node_names({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"})
techage.power.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, { Pipe:add_secondary_node_names({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"})
conn_sides = {"L"}, techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.recv_message)
power_network = Power,
after_place_node = function(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("R", node.param2)
M(pos):set_int("in_dir", indir)
Pipe:after_place_node(pos)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
end,
})
-- Register for tubes
techage.register_node({"techage:ta4_electrolyzer2", "techage:ta4_electrolyzer2_on"}, liquid.tubing)
-- Register for pipes
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})
minetest.register_craft({ minetest.register_craft({
output = "techage:ta4_electrolyzer2", output = "techage:ta4_electrolyzer2",

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -16,42 +16,53 @@
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local Power = techage.ElectricCable local Cable = techage.ElectricCable
local power = techage.power local power = techage.power
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local networks = techage.networks
local CYCLE_TIME = 2 local CYCLE_TIME = 2
local STANDBY_TICKS = 5 local STANDBY_TICKS = 5
local PWR_CAPA = 40 local PWR_CAPA = 25
local PWR_UNITS_PER_HYDROGEN_ITEM = 240 local PWR_UNITS_PER_HYDROGEN_ITEM = 80
local CAPACITY = 100
local function formspec(self, pos, nvm) local function formspec(self, pos, nvm)
return "size[8,6.6]".. local amount = (nvm.liquid and nvm.liquid.amount) or 0
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
local arrow = "image[3,1;1,1;techage_form_arrow_bg.png^[transformR270]"
if nvm.running then
arrow = "image[3,1;1,1;techage_form_arrow_fg.png^[transformR270]"
end
if amount > 0 then
lqd_name = lqd_name.." "..amount
end
return "size[6,4]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"list[context;src;0.5,0;2,2;]".. "box[0,-0.1;5.8,0.5;#c6e8ff]"..
"image[4,0;1,1;techage_form_arrow_fg.png^[transformR270]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]"..
"image_button[5,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. techage.item_image(0.5,2, lqd_name)..
"button[3.1,1;1.8,1;update;"..S("Update").."]".. "image[2,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]".. "image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"label[6.7,1.9;"..S("\\[ku\\]").."]".. "tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
"list[current_player;main;0,2.8;8,4;]" .. techage.power.formspec_label_bar(3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)
"listring[current_player;main]"..
"listring[context;src]" ..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 2.8)
end end
local function start_node(pos, nvm, state) local function start_node(pos, nvm, state)
nvm.running = true nvm.running = true
nvm.provided = 0 nvm.provided = 0
power.generator_start(pos, nvm, PWR_CAPA) local outdir = M(pos):get_int("outdir")
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
end end
local function stop_node(pos, nvm, state) local function stop_node(pos, nvm, state)
nvm.running = false nvm.running = false
nvm.provided = 0 nvm.provided = 0
power.generator_stop(pos, nvm) local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -60,15 +71,16 @@ local State = techage.NodeStates:new({
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec_func = formspec, formspec_func = formspec,
infotext_name = "TA4 Fuel Cell", infotext_name = S("TA4 Fuel Cell"),
start_node = start_node, start_node = start_node,
stop_node = stop_node, stop_node = stop_node,
}) })
local function get_hydrogen(pos) local function has_hydrogen(nvm)
local inv = M(pos):get_inventory() nvm.liquid = nvm.liquid or {}
local taken = inv:remove_item("src", ItemStack("techage:hydrogen")) nvm.liquid.amount = nvm.liquid.amount or 0
return taken:get_count() > 0 nvm.num_pwr_units = nvm.num_pwr_units or 0
return nvm.num_pwr_units > 0 or (nvm.liquid.amount > 0 and nvm.liquid.name == "techage:hydrogen")
end end
local function contains_hydrogen(pos) local function contains_hydrogen(pos)
@ -76,37 +88,31 @@ local function contains_hydrogen(pos)
return inv:contains_item("src", ItemStack("techage:hydrogen")) return inv:contains_item("src", ItemStack("techage:hydrogen"))
end end
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
end
-- converts hydrogen into power -- converts hydrogen into power
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.num_pwr_units = nvm.num_pwr_units or 0 print("fuelcell", nvm.running, nvm.given, nvm.num_pwr_units)
--print("fuelcell", nvm.running, nvm.provided, nvm.num_pwr_units, techage.get_state_string(nvm)) if has_hydrogen(nvm) then
if nvm.running then local outdir = M(pos):get_int("outdir")
if techage.needs_power(nvm) then nvm.given = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
if nvm.num_pwr_units <= 0 then consuming(pos, nvm)
if get_hydrogen(pos) then
State:keep_running(pos, nvm, 1, 0) -- count items State:keep_running(pos, nvm, 1, 0) -- count items
nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
else else
State:standby(pos, nvm) State:standby(pos, nvm)
nvm.provided = 0 nvm.given = 0
power.generator_stop(pos, nvm) 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 return true
end
end
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, nvm)
nvm.provided = 0
power.generator_start(pos, nvm, PWR_CAPA)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
end
end
return nvm.running
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -115,26 +121,72 @@ local function on_receive_fields(pos, formname, fields, player)
end end
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields) State:state_button_event(pos, nvm, fields)
if fields.update then
M(pos):set_string("formspec", formspec(State, pos, nvm)) 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, nvm))
end
local function after_place_node(pos)
local nvm = techage.get_nvm(pos)
nvm.running = false
nvm.num_pwr_units = 0
local number = techage.add_node(pos, "techage:ta4_fuelcell")
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)
Cable:after_place_node(pos)
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos)
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)
end end
end end
local function allow_metadata_inventory(pos, listname, index, stack, player) local netw_def = {
if minetest.is_protected(pos, player:get_player_name()) then pipe2 = {
return 0 sides = {L = 1}, -- Pipe connection sides
end ntype = "tank",
if stack:get_name() == "techage:hydrogen" then },
return stack:get_count() ele1 = {
end sides = {R = 1}, -- Cable connection sides
return 0 ntype = "gen2",
end nominal = PWR_CAPA,
},
}
local function on_rightclick(pos) 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) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end 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, nvm))
end
return amount, name
end
}
minetest.register_node("techage:ta4_fuelcell", { minetest.register_node("techage:ta4_fuelcell", {
description = S("TA4 Fuel Cell"), description = S("TA4 Fuel Cell"),
@ -143,30 +195,24 @@ minetest.register_node("techage:ta4_fuelcell", {
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png", "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_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inp.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^[transformFX",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png",
}, },
on_construct = function(pos)
local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:ta4_fuelcell")
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, nvm))
local inv = meta:get_inventory()
inv:set_size('src', 4)
end,
can_dig = function(pos, player) can_dig = function(pos, player)
local inv = M(pos):get_inventory() if minetest.is_protected(pos, player:get_player_name()) then
return inv:is_empty("src") return false
end
return liquid.is_empty(pos)
end, end,
allow_metadata_inventory_put = allow_metadata_inventory, after_place_node = after_place_node,
allow_metadata_inventory_take = allow_metadata_inventory, 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_receive_fields = on_receive_fields,
on_timer = node_timer, on_timer = node_timer,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
@ -184,7 +230,7 @@ minetest.register_node("techage:ta4_fuelcell_on", {
"techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png", "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_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png",
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inp.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", image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_fuelcell4.png^techage_appl_ctrl_unit4.png^[transformFX",
backface_culling = false, backface_culling = false,
@ -207,9 +253,11 @@ minetest.register_node("techage:ta4_fuelcell_on", {
}, },
}, },
allow_metadata_inventory_put = allow_metadata_inventory, tubelib2_on_update2 = tubelib2_on_update2,
allow_metadata_inventory_take = allow_metadata_inventory, networks = netw_def,
liquid = liquid_def,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_punch = liquid.on_punch,
on_timer = node_timer, on_timer = node_timer,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
@ -222,43 +270,9 @@ minetest.register_node("techage:ta4_fuelcell_on", {
light_source = 6, light_source = 6,
}) })
techage.power.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, { Cable:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"})
conn_sides = {"R"}, Pipe:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"})
power_network = Power, techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, liquid.recv_message)
after_place_node = function(pos)
local node = minetest.get_node(pos)
local indir = techage.side_to_indir("L", node.param2)
M(pos):set_int("in_dir", indir)
end,
})
techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, {
on_pull_item = function(pos, in_dir, num)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.get_items(inv, "src", num)
end
end,
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
State:start_if_standby(pos)
return techage.put_items(inv, "src", stack)
end
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
if meta:get_int("in_dir") == in_dir then
local inv = M(pos):get_inventory()
return techage.put_items(inv, "src", stack)
end
end,
on_recv_message = function(pos, src, topic, payload)
return State:on_receive_message(pos, topic, payload)
end,
})
minetest.register_craft({ minetest.register_craft({
output = "techage:ta4_fuelcell", output = "techage:ta4_fuelcell",

View File

@ -121,7 +121,7 @@ else
dofile(MP.."/coal_power_station/cooler.lua") dofile(MP.."/coal_power_station/cooler.lua")
dofile(MP.."/coal_power_station/oilfirebox.lua") dofile(MP.."/coal_power_station/oilfirebox.lua")
-- -- Industrial Furnace -- Industrial Furnace
dofile(MP.."/furnace/firebox.lua") dofile(MP.."/furnace/firebox.lua")
dofile(MP.."/furnace/cooking.lua") dofile(MP.."/furnace/cooking.lua")
dofile(MP.."/furnace/furnace_top.lua") dofile(MP.."/furnace/furnace_top.lua")
@ -144,7 +144,7 @@ else
dofile(MP.."/lamps/industriallamp2.lua") dofile(MP.."/lamps/industriallamp2.lua")
dofile(MP.."/lamps/industriallamp3.lua") dofile(MP.."/lamps/industriallamp3.lua")
-- -- Oil -- Oil
dofile(MP.."/oil/explore.lua") dofile(MP.."/oil/explore.lua")
dofile(MP.."/oil/tower.lua") dofile(MP.."/oil/tower.lua")
dofile(MP.."/oil/drillbox.lua") dofile(MP.."/oil/drillbox.lua")
@ -153,7 +153,7 @@ else
dofile(MP.."/oil/reboiler.lua") dofile(MP.."/oil/reboiler.lua")
-- dofile(MP.."/oil/gasflare.lua") -- dofile(MP.."/oil/gasflare.lua")
-- TA3 power based -- TA3 power based
dofile(MP.."/ta3_power/tiny_generator.lua") dofile(MP.."/ta3_power/tiny_generator.lua")
dofile(MP.."/ta3_power/akkubox.lua") dofile(MP.."/ta3_power/akkubox.lua")
@ -177,19 +177,19 @@ else
-- Test -- Test
dofile(MP.."/recipe_checker.lua") dofile(MP.."/recipe_checker.lua")
dofile(MP.."/.test/sink.lua") dofile(MP.."/.test/sink.lua")
dofile(MP.."/.test/meta_node.lua") --dofile(MP.."/.test/meta_node.lua")
-- Solar -- Solar
dofile(MP.."/solar/minicell.lua") dofile(MP.."/solar/minicell.lua")
dofile(MP.."/solar/solarcell.lua") dofile(MP.."/solar/solarcell.lua")
dofile(MP.."/solar/inverter.lua") dofile(MP.."/solar/inverter.lua")
-- -- Wind -- Wind
dofile(MP.."/wind_turbine/rotor.lua") dofile(MP.."/wind_turbine/rotor.lua")
dofile(MP.."/wind_turbine/pillar.lua") dofile(MP.."/wind_turbine/pillar.lua")
dofile(MP.."/wind_turbine/signallamp.lua") dofile(MP.."/wind_turbine/signallamp.lua")
-- -- TA4 Energy Storage -- TA4 Energy Storage
dofile(MP.."/energy_storage/heatexchanger3.lua") dofile(MP.."/energy_storage/heatexchanger3.lua")
dofile(MP.."/energy_storage/heatexchanger2.lua") dofile(MP.."/energy_storage/heatexchanger2.lua")
dofile(MP.."/energy_storage/heatexchanger1.lua") dofile(MP.."/energy_storage/heatexchanger1.lua")
@ -198,16 +198,15 @@ else
dofile(MP.."/energy_storage/inlet.lua") dofile(MP.."/energy_storage/inlet.lua")
dofile(MP.."/energy_storage/nodes.lua") dofile(MP.."/energy_storage/nodes.lua")
-- -- Chemistry -- Chemistry
dofile(MP.."/chemistry/ta4_reactor.lua") dofile(MP.."/chemistry/ta4_reactor.lua")
dofile(MP.."/chemistry/ta4_stand.lua") dofile(MP.."/chemistry/ta4_stand.lua")
dofile(MP.."/chemistry/ta4_doser.lua") dofile(MP.."/chemistry/ta4_doser.lua")
-- -- Hydrogen -- Hydrogen
-- dofile(MP.."/hydrogen/fuelcellstack.lua") dofile(MP.."/hydrogen/fuelcellstack.lua")
-- dofile(MP.."/hydrogen/electrolyzer.lua") dofile(MP.."/hydrogen/electrolyzer.lua")
-- dofile(MP.."/hydrogen/fuelcell.lua") dofile(MP.."/hydrogen/fuelcell.lua")
-- dofile(MP.."/hydrogen/legacy.lua")
-- Items -- Items
dofile(MP.."/items/barrel.lua") dofile(MP.."/items/barrel.lua")
@ -228,20 +227,4 @@ else
if techage.basalt_stone_enabled then if techage.basalt_stone_enabled then
dofile(MP.."/items/basalt.lua") dofile(MP.."/items/basalt.lua")
end end
-- dofile(MP.."/power3/electric_cable.lua")
-- dofile(MP.."/power3/node_api.lua")
-- dofile(MP.."/power3/distribution.lua")
-- dofile(MP.."/power3/schedule.lua")
-- dofile(MP.."/power3/hud_debug.lua")
-- dofile(MP.."/power3/junctionbox.lua")
-- dofile(MP.."/power3/ele3_sink.lua")
-- dofile(MP.."/power3/ele3_source.lua")
-- dofile(MP.."/power3/accu.lua")
-- dofile(MP.."/power3/power_terminal.lua")
-- dofile(MP.."/power3/powerswitchbox.lua")
-- dofile(MP.."/power3/drive_axle.lua")
-- dofile(MP.."/power3/gearbox.lua")
-- dofile(MP.."/power3/axle_sink.lua")
-- dofile(MP.."/power3/axle_source.lua")
end end

View File

@ -1,149 +0,0 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Liquid lib
]]--
local M = minetest.get_meta
local S = techage.S
local P2S = minetest.pos_to_string
local liquid = techage.liquid
local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end
local function help(x, y)
local tooltip = S("To add liquids punch\nthe tank\nwith a liquid container")
return "label["..x..","..y..";"..minetest.colorize("#000000", minetest.formspec_escape("[?]")).."]"..
"tooltip["..x..","..y..";0.5,0.5;"..tooltip..";#0C3D32;#FFFFFF]"
end
function techage.liquid.formspec(pos, nvm)
local title = S("Liquid Tank")
local itemname = "techage:liquid"
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 "size[5,3]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1.5,-0.1;"..minetest.colorize("#000000", title).."]"..
help(4.4, -0.1)..
techage.item_image(2, 1, itemname)
end
local function fill_container(pos, inv, empty_container)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
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 nvm.liquid.amount - ldef.size >= 0 then
if inv:room_for_item("dst", {name = full_container}) then
inv:add_item("dst", {name = full_container})
nvm.liquid.amount = nvm.liquid.amount - ldef.size
if nvm.liquid.amount == 0 then
nvm.liquid.name = nil
end
return true
end
end
end
-- undo
inv:add_item("src", {name = empty_container})
return false
end
local function empty_container(pos, inv, full_container)
local nvm = techage.get_nvm(pos)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local tank_size = LQD(pos).capa or 0
local ldef = liquid.get_liquid_def(full_container)
print("ldef", dump(ldef), "tank_size", tank_size)
if ldef and (not nvm.liquid.name or ldef.inv_item == nvm.liquid.name) then
if nvm.liquid.amount + ldef.size <= tank_size then
if inv:room_for_item("dst", {name = ldef.container}) then
inv:add_item("dst", {name = ldef.container})
nvm.liquid.amount = nvm.liquid.amount + ldef.size
nvm.liquid.name = ldef.inv_item
return true
end
end
end
-- undo
inv:add_item("src", {name = full_container})
return false
end
--function techage.liquid.move_item(pos, stack, size, formspec)
-- 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, nvm))
--end
function techage.liquid.is_empty(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 nvm.liquid or (nvm.liquid.amount or 0) == 0)
end
techage.liquid.tubing = {
-- on_pull_item = function(pos, in_dir, num)
-- local inv = M(pos):get_inventory()
-- if not inv:is_empty("dst") then
-- local taken = techage.get_items(inv, "dst", num)
-- if not inv:is_empty("src") then
-- fill_container(pos, inv)
-- end
-- return taken
-- end
-- end,
-- on_push_item = function(pos, in_dir, stack)
-- local inv = M(pos):get_inventory()
-- if inv:room_for_item("src", stack) then
-- inv:add_item("src", stack)
-- if liquid.is_container_empty(stack:get_name()) then
-- fill_container(pos, inv)
-- else
-- empty_container(pos, inv)
-- end
-- return true
-- end
-- return false
-- end,
-- on_unpull_item = function(pos, in_dir, stack)
-- local meta = M(pos)
-- local inv = meta:get_inventory()
-- return techage.put_items(inv, "dst", stack)
-- end,
on_recv_message = function(pos, src, topic, payload)
if topic == "load" then
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
return "unsupported"
end
end,
}
techage.liquid.fill_container = fill_container
techage.liquid.empty_container = empty_container

View File

@ -222,7 +222,7 @@ minetest.register_node("techage:ta4_tank", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.tubing) techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.recv_message)
Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}) Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"})

View File

@ -171,7 +171,7 @@ Der Generator dient zur Stromerzeugung. Daher muss auch der Generator am Stromne
### TA4 Röhre / Pipe ### TA4 Röhre / Pipe
Die Röhren dienen bei TA4 zur Weiterleitung von Gas und Dampf. Die Röhren dienen bei TA4 zur Weiterleitung von Gas und Flüssigkeiten.
Die maximale Leitungslänge beträgt 100 m. Die maximale Leitungslänge beträgt 100 m.
[ta4_pipe|image] [ta4_pipe|image]
@ -182,10 +182,10 @@ Die maximale Leitungslänge beträgt 100 m.
Strom kann mittels Elektrolyse in Wasserstoff und Sauerstoff aufgespalten werden. Auf der anderen Seite kann über eine Brennstoffzelle Wasserstoff mit Sauerstoff aus der Luft wieder in Strom umgewandelt werden. Strom kann mittels Elektrolyse in Wasserstoff und Sauerstoff aufgespalten werden. Auf der anderen Seite kann über eine Brennstoffzelle Wasserstoff mit Sauerstoff aus der Luft wieder in Strom umgewandelt werden.
Damit können Stromspitzen oder ein Überangebot an Strom in Wasserstoff umgewandelt und so gespeichert werden. Damit können Stromspitzen oder ein Überangebot an Strom in Wasserstoff umgewandelt und so gespeichert werden.
Im Spiel kann Strom mit Hilfe des Elektrolyseurs in Wasserstoff-Items und Wasserstoff-Items über die Brennstoffzelle wieder in Strom umgewandelt werden. Im Spiel kann Strom mit Hilfe des Elektrolyseurs in Wasserstoff und Wasserstoff über die Brennstoffzelle wieder in Strom umgewandelt werden.
Damit kann Strom (in Form von Wasserstoff-Items) nicht nur in Kisten gelagert, sonder auch über Wagen (carts) oder Röhren transportiert werden. Damit kann Strom (in Form von Wasserstoff) nicht nur in Tanks gelagert, sonder mit Hilfe von Gasflaschen auch mit Wagen (carts) transportiert werden.
Die Umwandlung von Strom in Wasserstoff und zurück ist aber verlustbehaftet. Von 100 Einheiten Strom kommen nach der Umwandlung in Wasserstoff und zurück nur 75 Einheiten Strom wieder raus. Die Umwandlung von Strom in Wasserstoff und zurück ist aber verlustbehaftet. Von 100 Einheiten Strom kommen nach der Umwandlung in Wasserstoff und zurück nur 83 Einheiten Strom wieder raus.
[ta4_hydrogen|image] [ta4_hydrogen|image]
@ -193,9 +193,10 @@ Die Umwandlung von Strom in Wasserstoff und zurück ist aber verlustbehaftet. Vo
### Elektrolyseur ### Elektrolyseur
Der Elektrolyseur wandelt Strom in Wasserstoff um. Der Elektrolyseur wandelt Strom in Wasserstoff um.
Es muss von links mit Strom versorgt werden. Rechts können die Wasserstoff-Items per Schieber entnommen werden. Es muss von links mit Strom versorgt werden. Rechts kann Wasserstoff über Röhren und Pumpen entnommen werden.
Der Elektrolyseur kann bis zu 40 ku an Strom aufnehmen und generiert alle 8 s ein Wasserstoff Item. Der Elektrolyseur kann bis zu 30 ku an Strom aufnehmen und generiert dann alle 4 s ein Wasserstoff Item.
In den Elektrolyseur passen 200 Einheiten Wasserstoff.
[ta4_electrolyzer|image] [ta4_electrolyzer|image]
@ -203,9 +204,9 @@ Der Elektrolyseur kann bis zu 40 ku an Strom aufnehmen und generiert alle 8 s ei
### Brennstoffzelle ### Brennstoffzelle
Die Brennstoffzelle wandelt Wasserstoff in Strom um. Die Brennstoffzelle wandelt Wasserstoff in Strom um.
Sie muss von links per Schieber mit Wasserstoff-Items versorgt werden. Rechts ist der Stromanschluss. Sie muss von links per Pumpe mit Wasserstoff versorgt werden. Rechts ist der Stromanschluss.
Die Brennstoffzelle kann bis zu 40 ku an Strom abgeben und benötigt dazu alle 6 s ein Wasserstoff Item. Die Brennstoffzelle kann bis zu 25 ku an Strom abgeben und benötigt dazu alle 4 s ein Wasserstoff Item.
[ta4_fuelcell|image] [ta4_fuelcell|image]

View File

@ -136,7 +136,6 @@ local function after_dig_node(pos, oldnode)
end end
local function tubelib2_on_update2(pos, outdir, tlib2, node) local function tubelib2_on_update2(pos, outdir, tlib2, node)
print("tubelib2_on_update2", tlib2.tube_type)
if tlib2.tube_type == "pipe2" then if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2) liquid.update_network(pos, outdir, tlib2)
else else

View File

@ -37,10 +37,10 @@ local function formspec(self, pos, nvm)
"box[0,-0.1;4.8,0.5;#c6e8ff]".. "box[0,-0.1;4.8,0.5;#c6e8ff]"..
"label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]".. "label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]"..
power.formspec_label_bar(0, 0.8, S("Load"), PWR_CAPA, capa).. power.formspec_label_bar(0, 0.8, S("Load"), PWR_CAPA, capa)..
"image_button[3,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"label[4.2,1.2;Flow]".. "label[3.7,1.2;"..S("Electricity").."]"..
"image[4,1.7;1,2;"..techage.power.formspec_load_bar(needed, PWR_PERF).."]" "image[3.8,1.7;1,2;"..techage.power.formspec_load_bar(needed, PWR_PERF).."]"
end end
local function on_power(pos) local function on_power(pos)

View File

@ -39,7 +39,7 @@ local function formspec(self, pos, nvm)
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]".. "image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]".. "tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
power.formspec_label_bar(2.5, 0.8, S("power"), PWR_CAPA, nvm.provided) power.formspec_label_bar(2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided)
end end
local function play_sound(pos) local function play_sound(pos)
@ -211,6 +211,14 @@ minetest.register_node("techage:tiny_generator", {
State:node_init(pos, nvm, number) State:node_init(pos, nvm, number)
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
Pipe:after_place_node(pos)
Cable:after_place_node(pos)
end,
after_dig_node = function(pos, oldnode)
Pipe:after_dig_node(pos)
Cable:after_dig_node(pos)
techage.del_mem(pos)
end, end,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,