kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ede397 1 -- The high voltage solar array is an assembly of medium voltage arrays.
K 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     drawtype = "nodebox",
14     paramtype = "light",
15     is_ground_content = true,    
16     node_box = {
17             type = "fixed",
18             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
19         },
20         selection_box = {
21             type = "fixed",
22             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
23         },
24     on_construct = function(pos)
25         local meta = minetest.env:get_meta(pos)
26         meta:set_float("technic_hv_power_machine", 1)
ee5c6c 27         meta:set_int("HV_EU_supply", 0)
ede397 28         meta:set_string("infotext", "HV Solar Array")
K 29     end,
30 })
31
ee5c6c 32 minetest.register_craft(
K 33    {output = 'technic:solar_array_hv 1',
34     recipe = {
35        {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'},
36        {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'},
37        {'default:steel_ingot',    'technic:hv_cable',      'default:steel_ingot'},
38     }
39  })
ede397 40
K 41 minetest.register_abm(
ee5c6c 42    {nodenames = {"technic:solar_array_hv"},
K 43     interval   = 1,
44     chance     = 1,
45     action = function(pos, node, active_object_count, active_object_count_wider)
ede397 46         -- The action here is to make the solar array produce power
K 47         -- Power is dependent on the light level and the height above ground
48         -- 130m and above is optimal as it would be above cloud level.
49                 -- Height gives 1/4 of the effect, light 3/4. Max. effect is 2880EU for the array.
50                 -- There are many ways to cheat by using other light sources like lamps.
51                 -- As there is no way to determine if light is sunlight that is just a shame.
52                 -- To take care of some of it solar panels do not work outside daylight hours or if
53                 -- built below -10m
54         local pos1={}
55         pos1.y=pos.y+1
56         pos1.x=pos.x
57         pos1.z=pos.z
ee5c6c 58         
ede397 59         local light = minetest.env:get_node_light(pos1, nil)
K 60         local time_of_day = minetest.env:get_timeofday()
61         local meta = minetest.env:get_meta(pos)
62         if light == nil then light = 0 end
63         -- turn on array only during day time and if sufficient light
64                 -- I know this is counter intuitive when cheating by using other light sources.
65         if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
ee5c6c 66            local charge_to_give          = math.floor(light*(light*9.6+pos1.y/130*48))
K 67            if charge_to_give<0   then charge_to_give=0 end
68            if charge_to_give>160 then charge_to_give=160 end
69            meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
70            meta:set_int("HV_EU_supply", charge_to_give)
ede397 71         else
ee5c6c 72            meta:set_string("infotext", "Solar Array is inactive");
K 73            meta:set_int("HV_EU_supply", 0)
ede397 74         end
ee5c6c 75          end,
K 76  }) 
ede397 77
ee5c6c 78 technic.register_HV_machine ("technic:solar_array_hv","PR")