kpoppel
2013-08-27 ec9f92d98b88b13adada6250622b9a51f3705026
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     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)
8e03d7 28         meta:set_string("infotext", "LV Solar Array")
R 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  })
8e03d7 40
R 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)
8e03d7 46         -- The action here is to make the solar array produce power
R 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
8e03d7 54         local pos1={}
R 55         pos1.y=pos.y+1
56         pos1.x=pos.x
57         pos1.z=pos.z
58         local light = minetest.env:get_node_light(pos1, nil)
59         local time_of_day = minetest.env:get_timeofday()
60         local meta = minetest.env:get_meta(pos)
61         if light == nil then light = 0 end
62         -- turn on array only during day time and if sufficient light
ee5c6c 63         -- I know this is counter intuitive when cheating by using other light sources.
8e03d7 64         if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
ee5c6c 65            local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667))
K 66            if charge_to_give<0   then charge_to_give=0 end
67            if charge_to_give>160 then charge_to_give=160 end
68            meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
69            meta:set_int("LV_EU_supply", charge_to_give)
8e03d7 70         else
ee5c6c 71            meta:set_string("infotext", "Solar Array is inactive");
K 72            meta:set_int("LV_EU_supply", 0)
8e03d7 73         end
ee5c6c 74          end,
K 75  })
8e03d7 76
ee5c6c 77 technic.register_LV_machine ("technic:solar_array_lv","PR")
19c9a0 78