starlit  Diff

Differences From Artifact [d1f4916ac1]:

To Artifact [de51a702a5]:


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
79
80
81
82
83
84
85


86
87












































































































88
89
90
91
92
93
94
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
175
176
177
178
179
180
181

182
183
184










185
186
187
188
189
190
191
		surfaceTemp = heat;
		waterTemp = heat + biome.waterTempDelta;
		surfaceHumid = humid;
	}
end

local vdsq = lib.math.vdsq
function world.climate.temp(pos) --> irradiance at pos in W
	local cl = world.climate.eval(pos)
	local radCenters = starlit.region.radiator.store:get_areas_for_pos(pos, false, true)
	local irradiance = 0
	for _,e in pairs(radCenters) do
		local rpos = minetest.string_to_pos(e.data)
		local rdef = assert(minetest.registered_nodes[assert(minetest.get_node(rpos)).name])
		local rc = rdef._starlit.radiator
................................................................................
					power = power * (1 - (dist_sq / ((r_max+1)^2)))
				end
				power = power * (1 - (obstruct/5))
				irradiance = irradiance + power
			end
		end
	end


	return irradiance + cl.surfaceTemp
end













































































































world.ecology.biomes.foreach('starlit:biome-gen', {}, function(id, b)
	b.def.name = id
	minetest.register_biome(b.def)
end)

world.ecology.plants.foreach('starlit:plant-gen', {}, function(id, b)
................................................................................
	}
	for k,v in pairs(b.decoration) do dec[k] = v end
	b.decoration = minetest.register_decoration(dec)
end)

local toward = lib.math.toward
local hfinterval = 1.5
starlit.startJob('starlit:heatflow', hfinterval, function(delta)

	-- our base thermal conductivity (κ) is measured in °C/°C/s. say the
	-- player is in -30°C weather, and has an internal temperature of
	-- 10°C. then:
	--   κ  = .1°C/C/s (which is apparently 100mHz)
	--   Tₚ =  10°C
	--   Tₑ = -30°C
................................................................................
	--   d  = Tₑ − Tₚ = -40°C
	--   ΔT = κ×d = -.4°C/s
	-- too cold:
	--		x = beginning of danger zone
	--    κ × (x - Tₚ) = y where y < Tₚ
	-- our final change in temperature is computed as tΔC where t is time
	local kappa = starlit.constant.heat.thermalConductivity

	for name,user in pairs(starlit.activeUsers) do
		local tr = user:species().tempRange
		local t = starlit.world.climate.temp(user.entity:get_pos())











		do -- this bit probably belongs in starlit:bio but we do it here in order
		   -- to spare ourselves another call into the dark swamp of climate.temp
		   local urg = 1
		   local hz = user:tempHazard(t)
			local tr = user:species().tempRange.survivable
		   if hz == 'cold' then







|







 







>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>



>
>
>
>
>
>
>
>
>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
		surfaceTemp = heat;
		waterTemp = heat + biome.waterTempDelta;
		surfaceHumid = humid;
	}
end

local vdsq = lib.math.vdsq
function world.climate.temp(pos, timeshift) --> irradiance at pos in W
	local cl = world.climate.eval(pos)
	local radCenters = starlit.region.radiator.store:get_areas_for_pos(pos, false, true)
	local irradiance = 0
	for _,e in pairs(radCenters) do
		local rpos = minetest.string_to_pos(e.data)
		local rdef = assert(minetest.registered_nodes[assert(minetest.get_node(rpos)).name])
		local rc = rdef._starlit.radiator
................................................................................
					power = power * (1 - (dist_sq / ((r_max+1)^2)))
				end
				power = power * (1 - (obstruct/5))
				irradiance = irradiance + power
			end
		end
	end
	local w = world.climate.weatherAt(pos, timeshift)

	return irradiance + cl.surfaceTemp
end

function world.ecology.biomeAt(pos)
	return world.ecology.biomes.db[minetest.get_biome_name(minetest.get_biome_data(pos).biome)]
end


minetest.after(0, function()
	world.climate.weatherMap.kind = minetest.get_perlin {
		seed = 0x925afe;
		octaves = 2;
		spread = vector.new(256,256,120);
	};
	world.climate.weatherMap.severity = minetest.get_perlin {
		seed = 0x39de1d;
		octaves = 1;
		spread = vector.new(256,256,60);
	};
end)

function world.climate.weatherAt(pos, timeshift)
	timeshift = timeshift or 0
	local wv  = world.climate.weatherMap.kind:get_3d(vector.new(pos.x, pos.z, minetest.get_gametime() + timeshift))
	local sev = world.climate.weatherMap.severity:get_3d(vector.new(pos.x, pos.z, minetest.get_gametime() + timeshift))
	local b = world.ecology.biomeAt(pos)
	local w = 'starlit:clear'
	for i,v in ipairs(b.weather) do
		if wv < v[1] then
			w = v[2]
			break
		end
	end
	local mods = {
		cloudCover = 0;
		rain = 0; -- affects plant growth
		snow = 0; -- spawns snow layer
		fog = 0;
		temp = 0;
		hum = 0;
		rad = 0;
	}
	return world.climate.weather.db[w], sev
end


-- weather manages particle systems, and provides modifiers for
-- temp, cloud cover, received precipitation, and fog

world.climate.weather.link('starlit:clear', {
	name = 'Clear';
})
world.climate.weather.link('starlit:cloudy', {
	name = 'Cloudy';
	mod = function(m, temp, hum, sev)
		m.cloudCover = math.max(m.cloudCover, sev)
	end;
})
world.climate.weather.link('starlit:precip', {
	name = function(temp, hum, sev)
		if temp < 0 then return 'Snow' else return 'Rain' end
	end;
	mod = function(m, temp, hum, sev)
		m.cloudCover = math.max(m.cloudCover, sev)
		if temp < 0 then
			m.snow = math.max(m.snow, sev/2)
		else
			m.rain = math.max(m.rain, sev/2)
		end
	end;
})
world.climate.weather.link('starlit:storm', {
	name = function(temp, hum, sev)
		if temp < 0 then
			if sev > .5
				then return 'Blizzard'
				else return 'Snowstorm'
			end
		else
			if sev > .5
				then return 'Monsoon'
				else return 'Rainstorm'
			end
		end
	end;
	mod = function(m, temp, hum, sev)
		m.cloudCover = math.max(m.cloudCover, sev)
		if temp < 0 then
			m.snow = math.max(m.snow, sev/2 + .5)
		else
			m.rain = math.max(m.rain, sev/2 + .5)
		end
	end;
})
world.climate.weather.link('starlit:tstorm', {
	name = 'Thunderstorm';
	danger = 1;
	mod = function(m, temp, hum, sev)
		m.cloudCover = math.max(m.cloudCover, sev)
		m.danger = (sev>.5) and 2 or 1
	end;
})
world.climate.weather.link('starlit:sstorm', {
	name = 'Solar Storm';
	danger = 2;
})
world.climate.weather.link('starlit:meteorShower', {
	name = 'Meteor Shower';
	danger = 2;
})

world.ecology.biomes.foreach('starlit:biome-gen', {}, function(id, b)
	b.def.name = id
	minetest.register_biome(b.def)
end)

world.ecology.plants.foreach('starlit:plant-gen', {}, function(id, b)
................................................................................
	}
	for k,v in pairs(b.decoration) do dec[k] = v end
	b.decoration = minetest.register_decoration(dec)
end)

local toward = lib.math.toward
local hfinterval = 1.5
starlit.startJob('starlit:temps', hfinterval, function(delta)

	-- our base thermal conductivity (κ) is measured in °C/°C/s. say the
	-- player is in -30°C weather, and has an internal temperature of
	-- 10°C. then:
	--   κ  = .1°C/C/s (which is apparently 100mHz)
	--   Tₚ =  10°C
	--   Tₑ = -30°C
................................................................................
	--   d  = Tₑ − Tₚ = -40°C
	--   ΔT = κ×d = -.4°C/s
	-- too cold:
	--		x = beginning of danger zone
	--    κ × (x - Tₚ) = y where y < Tₚ
	-- our final change in temperature is computed as tΔC where t is time
	local kappa = starlit.constant.heat.thermalConductivity
	local now = minetest.get_gametime()
	for name,user in pairs(starlit.activeUsers) do
		local tr = user:species().tempRange
		local t = starlit.world.climate.temp(user.entity:get_pos())

		local weather,wsev = starlit.world.climate.weatherAt(user.entity:get_pos())
		local wfac
		if user.env.weather == nil
			then wfac = 1
			else wfac = (now - user.env.weather.when) / 10
		end
		if user.env.weather == nil or now - user.env.weather.when >= 10 then
			user.env.weather = {when = now, what = weather}
		end

		do -- this bit probably belongs in starlit:bio but we do it here in order
		   -- to spare ourselves another call into the dark swamp of climate.temp
		   local urg = 1
		   local hz = user:tempHazard(t)
			local tr = user:species().tempRange.survivable
		   if hz == 'cold' then