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