further nodes adapter to new APIs
This commit is contained in:
parent
c0a4e9d3d8
commit
a3935db108
@ -201,7 +201,7 @@ end
|
||||
-- if outdirs is given, only this dirs are used
|
||||
local function connection_walk(pos, outdirs, indir, node, tlib2, clbk)
|
||||
if clbk then clbk(pos, indir, node) end
|
||||
techage.mark_position("singleplayer", pos, "walk", "", 1)
|
||||
--techage.mark_position("singleplayer", pos, "walk", "", 1)
|
||||
--print("connection_walk", node.name, outdirs or is_junction(pos, node.name, tlib2.tube_type))
|
||||
if outdirs or is_junction(pos, node.name, tlib2.tube_type) then
|
||||
for _,outdir in pairs(outdirs or get_node_connections(pos, tlib2.tube_type)) do
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -14,8 +14,6 @@
|
||||
|
||||
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
|
||||
@ -67,7 +65,7 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {U=1}, -- Pipe connection sides
|
||||
sides = {U = 1}, -- Pipe connection sides
|
||||
ntype = "tank",
|
||||
},
|
||||
},
|
||||
|
@ -95,7 +95,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
local nvm,_ = techage.get_nvm(pos, true)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
end
|
||||
|
||||
@ -207,6 +207,7 @@ minetest.register_node("techage:generator_on", {
|
||||
|
||||
Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"})
|
||||
|
||||
-- controlled by the turbine
|
||||
techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
@ -3,12 +3,12 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Dummy Generator for the TES
|
||||
TA4 TES Generator
|
||||
|
||||
]]--
|
||||
|
||||
@ -16,31 +16,121 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 60
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local networks = techage.networks
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
local function formspec(self, pos, nvm)
|
||||
return "size[4,4]"..
|
||||
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
||||
"label[1,-0.1;"..minetest.colorize( "#000000", S("Generator")).."]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
|
||||
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
|
||||
end
|
||||
|
||||
-- to detect the missing turbine
|
||||
local function transfer_turbine(pos, topic, payload)
|
||||
return techage.transfer(pos, "L", topic, payload, nil,
|
||||
{"techage:ta4_turbine", "techage:ta4_turbine_on"})
|
||||
end
|
||||
|
||||
local function can_start(pos, nvm, state)
|
||||
return (nvm.heatexchanger_trigger or 0) > 0 -- by means of heatexchanger
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
|
||||
transfer_turbine(pos, "start")
|
||||
nvm.running = true
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Cable, outdir)
|
||||
nvm.provided = 0
|
||||
transfer_turbine(pos, "stop")
|
||||
nvm.running = false
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:ta4_generator",
|
||||
node_name_active = "techage:ta4_generator_on",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
infotext_name = S("TA4 Generator"),
|
||||
can_start = can_start,
|
||||
start_node = start_node,
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
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")
|
||||
nvm.running = false
|
||||
nvm.heatexchanger_trigger = (nvm.heatexchanger_trigger or 0) - 1
|
||||
if nvm.heatexchanger_trigger <= 0 then
|
||||
State:nopower(pos, nvm)
|
||||
stop_node(pos, nvm, State)
|
||||
transfer_turbine(pos, "stop")
|
||||
else
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
return true
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
local nvm,_ = techage.get_nvm(pos, true)
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local number = techage.add_node(pos, "techage:ta4_generator")
|
||||
State:node_init(pos, nvm, number)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
|
||||
local net_def = {
|
||||
ele1 = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen2",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:ta4_generator", {
|
||||
description = S("TA4 Generator"),
|
||||
tiles = {
|
||||
@ -52,7 +142,15 @@ minetest.register_node("techage:ta4_generator", {
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_generator.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_generator.png^[transformFX]",
|
||||
},
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -90,11 +188,14 @@ minetest.register_node("techage:ta4_generator_on", {
|
||||
},
|
||||
},
|
||||
|
||||
on_rightclick = function(pos)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
@ -104,6 +205,36 @@ minetest.register_node("techage:ta4_generator_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"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 nvm = techage.get_nvm(pos)
|
||||
if topic == "trigger" then
|
||||
print("trigger", nvm.provided)
|
||||
nvm.heatexchanger_trigger = 3
|
||||
if nvm.running then
|
||||
return nvm.provided or 0.1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "load" then
|
||||
return techage.power.percent(PWR_CAPA, nvm.provided)
|
||||
else
|
||||
return State:on_receive_message(pos, topic, payload)
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
State:on_node_load(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_generator",
|
||||
recipe = {
|
||||
@ -113,41 +244,4 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
-- need a dummy power connection
|
||||
techage.power.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
|
||||
conn_sides = {"R"},
|
||||
power_network = Cable,
|
||||
after_place_node = function(pos, placer)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.running = false
|
||||
nvm.remote_trigger = 0
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
-- controlled by the turbine
|
||||
techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "power" then
|
||||
nvm.remote_trigger = 2
|
||||
return techage.power.power_network_available(pos)
|
||||
elseif topic == "start" then
|
||||
nvm.remote_trigger = 2
|
||||
swap_node(pos, "techage:ta4_generator_on")
|
||||
nvm.running = true
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
return true
|
||||
elseif topic == "stop" then
|
||||
swap_node(pos, "techage:ta4_generator")
|
||||
nvm.running = false
|
||||
nvm.remote_trigger = 0
|
||||
minetest.get_node_timer(pos):stop()
|
||||
return true
|
||||
elseif topic == "trigger" then
|
||||
nvm.remote_trigger = 2
|
||||
return true
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
274
energy_storage/heatexchanger1.lua
Normal file
274
energy_storage/heatexchanger1.lua
Normal file
@ -0,0 +1,274 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Heat Exchanger1 (bottom part)
|
||||
|
||||
]]--
|
||||
|
||||
-- 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 CYCLE_TIME = 2
|
||||
local PWR_PERF = 60
|
||||
local GRVL_CAPA = 700
|
||||
local PWR_CAPA = {
|
||||
[3] = GRVL_CAPA * 3 * 3 * 3, -- 18900 Cyc = 630 min = 31.5 Tage bei einem ku, oder 31,5 * 24 kuh = 756 kuh = 12,6 h bei 60 ku
|
||||
[5] = GRVL_CAPA * 5 * 5 * 5, -- ~2.5 days
|
||||
[7] = GRVL_CAPA * 7 * 7 * 7, -- ~6 days
|
||||
}
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local Pipe = techage.LiquidPipe
|
||||
local power = techage.power
|
||||
local in_range = techage.in_range
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function glowing(pos, nvm, should_glow)
|
||||
if nvm.win_pos then
|
||||
if should_glow then
|
||||
swap_node(nvm.win_pos, "techage:glow_gravel")
|
||||
else
|
||||
swap_node(nvm.win_pos, "default:gravel")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function turbine_cmnd(pos, topic, payload)
|
||||
return techage.transfer(pos, "R", topic, payload, Pipe,
|
||||
{"techage:ta4_turbine", "techage:ta4_turbine_on"})
|
||||
end
|
||||
|
||||
local function inlet_cmnd(pos, topic, payload)
|
||||
return techage.transfer(pos, "L", topic, payload, Pipe,
|
||||
{"techage:ta4_pipe_inlet"})
|
||||
end
|
||||
|
||||
local function play_sound(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
if not mem.handle or mem.handle == -1 then
|
||||
mem.handle = minetest.sound_play("techage_booster", {
|
||||
pos = pos,
|
||||
gain = 0.2,
|
||||
max_hear_distance = 10,
|
||||
loop = true})
|
||||
if mem.handle == -1 then
|
||||
minetest.after(1, play_sound, pos)
|
||||
end
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.charging = true
|
||||
end
|
||||
|
||||
local function stop_sound(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
if mem.handle then
|
||||
minetest.sound_stop(mem.handle)
|
||||
mem.handle = nil
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.charging = false
|
||||
end
|
||||
|
||||
local function on_power(pos)
|
||||
play_sound(pos)
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
nvm.needed = 0
|
||||
stop_sound(pos)
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm)
|
||||
nvm.running = true
|
||||
nvm.needed = 0
|
||||
nvm.win_pos = inlet_cmnd(pos, "window")
|
||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
return true
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm)
|
||||
nvm.running = false
|
||||
nvm.needed = 0
|
||||
power.consumer_stop(pos, Cable)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
stop_sound(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer, itemstack)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.capa = 0
|
||||
M(pos):set_string("owner", placer:get_player_name())
|
||||
Cable:after_place_node(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return not nvm.running
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_node(pos)
|
||||
Pipe: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 function can_start(pos, nvm)
|
||||
-- the heat exchanger shall be able to start even without
|
||||
-- having power. Therefore, no "if power.power_available(pos, Cable) then"
|
||||
local diameter = inlet_cmnd(pos, "diameter")
|
||||
if diameter then
|
||||
nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0
|
||||
if nvm.capa_max ~= 0 then
|
||||
local owner = M(pos):get_string("owner") or ""
|
||||
return inlet_cmnd(pos, "volume", owner)
|
||||
else
|
||||
return S("wrong storage diameter")..": "..diameter
|
||||
end
|
||||
else
|
||||
return S("inlet/pipe error")
|
||||
end
|
||||
return S("did you check the plan?")
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.capa = nvm.capa or 0
|
||||
local taken = 0
|
||||
local given = 0
|
||||
|
||||
if nvm.capa < (nvm.capa_max * 0.9) then
|
||||
taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
end
|
||||
if nvm.capa > 0 then
|
||||
given = turbine_cmnd(pos, "trigger") or 0
|
||||
end
|
||||
|
||||
if taken > 0 and not nvm.charging then
|
||||
play_sound(pos)
|
||||
elseif taken == 0 and nvm.charging then
|
||||
stop_sound(pos)
|
||||
end
|
||||
|
||||
nvm.needed = taken - given
|
||||
nvm.capa = in_range(nvm.capa + nvm.needed, 0, nvm.capa_max)
|
||||
glowing(pos, nvm, nvm.capa > nvm.capa_max * 0.8)
|
||||
print("node_timer TES "..P2S(pos), nvm.needed, nvm.capa, nvm.capa_max)
|
||||
return true
|
||||
end
|
||||
|
||||
local net_def = {
|
||||
ele1 = {
|
||||
sides = {F = 1, B = 1},
|
||||
ntype = "con2",
|
||||
nominal = PWR_PERF,
|
||||
},
|
||||
pipe2 = {
|
||||
sides = {L = 1, R = 1},
|
||||
ntype = "con1",
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:heatexchanger1", {
|
||||
description = S("TA4 Heat Exchanger 1"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_hole_ta4.png^techage_appl_arrow_white.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png",
|
||||
"techage_filling_ta4.png^techage_frameB_ta4.png^techage_appl_hole_pipe.png",
|
||||
"techage_filling_ta4.png^techage_frameB_ta4.png^techage_appl_hole_pipe.png",
|
||||
"techage_filling_ta4.png^techage_frameB_ta4.png^techage_appl_hole_electric.png",
|
||||
"techage_filling_ta4.png^techage_frameB_ta4.png^techage_appl_hole_electric.png",
|
||||
},
|
||||
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
can_dig = can_dig,
|
||||
after_dig_node = after_dig_node,
|
||||
--tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:heatexchanger1"})
|
||||
Cable:add_secondary_node_names({"techage:heatexchanger1"})
|
||||
|
||||
-- command interface
|
||||
techage.register_node({"techage:heatexchanger1"}, {
|
||||
on_transfer = function(pos, indir, topic, payload)
|
||||
print("on_transfer")
|
||||
local nvm = techage.get_nvm(pos)
|
||||
-- used by heatexchanger2
|
||||
if topic == "state" then
|
||||
return nvm.capa_max, nvm.capa, PWR_PERF, math.max(nvm.needed, 0)
|
||||
elseif topic == "integrity" then
|
||||
return inlet_cmnd(pos, "volume", payload)
|
||||
elseif topic == "state" then
|
||||
return inlet_cmnd(pos, "volume", payload)
|
||||
elseif topic == "can_start" then
|
||||
return can_start(pos, nvm)
|
||||
elseif topic == "start" then
|
||||
return start_node(pos, nvm)
|
||||
elseif topic == "stop" then
|
||||
return stop_node(pos, nvm)
|
||||
end
|
||||
end,
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "load" then
|
||||
return techage.power.percent(nvm.capa_max, nvm.capa)
|
||||
elseif topic == "size" then
|
||||
return (nvm.capa_max or 0) / GRVL_CAPA
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos, node)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running and nvm.charging then
|
||||
play_sound(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:heatexchanger1",
|
||||
recipe = {
|
||||
{"default:tin_ingot", "techage:electric_cableS", "default:steel_ingot"},
|
||||
{"techage:ta4_pipeS", "basic_materials:gear_steel", "techage:ta4_pipeS"},
|
||||
{"", "techage:baborium_ingot", ""},
|
||||
},
|
||||
})
|
||||
|
171
energy_storage/heatexchanger2.lua
Normal file
171
energy_storage/heatexchanger2.lua
Normal file
@ -0,0 +1,171 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Heat Exchanger2 (middle part)
|
||||
|
||||
]]--
|
||||
|
||||
-- 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 CYCLE_TIME = 2
|
||||
|
||||
local function he1_cmnd(pos, topic, payload)
|
||||
return techage.transfer({x = pos.x, y = pos.y - 1, z = pos.z},
|
||||
nil, topic, payload, nil,
|
||||
{"techage:heatexchanger1"})
|
||||
end
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
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]"
|
||||
if needed > 0 then
|
||||
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR90]"
|
||||
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,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]"..
|
||||
power.formspec_label_bar(0, 0.8, S("Thermal"), capa_max, capa, "")..
|
||||
power.formspec_label_bar(3.5, 0.8, S("Input"), needed_max, needed)..
|
||||
arrow..
|
||||
"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).."]"
|
||||
end
|
||||
|
||||
local function can_start(pos, nvm, state)
|
||||
print("can_start", he1_cmnd(pos, "can_start"))
|
||||
return he1_cmnd(pos, "can_start") or S("did you check the plan?")
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
he1_cmnd(pos, "start")
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
he1_cmnd(pos, "stop")
|
||||
end
|
||||
|
||||
local function check_TES_integrity(pos, nvm)
|
||||
nvm.ticks = (nvm.ticks or 0) + 1
|
||||
if (nvm.ticks % 100) == 0 then -- not to often
|
||||
return he1_cmnd(pos, "integrity", "singleplayer")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:heatexchanger2",
|
||||
cycle_time = CYCLE_TIME,
|
||||
infotext_name = S("TA4 Heat Exchanger"),
|
||||
standby_ticks = 0,
|
||||
can_start = can_start,
|
||||
start_node = start_node,
|
||||
stop_node = stop_node,
|
||||
formspec_func = formspec,
|
||||
})
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
print("node_timer")
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local res = check_TES_integrity(pos, nvm)
|
||||
if res ~= true then
|
||||
State:fault(pos, nvm, res)
|
||||
he1_cmnd(pos, "stop")
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return not nvm.running
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer)
|
||||
if techage.orientate_node(pos, "techage:heatexchanger1") then
|
||||
return true
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local own_num = techage.add_node(pos, "techage:heatexchanger2")
|
||||
State:node_init(pos, nvm, own_num)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
M(pos):set_string("infotext", S("TA4 Heat Exchanger").." "..own_num)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
-- Middle node with the formspec from the bottom node
|
||||
minetest.register_node("techage:heatexchanger2", {
|
||||
description = S("TA4 Heat Exchanger 2"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_hole_ta4.png",
|
||||
"techage_hole_ta4.png",
|
||||
"techage_filling_ta4.png^techage_frameM_ta4.png^techage_appl_tes_turb.png",
|
||||
"techage_filling_ta4.png^techage_frameM_ta4.png^techage_appl_tes_core.png",
|
||||
"techage_filling_ta4.png^techage_frameM_ta4.png^techage_appl_ribsB.png",
|
||||
"techage_filling_ta4.png^techage_frameM_ta4.png^techage_appl_ribsB.png",
|
||||
},
|
||||
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-1/2, -1.5/2, -1/2, 1/2, 1/2, 1/2},
|
||||
},
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
can_dig = can_dig,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:heatexchanger2",
|
||||
recipe = {
|
||||
{"default:tin_ingot", "", "default:steel_ingot"},
|
||||
{"", "techage:ta4_wlanchip", ""},
|
||||
{"", "techage:baborium_ingot", ""},
|
||||
},
|
||||
})
|
84
energy_storage/heatexchanger3.lua
Normal file
84
energy_storage/heatexchanger3.lua
Normal file
@ -0,0 +1,84 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Heat Exchanger3 (top part)
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local Pipe = techage.LiquidPipe
|
||||
|
||||
local function orientate_node(pos, name)
|
||||
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||
if node.name == name then
|
||||
local param2 = node.param2
|
||||
node = minetest.get_node(pos)
|
||||
node.param2 = param2
|
||||
minetest.swap_node(pos, node)
|
||||
else
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
if orientate_node(pos, "techage:heatexchanger2") then
|
||||
return true
|
||||
end
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
Pipe:after_dig_node(pos)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:heatexchanger3", {
|
||||
description = S("TA4 Heat Exchanger 3"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
||||
"techage_hole_ta4.png",
|
||||
"techage_filling_ta4.png^techage_frameT_ta4.png^techage_appl_hole_pipe.png",
|
||||
"techage_filling_ta4.png^techage_frameT_ta4.png^techage_appl_hole_pipe.png",
|
||||
"techage_filling_ta4.png^techage_frameT_ta4.png^techage_appl_ribsT.png",
|
||||
"techage_filling_ta4.png^techage_frameT_ta4.png^techage_appl_ribsT.png",
|
||||
},
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:heatexchanger3"})
|
||||
|
||||
techage.register_node({"techage:heatexchanger3"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:heatexchanger3",
|
||||
recipe = {
|
||||
{"default:tin_ingot", "dye:blue", "default:steel_ingot"},
|
||||
{"techage:ta4_pipeS", "basic_materials:gear_steel", "techage:ta4_pipeS"},
|
||||
{"", "techage:baborium_ingot", ""},
|
||||
},
|
||||
})
|
||||
|
||||
techage.orientate_node = orientate_node
|
@ -21,6 +21,14 @@ local S = techage.S
|
||||
|
||||
local Pipe = techage.LiquidPipe
|
||||
|
||||
local function after_place_node(pos, placer, itemstack)
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta4_pipe_inlet", {
|
||||
description = S("TA4 Pipe Inlet"),
|
||||
tiles = {
|
||||
@ -33,6 +41,9 @@ minetest.register_node("techage:ta4_pipe_inlet", {
|
||||
"basic_materials_concrete_block.png^techage_tes_inlet.png",
|
||||
},
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
|
||||
paramtype2 = "facedir", -- important!
|
||||
on_rotate = screwdriver.disallow, -- important!
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
@ -40,11 +51,7 @@ minetest.register_node("techage:ta4_pipe_inlet", {
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
-- for mechanical pipe connections
|
||||
techage.power.register_node({"techage:ta4_pipe_inlet"}, {
|
||||
conn_sides = {"F", "B"},
|
||||
power_network = Pipe,
|
||||
})
|
||||
Pipe:add_secondary_node_names({"techage:ta4_pipe_inlet"})
|
||||
|
||||
local Numbers = {
|
||||
shell = {
|
||||
@ -63,6 +70,7 @@ local function chat(owner, text)
|
||||
if owner ~= nil then
|
||||
minetest.chat_send_player(owner, string.char(0x1b).."(c@#ff0000)".."[Techage] Error: "..text.."!")
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
local function get_radius(pos, in_dir)
|
||||
@ -91,18 +99,14 @@ local function check_volume(pos, in_dir, owner)
|
||||
"basic_materials:concrete_block", "default:obsidian_glass",
|
||||
"techage:glow_gravel"})
|
||||
if node_tbl["default:obsidian_glass"] > 1 then
|
||||
chat(owner, "one window maximum")
|
||||
return false
|
||||
return chat(owner, "one window maximum")
|
||||
elseif node_tbl["default:obsidian_glass"] + node_tbl["basic_materials:concrete_block"] ~= Numbers.shell[radius] then
|
||||
chat(owner, "wrong number of shell nodes")
|
||||
return false
|
||||
return chat(owner, "wrong number of shell nodes")
|
||||
elseif node_tbl["default:gravel"] + node_tbl["techage:glow_gravel"] ~= Numbers.filling[radius] then
|
||||
chat(owner, "wrong number of gravel nodes")
|
||||
return false
|
||||
return chat(owner, "wrong number of gravel nodes")
|
||||
end
|
||||
else
|
||||
chat(owner, "wrong diameter (should be 5, 7, or 9)")
|
||||
return false
|
||||
return chat(owner, "wrong diameter (should be 5, 7, or 9)")
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -131,6 +135,8 @@ techage.register_node({"techage:ta4_pipe_inlet"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
if topic == "diameter" then
|
||||
return get_radius(pos, in_dir) * 2 - 1
|
||||
elseif topic == "integrity" then
|
||||
return check_volume(pos, in_dir, payload)
|
||||
elseif topic == "volume" then
|
||||
return check_volume(pos, in_dir, payload)
|
||||
elseif topic == "window" then
|
||||
|
@ -3,12 +3,12 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Gas Turbine
|
||||
TA4 TES Gas Turbine
|
||||
|
||||
]]--
|
||||
|
||||
@ -16,10 +16,18 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Pipe = techage.LiquidPipe
|
||||
|
||||
local function transfer_heatexchanger3(pos, topic, payload)
|
||||
return techage.transfer(pos, 6, topic, payload, Pipe,
|
||||
{"techage:heatexchanger3"})
|
||||
end
|
||||
|
||||
local function transfer_generator(pos, topic, payload)
|
||||
return techage.transfer(pos, "R", topic, payload, nil,
|
||||
{"techage:ta4_generator", "techage:ta4_generator_on"})
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
@ -34,7 +42,7 @@ local function play_sound(pos)
|
||||
if not mem.handle or mem.handle == -1 then
|
||||
mem.handle = minetest.sound_play("techage_turbine", {
|
||||
pos = pos,
|
||||
gain = 0.5,
|
||||
gain = 0.4,
|
||||
max_hear_distance = 10,
|
||||
loop = true})
|
||||
if mem.handle == -1 then
|
||||
@ -51,29 +59,20 @@ local function stop_sound(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function generator_cmnd(pos, cmnd)
|
||||
return techage.transfer(
|
||||
pos,
|
||||
"R", -- outdir
|
||||
cmnd, -- topic
|
||||
nil, -- payload
|
||||
nil, -- network
|
||||
{"techage:ta4_generator", "techage:ta4_generator_on"})
|
||||
local function after_place_node(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
-- to detect the missing "steam pressure"
|
||||
local function node_timer(pos, elapsed)
|
||||
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)
|
||||
nvm.running = false
|
||||
end
|
||||
play_sound(pos)
|
||||
return true
|
||||
local function after_dig_node(pos, oldnode)
|
||||
stop_sound(pos)
|
||||
Pipe:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
swap_node(pos, "techage:ta4_turbine")
|
||||
stop_sound(pos)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta4_turbine", {
|
||||
description = S("TA4 Turbine"),
|
||||
@ -86,7 +85,11 @@ minetest.register_node("techage:ta4_turbine", {
|
||||
"techage_filling_ta4.png^techage_appl_turbine.png^techage_frame_ta4.png",
|
||||
"techage_filling_ta4.png^techage_appl_turbine.png^techage_frame_ta4.png",
|
||||
},
|
||||
on_timer = node_timer,
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -123,12 +126,8 @@ minetest.register_node("techage:ta4_turbine_on", {
|
||||
},
|
||||
},
|
||||
|
||||
on_rightclick = function(pos)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
|
||||
on_timer = node_timer,
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
@ -137,43 +136,45 @@ minetest.register_node("techage:ta4_turbine_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
-- for mechanical pipe connections
|
||||
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 nvm = techage.get_nvm(pos)
|
||||
nvm.running = false
|
||||
nvm.remote_trigger = 0
|
||||
end,
|
||||
})
|
||||
Pipe:add_secondary_node_names({"techage:ta4_turbine", "techage:ta4_turbine_on"})
|
||||
|
||||
-- for logical communication
|
||||
techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "power" then
|
||||
nvm.remote_trigger = 2
|
||||
return generator_cmnd(pos, topic)
|
||||
elseif topic == "start" then
|
||||
nvm.remote_trigger = 2
|
||||
if topic == "trigger" then -- used by heatexchanger1
|
||||
if not transfer_heatexchanger3(pos, topic, payload) then
|
||||
return 0
|
||||
end
|
||||
local power = transfer_generator(pos, topic, payload)
|
||||
if not power or power <= 0 and nvm.running then
|
||||
swap_node(pos, "techage:ta4_turbine")
|
||||
stop_sound(pos)
|
||||
nvm.running = false
|
||||
return 0
|
||||
elseif power and power > 0 and not nvm.running then
|
||||
swap_node(pos, "techage:ta4_turbine_on")
|
||||
play_sound(pos)
|
||||
nvm.running = true
|
||||
end
|
||||
return power
|
||||
elseif topic == "start" then -- used by generator
|
||||
swap_node(pos, "techage:ta4_turbine_on")
|
||||
nvm.running = true
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
play_sound(pos)
|
||||
return generator_cmnd(pos, topic)
|
||||
elseif topic == "stop" then
|
||||
nvm.running = true
|
||||
return true
|
||||
elseif topic == "stop" then -- used by generator
|
||||
swap_node(pos, "techage:ta4_turbine")
|
||||
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
|
||||
nvm.remote_trigger = 2
|
||||
return generator_cmnd(pos, topic)
|
||||
nvm.running = false
|
||||
return true
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos, node)
|
||||
--print("on_node_load", node.name)
|
||||
if node.name == "techage:ta4_turbine_on" then
|
||||
play_sound(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
27
init.lua
27
init.lua
@ -90,7 +90,6 @@ else
|
||||
-- Liquids I
|
||||
dofile(MP.."/liquids/liquid_pipe.lua")
|
||||
dofile(MP.."/liquids/node_api.lua")
|
||||
--dofile(MP.."/liquids/liquid_lib.lua")
|
||||
|
||||
-- Basic Machines
|
||||
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
|
||||
@ -182,24 +181,26 @@ else
|
||||
--dofile(MP.."/.test/accu.lua")
|
||||
|
||||
-- Solar
|
||||
-- dofile(MP.."/solar/minicell.lua")
|
||||
-- dofile(MP.."/solar/solarcell.lua")
|
||||
-- dofile(MP.."/solar/inverter.lua")
|
||||
dofile(MP.."/solar/minicell.lua")
|
||||
dofile(MP.."/solar/solarcell.lua")
|
||||
dofile(MP.."/solar/inverter.lua")
|
||||
|
||||
-- -- Wind
|
||||
-- dofile(MP.."/wind_turbine/rotor.lua")
|
||||
-- dofile(MP.."/wind_turbine/pillar.lua")
|
||||
-- dofile(MP.."/wind_turbine/signallamp.lua")
|
||||
dofile(MP.."/wind_turbine/rotor.lua")
|
||||
dofile(MP.."/wind_turbine/pillar.lua")
|
||||
dofile(MP.."/wind_turbine/signallamp.lua")
|
||||
|
||||
-- -- TA4 Energy Storage
|
||||
-- dofile(MP.."/energy_storage/heatexchanger.lua")
|
||||
-- dofile(MP.."/energy_storage/generator.lua")
|
||||
-- dofile(MP.."/energy_storage/turbine.lua")
|
||||
-- dofile(MP.."/energy_storage/inlet.lua")
|
||||
-- dofile(MP.."/energy_storage/nodes.lua")
|
||||
dofile(MP.."/energy_storage/heatexchanger3.lua")
|
||||
dofile(MP.."/energy_storage/heatexchanger2.lua")
|
||||
dofile(MP.."/energy_storage/heatexchanger1.lua")
|
||||
dofile(MP.."/energy_storage/generator.lua")
|
||||
dofile(MP.."/energy_storage/turbine.lua")
|
||||
dofile(MP.."/energy_storage/inlet.lua")
|
||||
dofile(MP.."/energy_storage/nodes.lua")
|
||||
|
||||
-- -- Chemistry
|
||||
-- dofile(MP.."/chemistry/ta4_reactor.lua")
|
||||
dofile(MP.."/chemistry/ta4_reactor.lua")
|
||||
-- dofile(MP.."/chemistry/ta4_stand.lua")
|
||||
-- dofile(MP.."/chemistry/ta4_doser.lua")
|
||||
|
||||
|
@ -70,7 +70,6 @@ local function on_rightclick(pos, node, clicker)
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
print("node_timer")
|
||||
local inv = M(pos):get_inventory()
|
||||
if not inv:is_empty("src") then
|
||||
local taken = techage.get_items(inv, "src", 1)
|
||||
|
@ -122,7 +122,6 @@ local function on_node_state_change(pos, old_state, new_state)
|
||||
end
|
||||
|
||||
local function drilling(pos, crd, nvm, inv)
|
||||
print("drilling")
|
||||
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")
|
||||
|
@ -56,7 +56,7 @@ local function get_generator_sum(tbl, tlib_type)
|
||||
if def and def["gstate"] ~= STOPPED then
|
||||
def["galive"] = (def["galive"] or 1) - 1
|
||||
if def["galive"] > 0 then
|
||||
sum = sum + v.nominal
|
||||
sum = sum + (def.curr_power or v.nominal)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -82,7 +82,11 @@ local function set_given(pos, given, tlib_type)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local def = nvm[tlib_type] -- power related network data
|
||||
if (def and def["galive"] or 0) > 0 then
|
||||
def["given"] = given
|
||||
if def.curr_power and def.curr_power < given then
|
||||
def["given"] = def.curr_power
|
||||
else
|
||||
def["given"] = given
|
||||
end
|
||||
return given
|
||||
end
|
||||
return 0
|
||||
|
@ -48,9 +48,11 @@ function techage.power.formspec_power_bar(max_power, current_power)
|
||||
return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png"
|
||||
end
|
||||
|
||||
function techage.power.formspec_label_bar(x, y, label, max_power, current_power)
|
||||
function techage.power.formspec_label_bar(x, y, label, max_power, current_power, unit)
|
||||
local percent, ypos
|
||||
current_power = current_power or 0
|
||||
max_power = max_power or 1
|
||||
unit = unit or "ku"
|
||||
if current_power == 0 then
|
||||
percent = 0
|
||||
ypos = 2.8
|
||||
@ -64,11 +66,11 @@ function techage.power.formspec_label_bar(x, y, label, max_power, current_power)
|
||||
return "container["..x..","..y.."]"..
|
||||
"box[0,0;2.3,3.3;#395c74]"..
|
||||
"label[0.2,0;"..label.."]"..
|
||||
"label[0.7,0.4;"..max_power.." ku]"..
|
||||
"label[0.7,0.4;"..max_power.." "..unit.."]"..
|
||||
"image[0,0.5;1,3;"..
|
||||
"techage_form_level_bg.png^[lowpart:"..percent..
|
||||
":techage_form_level_fg.png]"..
|
||||
"label[0.7,"..ypos..";"..current_power.." ku]"..
|
||||
"label[0.7,"..ypos..";"..current_power.." "..unit.."]"..
|
||||
"container_end[]"
|
||||
|
||||
end
|
||||
|
@ -98,6 +98,31 @@ function techage.power.update_network(pos, outdir, Cable)
|
||||
delete_netID(pos, outdir, Cable) -- network walk to delete all IDs
|
||||
end
|
||||
|
||||
--
|
||||
-- Read the current power value from all connected devices (used for solar cells)
|
||||
-- Only used by the solar inverter to collect the power of all solar cells.
|
||||
-- Only one inverter per network is allowed. Therefore, we have to check,
|
||||
-- if additional inverters are in the network.
|
||||
-- Function returns in addition the number of found inverters.
|
||||
function techage.power.get_power(pos, outdir, Cable, inverter)
|
||||
local sum = 0
|
||||
local num_inverter = 0
|
||||
networks.connection_walk(pos, outdir, Cable, function(pos, indir, node)
|
||||
techage.mark_position("singleplayer", pos, "get_power", "", 2)-----------------------------------------
|
||||
local def = net_def(pos, Cable.tube_type)
|
||||
if def and def.on_getpower then
|
||||
sum = sum + def.on_getpower(pos)
|
||||
else
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == inverter then
|
||||
num_inverter = num_inverter + 1
|
||||
end
|
||||
end
|
||||
end)
|
||||
return sum, num_inverter
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Consumer related functions
|
||||
@ -154,13 +179,15 @@ end
|
||||
--
|
||||
-- Generator related functions
|
||||
--
|
||||
function techage.power.generator_start(pos, Cable, cycle_time, outdir)
|
||||
-- curr_power is optional, only needed for generators with variable output power
|
||||
function techage.power.generator_start(pos, Cable, cycle_time, outdir, curr_power)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local tlib_type = Cable.tube_type
|
||||
nvm[tlib_type] = nvm[tlib_type] or {}
|
||||
nvm[tlib_type]["galive"] = (cycle_time / 2) + 2
|
||||
nvm[tlib_type]["gstate"] = RUNNING
|
||||
nvm[tlib_type]["given"] = 0
|
||||
nvm[tlib_type]["curr_power"] = curr_power
|
||||
trigger_network(pos, outdir, Cable)
|
||||
end
|
||||
|
||||
@ -173,12 +200,14 @@ function techage.power.generator_stop(pos, Cable, outdir)
|
||||
nvm[tlib_type]["given"] = 0
|
||||
end
|
||||
|
||||
function techage.power.generator_alive(pos, Cable, cycle_time, outdir)
|
||||
-- curr_power is optional, only needed for generators with variable output power
|
||||
function techage.power.generator_alive(pos, Cable, cycle_time, outdir, curr_power)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local def = nvm[Cable.tube_type] -- power related network data
|
||||
if def then
|
||||
trigger_network(pos, outdir, Cable)
|
||||
def["galive"] = (cycle_time / 2) + 2
|
||||
def["curr_power"] = curr_power
|
||||
return def["given"] or 0
|
||||
end
|
||||
return 0
|
||||
|
@ -38,10 +38,10 @@ local function generator_data(gen_tbl)
|
||||
tbl.pow_all = tbl.pow_all + (gen.nominal or 0)
|
||||
if nvm.ele1 and nvm.ele1.gstate and nvm.ele1.gstate ~= STOPPED then
|
||||
tbl.num_on = tbl.num_on + 1
|
||||
tbl.pow_on = tbl.pow_on + (gen.nominal or 0)
|
||||
tbl.pow_on = tbl.pow_on + (nvm.ele1.curr_power or gen.nominal or 0)
|
||||
if (nvm.ele1.galive or 0) > 0 then
|
||||
tbl.num_act = tbl.num_act + 1
|
||||
tbl.pow_act = tbl.pow_act + (gen.nominal or 0)
|
||||
tbl.pow_act = tbl.pow_act + (nvm.ele1.curr_power or gen.nominal or 0)
|
||||
if (nvm.ele1.given or 0) > 0 then
|
||||
tbl.num_used = tbl.num_used + 1
|
||||
tbl.pow_used = tbl.pow_used + (nvm.ele1.given or 0)
|
||||
|
@ -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,18 +18,18 @@ local S = techage.S
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
|
||||
local Power = techage.ElectricCable
|
||||
local Cable = techage.ElectricCable
|
||||
local Solar = techage.TA4_Cable
|
||||
local power = techage.power
|
||||
local networks = techage.networks
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 100
|
||||
|
||||
local function determine_power(pos, nvm)
|
||||
-- determine DC node position
|
||||
local dir = M(pos):get_int("left_dir")
|
||||
local pos1 = techage.get_pos(pos, dir)
|
||||
local max_power, num_inverter = power.get_power(pos1, "techage:ta4_solar_inverterDC")
|
||||
local outdir = M(pos):get_int("leftdir")
|
||||
local max_power, num_inverter = power.get_power(pos, outdir, Solar, "techage:ta4_solar_inverter")
|
||||
if num_inverter == 1 then
|
||||
nvm.max_power = math.min(PWR_PERF, max_power)
|
||||
else
|
||||
@ -43,13 +43,11 @@ local function determine_power_from_time_to_time(pos, nvm)
|
||||
if time < 6.00/24.00 or time > 18.00/24.00 then
|
||||
nvm.ticks = 0
|
||||
nvm.max_power = 0
|
||||
power.generator_update(pos, nvm, nvm.max_power)
|
||||
return
|
||||
end
|
||||
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
|
||||
nvm.max_power = nvm.max_power or 0
|
||||
end
|
||||
@ -57,23 +55,23 @@ local function determine_power_from_time_to_time(pos, nvm)
|
||||
end
|
||||
|
||||
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]"..
|
||||
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||
if nvm.running then
|
||||
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||
end
|
||||
return "size[6,4]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"label[0.2,0;DC]"..
|
||||
"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(nvm) ..";state_button;]"..
|
||||
"label[4.2,0;AC]"..
|
||||
"image[4,0.5;1,2;"..bar_out.."]"..
|
||||
"label[4,2.5;"..delivered.." ku]"
|
||||
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
|
||||
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]"..
|
||||
power.formspec_label_bar(0, 0.8, S("Power DC"), PWR_PERF, max_power)..
|
||||
power.formspec_label_bar(3.5, 0.8, S("Power AC"), PWR_PERF, delivered)..
|
||||
arrow..
|
||||
"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).."]"
|
||||
end
|
||||
|
||||
local function can_start(pos, nvm, state)
|
||||
@ -87,13 +85,15 @@ local function start_node(pos, nvm, state)
|
||||
nvm.running = true
|
||||
nvm.delivered = 0
|
||||
nvm.ticks = 0
|
||||
power.generator_start(pos, nvm, nvm.max_power)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir, nvm.max_power)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.delivered = 0
|
||||
power.generator_stop(pos, nvm)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -109,15 +109,17 @@ local State = techage.NodeStates:new({
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
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
|
||||
nvm.delivered = 0
|
||||
end
|
||||
determine_power_from_time_to_time(pos, nvm)
|
||||
--if nvm.max_power > 0 then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.delivered = power.generator_alive(pos, Cable, CYCLE_TIME, outdir, nvm.max_power)
|
||||
--else
|
||||
--nvm.delivered = 0
|
||||
--end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
return nvm.running
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
@ -132,19 +134,25 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_rightclick(pos)
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
determine_power(pos, nvm)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta4_solar_inverter", {
|
||||
description = S("TA4 Solar Inverter AC"),
|
||||
description = S("TA4 Solar Inverter"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta4.png^techage_frame_ta4_top.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_appl_hole_electric.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_open.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_ta4_cable.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverter.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverter.png",
|
||||
},
|
||||
@ -153,46 +161,75 @@ minetest.register_node("techage:ta4_solar_inverter", {
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
|
||||
after_place_node = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L"))
|
||||
Cable:after_place_node(pos)
|
||||
Solar:after_place_node(pos)
|
||||
local number = techage.add_node(pos, "techage:ta4_solar_inverter")
|
||||
State:node_init(pos, nvm, number)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
Solar:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
networks = {
|
||||
ele1 = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_PERF,
|
||||
},
|
||||
ele2 = {
|
||||
sides = {L = 1},
|
||||
ntype = "con1",
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("techage:ta4_solar_inverterDC", {
|
||||
description = S("TA4 Solar Inverter DC"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta4.png^techage_frame_ta4_top.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_open.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_ta4_cable.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverterDC.png",
|
||||
"techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverterDC.png",
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
})
|
||||
--minetest.register_node("techage:ta4_solar_inverterDC", {
|
||||
-- description = S("TA4 Solar Inverter DC"),
|
||||
-- tiles = {
|
||||
-- -- up, down, right, left, back, front
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4_top.png",
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4.png",
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_open.png",
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_ta4_cable.png",
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverterDC.png",
|
||||
-- "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_inverterDC.png",
|
||||
-- },
|
||||
|
||||
-- after_place_node = function(pos)
|
||||
-- Solar:after_place_node(pos)
|
||||
-- end,
|
||||
|
||||
-- after_dig_node = function(pos, oldnode)
|
||||
-- Solar:after_dig_node(pos)
|
||||
-- end,
|
||||
|
||||
-- tubelib2_on_update2 = tubelib2_on_update2,
|
||||
-- paramtype2 = "facedir",
|
||||
-- groups = {cracky=2, crumbly=2, choppy=2},
|
||||
-- on_rotate = screwdriver.disallow,
|
||||
-- is_ground_content = false,
|
||||
-- networks = {
|
||||
-- ele2 = {
|
||||
-- sides = {L = 1},
|
||||
-- ntype = "con1",
|
||||
-- },
|
||||
-- }
|
||||
--})
|
||||
|
||||
techage.power.register_node({"techage:ta4_solar_inverter"}, {
|
||||
conn_sides = {"R"},
|
||||
power_network = Power,
|
||||
after_place_node = function(pos, placer)
|
||||
-- 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 nvm = techage.get_nvm(pos)
|
||||
State:node_init(pos, nvm, number)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:ta4_solar_inverterDC"}, {
|
||||
conn_sides = {"L"},
|
||||
power_network = Solar,
|
||||
})
|
||||
Cable:add_secondary_node_names({"techage:ta4_solar_inverter"})
|
||||
Solar:add_secondary_node_names({"techage:ta4_solar_inverter"})
|
||||
|
||||
techage.register_node({"techage:ta4_solar_inverter"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
@ -212,11 +249,11 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_solar_inverterDC",
|
||||
recipe = {
|
||||
{'default:steel_ingot', 'dye:green', 'default:steel_ingot'},
|
||||
{'techage:ta4_power_cableS', '', ''},
|
||||
{'default:steel_ingot', "techage:baborium_ingot", 'default:steel_ingot'},
|
||||
},
|
||||
})
|
||||
--minetest.register_craft({
|
||||
-- output = "techage:ta4_solar_inverterDC",
|
||||
-- recipe = {
|
||||
-- {'default:steel_ingot', 'dye:green', 'default:steel_ingot'},
|
||||
-- {'techage:ta4_power_cableS', '', ''},
|
||||
-- {'default:steel_ingot', "techage:baborium_ingot", 'default:steel_ingot'},
|
||||
-- },
|
||||
--})
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -38,7 +38,7 @@ local function node_timer(pos, elapsed)
|
||||
|
||||
if light >= (minetest.LIGHT_MAX - 1) then
|
||||
if nvm.providing then
|
||||
power.generator_stop(pos, nvm)
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
nvm.providing = false
|
||||
nvm.provided = 0
|
||||
end
|
||||
@ -46,13 +46,14 @@ local function node_timer(pos, elapsed)
|
||||
else
|
||||
if nvm.capa > 0 then
|
||||
if not nvm.providing then
|
||||
power.generator_start(pos, nvm, PWR_PERF)
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, 5)
|
||||
nvm.providing = true
|
||||
else
|
||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, 5)
|
||||
nvm.capa = nvm.capa - nvm.provided
|
||||
end
|
||||
nvm.provided = power.generator_alive(pos, nvm)
|
||||
nvm.capa = nvm.capa - nvm.provided
|
||||
else
|
||||
power.generator_stop(pos, nvm)
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
nvm.providing = false
|
||||
nvm.provided = 0
|
||||
nvm.capa = 0
|
||||
@ -61,6 +62,36 @@ local function node_timer(pos, elapsed)
|
||||
return true
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
local meta = M(pos)
|
||||
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 nvm = techage.get_nvm(pos)
|
||||
nvm.capa = 0
|
||||
nvm.providing = false
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
techage.remove_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 = {D = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:ta4_solar_minicell", {
|
||||
description = S("TA4 Streetlamp Solar Cell"),
|
||||
tiles = {
|
||||
@ -80,28 +111,14 @@ minetest.register_node("techage:ta4_solar_minicell", {
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
is_ground_content = false,
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
on_timer = node_timer,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:ta4_solar_minicell"}, {
|
||||
power_network = Cable,
|
||||
conn_sides = {"D"},
|
||||
after_place_node = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
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 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)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
})
|
||||
Cable:add_secondary_node_names({"techage:ta4_solar_minicell"})
|
||||
|
||||
techage.register_node({"techage:ta4_solar_minicell"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
@ -119,12 +136,7 @@ techage.register_node({"techage:ta4_solar_minicell"}, {
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
local meta = M(pos)
|
||||
local number = meta:get_string("number") or ""
|
||||
if number ~= "" then
|
||||
meta:set_string("node_number", number)
|
||||
meta:set_string("number", nil)
|
||||
end
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -32,8 +32,7 @@ end
|
||||
|
||||
-- return the required param2 for solar modules
|
||||
local function get_param2(pos, side)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
local dir = power.side_to_dir(node.param2, side)
|
||||
local dir = techage.networks.side_to_outdir(pos, side)
|
||||
return (dir + 1) % 4
|
||||
end
|
||||
|
||||
@ -62,7 +61,7 @@ local function is_solar_module(base_pos, pos, side)
|
||||
end
|
||||
|
||||
-- provide the available power, which is temperature dependent
|
||||
local function on_getpower1(pos, mem)
|
||||
local function on_getpower1(pos)
|
||||
local pos1 = {x = pos.x, y = pos.y, z = pos.z}
|
||||
if is_solar_module(pos, pos1, "L") and is_solar_module(pos, pos1, "R") then
|
||||
return PWR_PERF * M(pos):get_int("temperature") / 100.0
|
||||
@ -70,7 +69,7 @@ local function on_getpower1(pos, mem)
|
||||
return 0
|
||||
end
|
||||
|
||||
local function on_getpower2(pos, mem)
|
||||
local function on_getpower2(pos)
|
||||
local pos1 = {x = pos.x, y = pos.y+1, z = pos.z}
|
||||
if is_solar_module(pos, pos1, "L") and is_solar_module(pos, pos1, "R") then
|
||||
return PWR_PERF * M(pos):get_int("temperature") / 100.0
|
||||
@ -78,6 +77,36 @@ local function on_getpower2(pos, mem)
|
||||
return 0
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
M(pos):set_int("temperature", temperature(pos))
|
||||
M(pos):set_int("left_param2", get_param2(pos, "L"))
|
||||
M(pos):set_int("right_param2", get_param2(pos, "R"))
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
|
||||
local net_def1 = {
|
||||
ele2 = {
|
||||
sides = {F=1, B=1},
|
||||
ntype = "junc",
|
||||
on_getpower = on_getpower1,
|
||||
},
|
||||
}
|
||||
|
||||
local net_def2 = {
|
||||
ele2 = {
|
||||
sides = {F=1, B=1},
|
||||
ntype = "junc",
|
||||
on_getpower = on_getpower2,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:ta4_solar_module", {
|
||||
description = S("TA4 Solar Module"),
|
||||
@ -130,6 +159,17 @@ minetest.register_node("techage:ta4_solar_carrier", {
|
||||
{-3/8, 5/16, -1/2, 3/8, 7/16, 1/2},
|
||||
},
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
M(pos):set_int("temperature", temperature(pos))
|
||||
M(pos):set_int("left_param2", get_param2(pos, "L"))
|
||||
M(pos):set_int("right_param2", get_param2(pos, "R"))
|
||||
end,
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def1,
|
||||
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -156,6 +196,18 @@ minetest.register_node("techage:ta4_solar_carrierB", {
|
||||
{-1/8, -6/16, -1/2, 1/8, 8/16, 1/2},
|
||||
},
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
M(pos):set_int("temperature", temperature(pos))
|
||||
M(pos):set_int("left_param2", get_param2(pos, "L"))
|
||||
M(pos):set_int("right_param2", get_param2(pos, "R"))
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def2,
|
||||
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -189,27 +241,8 @@ minetest.register_node("techage:ta4_solar_carrierT", {
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
||||
techage.power.register_node({"techage:ta4_solar_carrier"}, {
|
||||
power_network = Cable,
|
||||
on_getpower = on_getpower1,
|
||||
conn_sides ={"F", "B"},
|
||||
after_place_node = function(pos)
|
||||
M(pos):set_int("temperature", temperature(pos))
|
||||
M(pos):set_int("left_param2", get_param2(pos, "L"))
|
||||
M(pos):set_int("right_param2", get_param2(pos, "R"))
|
||||
end,
|
||||
})
|
||||
Cable:add_secondary_node_names({"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"})
|
||||
|
||||
techage.power.register_node({"techage:ta4_solar_carrierB"}, {
|
||||
power_network = Cable,
|
||||
on_getpower = on_getpower2,
|
||||
conn_sides ={"F", "B"},
|
||||
after_place_node = function(pos)
|
||||
M(pos):set_int("temperature", temperature(pos))
|
||||
M(pos):set_int("left_param2", get_param2(pos, "L"))
|
||||
M(pos):set_int("right_param2", get_param2(pos, "R"))
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta4_solar_module",
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -31,8 +31,6 @@ minetest.register_node("techage:pillar", {
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "techage:pillar",
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 DS-Minetest, Joachim Stolberg
|
||||
Copyright (C) 2019-2020 DS-Minetest, Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -119,7 +119,7 @@ local function start_rotor(pos, nvm)
|
||||
|
||||
nvm.providing = true
|
||||
nvm.delivered = 0
|
||||
power.generator_start(pos, nvm, PWR_PERF)
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] then
|
||||
Rotors[hash]:set_animation_frame_speed(50)
|
||||
@ -129,7 +129,7 @@ end
|
||||
local function stop_rotor(pos, nvm)
|
||||
nvm.providing = false
|
||||
nvm.delivered = 0
|
||||
power.generator_stop(pos, nvm)
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] then
|
||||
Rotors[hash]:set_animation_frame_speed(0)
|
||||
@ -153,12 +153,39 @@ local function node_timer(pos, elapsed)
|
||||
stop_rotor(pos, nvm)
|
||||
end
|
||||
end
|
||||
if nvm.providing then
|
||||
nvm.delivered = power.generator_alive(pos, nvm)
|
||||
end
|
||||
nvm.delivered = power.generator_alive(pos, Cable, CYCLE_TIME, 5, (nvm.providing and PWR_PERF) or 0)
|
||||
return true
|
||||
end
|
||||
|
||||
local function after_place_node(pos, placer)
|
||||
local meta = M(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)
|
||||
nvm.providing = false
|
||||
nvm.running = true
|
||||
add_rotor(pos, nvm, placer:get_player_name())
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] and Rotors[hash]:get_luaentity() then
|
||||
Rotors[hash]:remove()
|
||||
end
|
||||
Rotors[hash] = nil
|
||||
Cable:after_dig_node(pos)
|
||||
techage.remove_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta4_wind_turbine", {
|
||||
description = S("TA4 Wind Turbine"),
|
||||
inventory_image = "techage_wind_turbine_inv.png",
|
||||
@ -172,6 +199,16 @@ minetest.register_node("techage:ta4_wind_turbine", {
|
||||
"techage_rotor.png^techage_appl_open.png",
|
||||
},
|
||||
|
||||
networks = {
|
||||
ele1 = {
|
||||
sides = {D = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_PERF,
|
||||
},
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
on_timer = node_timer,
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
@ -207,32 +244,7 @@ minetest.register_entity("techage:rotor_ent", {initial_properties = {
|
||||
static_save = false,
|
||||
}})
|
||||
|
||||
techage.power.register_node({"techage:ta4_wind_turbine"}, {
|
||||
power_network = Cable,
|
||||
conn_sides = {"D"},
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = M(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)
|
||||
nvm.providing = false
|
||||
nvm.running = true
|
||||
add_rotor(pos, nvm, placer:get_player_name())
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] and Rotors[hash]:get_luaentity() then
|
||||
Rotors[hash]:remove()
|
||||
end
|
||||
Rotors[hash] = nil
|
||||
techage.remove_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
})
|
||||
Cable:add_secondary_node_names({"techage:ta4_wind_turbine"})
|
||||
|
||||
techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
|
Loading…
Reference in New Issue
Block a user