3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
function world.date()
local days = minetest.get_day_count()
local year = math.floor(days / world.planet.orbit);
local day = days % world.planet.orbit;
return {
year = year, day = day;
season = day / world.planet.orbit;
}
end
local lerp = lib.math.lerp
local function gradient(grad, pos)
local n = #grad
if n == 1 then return grad[1] end
................................................................................
local op = pos*(n-1)
local idx = math.floor(op)
local t = op-idx
return lerp(t, grad[1 + idx], grad[2 + idx])
end
local altitudeCooling = 10 / 100
-- this function provides the basis for temperature calculation,
-- which is performed by adding this value to the ambient temperature,
-- determined by querying nearby group:heatSource items in accordance
-- with the inverse-square law
function world.climate.eval(pos, tod, season)
local data = minetest.get_biome_data(pos)
local biome = world.ecology.biomes.db[minetest.get_biome_name(data.biome)]
local heat, humid = data.heat, data.humidity
tod = tod or minetest.get_timeofday()
heat = lerp(math.abs(tod - 0.5)*2, heat, heat + biome.nightTempDelta)
local td = world.date()
heat = heat + gradient(biome.seasonalTemp, season or td.season)
if pos.y > 0 then
heat = heat - pos.y*altitudeCooling
end
return {
surfaceTemp = heat;
waterTemp = heat + biome.waterTempDelta;
surfaceHumid = humid;
}
end
|
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
function world.date()
local days = minetest.get_day_count()
local year = math.floor(days / world.planet.orbit);
local day = days % world.planet.orbit;
return {
year = year, day = day;
season = day / world.planet.orbit + 0.5; -- begin summer
}
end
local lerp = lib.math.lerp
local function gradient(grad, pos)
local n = #grad
if n == 1 then return grad[1] end
................................................................................
local op = pos*(n-1)
local idx = math.floor(op)
local t = op-idx
return lerp(t, grad[1 + idx], grad[2 + idx])
end
local altitudeCooling = 10 / 100
local heatRange = {min = -70, max = 70} -- translate mt temps into real temps
-- this function provides the basis for temperature calculation,
-- which is performed by adding this value to the ambient temperature,
-- determined by querying nearby group:heatSource items in accordance
-- with the inverse-square law
function world.climate.eval(pos, tod, season)
local data = minetest.get_biome_data(pos)
local biome = world.ecology.biomes.db[minetest.get_biome_name(data.biome)]
local heat, humid = data.heat, data.humidity
heat = lerp(heat/100, heatRange.min, heatRange.max)
tod = tod or minetest.get_timeofday()
heat = lerp(math.abs(tod - 0.5)*2, heat, heat + biome.nightTempDelta)
-- print('base heat', heat)
local td = world.date()
heat = heat + gradient(biome.seasonalTemp, season or td.season)
-- print('seasonal heat', heat)
if pos.y > 0 then
heat = heat - pos.y*altitudeCooling
end
-- print('altitude heat', heat)
return {
surfaceTemp = heat;
waterTemp = heat + biome.waterTempDelta;
surfaceHumid = humid;
}
end
|