veikk0
2016-03-30 2258adb2a9b2ec223ea3614a39ecbd59d2d6c948
commit | author | age
ee0765 1
be2f30 2 local S = technic.getter
S 3
ee0765 4 function technic.register_solar_array(data)
S 5     local tier = data.tier
6     local ltier = string.lower(tier)
be2f30 7
563a4c 8     local run = function(pos, node)
N 9         -- The action here is to make the solar array produce power
10         -- Power is dependent on the light level and the height above ground
11         -- There are many ways to cheat by using other light sources like lamps.
12         -- As there is no way to determine if light is sunlight that is just a shame.
13         -- To take care of some of it solar panels do not work outside daylight hours or if
14         -- built below 0m
15         local pos1 = {}
16         local machine_name = S("Arrayed Solar %s Generator"):format(tier)
17         pos1.y = pos.y + 1
18         pos1.x = pos.x
19         pos1.z = pos.z
161568 20
E 21         technic.get_or_load_node(pos1)
563a4c 22         local light = minetest.get_node_light(pos1, nil)
N 23         local time_of_day = minetest.get_timeofday()
24         local meta = minetest.get_meta(pos)
25         light = light or 0
26
27         -- turn on array only during day time and if sufficient light
28         -- I know this is counter intuitive when cheating by using other light sources.
29         if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > 0 then
30             local charge_to_give = math.floor((light + pos.y) * data.power)
31             charge_to_give = math.max(charge_to_give, 0)
32             charge_to_give = math.min(charge_to_give, data.power * 50)
85a984 33             meta:set_string("infotext", S("@1 Active (@2 EU)", machine_name, technic.pretty_num(charge_to_give)))
563a4c 34             meta:set_int(tier.."_EU_supply", charge_to_give)
N 35         else
36             meta:set_string("infotext", S("%s Idle"):format(machine_name))
37             meta:set_int(tier.."_EU_supply", 0)
38         end
39     end
40     
ee0765 41     minetest.register_node("technic:solar_array_"..ltier, {
S 42         tiles = {"technic_"..ltier.."_solar_array_top.png",  "technic_"..ltier.."_solar_array_bottom.png",
43              "technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png",
44              "technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png"},
83c649 45         groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1, ["technic_"..ltier]=1},
S 46         connect_sides = {"bottom"},
ee0765 47         sounds = default.node_sound_wood_defaults(),
7c4b70 48         description = S("Arrayed Solar %s Generator"):format(tier),
ee0765 49         active = false,
S 50         drawtype = "nodebox",
51         paramtype = "light",
52         node_box = {
53             type = "fixed",
54             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
55         },
56         on_construct = function(pos)
57             local meta = minetest.get_meta(pos)
58             local name = minetest.get_node(pos).name
59             meta:set_int(tier.."_EU_supply", 0)
60         end,
563a4c 61         technic_run = run,
ee0765 62     })
S 63
64     technic.register_machine(tier, "technic:solar_array_"..ltier, technic.producer)
65 end
66