From d092bec7c1dc0f382d4c248c0335f3c0eae27c30 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 18 Aug 2019 01:24:34 +0200 Subject: [PATCH] solar panel added --- init.lua | 8 +- nodes/silicon.lua | 28 ++++ power/power.lua | 2 +- solar/minicell.lua | 135 ++++++++++++++++++++ textures/techage_silicon_wafer.png | Bin 0 -> 2553 bytes textures/techage_solar_cell_mini_bottom.png | Bin 0 -> 322 bytes textures/techage_solar_cell_mini_side.png | Bin 0 -> 269 bytes textures/techage_solar_cell_mini_top.png | Bin 0 -> 261 bytes 8 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 nodes/silicon.lua create mode 100644 solar/minicell.lua create mode 100644 textures/techage_silicon_wafer.png create mode 100644 textures/techage_solar_cell_mini_bottom.png create mode 100644 textures/techage_solar_cell_mini_side.png create mode 100644 textures/techage_solar_cell_mini_top.png diff --git a/init.lua b/init.lua index eeba386..2f09957 100644 --- a/init.lua +++ b/init.lua @@ -25,7 +25,8 @@ else --pwr = true, -- power distribution sts = true, -- status plots --dbg = true, - dbg2 = true, + --dbg2 = true, + tst = true, } -- Basis features @@ -154,4 +155,9 @@ else dofile(MP.."/.test/source.lua") dofile(MP.."/.test/akku.lua") --dofile(MP.."/.test/switch.lua") + + -- Solar + dofile(MP.."/nodes/silicon.lua") + dofile(MP.."/solar/minicell.lua") + end \ No newline at end of file diff --git a/nodes/silicon.lua b/nodes/silicon.lua new file mode 100644 index 0000000..213a155 --- /dev/null +++ b/nodes/silicon.lua @@ -0,0 +1,28 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + TA4 Silicon Wafer + +]]-- + +local S = techage.S + +minetest.register_craftitem("techage:ta4_silicon_wafer", { + description = S("TA4 Silicon Wafer"), + inventory_image = "techage_silicon_wafer.png", +}) + +techage.furnace.register_recipe({ + output = "techage:ta4_silicon_wafer 8", + recipe = { + "basic_materials:silicon", + }, + time = 6, +}) \ No newline at end of file diff --git a/power/power.lua b/power/power.lua index 97f71d7..837fd4c 100644 --- a/power/power.lua +++ b/power/power.lua @@ -449,7 +449,7 @@ function techage.power.generator_alive(pos, mem) if mem.pwr_is_master then power_distribution(pos, mem, 1) end - return mem.pwr_provided + return mem.pwr_provided or 0 end -- diff --git a/solar/minicell.lua b/solar/minicell.lua new file mode 100644 index 0000000..26c8fce --- /dev/null +++ b/solar/minicell.lua @@ -0,0 +1,135 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019 Joachim Stolberg + + LGPLv2.1+ + 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 +local PWR_CAPA = 30 * 20 -- default day + +minetest.after(2, function() + -- calculate the capacity depending on the day duration + PWR_CAPA = math.max(minetest.get_gametime() / minetest.get_day_count() / 2, PWR_CAPA) +end) + +local Cable = techage.ElectricCable +local power = techage.power + +local function node_timer(pos, elapsed) + local mem = tubelib2.get_mem(pos) + mem.capa = mem.capa or 0 + pos.y = pos.y + 1 + local light = minetest.get_node_light(pos) + pos.y = pos.y - 1 + + if light >= (minetest.LIGHT_MAX - 1) then + if mem.providing then + power.generator_stop(pos, mem) + mem.providing = false + mem.provided = 0 + end + mem.capa = math.min(mem.capa + PWR_PERF * 1.2, PWR_CAPA) + else + if mem.capa > 0 then + if not mem.providing then + power.generator_start(pos, mem, PWR_PERF) + mem.providing = true + end + mem.provided = power.generator_alive(pos, mem) + mem.capa = mem.capa - mem.provided + else + power.generator_stop(pos, mem) + mem.providing = false + mem.provided = 0 + mem.capa = 0 + end + end + mydbg("tst", "PWR_CAPA = "..PWR_CAPA..", mem.capa = "..mem.capa..", light = "..light) + return true +end + +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}, + }, + }, + + after_place_node = function(pos) + local meta = minetest.get_meta(pos) + local number = techage.add_node(pos, "techage:ta4_solar_minicell") + meta:set_string("number", number) + meta:set_string("infotext", S("TA4 Streetlamp Solar Cell").." "..number) + local mem = tubelib2.get_mem(pos) + mem.capa = 0 + mem.providing = false + minetest.get_node_timer(pos):start(CYCLE_TIME) + end, + + after_dig_node = function(pos) + techage.remove_node(pos) + end, + + paramtype2 = "facedir", + groups = {cracky=2, crumbly=2, choppy=2}, + is_ground_content = false, + on_timer = node_timer, +}) + +techage.power.register_node({"techage:ta4_solar_minicell"}, { + power_network = Cable, +}) + +techage.register_node({"techage:ta4_solar_minicell"}, { + on_recv_message = function(pos, topic, payload) + local mem = tubelib2.get_mem(pos) + if topic == "state" then + if mem.providing then + if (mem.provided or 0) > 0 then + return "discharging" + else + return "unused" + end + else + return "charging" + end + else + return "unsupported" + end + end, +}) + +minetest.register_craft({ + output = "techage:ta4_solar_minicell", + recipe = { + {"", "", ""}, + {"techage:ta4_silicon_wafer", "techage:ta4_silicon_wafer", "techage:ta4_silicon_wafer"}, + {"default:tin_ingot", "techage:iron_ingot", "default:copper_ingot"}, + }, +}) + diff --git a/textures/techage_silicon_wafer.png b/textures/techage_silicon_wafer.png new file mode 100644 index 0000000000000000000000000000000000000000..6c9318d2cd1b69a7a642702948e13b6861e8d5ad GIT binary patch literal 2553 zcmWlac{~#g9LDEfGhyT^tW9XftLCbgT$_wF*OW+(=8BRl6?&1}lOro*At874ijX@; zk|I)~!mHjKd6Pof@6{jA^L)O~|Ig=1vZWsuLn)vT2!t5bl5D?~CclLg*m7<|%mMkKQgUwF9jrp-xaRz~b?{RQ0sgMGRCJ^gXAkr0uGP8pZ|^ zS|(UyBV#i&sgtJ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6~-ektBN>kt`r$pK2x%WVJiNDbW@=%YUVCY;(D>=Ga>2 z+dj#Hv%x24XR$He{MDM%S9LT)CbFiGiOU7s?(D!ur?))z&2VyWZ;N~)b>-kvaC)b$ zv;aSwHptwEdPt(u#Jx;W|e?C-;&Qt0GrGxym40k9|SyZ`_I literal 0 HcmV?d00001 diff --git a/textures/techage_solar_cell_mini_bottom.png b/textures/techage_solar_cell_mini_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..7ee7cf8e4b8361211af4b6eca5226b127844c707 GIT binary patch literal 322 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv-2k5uS1}-aQoMvuhFsYGh3Ec6VXuV3qX%aySb- zB8wRqxP?KOkzv*x37{Z*iKnkC`(qA45izZZyXU2VLb9155hc#~xw)x%B|t6%gL6@8 zVo7R>LV0FMhJw4NZ$OG(DmzfT$kW9!MB{w2MKha(0jpI2g9k&ToXUmE%@5{VFbY{T z3cO(Cp3|spS;(fu5PpeSv_TWdR4WJ&;7RciD$v*0cNAQ)xB9!)ssr!tW-#4OTg>^U z#@B;;*FuSFlirk+yiaBks1itGF{(02a1n6}5$dXCXygqnT(tI~8pv6mu6{1-oD!M< DSpr^h literal 0 HcmV?d00001 diff --git a/textures/techage_solar_cell_mini_side.png b/textures/techage_solar_cell_mini_side.png new file mode 100644 index 0000000000000000000000000000000000000000..132fb65e68f491a036803a62bde9e4a3a28b55d5 GIT binary patch literal 269 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pI^Lr_$ZJIY*n3s6WlGbEzKIX^cyHLnE7WngeFN=+G vua>pF$Lr3!|GUi^WnTB3b;j%Kx^H(faDNl=@jLxB8DxN`tDnm{r-UW|-aQoMvuhFsYGh3Ec6VXuV3qX%aySb- zB8wRqxP?KOkzv*x37{Z*iKnkC`(qA45ix6{-1jelLb9155hc#~xw)x%B|t6%gL6@8 zVo7R>LV0FMhJw4NZ$OG(Dmzfz)YHW=MB{w2MKha3hk(V!MwTiECN{T&r&hTMFzF~hF>ap{7FhT}TP#chkY7PyO?oXE?dTl2i!?neDLkjb8|elF{r5}E-2V@rqt literal 0 HcmV?d00001