kpoppel
2013-06-12 390ea043527203bb2d0cb6f873fedbffa68ae83f
commit | author | age
ede397 1 -- The medium voltage solar array is an assembly of low voltage arrays.
K 2 -- The assembly can deliver medium voltage levels and is a 10% less efficient
3 -- compared to 5 individual low voltage arrays due to losses in the transformer.
4 -- However medium voltage is supplied.
5 -- Solar arrays are not able to store large amounts of energy.
6 -- The MV arrays are used to make high voltage arrays.
7 minetest.register_node("technic:solar_array_mv", {
8     tiles = {"technic_mv_solar_array_top.png", "technic_mv_solar_array_bottom.png", "technic_mv_solar_array_side.png",
9          "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png"},
10     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
11     sounds = default.node_sound_wood_defaults(),
12         description="MV Solar Array",
13     active = false,
14     technic_mv_power_machine=1,
15     internal_EU_buffer=0;
16     internal_EU_buffer_size=1000;
17     drawtype = "nodebox",
18     paramtype = "light",
19     is_ground_content = true,    
20     node_box = {
21             type = "fixed",
22             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
23         },
24         selection_box = {
25             type = "fixed",
26             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
27         },
28     on_construct = function(pos)
29         local meta = minetest.env:get_meta(pos)
30         meta:set_float("technic_mv_power_machine", 1)
31         meta:set_float("internal_EU_buffer", 0)
32         meta:set_float("internal_EU_buffer_size", 1000)
33
34         meta:set_string("infotext", "MV Solar Array")
35         meta:set_float("active", false)
36     end,
37 })
38
39 minetest.register_craft({
40     output = 'technic:solar_array_mv 1',
41     recipe = {
42         {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'},
43         {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'},
be7744 44         {'default:steel_ingot',    'technic:mv_cable',      'default:steel_ingot'},
ede397 45
K 46     }
47 })
48
49 minetest.register_abm(
50     {nodenames = {"technic:solar_array_mv"},
51     interval   = 1,
52     chance     = 1,
53     action = function(pos, node, active_object_count, active_object_count_wider)
54         -- The action here is to make the solar array produce power
55         -- Power is dependent on the light level and the height above ground
56         -- 130m and above is optimal as it would be above cloud level.
57                 -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array.
58                 -- There are many ways to cheat by using other light sources like lamps.
59                 -- As there is no way to determine if light is sunlight that is just a shame.
60                 -- To take care of some of it solar panels do not work outside daylight hours or if
61                 -- built below -10m
62         local pos1={}
63         pos1.y=pos.y+1
64         pos1.x=pos.x
65         pos1.z=pos.z
66
67         local light = minetest.env:get_node_light(pos1, nil)
68         local time_of_day = minetest.env:get_timeofday()
69         local meta = minetest.env:get_meta(pos)
70         if light == nil then light = 0 end
71         -- turn on array only during day time and if sufficient light
72                 -- I know this is counter intuitive when cheating by using other light sources.
73         if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
74             local internal_EU_buffer      = meta:get_float("internal_EU_buffer")
75             local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size")
76             local charge_to_give          = math.floor(light*(light*2.4+pos1.y/130*12))
77             if charge_to_give<0   then charge_to_give=0 end
78             if charge_to_give>720 then charge_to_give=720 end
79             if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
80                charge_to_give=internal_EU_buffer_size-internal_EU_buffer
81             end
82             meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
83             meta:set_float("active",1)
84             internal_EU_buffer=internal_EU_buffer+charge_to_give
85             meta:set_float("internal_EU_buffer",internal_EU_buffer)
cfb5bd 86             -- Idea: How about letting solar panels provide power without battery boxes?
K 87             -- This could provide an even distribution to all receivers.            
ede397 88         else
K 89             meta:set_string("infotext", "Solar Array is inactive");
90             meta:set_float("active",0)
91         end
92     end,
93 }) 
94
95 register_MV_machine ("technic:solar_array_mv","PR")