Improve power terminal
This commit is contained in:
parent
66937f5743
commit
6d9c9bb51f
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
Copyright (C) 2019-2023 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -27,10 +27,11 @@ local control = networks.control
|
||||
|
||||
local HELP = S([[Commands
|
||||
help . . . print this text
|
||||
cls . . . . . clear screen
|
||||
gen . . . . print all generators
|
||||
sto . . . . . print all storage systems
|
||||
con . . . . . print main consumers
|
||||
cls . . . . clear screen
|
||||
gen . . print generators
|
||||
sto . . print storage systems
|
||||
con1 . . print consumers with power consumption between 1 and 10 ku
|
||||
con2 . . print consumers with power consumption with 10 ku or above
|
||||
]])
|
||||
|
||||
local function row(num, label, data)
|
||||
@ -41,7 +42,6 @@ local function row(num, label, data)
|
||||
"label[8.5,"..y..";" .. data .. "]"
|
||||
end
|
||||
|
||||
|
||||
local function formspec1(pos, data)
|
||||
local mem = techage.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
@ -94,12 +94,32 @@ local function formspec2(pos)
|
||||
"button[7.9,7.4;2,1;enter;"..S("Enter").."]"
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------------
|
||||
--Overwrite networks.power.consume_power function
|
||||
--------------------------------------------------------------------------------------
|
||||
local origin_consume_power = networks.power.consume_power
|
||||
|
||||
function networks.power.consume_power(pos, tlib2, outdir, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.power_taken = origin_consume_power(pos, tlib2, outdir, amount)
|
||||
return nvm.power_taken
|
||||
end
|
||||
|
||||
local function get_consumer_power_consumption(pos)
|
||||
if pos then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running or techage.needs_power(nvm) then
|
||||
return nvm.power_taken or 0
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function generators(pos)
|
||||
local tbl = {}
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local resp = control.request(pos, Cable, outdir, "gen", "info")
|
||||
for _, item in ipairs(resp) do
|
||||
local name = item.type .. " (" .. item.number .. ")"
|
||||
if item.running then
|
||||
local s = string.format("%s (%s): %s/%u ku (%s)",
|
||||
item.type, item.number, techage.round(item.provided), item.available, item.termpoint)
|
||||
@ -119,26 +139,28 @@ local function storages(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local resp = control.request(pos, Cable, outdir, "sto", "info")
|
||||
for _, item in ipairs(resp) do
|
||||
local name = item.type .. " (" .. item.number .. ")"
|
||||
if item.running then
|
||||
local s = string.format("%s (%s): %s/%s kud",
|
||||
item.type, item.number,
|
||||
techage.round(item.load / techage.CYCLES_PER_DAY),
|
||||
techage.round(item.capa / techage.CYCLES_PER_DAY))
|
||||
tbl[#tbl + 1] = s
|
||||
else
|
||||
local s = string.format("%s (%s): %s/%s kud (off)",
|
||||
item.type, item.number,
|
||||
techage.round(item.load / techage.CYCLES_PER_DAY),
|
||||
techage.round(item.capa / techage.CYCLES_PER_DAY))
|
||||
tbl[#tbl + 1] = s
|
||||
-- TA4/TA5 heatexchangers are no storage systems
|
||||
if item.capa and item.capa > 1 then
|
||||
if item.running then
|
||||
local s = string.format("%s (%s): %s/%s kud",
|
||||
item.type, item.number,
|
||||
techage.round(item.load / techage.CYCLES_PER_DAY),
|
||||
techage.round(item.capa / techage.CYCLES_PER_DAY))
|
||||
tbl[#tbl + 1] = s
|
||||
else
|
||||
local s = string.format("%s (%s): %s/%s kud (off)",
|
||||
item.type, item.number,
|
||||
techage.round(item.load / techage.CYCLES_PER_DAY),
|
||||
techage.round(item.capa / techage.CYCLES_PER_DAY))
|
||||
tbl[#tbl + 1] = s
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(tbl)
|
||||
return table.concat(tbl, "\n")
|
||||
end
|
||||
|
||||
local function consumers(pos)
|
||||
local function consumers(pos, min, max)
|
||||
local tbl = {}
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local netw = networks.get_network_table(pos, Cable, outdir) or {}
|
||||
@ -147,7 +169,17 @@ local function consumers(pos)
|
||||
if number then
|
||||
local name = techage.get_node_lvm(item.pos).name
|
||||
name = (minetest.registered_nodes[name] or {}).description or "unknown"
|
||||
tbl[#tbl + 1] = name .. " (" .. number .. ")"
|
||||
local taken = techage.round(get_consumer_power_consumption(item.pos))
|
||||
if taken > min and taken < max then
|
||||
tbl[#tbl + 1] = string.format("%s (%s): %s ku", name, number, taken)
|
||||
end
|
||||
else
|
||||
local name = techage.get_node_lvm(item.pos).name
|
||||
name = (minetest.registered_nodes[name] or {}).description or "unknown"
|
||||
local taken = techage.round(get_consumer_power_consumption(item.pos))
|
||||
if taken > min and taken < max then
|
||||
tbl[#tbl + 1] = string.format("%s: %s ku", name, taken)
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(tbl)
|
||||
@ -157,7 +189,7 @@ end
|
||||
local function output(pos, command, text)
|
||||
local meta = M(pos)
|
||||
text = meta:get_string("output") .. "\n$ " .. command .. "\n" .. (text or "")
|
||||
text = text:sub(-2000,-1)
|
||||
text = text:sub(-5000,-1)
|
||||
meta:set_string("output", text)
|
||||
end
|
||||
|
||||
@ -177,8 +209,10 @@ local function command(pos, nvm, command)
|
||||
output(pos, command, generators(pos))
|
||||
elseif cmd == "sto" then
|
||||
output(pos, command, storages(pos))
|
||||
elseif cmd == "con" then
|
||||
output(pos, command, consumers(pos))
|
||||
elseif cmd == "con1" then
|
||||
output(pos, command, consumers(pos, 1, 10))
|
||||
elseif cmd == "con2" then
|
||||
output(pos, command, consumers(pos, 9, 1000))
|
||||
elseif command ~= "" then
|
||||
output(pos, command, "")
|
||||
end
|
||||
|
@ -23,6 +23,7 @@ local PWR_CAPA = 2400 -- ticks (2s) with 1 ku ==> 80 min = 4 game days
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
@ -46,7 +47,7 @@ local function node_timer(pos, elapsed)
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
nvm.providing = true
|
||||
else
|
||||
nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF)
|
||||
nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF, 0.8, 1.0)
|
||||
nvm.capa = nvm.capa - nvm.provided
|
||||
end
|
||||
else
|
||||
@ -105,6 +106,27 @@ minetest.register_node("techage:ta4_solar_minicell", {
|
||||
|
||||
power.register_nodes({"techage:ta4_solar_minicell"}, Cable, "gen", {"D"})
|
||||
|
||||
control.register_nodes({"techage:ta4_solar_minicell"}, {
|
||||
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 Streetlamp Solar Cell"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.providing or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = "80% - 100%",
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
techage.register_node({"techage:ta4_solar_minicell"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
Copyright (C) 2019-2023 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -21,6 +21,7 @@ local S2P = minetest.string_to_pos
|
||||
local Cable = techage.ElectricCable
|
||||
local Axle = techage.Axle
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 24
|
||||
@ -45,9 +46,7 @@ local function node_timer_on(pos, elapsed)
|
||||
nvm.buffer = nvm.buffer + taken - 1 -- some loss
|
||||
|
||||
if nvm.buffer >= PWR_PERF then
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, 0.8, 1.0)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
nvm.buffer = nvm.buffer - nvm.provided
|
||||
end
|
||||
@ -172,6 +171,27 @@ techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"},
|
||||
power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Axle, "con", {"L"})
|
||||
power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Cable, "gen", {"R"})
|
||||
|
||||
control.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local meta = M(pos)
|
||||
return {
|
||||
type = S("TA2 Power Generator"),
|
||||
number = "---",
|
||||
running = true,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = "80% - 100%",
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta2_generator_off",
|
||||
recipe = {
|
||||
|
@ -22,6 +22,7 @@ local fuel = techage.fuel
|
||||
local Pipe = techage.LiquidPipe
|
||||
local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STANDBY_TICKS = 1
|
||||
@ -327,6 +328,27 @@ local liquid_def = {
|
||||
power.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Cable, "gen", {"R"})
|
||||
liquid.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Pipe, "tank", nil, liquid_def)
|
||||
|
||||
control.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local meta = M(pos)
|
||||
return {
|
||||
type = S("TA3 Tiny Power Generator"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
Loading…
Reference in New Issue
Block a user