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