Zefram
2014-08-14 6cc471e986c694298716c257528c653395bd757d
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
20         local light = minetest.get_node_light(pos1, nil)
21         local time_of_day = minetest.get_timeofday()
22         local meta = minetest.get_meta(pos)
23         light = light or 0
24
25         -- turn on array only during day time and if sufficient light
26         -- I know this is counter intuitive when cheating by using other light sources.
27         if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > 0 then
28             local charge_to_give = math.floor((light + pos.y) * data.power)
29             charge_to_give = math.max(charge_to_give, 0)
30             charge_to_give = math.min(charge_to_give, data.power * 50)
31             meta:set_string("infotext", S("%s Active"):format(machine_name).." ("..charge_to_give.."EU)")
32             meta:set_int(tier.."_EU_supply", charge_to_give)
33         else
34             meta:set_string("infotext", S("%s Idle"):format(machine_name))
35             meta:set_int(tier.."_EU_supply", 0)
36         end
37     end
38     
ee0765 39     minetest.register_node("technic:solar_array_"..ltier, {
S 40         tiles = {"technic_"..ltier.."_solar_array_top.png",  "technic_"..ltier.."_solar_array_bottom.png",
41              "technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png",
42              "technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png"},
563a4c 43         groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1},
ee0765 44         sounds = default.node_sound_wood_defaults(),
7c4b70 45         description = S("Arrayed Solar %s Generator"):format(tier),
ee0765 46         active = false,
S 47         drawtype = "nodebox",
48         paramtype = "light",
49         node_box = {
50             type = "fixed",
51             fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
52         },
53         on_construct = function(pos)
54             local meta = minetest.get_meta(pos)
55             local name = minetest.get_node(pos).name
56             meta:set_int(tier.."_EU_supply", 0)
57         end,
563a4c 58         technic_run = run,
ee0765 59     })
S 60
61     technic.register_machine(tier, "technic:solar_array_"..ltier, technic.producer)
62 end
63