Add many improvements
This commit is contained in:
parent
104b1f179d
commit
3738a1659e
@ -42,7 +42,7 @@ function techage.fuel.fuel_container(x, y, nvm)
|
||||
itemname = nvm.liquid.name.." "..nvm.liquid.amount
|
||||
end
|
||||
local fuel_percent = 0
|
||||
if nvm.running then
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
|
||||
end
|
||||
return "container["..x..","..y.."]"..
|
||||
|
@ -19,6 +19,8 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
|
||||
local Tube = techage.Tube
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
if clicker and clicker:is_player() then
|
||||
if M(pos):get_int("userID") == 0 then
|
||||
@ -159,6 +161,8 @@ techage.register_node({"techage:chest_cart"}, {
|
||||
end,
|
||||
})
|
||||
|
||||
Tube:set_valid_sides("techage:chest_cart", {"L", "R", "F", "B"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:chest_cart",
|
||||
recipe = {
|
||||
|
@ -18,9 +18,9 @@ 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 Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
|
||||
local liquid = networks.liquid
|
||||
local CAPACITY = 100
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
@ -30,7 +30,7 @@ local function on_rightclick(pos, node, clicker)
|
||||
else
|
||||
local nvm = techage.get_nvm(pos)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
end
|
||||
end
|
||||
@ -39,50 +39,48 @@ end
|
||||
local function node_timer(pos, elapsed)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function take_liquid(pos, indir, name, amount)
|
||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local function peek_liquid(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
end
|
||||
return amount, name
|
||||
return liquid.srv_peek(nvm)
|
||||
end
|
||||
|
||||
local function untake_liquid(pos, indir, name, amount)
|
||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local function take_liquid(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
amount, name = liquid.srv_take(nvm, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
return amount, name
|
||||
end
|
||||
|
||||
local function put_liquid(pos, indir, name, amount)
|
||||
-- check if it is not powder
|
||||
local ndef = minetest.registered_craftitems[name] or {}
|
||||
if not ndef.groups or ndef.groups.powder ~= 1 then
|
||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
local networks_def = {
|
||||
pipe2 = {
|
||||
sides = {U = 1}, -- Pipe connection side
|
||||
ntype = "tank",
|
||||
},
|
||||
}
|
||||
local function untake_liquid(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
|
||||
minetest.register_node("techage:tank_cart", {
|
||||
description = S("TA Tank Cart"),
|
||||
@ -119,7 +117,7 @@ minetest.register_node("techage:tank_cart", {
|
||||
after_place_node = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end,
|
||||
|
||||
set_cargo = function(pos, data)
|
||||
@ -135,26 +133,24 @@ minetest.register_node("techage:tank_cart", {
|
||||
end,
|
||||
|
||||
has_cargo = function(pos)
|
||||
return not liquid.is_empty(pos)
|
||||
return not techage.liquid.is_empty(pos)
|
||||
end,
|
||||
|
||||
on_timer = node_timer,
|
||||
|
||||
liquid = {
|
||||
capa = CAPACITY,
|
||||
peek = liquid.srv_peek,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
untake = untake_liquid,
|
||||
},
|
||||
networks = networks_def,
|
||||
on_rightclick = on_rightclick,
|
||||
})
|
||||
|
||||
techage.register_node({"techage:tank_cart"}, liquid.recv_message)
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:tank_cart"})
|
||||
techage.register_node({"techage:tank_cart"}, techage.liquid.recv_message)
|
||||
|
||||
liquid.register_nodes({"techage:tank_cart"},
|
||||
Pipe, "tank", {"U"}, {
|
||||
capa = CAPACITY,
|
||||
peek = peek_liquid,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
untake = untake_liquid,
|
||||
}
|
||||
)
|
||||
|
||||
minecart.register_cart_entity("techage:tank_cart_entity", "techage:tank_cart", "tank", {
|
||||
initial_properties = {
|
||||
|
@ -16,17 +16,17 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 80
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local PWR_PERF = 80
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return techage.generator_formspec(self, pos, nvm, S("Generator"), nvm.provided, PWR_CAPA)
|
||||
return techage.generator_formspec(self, pos, nvm, S("Generator"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
local function transfer_turbine(pos, topic, payload)
|
||||
@ -38,19 +38,24 @@ local function can_start(pos, nvm, state)
|
||||
return (nvm.firebox_trigger or 0) > 0 -- by means of firebox
|
||||
end
|
||||
|
||||
local function has_fire(nvm)
|
||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||
return nvm.firebox_trigger > 0
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
techage.evaluate_charge_termination(nvm, M(pos))
|
||||
local meta = M(pos)
|
||||
nvm.provided = 0
|
||||
local outdir = meta:get_int("outdir")
|
||||
transfer_turbine(pos, "start")
|
||||
nvm.running = true
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
transfer_turbine(pos, "stop")
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
@ -67,23 +72,29 @@ local State = techage.NodeStates:new({
|
||||
})
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||
if nvm.firebox_trigger <= 0 then
|
||||
State:nopower(pos, nvm)
|
||||
local running = techage.is_running(nvm)
|
||||
local fire = has_fire(nvm)
|
||||
if running and not fire then
|
||||
State:standby(pos, nvm)
|
||||
stop_node(pos, nvm, State)
|
||||
transfer_turbine(pos, "stop")
|
||||
else
|
||||
elseif not running and fire then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_CAPA, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
local val = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
@ -108,7 +119,6 @@ local function after_place_node(pos)
|
||||
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))
|
||||
techage.evaluate_charge_termination(nvm, M(pos))
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
@ -119,8 +129,8 @@ 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_CAPA, perf = PWR_CAPA, capa = PWR_CAPA * 2}
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
|
||||
@ -142,7 +152,7 @@ minetest.register_node("techage:generator", {
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
@ -187,7 +197,7 @@ minetest.register_node("techage:generator_on", {
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
@ -206,8 +216,8 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "trigger" then
|
||||
nvm.firebox_trigger = 3
|
||||
if nvm.running then
|
||||
return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.02)
|
||||
if techage.is_running(nvm) then
|
||||
return math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.02)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
@ -234,8 +244,8 @@ control.register_nodes({"techage:generator", "techage:generator_on"}, {
|
||||
return {
|
||||
type = S("TA3 Generator"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
available = PWR_CAPA,
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ local S = techage.S
|
||||
local Cable = techage.ElectricCable
|
||||
local Pipe = techage.LiquidPipe
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local GRVL_CAPA = 500
|
||||
@ -37,6 +38,12 @@ local function heatexchanger1_cmnd(pos, topic, payload)
|
||||
{"techage:heatexchanger1"})
|
||||
end
|
||||
|
||||
local function heatexchanger3_cmnd(pos, topic, payload)
|
||||
return techage.transfer({x = pos.x, y = pos.y + 1, z = pos.z},
|
||||
nil, topic, payload, nil,
|
||||
{"techage:heatexchanger3"})
|
||||
end
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
@ -77,6 +84,7 @@ local function can_start(pos, nvm)
|
||||
if diameter then
|
||||
nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0
|
||||
if nvm.capa_max ~= 0 then
|
||||
nvm.capa = math.min(nvm.capa, nvm.capa_max)
|
||||
local owner = M(pos):get_string("owner") or ""
|
||||
return heatexchanger1_cmnd(pos, "volume", owner)
|
||||
else
|
||||
@ -89,7 +97,6 @@ local function can_start(pos, nvm)
|
||||
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)
|
||||
@ -97,7 +104,6 @@ local function start_node(pos, nvm)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm)
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Cable, DOWN)
|
||||
stop_sound(pos)
|
||||
heatexchanger1_cmnd(pos, "stop")
|
||||
@ -106,7 +112,7 @@ end
|
||||
local function formspec(self, pos, nvm)
|
||||
local data
|
||||
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) 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)
|
||||
@ -124,13 +130,25 @@ end
|
||||
|
||||
local function check_TES_integrity(pos, nvm)
|
||||
nvm.ticks = (nvm.ticks or 0) + 1
|
||||
if (nvm.ticks % 100) == 0 then -- not to often
|
||||
if (nvm.ticks % 30) == 0 then -- every minute
|
||||
return heatexchanger1_cmnd(pos, "volume")
|
||||
end
|
||||
if (nvm.ticks % 30) == 10 then -- every minute
|
||||
return heatexchanger3_cmnd(pos, "diameter") ~= nil or S("inlet/pipe error")
|
||||
end
|
||||
if (nvm.ticks % 30) == 20 then -- every minute
|
||||
return heatexchanger3_cmnd(pos, "diameter") ~= nil or S("inlet/pipe error")
|
||||
end
|
||||
local netID = networks.determine_netID(pos, Cable, DOWN)
|
||||
if heatexchanger1_cmnd(pos, "netID") ~= netID then
|
||||
if nvm.check_once_again then
|
||||
nvm.check_once_again = false
|
||||
return true
|
||||
else
|
||||
return S("Power network connection error")
|
||||
end
|
||||
end
|
||||
nvm.check_once_again = true
|
||||
return true
|
||||
end
|
||||
|
||||
@ -151,9 +169,15 @@ local function node_timer(pos, elapsed)
|
||||
if res ~= true then
|
||||
State:fault(pos, nvm, res)
|
||||
heatexchanger1_cmnd(pos, "stop")
|
||||
power.start_storage_calc(pos, Cable, DOWN)
|
||||
end
|
||||
|
||||
nvm.capa = power.get_storage_load(pos, Cable, DOWN, nvm.capa_max)
|
||||
if techage.is_running(nvm) then
|
||||
local capa = power.get_storage_load(pos, Cable, DOWN, nvm.capa_max) or 0
|
||||
if capa > 0 then
|
||||
nvm.capa = capa
|
||||
end
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
@ -165,7 +189,7 @@ local function can_dig(pos, player)
|
||||
return false
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return not nvm.running
|
||||
return not techage.is_running(nvm)
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
@ -188,6 +212,11 @@ local function after_place_node(pos, placer)
|
||||
State:node_init(pos, nvm, own_num)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
@ -200,8 +229,8 @@ 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
|
||||
nvm.capa_max = nvm.capa_max or 1
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.capa or 0) / nvm.capa_max, capa = nvm.capa_max}
|
||||
end
|
||||
end
|
||||
@ -229,6 +258,7 @@ minetest.register_node("techage:heatexchanger2", {
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
can_dig = can_dig,
|
||||
after_dig_node = after_dig_node,
|
||||
get_storage_data = get_storage_data,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
@ -240,6 +270,79 @@ minetest.register_node("techage:heatexchanger2", {
|
||||
|
||||
power.register_nodes({"techage:heatexchanger2"}, Cable, "sto", {"D"})
|
||||
|
||||
techage.register_node({"techage:heatexchanger2"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "state" then
|
||||
if techage.is_running(nvm) then
|
||||
return "running"
|
||||
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
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos, node)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if techage.is_running(nvm) then
|
||||
play_sound(pos)
|
||||
else
|
||||
stop_sound(pos)
|
||||
end
|
||||
-- convert to v1
|
||||
if not nvm.capa_max then
|
||||
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
local nvm1 = techage.get_nvm(pos1)
|
||||
nvm.capa_max = nvm1.capa_max or 1
|
||||
nvm.capa = nvm1.capa or 0
|
||||
|
||||
local own_num = techage.add_node(pos, "techage:heatexchanger2")
|
||||
State:node_init(pos, nvm, own_num)
|
||||
if nvm1.running then
|
||||
State:start(pos, nvm)
|
||||
end
|
||||
M(pos):set_string("owner", M(pos1):get_string("owner"))
|
||||
M(pos):set_string("infotext", S("TA4 Heat Exchanger")..": "..own_num)
|
||||
|
||||
M(pos1):set_string("node_number", "")
|
||||
M(pos1):set_string("infotext", "")
|
||||
techage.del_mem(pos1)
|
||||
Cable:after_place_node(pos)
|
||||
Cable:after_place_node(pos1)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
control.register_nodes({"techage:heatexchanger2"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return {
|
||||
type = S("TA4 Heat Exchanger"),
|
||||
number = M(pos):get_string("node_number") or "",
|
||||
running = techage.is_running(nvm) or false,
|
||||
capa = nvm.capa_max or 1,
|
||||
load = nvm.capa or 0,
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:heatexchanger2",
|
||||
recipe = {
|
||||
|
@ -42,6 +42,11 @@ local function after_dig_node(pos, oldnode)
|
||||
Pipe:after_dig_node(pos)
|
||||
end
|
||||
|
||||
local function inlet_cmnd(pos, topic, payload)
|
||||
return techage.transfer(pos, "L", topic, payload, Pipe,
|
||||
{"techage:ta4_pipe_inlet"})
|
||||
end
|
||||
|
||||
minetest.register_node("techage:heatexchanger3", {
|
||||
description = S("TA4 Heat Exchanger 3"),
|
||||
tiles = {
|
||||
@ -69,10 +74,11 @@ minetest.register_node("techage:heatexchanger3", {
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:heatexchanger3"})
|
||||
|
||||
-- command interface, used by heatexchanger2
|
||||
techage.register_node({"techage:heatexchanger3"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
return true
|
||||
end
|
||||
on_transfer = function(pos, indir, topic, payload)
|
||||
return inlet_cmnd(pos, topic, payload)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -35,7 +35,7 @@ local function formspec(self, pos, nvm)
|
||||
local amount = (nvm.liquid and nvm.liquid.amount) or 0
|
||||
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
|
||||
local arrow = "image[3,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
arrow = "image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||
end
|
||||
if amount > 0 then
|
||||
@ -65,14 +65,12 @@ local function can_start(pos, nvm, state)
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
nvm.running = true
|
||||
nvm.taken = 0
|
||||
nvm.reduction = evaluate_percent(M(pos):get_string("reduction"))
|
||||
nvm.turnoff = evaluate_percent(M(pos):get_string("turnoff"))
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.taken = 0
|
||||
end
|
||||
|
||||
@ -91,7 +89,6 @@ local State = techage.NodeStates:new({
|
||||
local function generating(pos, nvm)
|
||||
nvm.num_pwr_units = nvm.num_pwr_units or 0
|
||||
nvm.countdown = nvm.countdown or 0
|
||||
--print("electrolyzer", nvm.running, nvm.taken, nvm.num_pwr_units, nvm.liquid.amount)
|
||||
if nvm.taken > 0 then
|
||||
nvm.num_pwr_units = nvm.num_pwr_units + (nvm.taken or 0)
|
||||
if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then
|
||||
@ -115,12 +112,13 @@ local function node_timer(pos, elapsed)
|
||||
if curr_load > (nvm.turnoff or 0) then
|
||||
local to_be_taken = PWR_NEEDED * (nvm.reduction or 1)
|
||||
nvm.taken = power.consume_power(pos, Cable, in_dir, to_be_taken) or 0
|
||||
generating(pos, nvm)
|
||||
if not nvm.running and nvm.taken == to_be_taken then
|
||||
local running = techage.is_running(nvm)
|
||||
if not running and nvm.taken == to_be_taken then
|
||||
State:start(pos, nvm)
|
||||
elseif nvm.running and nvm.taken < to_be_taken then
|
||||
elseif running and nvm.taken < to_be_taken then
|
||||
State:nopower(pos, nvm)
|
||||
else
|
||||
elseif running then
|
||||
generating(pos, nvm)
|
||||
State:keep_running(pos, nvm, 1)
|
||||
end
|
||||
elseif curr_load == 0 then
|
||||
@ -130,7 +128,6 @@ local function node_timer(pos, elapsed)
|
||||
end
|
||||
else
|
||||
State:blocked(pos, nvm, S("Storage full"))
|
||||
power.consumer_stop(pos, Cable)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
@ -194,6 +191,7 @@ local tool_config = {
|
||||
name = "reduction",
|
||||
label = S("Power reduction"),
|
||||
tooltip = S("The reduced amount of power\nthe consumer should consume"),
|
||||
default = "100%",
|
||||
},
|
||||
{
|
||||
type = "dropdown",
|
||||
@ -201,6 +199,7 @@ local tool_config = {
|
||||
name = "turnoff",
|
||||
label = S("Turnoff point"),
|
||||
tooltip = S("If the load of the storage system\nreaches the configured value,\nthe consumer will be switched off"),
|
||||
default = "0%",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 2
|
||||
local PWR_PERF = 34
|
||||
local PWR_UNITS_PER_HYDROGEN_ITEM = 75
|
||||
local CAPACITY = 100
|
||||
@ -32,7 +33,7 @@ local function formspec(self, pos, nvm)
|
||||
local amount = (nvm.liquid and nvm.liquid.amount) or 0
|
||||
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
|
||||
local arrow = "image[2,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
arrow = "image[2,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||
end
|
||||
if amount > 0 then
|
||||
@ -51,20 +52,6 @@ local function formspec(self, pos, nvm)
|
||||
techage.formspec_power_bar(pos, 3.5, 0.8, S("Electricity"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
nvm.running = true
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local function has_hydrogen(nvm)
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
||||
@ -79,6 +66,29 @@ local function can_start(pos, nvm, state)
|
||||
return S("no hydrogen")
|
||||
end
|
||||
|
||||
|
||||
local function consuming(pos, nvm)
|
||||
if nvm.num_pwr_units <= 0 then
|
||||
nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
|
||||
nvm.liquid.amount = nvm.liquid.amount - 1
|
||||
end
|
||||
nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local meta = M(pos)
|
||||
nvm.provided = 0
|
||||
local outdir = meta:get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:ta4_fuelcell",
|
||||
node_name_active = "techage:ta4_fuelcell_on",
|
||||
@ -91,36 +101,33 @@ local State = techage.NodeStates:new({
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
|
||||
local function consuming(pos, nvm)
|
||||
if nvm.num_pwr_units <= 0 then
|
||||
nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM
|
||||
nvm.liquid.amount = nvm.liquid.amount - 1
|
||||
end
|
||||
nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided
|
||||
end
|
||||
|
||||
-- converts hydrogen into power
|
||||
local function node_timer(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
--print("fuelcell", nvm.running, nvm.provided, nvm.num_pwr_units)
|
||||
if has_hydrogen(nvm) then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local running = techage.is_running(nvm)
|
||||
local hydro = has_hydrogen(nvm)
|
||||
if running and not hydro then
|
||||
State:standby(pos, nvm, S("no hydrogen"))
|
||||
stop_node(pos, nvm, State)
|
||||
elseif not running and hydro then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
local val = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
consuming(pos, nvm)
|
||||
State:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS?
|
||||
else
|
||||
State:standby(pos, nvm)
|
||||
nvm.provided = 0
|
||||
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 true
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
@ -129,7 +136,6 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
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 on_rightclick(pos, node, clicker)
|
||||
@ -140,12 +146,11 @@ end
|
||||
|
||||
local function after_place_node(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.running = false
|
||||
nvm.num_pwr_units = 0
|
||||
local number = techage.add_node(pos, "techage:ta4_fuelcell")
|
||||
State:node_init(pos, nvm, number)
|
||||
local node = minetest.get_node(pos)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
Pipe:after_place_node(pos)
|
||||
Cable:after_place_node(pos)
|
||||
local inv = M(pos):get_inventory()
|
||||
@ -161,7 +166,7 @@ end
|
||||
|
||||
local function get_generator_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
@ -310,7 +315,7 @@ control.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, {
|
||||
return {
|
||||
type = S("TA4 Fuel Cell"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
|
32
init.lua
32
init.lua
@ -297,23 +297,23 @@ dofile(MP.."/hydrogen/electrolyzer.lua")
|
||||
dofile(MP.."/hydrogen/fuelcell.lua")
|
||||
|
||||
-- ICTA Controller
|
||||
--dofile(MP.."/icta_controller/submenu.lua")
|
||||
--dofile(MP.."/icta_controller/condition.lua")
|
||||
--dofile(MP.."/icta_controller/action.lua")
|
||||
--dofile(MP.."/icta_controller/formspec.lua")
|
||||
--dofile(MP.."/icta_controller/controller.lua")
|
||||
--dofile(MP.."/icta_controller/commands.lua")
|
||||
--dofile(MP.."/icta_controller/edit.lua")
|
||||
--dofile(MP.."/icta_controller/battery.lua")
|
||||
--dofile(MP.."/icta_controller/display.lua")
|
||||
--dofile(MP.."/icta_controller/signaltower.lua")
|
||||
dofile(MP.."/icta_controller/submenu.lua")
|
||||
dofile(MP.."/icta_controller/condition.lua")
|
||||
dofile(MP.."/icta_controller/action.lua")
|
||||
dofile(MP.."/icta_controller/formspec.lua")
|
||||
dofile(MP.."/icta_controller/controller.lua")
|
||||
dofile(MP.."/icta_controller/commands.lua")
|
||||
dofile(MP.."/icta_controller/edit.lua")
|
||||
dofile(MP.."/icta_controller/battery.lua")
|
||||
dofile(MP.."/icta_controller/display.lua")
|
||||
dofile(MP.."/icta_controller/signaltower.lua")
|
||||
|
||||
-- Lua Controller
|
||||
dofile(MP.."/lua_controller/controller.lua")
|
||||
--dofile(MP.."/lua_controller/commands.lua")
|
||||
--dofile(MP.."/lua_controller/server.lua")
|
||||
--dofile(MP.."/lua_controller/sensorchest.lua")
|
||||
--dofile(MP.."/lua_controller/terminal.lua")
|
||||
dofile(MP.."/lua_controller/commands.lua")
|
||||
dofile(MP.."/lua_controller/server.lua")
|
||||
dofile(MP.."/lua_controller/sensorchest.lua")
|
||||
dofile(MP.."/lua_controller/terminal.lua")
|
||||
|
||||
-- Items
|
||||
dofile(MP.."/items/registered_nodes.lua")
|
||||
@ -340,8 +340,8 @@ dofile(MP.."/items/basalt.lua")
|
||||
dofile(MP.."/items/moreblocks.lua")
|
||||
|
||||
-- Carts
|
||||
--dofile(MP.."/carts/tank_cart.lua")
|
||||
--dofile(MP.."/carts/chest_cart.lua")
|
||||
dofile(MP.."/carts/tank_cart.lua")
|
||||
dofile(MP.."/carts/chest_cart.lua")
|
||||
|
||||
|
||||
-- Prevent other mods from using IE
|
||||
|
@ -17,12 +17,11 @@ local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local networks = techage.networks
|
||||
local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
|
||||
local CYCLE_TIME = 4
|
||||
local CYCLE_TIME = 2
|
||||
local STANDBY_TICKS = 3
|
||||
local COUNTDOWN_TICKS = 3
|
||||
local PWR_NEEDED = 4
|
||||
@ -51,12 +50,11 @@ local function can_start(pos, nvm, state)
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
||||
nvm.running = true
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
power.consumer_stop(pos, Cable)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -70,30 +68,31 @@ local State = techage.NodeStates:new({
|
||||
stop_node = stop_node,
|
||||
})
|
||||
|
||||
local function on_power(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State:start(pos, nvm)
|
||||
nvm.running = true
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local function has_power(pos, nvm)
|
||||
local outdir = networks.Flip[M(pos):get_int("waterdir")]
|
||||
local taken = power.consume_power(pos, Cable, outdir, PWR_NEEDED)
|
||||
if techage.is_running(nvm) then
|
||||
if taken < PWR_NEEDED then
|
||||
State:nopower(pos, nvm)
|
||||
nvm.running = false
|
||||
else
|
||||
return true -- keep running
|
||||
end
|
||||
elseif taken == PWR_NEEDED then
|
||||
State:start(pos, nvm)
|
||||
end
|
||||
end
|
||||
|
||||
local function pumping(pos, nvm)
|
||||
if techage.needs_power(nvm) then
|
||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
end
|
||||
if nvm.running then
|
||||
if has_power(pos, nvm) then
|
||||
nvm.ticks = (nvm.ticks or 0) + 1
|
||||
if nvm.ticks % 4 == 0 then
|
||||
local leftover = liquid.put(pos, Pipe, 6, "techage:water", 1)
|
||||
if leftover and leftover > 0 then
|
||||
State:blocked(pos, nvm)
|
||||
return
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
return
|
||||
end
|
||||
State:keep_running(pos, nvm, 1)
|
||||
end
|
||||
end
|
||||
|
||||
@ -129,28 +128,6 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
--local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
-- if tlib2.tube_type == "pipe2" then
|
||||
-- liquid.update_network(pos, outdir, tlib2)
|
||||
-- else
|
||||
-- power.update_network(pos, outdir, tlib2)
|
||||
-- end
|
||||
--end
|
||||
|
||||
local netw_def = {
|
||||
pipe2 = {
|
||||
sides = {U = 1}, -- Pipe connection sides
|
||||
ntype = "pump",
|
||||
},
|
||||
ele1 = {
|
||||
sides = {L = 1}, -- Cable connection sides
|
||||
ntype = "con1",
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
nominal = PWR_NEEDED,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:t4_waterpump", {
|
||||
description = S("TA4 Water Pump"),
|
||||
tiles = {
|
||||
@ -165,8 +142,6 @@ minetest.register_node("techage:t4_waterpump", {
|
||||
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
--tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = netw_def,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_timer = node_timer,
|
||||
|
||||
@ -176,21 +151,11 @@ minetest.register_node("techage:t4_waterpump", {
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:t4_waterpump"})
|
||||
Pipe:add_secondary_node_names({"techage:t4_waterpump"})
|
||||
power.register_nodes({"techage:t4_waterpump"}, Cable, "con", {"L"})
|
||||
liquid.register_nodes({"techage:t4_waterpump"}, Pipe, "pump", {"U"}, {})
|
||||
|
||||
techage.register_node({"techage:t4_waterpump"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
return State:on_receive_message(pos, topic, payload)
|
||||
end,
|
||||
})
|
||||
|
||||
--minetest.register_craft({
|
||||
-- output = "techage:t4_waterpump",
|
||||
-- recipe = {
|
||||
-- {"", "default:mese_crystal", ""},
|
||||
-- {"", "techage:ta3_liquidsampler_pas", ""},
|
||||
-- {"", "techage:ta4_wlanchip", ""},
|
||||
-- },
|
||||
--})
|
||||
|
||||
|
2
mod.conf
2
mod.conf
@ -1,4 +1,4 @@
|
||||
name = techage
|
||||
depends = default,doors,flowers,tubelib2,networks,basic_materials,bucket,stairs,screwdriver,minecart,lcdlib,safer_lua
|
||||
optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay,moreblocks,autobahn
|
||||
optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay,moreblocks
|
||||
description = Techage, go through 4 tech ages in search of wealth and power!
|
||||
|
@ -121,7 +121,7 @@ local function on_timer(pos)
|
||||
new_state(pos, nvm, techage.RUNNING)
|
||||
end
|
||||
else
|
||||
nvm.waiting_cycles = nvm.waiting_cycles - 1
|
||||
nvm.waiting_cycles = (nvm.waiting_cycles or 0) - 1
|
||||
if nvm.waiting_cycles <= 0 then
|
||||
new_state(pos, nvm, techage.STANDBY)
|
||||
end
|
||||
@ -267,6 +267,7 @@ techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
|
||||
if node.name == "techage:ta3_reboiler_on" then
|
||||
play_sound(pos)
|
||||
end
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -85,7 +85,7 @@ end
|
||||
|
||||
local function storage_bar(current_power, max_power)
|
||||
local percent, ypos
|
||||
max_power = (max_power or 0) / CYCLES_PER_DAY
|
||||
max_power = (max_power or 1) / CYCLES_PER_DAY
|
||||
current_power = (current_power or 0) / CYCLES_PER_DAY
|
||||
|
||||
if current_power == 0 then
|
||||
@ -121,7 +121,7 @@ end
|
||||
|
||||
function techage.formspec_charging_bar(pos, x, y, label, data)
|
||||
local charging = 0
|
||||
local percent = 0
|
||||
local percent = 50
|
||||
local consumed = 0
|
||||
local available = 0
|
||||
|
||||
@ -205,6 +205,7 @@ function techage.generator_settings(tier, available)
|
||||
name = "termpoint",
|
||||
label = S("Charge termination"),
|
||||
tooltip = S("Range in which the generator reduces its power"),
|
||||
default = "80% - 100%",
|
||||
},
|
||||
}
|
||||
else
|
||||
@ -228,6 +229,7 @@ function techage.generator_settings(tier, available)
|
||||
name = "termpoint",
|
||||
label = S("Charge termination"),
|
||||
tooltip = S("Range in which the generator reduces its power"),
|
||||
default = "80% - 100%",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
@ -28,10 +28,8 @@ local control = networks.control
|
||||
local HELP = S([[Commands
|
||||
help . . . print this text
|
||||
cls . . . . . clear screen
|
||||
gen . . . . output all generators
|
||||
sto . . . . . output all storage systems
|
||||
load . . . . output storage load values
|
||||
rst . . . . . . reset storage min/max values
|
||||
gen . . . . print all generators
|
||||
sto . . . . . print all storage systems
|
||||
]])
|
||||
|
||||
local function row(num, label, data)
|
||||
@ -51,11 +49,8 @@ local function formspec1(pos, data)
|
||||
|
||||
mem.star = ((mem.star or 0) + 1) % 2
|
||||
local star = mem.star == 1 and "*" or ""
|
||||
--local state = get_state(netw, gen1, gen2, con1, con2)
|
||||
local state = "tbd"
|
||||
local storage_provided = math.max(data.consumed - data.available, 0)
|
||||
local available = math.max(data.consumed, data.available)
|
||||
print(data.provided, data.consumed, data.curr_load)
|
||||
|
||||
return "size[10,8]"..
|
||||
"tabheader[0,0;tab;status,console;1;;true]"..
|
||||
@ -142,38 +137,6 @@ local function storages(pos)
|
||||
return table.concat(tbl, "\n")
|
||||
end
|
||||
|
||||
local function determine_min_max(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local data = power.get_network_data(pos, Cable, outdir)
|
||||
if data then
|
||||
nvm.min_load = math.min(nvm.min_load or 0, data.curr_load)
|
||||
nvm.max_load = math.max(nvm.max_load or 0, data.curr_load)
|
||||
return data
|
||||
end
|
||||
end
|
||||
|
||||
local function storage_load(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local data = power.get_network_data(pos, Cable, outdir)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.min_load = nvm.min_load or data.curr_load
|
||||
nvm.max_load = nvm.max_load or data.curr_load
|
||||
|
||||
return string.format("load: %s/%s kud, min: %s kud, max: %s kud)",
|
||||
techage.round(data.curr_load / techage.CYCLES_PER_DAY),
|
||||
techage.round(data.max_capa / techage.CYCLES_PER_DAY),
|
||||
techage.round(nvm.min_load / techage.CYCLES_PER_DAY),
|
||||
techage.round(nvm.max_load / techage.CYCLES_PER_DAY))
|
||||
end
|
||||
|
||||
local function storage_reset(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.min_load = nil
|
||||
nvm.max_load = nil
|
||||
return "done."
|
||||
end
|
||||
|
||||
local function output(pos, command, text)
|
||||
local meta = M(pos)
|
||||
text = meta:get_string("output") .. "\n$ " .. command .. "\n" .. (text or "")
|
||||
@ -197,10 +160,6 @@ local function command(pos, nvm, command)
|
||||
output(pos, command, generators(pos))
|
||||
elseif cmd == "sto" then
|
||||
output(pos, command, storages(pos))
|
||||
elseif cmd == "load" then
|
||||
output(pos, command, storage_load(pos))
|
||||
elseif cmd == "rst" then
|
||||
output(pos, command, storage_reset(pos))
|
||||
elseif command ~= "" then
|
||||
output(pos, command, "")
|
||||
end
|
||||
@ -247,8 +206,9 @@ minetest.register_node("techage:ta3_power_terminal", {
|
||||
end
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local data = determine_min_max(pos)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local data = power.get_network_data(pos, Cable, outdir)
|
||||
M(pos):set_string("formspec", formspec1(pos, data))
|
||||
return true
|
||||
end
|
||||
|
@ -25,6 +25,7 @@ local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 100
|
||||
local COUNTDOWN_TICKS = 1
|
||||
|
||||
local function determine_power(pos, nvm)
|
||||
-- determine DC node position
|
||||
@ -44,12 +45,12 @@ local function determine_power(pos, nvm)
|
||||
return max_power, num_inv
|
||||
end
|
||||
|
||||
local function determine_power_from_time_to_time(pos, nvm)
|
||||
local function has_dc_power(pos, nvm)
|
||||
local time = minetest.get_timeofday() or 0
|
||||
if time < 6.00/24.00 or time > 18.00/24.00 then
|
||||
nvm.ticks = 0
|
||||
nvm.max_power = 0
|
||||
return
|
||||
return false
|
||||
end
|
||||
nvm.ticks = nvm.ticks or 0
|
||||
if (nvm.ticks % 30) == 0 then -- calculate max_power not to often
|
||||
@ -58,13 +59,14 @@ local function determine_power_from_time_to_time(pos, nvm)
|
||||
nvm.max_power = nvm.max_power or 0
|
||||
end
|
||||
nvm.ticks = nvm.ticks + 1
|
||||
return nvm.max_power > 0
|
||||
end
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
local max_power = nvm.max_power or 0
|
||||
local provided = nvm.provided or 0
|
||||
local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
|
||||
end
|
||||
return "size[6,4]"..
|
||||
@ -82,23 +84,21 @@ end
|
||||
|
||||
local function can_start(pos, nvm, state)
|
||||
local max_power, num_inverter = determine_power(pos, nvm)
|
||||
if num_inverter > 1 then return "solar network error" end
|
||||
if max_power == 0 then return "no solar power" end
|
||||
if num_inverter > 1 then return S("solar network error") end
|
||||
if max_power == 0 then return S("no solar power") end
|
||||
return true
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local meta = M(pos)
|
||||
nvm.running = true
|
||||
nvm.provided = 0
|
||||
nvm.ticks = 0
|
||||
local outdir = meta:get_int("outdir")
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
@ -116,21 +116,31 @@ local State = techage.NodeStates:new({
|
||||
})
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
determine_power_from_time_to_time(pos, nvm)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local running = techage.is_running(nvm)
|
||||
local has_power = has_dc_power(pos, nvm)
|
||||
if running and not has_power then
|
||||
State:standby(pos, nvm)
|
||||
stop_node(pos, nvm, State)
|
||||
elseif not running and has_power then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
if nvm.max_power and nvm.max_power > 0 then
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, nvm.max_power, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, nvm.max_power)
|
||||
local val = power.get_storage_load(pos, Cable, outdir, nvm.max_power)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
State:trigger_state(pos, nvm)
|
||||
return true
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
|
||||
local function on_receive_fields(pos, formname, fields, player)
|
||||
@ -139,10 +149,6 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
|
||||
if fields.update then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
@ -154,7 +160,7 @@ end
|
||||
|
||||
local function get_generator_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / nvm.max_power, perf = nvm.max_power, capa = nvm.max_power * 2}
|
||||
end
|
||||
end
|
||||
@ -223,7 +229,7 @@ control.register_nodes({"techage:ta4_solar_inverter"}, {
|
||||
return {
|
||||
type = S("TA4 Solar Inverter"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = nvm.max_power or 0,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
@ -242,12 +248,3 @@ minetest.register_craft({
|
||||
{'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-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -22,7 +22,7 @@ local PWR_PERF = 1
|
||||
local PWR_CAPA = 2400 -- ticks (2s) with 1 ku ==> 80 min = 4 game days
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local power = networks.power
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
@ -34,7 +34,6 @@ local function node_timer(pos, elapsed)
|
||||
|
||||
if t > 0.25 and t < 0.75 then
|
||||
if nvm.providing then
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
nvm.providing = false
|
||||
nvm.provided = 0
|
||||
end
|
||||
@ -44,14 +43,14 @@ local function node_timer(pos, elapsed)
|
||||
else
|
||||
if nvm.capa > 0 then
|
||||
if not nvm.providing then
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, 5)
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
nvm.providing = true
|
||||
else
|
||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, 5)
|
||||
nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF)
|
||||
nvm.capa = nvm.capa - nvm.provided
|
||||
end
|
||||
else
|
||||
power.generator_stop(pos, Cable, 5)
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
nvm.providing = false
|
||||
nvm.provided = 0
|
||||
nvm.capa = 0
|
||||
@ -78,18 +77,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
|
||||
|
||||
local net_def = {
|
||||
ele1 = {
|
||||
sides = {D = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_PERF,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:ta4_solar_minicell", {
|
||||
description = S("TA4 Streetlamp Solar Cell"),
|
||||
tiles = {
|
||||
@ -114,11 +101,9 @@ minetest.register_node("techage:ta4_solar_minicell", {
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
on_timer = node_timer,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:ta4_solar_minicell"})
|
||||
power.register_nodes({"techage:ta4_solar_minicell"}, Cable, "gen", {"D"})
|
||||
|
||||
techage.register_node({"techage:ta4_solar_minicell"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
|
@ -47,7 +47,6 @@ local function start_node(pos, nvm, state)
|
||||
switch_axles(pos, true)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
transfer_cylinder(pos, "start")
|
||||
nvm.running = true
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end
|
||||
|
||||
@ -56,7 +55,6 @@ local function stop_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = 0
|
||||
transfer_cylinder(pos, "stop")
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end
|
||||
|
||||
@ -74,18 +72,21 @@ local State = techage.NodeStates:new({
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||
if nvm.firebox_trigger <= 0 then
|
||||
State:nopower(pos, nvm)
|
||||
local running = techage.is_running(nvm)
|
||||
if running and nvm.firebox_trigger <= 0 then
|
||||
State:standby(pos, nvm)
|
||||
stop_node(pos, nvm, State)
|
||||
transfer_cylinder(pos, "stop")
|
||||
else
|
||||
elseif not running and nvm.firebox_trigger > 0 then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF)
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
local data = power.get_storage_data(pos, Axle, outdir)
|
||||
if data then
|
||||
nvm.load = data.level * PWR_PERF
|
||||
local val = power.get_storage_load(pos, Axle, outdir, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
@ -122,10 +123,8 @@ end
|
||||
|
||||
local function get_generator_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 4}
|
||||
else
|
||||
return {level = 0, perf = PWR_PERF, capa = PWR_PERF * 4}
|
||||
end
|
||||
end
|
||||
|
||||
@ -217,7 +216,7 @@ techage.register_node({"techage:flywheel", "techage:flywheel_on"}, {
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "trigger" then
|
||||
nvm.firebox_trigger = 3
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
return math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.1)
|
||||
else
|
||||
return 0
|
||||
|
@ -20,6 +20,7 @@ local S = techage.S
|
||||
|
||||
local MIN_LOAD = 99
|
||||
local MAX_ROPE_LEN = 10
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Axle = techage.Axle
|
||||
local power = networks.power
|
||||
@ -53,6 +54,17 @@ local function chest_full(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function add_chest_entity(pos, nvm)
|
||||
local mem = techage.get_mem(pos)
|
||||
local length = (nvm.length or MAX_ROPE_LEN) * (1 - nvm.load/nvm.capa)
|
||||
local y = pos.y - length - 1
|
||||
techage.renew_rope(pos, length, true)
|
||||
if mem.obj then
|
||||
mem.obj:remove()
|
||||
end
|
||||
mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity")
|
||||
end
|
||||
|
||||
-- Add chest node, remove chest entity instead
|
||||
local function add_chest(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
@ -108,38 +120,31 @@ minetest.register_node("techage:ta2_winch", {
|
||||
local outdir = networks.side_to_outdir(pos, "R")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Axle:after_place_node(pos, {outdir})
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
techage.renew_rope(pos, MAX_ROPE_LEN - 1)
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.capa = nvm.capa or 1
|
||||
nvm.load = nvm.load or 0
|
||||
nvm.length = nvm.length or 1
|
||||
|
||||
if not nvm.running and power.power_available(pos, Axle, outdir) and chest_full(pos) then
|
||||
remove_chest(pos)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
nvm.running = true
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
elseif nvm.running and nvm.load == 0 and not power.power_available(pos, Axle, outdir) then
|
||||
add_chest(pos)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end
|
||||
|
||||
if nvm.running then
|
||||
nvm.load = power.get_storage_load(pos, Axle, outdir, nvm.capa)
|
||||
if nvm.load then
|
||||
local length = nvm.length * (1 - nvm.load/nvm.capa)
|
||||
local y = pos.y - length - 1
|
||||
techage.renew_rope(pos, length, true)
|
||||
if mem.obj then
|
||||
mem.obj:remove()
|
||||
end
|
||||
mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity")
|
||||
local val = power.get_storage_load(pos, Axle, outdir, nvm.capa) or 0
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
add_chest_entity(pos, nvm)
|
||||
end
|
||||
end
|
||||
return true
|
||||
@ -155,10 +160,9 @@ minetest.register_node("techage:ta2_winch", {
|
||||
|
||||
get_storage_data = function(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.load = nvm.load or 0
|
||||
nvm.capa = nvm.capa or 1
|
||||
if nvm.running then
|
||||
return {level = nvm.load / nvm.capa, capa = nvm.capa}
|
||||
return {level = (nvm.load or 0) / nvm.capa, capa = nvm.capa}
|
||||
end
|
||||
end,
|
||||
|
||||
@ -170,6 +174,14 @@ minetest.register_node("techage:ta2_winch", {
|
||||
|
||||
power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"})
|
||||
|
||||
techage.register_node({"techage:ta2_winch"}, {
|
||||
on_node_load = function(pos, node)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
add_chest_entity(pos, nvm)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:ta2_winch",
|
||||
recipe = {
|
||||
|
@ -60,13 +60,16 @@ local State = techage.NodeStates:new({
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.capa = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
||||
|
||||
local capa = power.get_storage_load(pos, Cable, outdir, PWR_CAPA) or 0
|
||||
if capa > 0 then
|
||||
nvm.capa = capa
|
||||
end
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,9 @@ local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 12
|
||||
local STANDBY_TICKS = 1
|
||||
local COUNTDOWN_TICKS = 2
|
||||
local PWR_PERF = 12
|
||||
local EFFICIENCY = 2.5
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
@ -38,7 +40,7 @@ local function formspec(self, pos, nvm)
|
||||
"image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
|
||||
"image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||
"tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
|
||||
techage.formspec_power_bar(pos, 2.5, 0.8, S("Electricity"), nvm.provided, PWR_CAPA)
|
||||
techage.formspec_power_bar(pos, 2.5, 0.8, S("Electricity"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
local function play_sound(pos)
|
||||
@ -63,33 +65,38 @@ local function stop_sound(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function has_fuel(pos, nvm)
|
||||
return (nvm.burn_cycles or 0) > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
|
||||
end
|
||||
|
||||
local function can_start(pos, nvm, state)
|
||||
if (nvm.burn_cycles or 0) > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then
|
||||
if has_fuel(pos, nvm) then
|
||||
return true
|
||||
end
|
||||
return S("no fuel")
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
nvm.running = true -- needed by fuel_lib
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
local meta = M(pos)
|
||||
nvm.provided = 0
|
||||
local outdir = meta:get_int("outdir")
|
||||
play_sound(pos)
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
stop_sound(pos)
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
node_name_passive = "techage:tiny_generator",
|
||||
node_name_active = "techage:tiny_generator_on",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = 0,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
infotext_name = S("TA3 Tiny Power Generator"),
|
||||
can_start = can_start,
|
||||
@ -98,7 +105,7 @@ local State = techage.NodeStates:new({
|
||||
})
|
||||
|
||||
local function burning(pos, nvm)
|
||||
local ratio = math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.02)
|
||||
local ratio = math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.02)
|
||||
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
||||
@ -108,32 +115,37 @@ local function burning(pos, nvm)
|
||||
nvm.liquid.amount = nvm.liquid.amount - 1
|
||||
nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME
|
||||
nvm.burn_cycles_total = nvm.burn_cycles
|
||||
return true
|
||||
else
|
||||
nvm.liquid.name = nil
|
||||
State:fault(pos, nvm, S("no fuel"))
|
||||
stop_sound(pos)
|
||||
return false
|
||||
end
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local running = techage.is_running(nvm)
|
||||
local fuel = has_fuel(pos, nvm)
|
||||
if running and not fuel then
|
||||
State:standby(pos, nvm, S("no fuel"))
|
||||
stop_node(pos, nvm, State)
|
||||
elseif not running and fuel then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
if nvm.running and burning(pos, nvm) then
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_CAPA, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_CAPA)
|
||||
else
|
||||
nvm.provided = 0
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
local val = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
burning(pos, nvm)
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
meta:set_string("formspec", formspec(State, pos, nvm))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
@ -144,19 +156,18 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
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 on_rightclick(pos, node, clicker)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
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_CAPA, perf = PWR_CAPA, capa = PWR_CAPA * 2}
|
||||
if nvm.running and techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
|
||||
@ -195,7 +206,7 @@ minetest.register_node("techage:tiny_generator", {
|
||||
end,
|
||||
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_punch = fuel.on_punch,
|
||||
@ -242,7 +253,7 @@ minetest.register_node("techage:tiny_generator_on", {
|
||||
is_ground_content = false,
|
||||
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_CAPA),
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_punch = fuel.on_punch,
|
||||
|
@ -34,29 +34,41 @@ local function generate_formspec_substring(pos, meta, form_def)
|
||||
tbl[#tbl+1] = "label[0," .. offs .. ";" .. minetest.formspec_escape(elem.label) .. ":]"
|
||||
tbl[#tbl+1] = "tooltip[0," .. offs .. ";4,1;" .. elem.tooltip .. "]"
|
||||
if elem.type == "number" then
|
||||
local val = meta:get_int(elem.name)
|
||||
if nvm.running then
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_int(elem.name)
|
||||
end
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
else
|
||||
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||
end
|
||||
elseif elem.type == "numbers" then
|
||||
local val = meta:get_string(elem.name)
|
||||
if nvm.running then
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_string(elem.name)
|
||||
end
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
else
|
||||
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||
end
|
||||
elseif elem.type == "float" then
|
||||
local val = tonumber(meta:get_string(elem.name)) or 0
|
||||
if nvm.running then
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = tonumber(meta:get_string(elem.name)) or 0
|
||||
end
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
else
|
||||
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]"
|
||||
end
|
||||
elseif elem.type == "ascii" then
|
||||
local val = meta:get_string(elem.name)
|
||||
if nvm.running then
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_string(elem.name)
|
||||
end
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. minetest.formspec_escape(val) .. "]"
|
||||
else
|
||||
tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. minetest.formspec_escape(val) .. "]"
|
||||
@ -71,11 +83,17 @@ local function generate_formspec_substring(pos, meta, form_def)
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
elseif elem.type == "dropdown" then
|
||||
local l = elem.choices:split(",")
|
||||
if nvm.running then
|
||||
local val = meta:get_string(elem.name) or ""
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_string(elem.name) or ""
|
||||
end
|
||||
tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]"
|
||||
else
|
||||
local val = meta:get_string(elem.name) or ""
|
||||
local val = elem.default
|
||||
if meta:contains(elem.name) then
|
||||
val = meta:get_string(elem.name) or ""
|
||||
end
|
||||
local idx = index(l, val) or 1
|
||||
tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]"
|
||||
end
|
||||
@ -97,8 +115,9 @@ local function evaluate_data(pos, meta, form_def, fields)
|
||||
|
||||
if meta and form_def then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if not nvm.running then
|
||||
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
return res
|
||||
end
|
||||
for idx,elem in ipairs(form_def) do
|
||||
if elem.type == "number" then
|
||||
if fields[elem.name] then
|
||||
@ -106,7 +125,7 @@ local function evaluate_data(pos, meta, form_def, fields)
|
||||
local val = tonumber(fields[elem.name])
|
||||
if value_check(elem, val) then
|
||||
meta:set_int(elem.name, val)
|
||||
print("set_int", elem.name, val)
|
||||
--print("set_int", elem.name, val)
|
||||
else
|
||||
res = false
|
||||
end
|
||||
@ -146,7 +165,6 @@ local function evaluate_data(pos, meta, form_def, fields)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
|
@ -24,6 +24,7 @@ local S = techage.S
|
||||
local STANDBY_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_PERF = 70
|
||||
local COUNTDOWN_TICKS = 2
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = networks.power
|
||||
@ -48,17 +49,17 @@ local function pos_and_yaw(pos, param2)
|
||||
return pos, {x=0, y=yaw, z=0}
|
||||
end
|
||||
|
||||
local function is_wind()
|
||||
local function is_windy()
|
||||
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
|
||||
nvm.error = err
|
||||
return false
|
||||
end
|
||||
-- local resp, err = techage.valid_place_for_windturbine(pos, nil, 1)
|
||||
-- if not resp then
|
||||
-- nvm.error = err
|
||||
-- return false
|
||||
-- end
|
||||
|
||||
local npos = techage.get_pos(pos, "F")
|
||||
local node = techage.get_node_lvm(npos)
|
||||
@ -77,8 +78,8 @@ 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 function add_rotor(pos, nvm, force)
|
||||
if (force and not nvm.err) or check_rotor(pos, nvm) then
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if not Rotors[hash] then
|
||||
local node = minetest.get_node(pos)
|
||||
@ -94,20 +95,18 @@ end
|
||||
local function start_rotor(pos, nvm, state)
|
||||
if not nvm.error then
|
||||
local meta = M(pos)
|
||||
nvm.running = true
|
||||
nvm.delivered = 0
|
||||
nvm.provided = 0
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
if Rotors[hash] and is_wind() then
|
||||
if Rotors[hash] and is_windy() then
|
||||
Rotors[hash]:set_animation_frame_speed(50)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_rotor(pos, nvm, state)
|
||||
nvm.running = false
|
||||
nvm.delivered = 0
|
||||
nvm.provided = 0
|
||||
nvm.load = 0
|
||||
power.start_storage_calc(pos, Cable, 5)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
@ -133,41 +132,31 @@ local State = techage.NodeStates:new({
|
||||
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 nvm.error then
|
||||
return false
|
||||
end
|
||||
|
||||
if generating(pos, nvm) then
|
||||
local running = techage.is_running(nvm)
|
||||
local windy = is_windy()
|
||||
if running and not windy then
|
||||
State:standby(pos, nvm)
|
||||
stop_rotor(pos, nvm, State)
|
||||
elseif not running and windy then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
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
|
||||
State:idle(pos, nvm)
|
||||
local val = power.get_storage_load(pos, Cable, 5, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
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))
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
return true
|
||||
return State:is_active(nvm)
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
@ -187,7 +176,7 @@ end
|
||||
|
||||
local function get_generator_data(pos, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
@ -199,7 +188,6 @@ local function after_place_node(pos, placer)
|
||||
State:node_init(pos, nvm, number)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
nvm.running = true
|
||||
add_rotor(pos, nvm)
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
@ -228,14 +216,6 @@ minetest.register_node("techage:ta4_wind_turbine", {
|
||||
"techage_rotor.png^techage_appl_open.png",
|
||||
},
|
||||
|
||||
networks = {
|
||||
ele1 = {
|
||||
sides = {D = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_PERF,
|
||||
regenerative = true,
|
||||
},
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
get_generator_data = get_generator_data,
|
||||
@ -261,7 +241,7 @@ control.register_nodes({"techage:ta4_wind_turbine"}, {
|
||||
return {
|
||||
type = S("TA4 Wind Turbine"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
@ -309,7 +289,7 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
end
|
||||
if nvm.error then
|
||||
return "error"
|
||||
elseif nvm.running then
|
||||
elseif techage.is_running(nvm) then
|
||||
return "running"
|
||||
else
|
||||
return "stopped"
|
||||
@ -317,17 +297,16 @@ techage.register_node({"techage:ta4_wind_turbine"}, {
|
||||
elseif topic == "delivered" then
|
||||
return nvm.delivered or 0
|
||||
elseif topic == "on" then
|
||||
nvm.running = true
|
||||
State:start(pos, nvm)
|
||||
elseif topic == "off" then
|
||||
nvm.running = false
|
||||
State:stop(pos, nvm)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
end,
|
||||
on_node_load = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
add_rotor(pos, nvm)
|
||||
nvm.running = false -- to force the rotor start
|
||||
add_rotor(pos, nvm, true)
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user