2019-08-18 02:24:34 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-08-18 02:24:34 +03:00
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-08-18 02:24:34 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA4 Streetlamp Solar Cell
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local P = minetest.string_to_pos
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local CYCLE_TIME = 2
|
|
|
|
local PWR_PERF = 1
|
2020-03-31 22:37:07 +03:00
|
|
|
local PWR_CAPA = 2400 -- ticks (2s) with 1 ku ==> 80 min = 4 game days
|
2019-08-18 02:24:34 +03:00
|
|
|
|
|
|
|
local Cable = techage.ElectricCable
|
|
|
|
local power = techage.power
|
|
|
|
|
|
|
|
local function node_timer(pos, elapsed)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.capa = nvm.capa or 0
|
2019-08-18 02:24:34 +03:00
|
|
|
pos.y = pos.y + 1
|
2019-08-21 22:52:11 +03:00
|
|
|
local light = minetest.get_node_light(pos) or 0
|
2020-03-31 22:37:07 +03:00
|
|
|
local t = minetest.get_timeofday()
|
2019-08-18 02:24:34 +03:00
|
|
|
pos.y = pos.y - 1
|
|
|
|
|
2020-03-31 22:37:07 +03:00
|
|
|
if t > 0.25 and t < 0.75 then
|
2020-01-31 21:55:10 +03:00
|
|
|
if nvm.providing then
|
2020-02-06 22:51:30 +03:00
|
|
|
power.generator_stop(pos, Cable, 5)
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.providing = false
|
|
|
|
nvm.provided = 0
|
2019-08-18 02:24:34 +03:00
|
|
|
end
|
2020-03-31 22:37:07 +03:00
|
|
|
if light >= (minetest.LIGHT_MAX - 1) then
|
|
|
|
nvm.capa = math.min(nvm.capa + PWR_PERF * 1.2, PWR_CAPA)
|
|
|
|
end
|
2019-08-18 02:24:34 +03:00
|
|
|
else
|
2020-01-31 21:55:10 +03:00
|
|
|
if nvm.capa > 0 then
|
|
|
|
if not nvm.providing then
|
2020-02-06 22:51:30 +03:00
|
|
|
power.generator_start(pos, Cable, CYCLE_TIME, 5)
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.providing = true
|
2020-02-06 22:51:30 +03:00
|
|
|
else
|
|
|
|
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, 5)
|
|
|
|
nvm.capa = nvm.capa - nvm.provided
|
2019-08-18 02:24:34 +03:00
|
|
|
end
|
|
|
|
else
|
2020-02-06 22:51:30 +03:00
|
|
|
power.generator_stop(pos, Cable, 5)
|
2020-01-31 21:55:10 +03:00
|
|
|
nvm.providing = false
|
|
|
|
nvm.provided = 0
|
|
|
|
nvm.capa = 0
|
2019-08-18 02:24:34 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
local function after_place_node(pos)
|
|
|
|
local meta = M(pos)
|
|
|
|
local number = techage.add_node(pos, "techage:ta4_solar_minicell")
|
|
|
|
meta:set_string("node_number", number)
|
|
|
|
meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.capa = 0
|
|
|
|
nvm.providing = false
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
Cable:after_place_node(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_dig_node(pos, oldnode)
|
|
|
|
Cable:after_dig_node(pos)
|
|
|
|
techage.remove_node(pos)
|
|
|
|
techage.del_mem(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
|
|
|
power.update_network(pos, outdir, tlib2)
|
|
|
|
end
|
|
|
|
|
|
|
|
local net_def = {
|
|
|
|
ele1 = {
|
|
|
|
sides = {D = 1},
|
|
|
|
ntype = "gen1",
|
2020-03-31 22:37:07 +03:00
|
|
|
nominal = PWR_PERF,
|
2020-02-06 22:51:30 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-08-18 02:24:34 +03:00
|
|
|
minetest.register_node("techage:ta4_solar_minicell", {
|
|
|
|
description = S("TA4 Streetlamp Solar Cell"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_solar_cell_mini_top.png",
|
|
|
|
"techage_solar_cell_mini_bottom.png",
|
|
|
|
"techage_solar_cell_mini_side.png",
|
|
|
|
},
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-14/32, -8/32, -14/32, 14/32, -6/32, 14/32},
|
|
|
|
{-7/32, -16/32, -7/32, 7/32, -8/32, 7/32},
|
|
|
|
},
|
|
|
|
},
|
2019-10-05 20:19:18 +03:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky=2, crumbly=2, choppy=2},
|
|
|
|
is_ground_content = false,
|
2020-02-06 22:51:30 +03:00
|
|
|
|
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
2019-10-05 20:19:18 +03:00
|
|
|
on_timer = node_timer,
|
2020-02-06 22:51:30 +03:00
|
|
|
tubelib2_on_update2 = tubelib2_on_update2,
|
2020-03-28 15:22:12 +03:00
|
|
|
networks = net_def,
|
2019-10-05 20:19:18 +03:00
|
|
|
})
|
|
|
|
|
2020-02-06 22:51:30 +03:00
|
|
|
Cable:add_secondary_node_names({"techage:ta4_solar_minicell"})
|
2019-08-18 02:24:34 +03:00
|
|
|
|
|
|
|
techage.register_node({"techage:ta4_solar_minicell"}, {
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-08-18 02:24:34 +03:00
|
|
|
if topic == "state" then
|
2020-01-31 21:55:10 +03:00
|
|
|
if nvm.providing then
|
2019-08-21 22:52:11 +03:00
|
|
|
return "discharging"
|
2020-01-31 21:55:10 +03:00
|
|
|
elseif (nvm.capa or 0) > 0 then
|
2019-08-18 02:24:34 +03:00
|
|
|
return "charging"
|
2019-08-21 22:52:11 +03:00
|
|
|
else
|
|
|
|
return "unused"
|
2019-08-18 02:24:34 +03:00
|
|
|
end
|
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
|
|
|
end,
|
2019-08-24 00:35:37 +03:00
|
|
|
on_node_load = function(pos)
|
2020-02-06 22:51:30 +03:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-08-24 00:35:37 +03:00
|
|
|
end,
|
2019-08-18 02:24:34 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta4_solar_minicell",
|
|
|
|
recipe = {
|
2019-08-18 19:02:14 +03:00
|
|
|
{"", "techage:ta4_wlanchip", ""},
|
2019-08-18 02:24:34 +03:00
|
|
|
{"techage:ta4_silicon_wafer", "techage:ta4_silicon_wafer", "techage:ta4_silicon_wafer"},
|
|
|
|
{"default:tin_ingot", "techage:iron_ingot", "default:copper_ingot"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|