Differences From
Artifact [de51a702a5]:
1 1 local lib = starlit.mod.lib
2 2 local world = starlit.world
3 3
4 4 function world.date()
5 - local days = minetest.get_day_count()
5 + local days = core.get_day_count()
6 6 local year = math.floor(days / world.planet.orbit);
7 7 local day = days % world.planet.orbit;
8 8 return {
9 9 year = year, day = day;
10 10 season = day / world.planet.orbit + 0.5; -- begin summer
11 11 }
12 12 end
................................................................................
17 17 local heatRange = {min = -50, max = 50} -- translate mt temps into real temps
18 18
19 19 -- this function provides the basis for temperature calculation,
20 20 -- which is performed by adding this value to the ambient temperature,
21 21 -- determined by querying nearby group:heatSource items in accordance
22 22 -- with the inverse-square law
23 23 function world.climate.eval(pos, tod, season)
24 - local data = minetest.get_biome_data(pos)
25 - local biome = world.ecology.biomes.db[minetest.get_biome_name(data.biome)]
24 + local data = core.get_biome_data(pos)
25 + local biome = world.ecology.biomes.db[core.get_biome_name(data.biome)]
26 26 -- print('climate:', dump(data))
27 27 local heat, humid = data.heat, data.humidity
28 28 heat = lerp(heat/100, heatRange.min, heatRange.max)
29 - tod = tod or minetest.get_timeofday()
29 + tod = tod or core.get_timeofday()
30 30 heat = lerp(math.abs(tod - 0.5)*2, heat, heat + biome.nightTempDelta)
31 31 -- print('base heat', heat)
32 32
33 33 local td = world.date()
34 34 heat = heat + gradient(biome.seasonalTemp, season or td.season)
35 35 -- print('seasonal heat', heat)
36 36 if pos.y > 0 then
................................................................................
47 47
48 48 local vdsq = lib.math.vdsq
49 49 function world.climate.temp(pos, timeshift) --> irradiance at pos in W
50 50 local cl = world.climate.eval(pos)
51 51 local radCenters = starlit.region.radiator.store:get_areas_for_pos(pos, false, true)
52 52 local irradiance = 0
53 53 for _,e in pairs(radCenters) do
54 - local rpos = minetest.string_to_pos(e.data)
55 - local rdef = assert(minetest.registered_nodes[assert(minetest.get_node(rpos)).name])
54 + local rpos = core.string_to_pos(e.data)
55 + local rdef = assert(core.registered_nodes[assert(core.get_node(rpos)).name])
56 56 local rc = rdef._starlit.radiator
57 57 local r_max = rc.radius(rpos)
58 58
59 59 local dist_sq = vdsq(rpos,pos)
60 60 if dist_sq <= r_max^2 then
61 61 -- cheap bad way
62 - -- if minetest.line_of_sight(rpos,pos) then
62 + -- if core.line_of_sight(rpos,pos) then
63 63 --
64 64 -- expensive way
65 65 local obstruct = 0
66 66 local ray = Raycast(rpos, pos, true, true)
67 67 for p in ray do
68 68 if p.type == 'node' then obstruct = obstruct + 1 end
69 69 end
................................................................................
85 85 end
86 86 local w = world.climate.weatherAt(pos, timeshift)
87 87
88 88 return irradiance + cl.surfaceTemp
89 89 end
90 90
91 91 function world.ecology.biomeAt(pos)
92 - return world.ecology.biomes.db[minetest.get_biome_name(minetest.get_biome_data(pos).biome)]
92 + return world.ecology.biomes.db[core.get_biome_name(core.get_biome_data(pos).biome)]
93 93 end
94 94
95 95
96 -minetest.after(0, function()
97 - world.climate.weatherMap.kind = minetest.get_perlin {
96 +core.after(0, function()
97 + world.climate.weatherMap.kind = core.get_perlin {
98 98 seed = 0x925afe;
99 99 octaves = 2;
100 100 spread = vector.new(256,256,120);
101 101 };
102 - world.climate.weatherMap.severity = minetest.get_perlin {
102 + world.climate.weatherMap.severity = core.get_perlin {
103 103 seed = 0x39de1d;
104 104 octaves = 1;
105 105 spread = vector.new(256,256,60);
106 106 };
107 107 end)
108 108
109 109 function world.climate.weatherAt(pos, timeshift)
110 110 timeshift = timeshift or 0
111 - local wv = world.climate.weatherMap.kind:get_3d(vector.new(pos.x, pos.z, minetest.get_gametime() + timeshift))
112 - local sev = world.climate.weatherMap.severity:get_3d(vector.new(pos.x, pos.z, minetest.get_gametime() + timeshift))
111 + local wv = world.climate.weatherMap.kind:get_3d(vector.new(pos.x, pos.z, core.get_gametime() + timeshift))
112 + local sev = world.climate.weatherMap.severity:get_3d(vector.new(pos.x, pos.z, core.get_gametime() + timeshift))
113 113 local b = world.ecology.biomeAt(pos)
114 114 local w = 'starlit:clear'
115 115 for i,v in ipairs(b.weather) do
116 116 if wv < v[1] then
117 117 w = v[2]
118 118 break
119 119 end
................................................................................
194 194 world.climate.weather.link('starlit:meteorShower', {
195 195 name = 'Meteor Shower';
196 196 danger = 2;
197 197 })
198 198
199 199 world.ecology.biomes.foreach('starlit:biome-gen', {}, function(id, b)
200 200 b.def.name = id
201 - minetest.register_biome(b.def)
201 + core.register_biome(b.def)
202 202 end)
203 203
204 204 world.ecology.plants.foreach('starlit:plant-gen', {}, function(id, b)
205 205 local stageCt = #b.stages
206 206 local function stageID(n)
207 207 if n == stageCt then return id end
208 208 return id .. string.format('_stage_%s', n)
................................................................................
244 244 end;
245 245 };
246 246 }
247 247 if st.swap then
248 248 base.node_dig_prediction = ""
249 249 function base.after_dig_node(pos, node, digger)
250 250 node.name = stageID(st.swap)
251 - minetest.swap_node(pos, node)
251 + core.swap_node(pos, node)
252 252 return true
253 253 end
254 254 end
255 255 if st.biolum then base.light_source = st.biolum; end
256 256 return base
257 257 end
258 258 for i, v in ipairs(b.stages) do
259 259 local n = regStage(i, v)
260 - minetest.register_node(stageID(i), n)
260 + core.register_node(stageID(i), n)
261 261 b.stageNodes[i] = stageID(i)
262 262 end
263 263 b.fullyGrown = stageID(stageCt)
264 264
265 265 local dec = {
266 266 deco_type = 'simple';
267 267 decoration = b.stageNodes;
268 268 height = 1;
269 269 param2 = b.meshOpt or 0;
270 270 }
271 271 for k,v in pairs(b.decoration) do dec[k] = v end
272 - b.decoration = minetest.register_decoration(dec)
272 + b.decoration = core.register_decoration(dec)
273 273 end)
274 274
275 275 local toward = lib.math.toward
276 276 local hfinterval = 1.5
277 277 starlit.startJob('starlit:temps', hfinterval, function(delta)
278 278
279 279 -- our base thermal conductivity (κ) is measured in °C/°C/s. say the
................................................................................
285 285 -- d = Tₑ − Tₚ = -40°C
286 286 -- ΔT = κ×d = -.4°C/s
287 287 -- too cold:
288 288 -- x = beginning of danger zone
289 289 -- κ × (x - Tₚ) = y where y < Tₚ
290 290 -- our final change in temperature is computed as tΔC where t is time
291 291 local kappa = starlit.constant.heat.thermalConductivity
292 - local now = minetest.get_gametime()
292 + local now = core.get_gametime()
293 293 for name,user in pairs(starlit.activeUsers) do
294 294 local tr = user:species().tempRange
295 295 local t = starlit.world.climate.temp(user.entity:get_pos())
296 296
297 297 local weather,wsev = starlit.world.climate.weatherAt(user.entity:get_pos())
298 298 local wfac
299 299 if user.env.weather == nil
................................................................................
379 379 world.ecology.trees.foreach('starlit:tree-gen', {}, function(id, t)
380 380 for i,td in ipairs(t.decorate) do
381 381 local dec = {
382 382 deco_type = 'lsystem';
383 383 treedef = t.def;
384 384 }
385 385 for k,v in pairs(td) do dec[k]=v end
386 - minetest.register_decoration(dec)
386 + core.register_decoration(dec)
387 387 end
388 388 end)
389 389
390 -minetest.register_abm {
390 +core.register_abm {
391 391 label = "plant growth";
392 392 nodenames = {'group:plant_grow'};
393 393 chance = 15;
394 394 interval = 20;
395 395 catch_up = true;
396 396 action = function(pos, node)
397 - local def = minetest.registered_nodes[node.name]._starlit.plant
397 + local def = core.registered_nodes[node.name]._starlit.plant
398 398 -- 5 W: maximum power for UV lamps
399 399 -- 7 W: maximum solar power
400 - local uv = (minetest.get_natural_light(pos) / 15) * 7
400 + local uv = (core.get_natural_light(pos) / 15) * 7
401 401 -- TODO compute artificial contribution
402 402 local req = lib.tbl.defaults({
403 403 uv = 3;
404 404 soil = 'soil';
405 405 temp = -10;
406 406 humid = nil;
407 407 }, def.growReq);
408 408
409 409 -- TODO check other reqs
410 410
411 411 if uv > req.uv then
412 412 local plant = starlit.world.ecology.plants.db[def.id]
413 413 local nextStage = plant.stageNodes[def.stage + 1]
414 - minetest.swap_node(pos, {name=nextStage})
414 + core.swap_node(pos, {name=nextStage})
415 415 end
416 416 end;
417 417 }