kpoppel
2013-07-02 053fa59739f4b772174bf0a090969b3395ab3f98
commit | author | age
ede397 1 -- The solar array is an assembly of panels into a powerful array
K 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     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)
ee5c6c 26         meta:set_int("technic_power_machine", 1)
K 27         meta:set_int("LV_EU_supply", 0)
ede397 28         meta:set_string("infotext", "LV Solar Array")
K 29     end,
30 })
31
ee5c6c 32 minetest.register_craft(
K 33    {output = 'technic:solar_array_lv 1',
34     recipe = {
35        {'technic:solar_panel', 'technic:solar_panel',    'technic:solar_panel'},
36        {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'},
37        {'default:steel_ingot', 'technic:lv_cable',       'default:steel_ingot'},
38     }
39  })
ede397 40
K 41 minetest.register_abm(
ee5c6c 42    {nodenames = {"technic:solar_array_lv"},
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.
ee5c6c 49         -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array.
K 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 arrays do not work outside daylight hours or if
53         -- built below -10m
ede397 54         local pos1={}
K 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
ee5c6c 64         -- I know this is counter intuitive when cheating by using other light sources.
ede397 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*0.5333+pos1.y/130*2.6667))
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("LV_EU_supply", charge_to_give)
ede397 71         else
ee5c6c 72            meta:set_string("infotext", "Solar Array is inactive");
K 73            meta:set_int("LV_EU_supply", 0)
ede397 74         end
ee5c6c 75          end,
K 76  })
ede397 77
ee5c6c 78 technic.register_LV_machine ("technic:solar_array_lv","PR")