Prepare for lib 'networks'
This commit is contained in:
parent
054283cc4d
commit
1d7db7943b
@ -25,7 +25,7 @@ local control = networks.control
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 25
|
||||
local PWR_PERF = 100
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return techage.generator_formspec(self, pos, nvm, S("Power Source"), nvm.provided, PWR_PERF)
|
||||
|
@ -19,7 +19,6 @@ local S = techage.S
|
||||
|
||||
-- Consumer Related Data
|
||||
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
||||
local power = techage.power
|
||||
|
||||
local STANDBY_TICKS = 3
|
||||
local COUNTDOWN_TICKS = 4
|
||||
@ -49,7 +48,7 @@ local function formspec(self, pos, nvm)
|
||||
default.gui_slots..
|
||||
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
|
||||
"label[1,-0.1;"..minetest.colorize("#000000", S("Digtron Battery")).."]"..
|
||||
power.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents"))..
|
||||
techage.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents"))..
|
||||
"image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||
"tooltip[2.6,2;1,1;"..self:get_state_tooltip(nvm).."]"..
|
||||
"image[3.75,2;1,1;"..techage.get_power_image(pos, nvm).."]"
|
||||
@ -163,7 +162,7 @@ techage.register_consumer("digtron_battery", S("Digtron Battery"), { act = tiles
|
||||
groups = {choppy=2, cracky=2, crumbly=2, digtron=5},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
power_consumption = {0,25,25,25},
|
||||
power_sides = techage.networks.AllSides,
|
||||
power_sides = {L=1, R=1, U=1, D=1, F=1, B=1},
|
||||
}, {false, false, true, false})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -3,137 +3,32 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 TES Generator
|
||||
|
||||
TA4 TES Generator (dummy)
|
||||
- can be started and stopped
|
||||
- provides netID of cable network
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
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 power = networks.power
|
||||
|
||||
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(pos, 0, 0.8, S("Electricity"), 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
|
||||
|
||||
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)
|
||||
if (nvm.heatexchanger_trigger or 0) == 0 then -- by means of heatexchanger
|
||||
return S("storage empty?")
|
||||
end
|
||||
return true
|
||||
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.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
|
||||
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
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
local nvm,_ = techage.get_nvm(pos, true)
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
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 = {
|
||||
@ -146,13 +41,14 @@ minetest.register_node("techage:ta4_generator", {
|
||||
"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,
|
||||
after_place_node = function(pos)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
@ -191,16 +87,8 @@ minetest.register_node("techage:ta4_generator_on", {
|
||||
},
|
||||
},
|
||||
|
||||
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",
|
||||
drop = "",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -208,32 +96,27 @@ 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"})
|
||||
-- The generator is a dummy, it only has to network connection to check the netID
|
||||
power.register_nodes({"techage:ta4_generator", "techage:ta4_generator_on"}, Cable, "con", {"R"})
|
||||
|
||||
-- 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
|
||||
if topic == "netID" then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
return networks.determine_netID(pos, Cable, outdir)
|
||||
elseif topic == "start" then
|
||||
swap_node(pos, "techage:ta4_generator_on")
|
||||
elseif topic == "stop" then
|
||||
swap_node(pos, "techage:ta4_generator")
|
||||
end
|
||||
end,
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "delivered" then
|
||||
return math.floor((nvm.provided or 0) + 0.5)
|
||||
elseif topic == "load" then
|
||||
local capa_max, capa = transfer_turbine(pos, "state")
|
||||
return techage.power.percent(capa_max, capa)
|
||||
else
|
||||
return State:on_receive_message(pos, topic, payload)
|
||||
end
|
||||
return "unsupported"
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
-- remove legacy formspec
|
||||
M(pos):set_string("formspec", "")
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -3,13 +3,14 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA4 Heat Exchanger1 (bottom part)
|
||||
|
||||
- has a connection to storage and turbine (via pipes)
|
||||
- acts as a cable junction for Exchanger2
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
@ -18,38 +19,9 @@ 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 = {
|
||||
[5] = 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
|
||||
[7] = GRVL_CAPA * 5 * 5 * 5, -- ~2.5 days
|
||||
[9] = 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 power = networks.power
|
||||
|
||||
local function turbine_cmnd(pos, topic, payload)
|
||||
return techage.transfer(pos, "R", topic, payload, Pipe,
|
||||
@ -61,153 +33,6 @@ local function inlet_cmnd(pos, topic, payload)
|
||||
{"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.3,
|
||||
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)
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
end
|
||||
|
||||
local function is_running(pos, nvm)
|
||||
return nvm.charging
|
||||
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())
|
||||
local number = techage.add_node(pos, "techage:heatexchanger1")
|
||||
M(pos):set_string("node_number", number)
|
||||
M(pos):set_string("infotext", S("TA4 Heat Exchanger 1").." "..number)
|
||||
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)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.running = false
|
||||
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
|
||||
nvm.capa_max = nvm.capa_max or 0
|
||||
local taken = 0
|
||||
local given = 0
|
||||
|
||||
if nvm.capa < (nvm.capa_max * 0.95) and not nvm.charging then
|
||||
taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
elseif nvm.capa < nvm.capa_max and nvm.charging 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,
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
is_running = is_running,
|
||||
},
|
||||
pipe2 = {
|
||||
sides = {L = 1, R = 1},
|
||||
ntype = "con1",
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:heatexchanger1", {
|
||||
description = S("TA4 Heat Exchanger 1"),
|
||||
tiles = {
|
||||
@ -220,13 +45,27 @@ minetest.register_node("techage:heatexchanger1", {
|
||||
"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,
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
Cable:after_place_node(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
if tlib2 == Cable then
|
||||
power.update_network(pos, 0, tlib2, node)
|
||||
end
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
pos.y = pos.y + 1
|
||||
return minetest.get_node(pos).name ~= "techage:heatexchanger2"
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_node(pos)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
networks = {},
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -235,62 +74,21 @@ minetest.register_node("techage:heatexchanger1", {
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:heatexchanger1"})
|
||||
Cable:add_secondary_node_names({"techage:heatexchanger1"})
|
||||
Pipe:set_valid_sides("techage:heatexchanger1", {"R", "L"})
|
||||
|
||||
power.register_nodes({"techage:heatexchanger1"}, Cable, "junc", {"F", "B", "U"})
|
||||
|
||||
-- command interface
|
||||
techage.register_node({"techage:heatexchanger1"}, {
|
||||
on_transfer = function(pos, indir, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
-- used by heatexchanger2
|
||||
if topic == "state" then
|
||||
return (nvm.capa_max or 0), (nvm.capa or 0), PWR_PERF, math.max(nvm.needed or 0, 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 == "state" then
|
||||
if nvm.charging then
|
||||
return "running"
|
||||
elseif nvm.running then
|
||||
return "standby"
|
||||
else
|
||||
return "stopped"
|
||||
end
|
||||
elseif topic == "delivered" then
|
||||
return -math.max(nvm.needed or 0, 0)
|
||||
elseif topic == "load" then
|
||||
return techage.power.percent(nvm.capa_max, nvm.capa)
|
||||
elseif topic == "on" then
|
||||
start_node(pos, techage.get_nvm(pos))
|
||||
return true
|
||||
elseif topic == "off" then
|
||||
stop_node(pos, techage.get_nvm(pos))
|
||||
return true
|
||||
if topic == "diameter" or topic == "volume" or topic == "window" then
|
||||
return inlet_cmnd(pos, topic, payload)
|
||||
else
|
||||
return "unsupported"
|
||||
return turbine_cmnd(pos, topic, payload)
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos, node)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running and nvm.charging then
|
||||
play_sound(pos)
|
||||
else
|
||||
stop_sound(pos)
|
||||
end
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
nvm.capa = (nvm.capa or 0) + (mem.capa or 0)
|
||||
--tubelib2.del_mem(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -18,56 +18,118 @@ local P2S = minetest.pos_to_string
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local power = techage.power
|
||||
local Cable = techage.ElectricCable
|
||||
local Pipe = techage.LiquidPipe
|
||||
local power = networks.power
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local GRVL_CAPA = 500
|
||||
local PWR_CAPA = {
|
||||
[5] = GRVL_CAPA * 3 * 3 * 3, -- 13500 Cyc = 450 min = 22.5 kud
|
||||
[7] = GRVL_CAPA * 5 * 5 * 5, -- 104 kud
|
||||
[9] = GRVL_CAPA * 7 * 7 * 7, -- 286 kuh
|
||||
}
|
||||
local DOWN = 5
|
||||
|
||||
local function he1_cmnd(pos, topic, payload)
|
||||
local function heatexchanger1_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")
|
||||
capa_max = capa_max or 0
|
||||
capa = capa or 0
|
||||
needed_max = needed_max or 0
|
||||
needed = needed or 0
|
||||
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||
if needed > 0 then
|
||||
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
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(pos, 0, 0.8, S("Electricity"), needed_max, needed)..
|
||||
power.formspec_label_bar(pos, 3.5, 0.8, S("Thermal"), capa_max, capa, "")..
|
||||
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).."]"
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
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?")
|
||||
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.3,
|
||||
max_hear_distance = 10,
|
||||
loop = true})
|
||||
if mem.handle == -1 then
|
||||
minetest.after(1, play_sound, pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
he1_cmnd(pos, "start")
|
||||
local function stop_sound(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
if mem.handle then
|
||||
minetest.sound_stop(mem.handle)
|
||||
mem.handle = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
he1_cmnd(pos, "stop")
|
||||
local function can_start(pos, nvm)
|
||||
local netID = networks.determine_netID(pos, Cable, DOWN)
|
||||
if heatexchanger1_cmnd(pos, "netID") ~= netID then
|
||||
return S("Power network connection error")
|
||||
end
|
||||
local diameter = heatexchanger1_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 heatexchanger1_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 start_node(pos, nvm)
|
||||
nvm.running = true
|
||||
nvm.win_pos = heatexchanger1_cmnd(pos, "window")
|
||||
power.start_storage_calc(pos, Cable, DOWN)
|
||||
play_sound(pos)
|
||||
heatexchanger1_cmnd(pos, "start")
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm)
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Cable, DOWN)
|
||||
stop_sound(pos)
|
||||
heatexchanger1_cmnd(pos, "stop")
|
||||
end
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
local data
|
||||
|
||||
if nvm.running then
|
||||
data = power.get_network_data(pos, Cable, DOWN)
|
||||
end
|
||||
return techage.storage_formspec(self, pos, nvm, S("TA4 Heat Exchanger"), data, nvm.capa, nvm.capa_max)
|
||||
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 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")
|
||||
return heatexchanger1_cmnd(pos, "volume")
|
||||
end
|
||||
local netID = networks.determine_netID(pos, Cable, DOWN)
|
||||
if heatexchanger1_cmnd(pos, "netID") ~= netID then
|
||||
return S("Power network connection error")
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -88,13 +150,14 @@ local function node_timer(pos, elapsed)
|
||||
local res = check_TES_integrity(pos, nvm)
|
||||
if res ~= true then
|
||||
State:fault(pos, nvm, res)
|
||||
he1_cmnd(pos, "stop")
|
||||
heatexchanger1_cmnd(pos, "stop")
|
||||
end
|
||||
|
||||
nvm.capa = power.get_storage_load(pos, Cable, DOWN, nvm.capa_max)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
return true
|
||||
end
|
||||
return false
|
||||
return true
|
||||
end
|
||||
|
||||
local function can_dig(pos, player)
|
||||
@ -109,16 +172,20 @@ 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 meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State:node_init(pos, nvm, "")
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
local own_num = techage.add_node(pos, "techage:heatexchanger1")
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
meta:set_string("infotext", S("TA4 Heat Exchanger")..": "..own_num)
|
||||
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||
Cable:after_place_node(pos, {DOWN})
|
||||
State:node_init(pos, nvm, own_num)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
@ -131,6 +198,14 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
local function get_storage_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.capa_max = nvm.capa_max or 0
|
||||
if nvm.running then
|
||||
return {level = (nvm.capa or 0) / nvm.capa_max, capa = nvm.capa_max}
|
||||
end
|
||||
end
|
||||
|
||||
-- Middle node with the formspec from the bottom node
|
||||
minetest.register_node("techage:heatexchanger2", {
|
||||
description = S("TA4 Heat Exchanger 2"),
|
||||
@ -154,6 +229,7 @@ minetest.register_node("techage:heatexchanger2", {
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
can_dig = can_dig,
|
||||
get_storage_data = get_storage_data,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
@ -162,6 +238,8 @@ minetest.register_node("techage:heatexchanger2", {
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
power.register_nodes({"techage:heatexchanger2"}, Cable, "sto", {"D"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:heatexchanger2",
|
||||
recipe = {
|
||||
|
@ -57,6 +57,9 @@ minetest.register_node("techage:heatexchanger3", {
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
|
||||
networks = {
|
||||
pipe2 = {},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -44,6 +44,9 @@ minetest.register_node("techage:ta4_pipe_inlet", {
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
|
||||
networks = {
|
||||
pipe2 = {},
|
||||
},
|
||||
paramtype2 = "facedir", -- important!
|
||||
on_rotate = screwdriver.disallow, -- important!
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
@ -66,13 +69,6 @@ local Numbers = {
|
||||
}
|
||||
}
|
||||
|
||||
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_diameter(pos, in_dir)
|
||||
local dir = tubelib2.Dir6dToVector[in_dir]
|
||||
local pos2, node
|
||||
@ -125,14 +121,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
|
||||
return chat(owner, "one window maximum")
|
||||
return S("one window maximum")
|
||||
elseif node_tbl["default:obsidian_glass"] + node_tbl["basic_materials:concrete_block"] ~= Numbers.shell[radius] then
|
||||
return chat(owner, "wrong number of shell nodes")
|
||||
return S("wrong number of shell nodes")
|
||||
elseif node_tbl["default:gravel"] + node_tbl["techage:glow_gravel"] ~= Numbers.filling[radius] then
|
||||
return chat(owner, "wrong number of gravel nodes")
|
||||
return S("wrong number of gravel nodes")
|
||||
end
|
||||
else
|
||||
return chat(owner, "wrong diameter (should be 5, 7, or 9)")
|
||||
return S("wrong diameter (should be 5, 7, or 9)")
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -162,8 +158,6 @@ techage.register_node({"techage:ta4_pipe_inlet"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
if topic == "diameter" then
|
||||
return get_diameter(pos, in_dir)
|
||||
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,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -18,17 +18,7 @@ local S = techage.S
|
||||
|
||||
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_heatexchanger1(pos, topic, payload)
|
||||
return techage.transfer(pos, "L", topic, payload, Pipe,
|
||||
{"techage:heatexchanger1"})
|
||||
end
|
||||
|
||||
local function transfer_generator(pos, topic, payload)
|
||||
local function generator_cmnd(pos, topic, payload)
|
||||
return techage.transfer(pos, "R", topic, payload, nil,
|
||||
{"techage:ta4_generator", "techage:ta4_generator_on"})
|
||||
end
|
||||
@ -64,21 +54,6 @@ local function stop_sound(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
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"),
|
||||
tiles = {
|
||||
@ -91,10 +66,17 @@ minetest.register_node("techage:ta4_turbine", {
|
||||
"techage_filling_ta4.png^techage_appl_turbine.png^techage_frame_ta4.png",
|
||||
},
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
|
||||
after_place_node = function(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode)
|
||||
stop_sound(pos)
|
||||
Pipe:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
networks = {
|
||||
pipe2 = {},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -131,8 +113,14 @@ minetest.register_node("techage:ta4_turbine_on", {
|
||||
},
|
||||
},
|
||||
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
swap_node(pos, "techage:ta4_turbine")
|
||||
stop_sound(pos)
|
||||
generator_cmnd(pos, "stop")
|
||||
end,
|
||||
networks = {
|
||||
pipe2 = {},
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
diggable = false,
|
||||
@ -142,31 +130,25 @@ minetest.register_node("techage:ta4_turbine_on", {
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:ta4_turbine", "techage:ta4_turbine_on"})
|
||||
Pipe:set_valid_sides("techage:ta4_turbine", {"L", "U"})
|
||||
Pipe:set_valid_sides("techage:ta4_turbine_on", {"L", "U"})
|
||||
|
||||
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 == "trigger" then -- used by heatexchanger1
|
||||
if not transfer_heatexchanger3(pos, topic, payload) then
|
||||
return 0
|
||||
end
|
||||
return transfer_generator(pos, topic, payload)
|
||||
elseif topic == "start" then -- used by generator
|
||||
if topic == "start" then -- used by heatexchanger1
|
||||
swap_node(pos, "techage:ta4_turbine_on")
|
||||
play_sound(pos)
|
||||
nvm.running = true
|
||||
return true
|
||||
elseif topic == "stop" then -- used by generator
|
||||
return generator_cmnd(pos, topic, payload)
|
||||
elseif topic == "stop" then -- used by heatexchanger1
|
||||
swap_node(pos, "techage:ta4_turbine")
|
||||
stop_sound(pos)
|
||||
nvm.running = false
|
||||
return true
|
||||
elseif topic == "state" then
|
||||
return transfer_heatexchanger1(pos, topic, payload)
|
||||
return generator_cmnd(pos, topic, payload)
|
||||
else -- used by heatexchanger1
|
||||
return generator_cmnd(pos, topic, payload)
|
||||
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
|
||||
|
70
init.lua
70
init.lua
@ -234,33 +234,33 @@ dofile(MP.."/ta3_power/axle2power.lua")
|
||||
dofile(MP.."/ta3_power/power2axle.lua")
|
||||
|
||||
-- Digtron
|
||||
--if minetest.global_exists("digtron") then
|
||||
-- dofile(MP.."/digtron/battery.lua")
|
||||
--end
|
||||
if minetest.global_exists("digtron") then
|
||||
dofile(MP.."/digtron/battery.lua")
|
||||
end
|
||||
|
||||
-- Logic
|
||||
--dofile(MP.."/logic/lib.lua")
|
||||
--dofile(MP.."/logic/terminal.lua")
|
||||
--dofile(MP.."/logic/button.lua")
|
||||
--dofile(MP.."/logic/detector.lua")
|
||||
--dofile(MP.."/logic/repeater.lua")
|
||||
--dofile(MP.."/logic/programmer.lua")
|
||||
--dofile(MP.."/logic/signallamp.lua")
|
||||
--dofile(MP.."/logic/sequencer.lua")
|
||||
--dofile(MP.."/logic/timer.lua")
|
||||
--dofile(MP.."/logic/lua_logic.lua") -- old
|
||||
--dofile(MP.."/logic/logic_block.lua") -- new
|
||||
--dofile(MP.."/logic/node_detector.lua")
|
||||
--dofile(MP.."/logic/player_detector.lua")
|
||||
--dofile(MP.."/logic/cart_detector.lua")
|
||||
--dofile(MP.."/logic/gateblock.lua")
|
||||
--dofile(MP.."/logic/doorblock.lua")
|
||||
--dofile(MP.."/logic/doorcontroller.lua") -- old
|
||||
--dofile(MP.."/logic/doorcontroller2.lua") -- new
|
||||
--dofile(MP.."/logic/collector.lua")
|
||||
--if minetest.global_exists("mesecon") then
|
||||
-- dofile(MP.."/logic/mesecons_converter.lua")
|
||||
--end
|
||||
dofile(MP.."/logic/lib.lua")
|
||||
dofile(MP.."/logic/terminal.lua")
|
||||
dofile(MP.."/logic/button.lua")
|
||||
dofile(MP.."/logic/detector.lua")
|
||||
dofile(MP.."/logic/repeater.lua")
|
||||
dofile(MP.."/logic/programmer.lua")
|
||||
dofile(MP.."/logic/signallamp.lua")
|
||||
dofile(MP.."/logic/sequencer.lua")
|
||||
dofile(MP.."/logic/timer.lua")
|
||||
dofile(MP.."/logic/lua_logic.lua") -- old
|
||||
dofile(MP.."/logic/logic_block.lua") -- new
|
||||
dofile(MP.."/logic/node_detector.lua")
|
||||
dofile(MP.."/logic/player_detector.lua")
|
||||
dofile(MP.."/logic/cart_detector.lua")
|
||||
dofile(MP.."/logic/gateblock.lua")
|
||||
dofile(MP.."/logic/doorblock.lua")
|
||||
dofile(MP.."/logic/doorcontroller.lua") -- old
|
||||
dofile(MP.."/logic/doorcontroller2.lua") -- new
|
||||
dofile(MP.."/logic/collector.lua")
|
||||
if minetest.global_exists("mesecon") then
|
||||
dofile(MP.."/logic/mesecons_converter.lua")
|
||||
end
|
||||
|
||||
-- Test
|
||||
dofile(MP.."/recipe_checker.lua")
|
||||
@ -272,18 +272,18 @@ 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/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")
|
||||
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")
|
||||
|
@ -27,4 +27,5 @@ techage.FILLING_ITEMS = {
|
||||
"default:mese",
|
||||
"default:diamondblock",
|
||||
"techage:power_pole3",
|
||||
"techage:pillar",
|
||||
}
|
@ -233,6 +233,41 @@ function techage.generator_settings(tier, available)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Still used legacy functions
|
||||
-------------------------------------------------------------------------------
|
||||
function techage.formspec_label_bar(pos, x, y, label, max_power, current_power, unit)
|
||||
local percent, ypos
|
||||
|
||||
max_power = max_power or 1
|
||||
unit = unit or "ku"
|
||||
current_power = current_power or 0
|
||||
|
||||
if current_power == 0 then
|
||||
percent = 0
|
||||
ypos = 2.8
|
||||
else
|
||||
percent = techage.power.percent(max_power, current_power)
|
||||
-- 0.4 to 2.8 = 2.4
|
||||
local offs = 2.4 - (current_power / max_power) * 2.4
|
||||
ypos = 0.4 + in_range(offs, 0.4, 2.4)
|
||||
end
|
||||
if current_power >= 100 then
|
||||
current_power = math.floor(current_power)
|
||||
end
|
||||
percent = (percent + 5) / 1.1 -- texture correction
|
||||
return "container["..x..","..y.."]"..
|
||||
"box[0,0;2.3,3.3;#395c74]"..
|
||||
"label[0.2,0;"..label.."]"..
|
||||
"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.." "..unit.."]"..
|
||||
"container_end[]"
|
||||
|
||||
end
|
||||
|
||||
function techage.evaluate_charge_termination(nvm, meta)
|
||||
local termpoint = meta:get_string("termpoint")
|
||||
if termpoint == "40% - 60%" then
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 367 B After Width: | Height: | Size: 373 B |
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -23,6 +23,8 @@ minetest.register_node("techage:pillar", {
|
||||
type = "fixed",
|
||||
fixed = {-8/32, -16/32, -8/32, 8/32, 16/32, 8/32},
|
||||
},
|
||||
climbable = true,
|
||||
walkable = false,
|
||||
paramtype = "light",
|
||||
backface_culling = true,
|
||||
groups = {cracky=1},
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 DS-Minetest, Joachim Stolberg
|
||||
Copyright (C) 2019-2021 DS-Minetest, Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -21,11 +21,13 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 70
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local Rotors = {}
|
||||
|
||||
@ -46,28 +48,35 @@ local function pos_and_yaw(pos, param2)
|
||||
return pos, {x=0, y=yaw, z=0}
|
||||
end
|
||||
|
||||
local function is_wind()
|
||||
local time = minetest.get_timeofday() or 0
|
||||
return (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00)
|
||||
end
|
||||
|
||||
local function check_rotor(pos, nvm)
|
||||
local resp, err = techage.valid_place_for_windturbine(pos, nil, 1)
|
||||
if not resp then
|
||||
M(pos):set_string("infotext", S("TA4 Wind Turbine")..": "..err)
|
||||
nvm.error = true
|
||||
nvm.error = err
|
||||
return false
|
||||
end
|
||||
|
||||
local npos = techage.get_pos(pos, "F")
|
||||
local node = techage.get_node_lvm(npos)
|
||||
if node.name ~= "techage:ta4_wind_turbine_nacelle" then
|
||||
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Nacelle is missing"))
|
||||
nvm.error = true
|
||||
nvm.error = S("Nacelle is missing")
|
||||
return false
|
||||
end
|
||||
|
||||
local own_num = M(pos):get_string("node_number") or ""
|
||||
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
|
||||
M(pos):set_string("infotext", S("TA4 Wind Turbine")..": "..own_num)
|
||||
nvm.error = false
|
||||
return true
|
||||
end
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return techage.generator_formspec(self, pos, nvm, S("TA4 Wind Turbine"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
local function add_rotor(pos, nvm)
|
||||
if check_rotor(pos, nvm) then
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
@ -82,71 +91,119 @@ local function add_rotor(pos, nvm)
|
||||
end
|
||||
end
|
||||
|
||||
local function start_rotor(pos, nvm)
|
||||
local function start_rotor(pos, nvm, state)
|
||||
if not nvm.error then
|
||||
nvm.providing = true
|
||||
local meta = M(pos)
|
||||
nvm.running = true
|
||||
nvm.delivered = 0
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, 5)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] then
|
||||
if Rotors[hash] and is_wind() then
|
||||
Rotors[hash]:set_animation_frame_speed(50)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_rotor(pos, nvm)
|
||||
nvm.providing = false
|
||||
local function stop_rotor(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.delivered = 0
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
nvm.load = 0
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] then
|
||||
Rotors[hash]:set_animation_frame_speed(0)
|
||||
end
|
||||
end
|
||||
|
||||
local function can_start(pos, nvm)
|
||||
if nvm.error then
|
||||
return nvm.error
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:ta4_wind_turbine",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
start_node = start_rotor,
|
||||
stop_node = stop_rotor,
|
||||
can_start = can_start,
|
||||
})
|
||||
|
||||
local function generating(pos, nvm)
|
||||
if is_wind() then
|
||||
if not nvm.running then
|
||||
start_rotor(pos, nvm)
|
||||
end
|
||||
return true
|
||||
else
|
||||
if nvm.running then
|
||||
stop_rotor(pos, nvm)
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
||||
if not nvm.running or nvm.error then
|
||||
if nvm.error then
|
||||
return false
|
||||
end
|
||||
|
||||
local time = minetest.get_timeofday() or 0
|
||||
if (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) then
|
||||
if not nvm.providing then
|
||||
start_rotor(pos, nvm)
|
||||
end
|
||||
if generating(pos, nvm) then
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF, tp1, tp2)
|
||||
State:keep_running(pos, nvm, 2)
|
||||
else
|
||||
if nvm.providing then
|
||||
stop_rotor(pos, nvm)
|
||||
end
|
||||
State:idle(pos, nvm)
|
||||
end
|
||||
nvm.load = power.get_storage_load(pos, Cable, 5, PWR_PERF)
|
||||
if techage.is_activeformspec(pos) then
|
||||
meta:set_string("formspec", formspec(State, 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 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))
|
||||
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
|
||||
|
||||
local function get_generator_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
|
||||
local 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)
|
||||
local number = techage.add_node(pos, "techage:ta4_wind_turbine")
|
||||
State:node_init(pos, nvm, number)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
nvm.providing = false
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
nvm.running = true
|
||||
add_rotor(pos, nvm)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function on_punch(pos, node, puncher, pointed_thing)
|
||||
if minetest.is_protected(pos, puncher:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
local nvm = techage.get_nvm(pos)
|
||||
add_rotor(pos, nvm)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] and Rotors[hash]:get_luaentity() then
|
||||
@ -158,10 +215,6 @@ local function after_dig_node(pos, oldnode, oldmetadata)
|
||||
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",
|
||||
@ -185,15 +238,39 @@ minetest.register_node("techage:ta4_wind_turbine", {
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
get_generator_data = get_generator_data,
|
||||
on_timer = node_timer,
|
||||
on_punch = on_punch,
|
||||
on_rightclick = on_rightclick,
|
||||
on_receive_fields = on_receive_fields,
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
ta4_formspec = techage.generator_settings("ta4", PWR_PERF),
|
||||
})
|
||||
|
||||
power.register_nodes({"techage:ta4_wind_turbine"}, Cable, "gen", {"D"})
|
||||
|
||||
control.register_nodes({"techage:ta4_wind_turbine"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local meta = M(pos)
|
||||
return {
|
||||
type = S("TA4 Wind Turbine"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
minetest.register_node("techage:ta4_wind_turbine_nacelle", {
|
||||
description = S("TA4 Wind Turbine Nacelle"),
|
||||
@ -222,8 +299,6 @@ minetest.register_entity("techage:rotor_ent", {initial_properties = {
|
||||
static_save = false,
|
||||
}})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:ta4_wind_turbine"})
|
||||
|
||||
techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
@ -234,7 +309,7 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
end
|
||||
if nvm.error then
|
||||
return "error"
|
||||
elseif nvm.running and nvm.providing then
|
||||
elseif nvm.running then
|
||||
return "running"
|
||||
else
|
||||
return "stopped"
|
||||
@ -252,7 +327,7 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
on_node_load = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
add_rotor(pos, nvm)
|
||||
nvm.providing = false -- to force the rotor start
|
||||
nvm.running = false -- to force the rotor start
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user