starlit  Diff

Differences From Artifact [788077fd8e]:

To Artifact [7074af2318]:


37
38
39
40
41
42
43

44
45
46
47
48
49
50
..
59
60
61
62
63
64
65

66
67
68
69
70
71
72
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
...
499
500
501
502
503
504
505
























506
507
508
509
510
511
512
...
872
873
874
875
876
877
878





































879
880
881
882
883
884
885
...
933
934
935
936
937
938
939






940
941
942
943
944
945
946
		end
		return {
			entity = luser;
			name = name;
			hud = {
				elt = {};
				bar = {};

			};
			tree = {};
			action = {
				bits = 0; -- for control deltas
				prog = {}; -- for recording action progress on a node; reset on refocus
				tgt = {type='nothing'};
				sfx = {};
................................................................................
			};
			pref = {
				calendar = 'commune';
			};
			overlays = {};
			cooldownTimes = {
				stamina = 0;

			};
		}
	end;
	__index = {
		--------------
		-- overlays --
		--------------
................................................................................
		end;

		---------
		-- HUD --
		---------
		attachImage = function(self, def)
			local user = self.entity
			local img = {}
			img.id = user:hud_add {
				type = 'image';
				text = def.tex;
				scale = def.scale;
				alignment = def.align;
				position = def.pos;
				offset = def.ofs;
................................................................................
					end, def)
				end
			end
			return img
		end;
		attachMeter = function(self, def)
			local luser = self.entity
			local m = {}
			local w = def.size or 80
			local szf = w / 80
			local h = szf * 260
			m.meter = luser:hud_add {
				type = 'image';
				scale = {x = szf, y = szf};
				alignment = def.align;
................................................................................
					luser:hud_change(m.readout, 'number', txtcolor:hex())
				end
			end
			return m
		end;
		attachTextBox = function(self, def)
			local luser = self.entity
			local box = {}
			box.id = luser:hud_add {
				type = 'text';
				text = '';
				alignment = def.align;
				number = def.color and def.color:int24() or 0xFFffFF;
				scale = def.bound;
				size = {x = def.size, y=0};
................................................................................
					luser:hud_change(box.id, 'number', color:int24())
				end
			end
			return box
		end;
		attachStatBar = function(self, def)
			local luser = self.entity
			local bar = {}
			local img = lib.image 'starlit-ui-bar.png'
			local colorized = img
			if type(def.color) ~= 'function' then
				colorized = colorized:shift(def.color)
			end

			bar.id = luser:hud_add {
................................................................................
					set('text', hudAdjustBacklight(hudCenterBG):render())
				end;
			};
			self:updateHUD()
		end;
		deleteHUD = function(self)
			for name, e in pairs(self.hud.elt) do
				self:hud_delete(e.id)
			end
		end;
		updateHUD = function(self)
			for name, e in pairs(self.hud.elt) do
				if e.update then e.update() end
			end
		end;
................................................................................
		-- intel-gathering --
		---------------------
		clientInfo = function(self)
			return minetest.get_player_information(self.name)
		end;
		species = function(self)
			return starlit.world.species.index[self.persona.species]
























		end;

		--------------------
		-- event handlers --
		--------------------
		onSignup = function(self)
			local meta = self.entity:get_meta()
................................................................................
			end
			if run then
				run(self, ctx)
				return true
			end
			return false
		end;






































		-------------
		-- weather --
		-------------
		updateWeather = function(self)
		end;

................................................................................

local clockInterval = 1.0
starlit.startJob('starlit:clock', clockInterval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		u.hud.elt.time:update()
	end
end)







local biointerval = 1.0
starlit.startJob('starlit:bio', biointerval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		if u:effectiveStat 'health' ~= 0 then
			local bmr = u:phenoTrait 'metabolism' * biointerval
			-- TODO apply modifiers







>







 







>







 







|







 







|







 







|







 







|







 







|







 







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







 







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







 







>
>
>
>
>
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
...
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
...
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
...
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
		end
		return {
			entity = luser;
			name = name;
			hud = {
				elt = {};
				bar = {};
				alarm = {};
			};
			tree = {};
			action = {
				bits = 0; -- for control deltas
				prog = {}; -- for recording action progress on a node; reset on refocus
				tgt = {type='nothing'};
				sfx = {};
................................................................................
			};
			pref = {
				calendar = 'commune';
			};
			overlays = {};
			cooldownTimes = {
				stamina = 0;
				alarm = 0;
			};
		}
	end;
	__index = {
		--------------
		-- overlays --
		--------------
................................................................................
		end;

		---------
		-- HUD --
		---------
		attachImage = function(self, def)
			local user = self.entity
			local img = {def = def}
			img.id = user:hud_add {
				type = 'image';
				text = def.tex;
				scale = def.scale;
				alignment = def.align;
				position = def.pos;
				offset = def.ofs;
................................................................................
					end, def)
				end
			end
			return img
		end;
		attachMeter = function(self, def)
			local luser = self.entity
			local m = {def = def}
			local w = def.size or 80
			local szf = w / 80
			local h = szf * 260
			m.meter = luser:hud_add {
				type = 'image';
				scale = {x = szf, y = szf};
				alignment = def.align;
................................................................................
					luser:hud_change(m.readout, 'number', txtcolor:hex())
				end
			end
			return m
		end;
		attachTextBox = function(self, def)
			local luser = self.entity
			local box = {def = def}
			box.id = luser:hud_add {
				type = 'text';
				text = '';
				alignment = def.align;
				number = def.color and def.color:int24() or 0xFFffFF;
				scale = def.bound;
				size = {x = def.size, y=0};
................................................................................
					luser:hud_change(box.id, 'number', color:int24())
				end
			end
			return box
		end;
		attachStatBar = function(self, def)
			local luser = self.entity
			local bar = {def = def}
			local img = lib.image 'starlit-ui-bar.png'
			local colorized = img
			if type(def.color) ~= 'function' then
				colorized = colorized:shift(def.color)
			end

			bar.id = luser:hud_add {
................................................................................
					set('text', hudAdjustBacklight(hudCenterBG):render())
				end;
			};
			self:updateHUD()
		end;
		deleteHUD = function(self)
			for name, e in pairs(self.hud.elt) do
				self.entity:hud_remove(e.id)
			end
		end;
		updateHUD = function(self)
			for name, e in pairs(self.hud.elt) do
				if e.update then e.update() end
			end
		end;
................................................................................
		-- intel-gathering --
		---------------------
		clientInfo = function(self)
			return minetest.get_player_information(self.name)
		end;
		species = function(self)
			return starlit.world.species.index[self.persona.species]
		end;
		-- can the suit heater sustain its current internal temperature in an area of t°C
		tempCanSustain = function(self, t)
			if self:naked() then return false end
			local s = self:getSuit()
			if s:powerState() == 'off' then return false end
			local sd = s:def()
			local w = self:effectiveStat 'warmth'
			local kappa = starlit.constant.heat.thermalConductivity
			local insul = sd.temp.insulation
			local dt = (kappa * (1-insul)) * (t - w)
			print('dt', dt, dump(sd.temp))
			if (dt > 0 and          dt  > sd.temp.maxCool)
			or (dt < 0 and math.abs(dt) > sd.temp.maxHeat) then return false end
			return true
		end;
		-- will exposure to temperature t cause the player eventual harm
		tempHazard = function(self, t)
			local tr = self:species().tempRange.survivable
			if t >= tr[1] and t <= tr[2] then return nil end
			if self:tempCanSustain(t)    then return nil end

			if t < tr[1] then return 'cold' end
			return 'hot'
		end;

		--------------------
		-- event handlers --
		--------------------
		onSignup = function(self)
			local meta = self.entity:get_meta()
................................................................................
			end
			if run then
				run(self, ctx)
				return true
			end
			return false
		end;

		alarm = function(self, urgency, kind, freq, where)
			freq = freq or 3
			local urgencies = {
				[1] = {sound = 'starlit-alarm'};
				[2] = {sound = 'starlit-alarm-urgent'};
			}
		   local gt = minetest.get_gametime()
		   local urg = urgencies[urgency] or urgencies[#urgencies]

		   if gt - self.cooldownTimes.alarm < freq then return end

		   self.cooldownTimes.alarm = gt
		   self:suitSound(urg.sound)

		   if where then
			   local elt = {
				   tex = where.tex or 'starlit-ui-alert.png';
				   scale = {x=1, y=1};
				   align = table.copy(where.elt.def.align);
				   pos = table.copy(where.elt.def.pos);
				   ofs = table.copy(where.elt.def.ofs);
			   }
			   elt.ofs.x = elt.ofs.x + where.ofs.x
			   elt.ofs.y = elt.ofs.y + where.ofs.y
			   local attached = self:attachImage(elt)
				table.insert(self.hud.alarm, attached)

			   -- HATE. HATE. HAAAAAAAAAAATE
			   minetest.after(freq/2, function()
				   for k,v in pairs(self.hud.alarm) do
					   self.entity:hud_remove(v.id)
				   end
				   self.hud.alarm={}
			   end)
		   end
	   end;

		-------------
		-- weather --
		-------------
		updateWeather = function(self)
		end;

................................................................................

local clockInterval = 1.0
starlit.startJob('starlit:clock', clockInterval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		u.hud.elt.time:update()
	end
end)

-- performs a general HUD refresh, mainly to update the HUD backlight brightness
local hudInterval = 10
starlit.startJob('starlit:hud-refresh', hudInterval, function(delta)
	for id, u in pairs(starlit.activeUsers) do u:updateHUD() end
end)

local biointerval = 1.0
starlit.startJob('starlit:bio', biointerval, function(delta)
	for id, u in pairs(starlit.activeUsers) do
		if u:effectiveStat 'health' ~= 0 then
			local bmr = u:phenoTrait 'metabolism' * biointerval
			-- TODO apply modifiers