RealBadAngel
2013-06-30 8e03d7ded6441b26e9d44102c0cd2ee39f9e90bc
commit | author | age
8e03d7 1 -- The solar array is an assembly of panels into a powerful array
R 2 -- The assembly can deliver more energy than the individual panel because
3 -- of the transformer unit which converts the panel output variations into
4 -- a stable supply.
5 -- Solar arrays are not able to store large amounts of energy.
6 -- The LV arrays are used to make medium voltage arrays.
7 minetest.register_node("technic:solar_array_lv", {
8     tiles = {"technic_lv_solar_array_top.png", "technic_lv_solar_array_bottom.png", "technic_lv_solar_array_side.png",
9         "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png"},
10     groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
11     sounds = default.node_sound_wood_defaults(),
12         description="LV Solar Array",
13     active = false,
14     technic_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_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", "LV Solar Array")
35         meta:set_float("active", false)
36     end,
37 })
38
39 minetest.register_craft({
40     output = 'technic:solar_array_lv 1',
41     recipe = {
42         {'technic:solar_panel', 'technic:solar_panel',    'technic:solar_panel'},
43         {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'},
44         {'default:steel_ingot', 'technic:lv_cable',       'default:steel_ingot'},
45
46     }
47 })
48
49 minetest.register_abm(
50     {nodenames = {"technic:solar_array_lv"},
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 160EU 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 arrays 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*0.5333+pos1.y/130*2.6667))
77             if charge_to_give<0   then charge_to_give=0 end
78             if charge_to_give>160 then charge_to_give=160 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)
86             
87         else
88             meta:set_string("infotext", "Solar Array is inactive");
89             meta:set_float("active",0)
90         end
91     end,
92 }) 
93
94 register_LV_machine ("technic:solar_array_lv","PR")