starlit  Diff

Differences From Artifact [b2784a81d4]:

To Artifact [c928629a64]:


19
20
21
22
23
24
25
26


































27
28

29
30
31
32
33
34
35
..
38
39
40
41
42
43
44

45
46
47
48
49
50
51
..
69
70
71
72
73
74
75



76
77
78
79
80
81
82
83
84
85
86
...
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
477
478
479
480
481
482
483







































484
485
486
487
488
489
490
...
920
921
922
923
924
925
926
927




































928
929
930
931
932
933
934
...
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
....
1015
1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
....
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
	persona = {
		key  = 'starlit:persona';
		type = starlit.store.persona;
	};
}

local suitStore = starlit.store.suitMeta



































starlit.type.user = lib.class {
	name = 'starlit:user';

	construct = function(ident)
		local name, luser
		if type(ident) == 'string' then
			name = ident
			luser = minetest.get_player_by_name(name)
		else
			luser = ident
................................................................................
		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 = {};
................................................................................
		}
	end;
	__index = {
		--------------
		-- overlays --
		--------------
		updateOverlays = function(self)



			local phys = {
				speed = self.pheno:trait('speed',1);
				jump = self.pheno:trait('jump',1);
				gravity = 1;
				speed_climb = 1;
				speed_crouch = 1;
				speed_walk = 1;
				acceleration_default = 1;
				acceleration_air = 1;
			}
			for i, o in ipairs(self.overlays) do o(phys) end
................................................................................
			self.hud.elt.bat = self:attachStatBar {
				name = 'battery', stat = batteryLookup;
				color = C(190,0,.2), size = 100;
				pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-48 - bpad};
				dir = 0;
				align = {x=1, y=-1};
			}
			self.hud.elt.psi = attachBasicStat {
				name = 'psi', stat = 'psi';
				color = C(320,0,.2), size = 100;
				pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-24 - bpad};
				dir = 0;
				align = {x=1, y=-1};
			}
			self.hud.elt.time = self:attachTextBox {
				name = 'time';
................................................................................
				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;

		---------------------
		-- actions & modes --
		---------------------
		onModeChange = function(self, oldMode, silent)
			self.hud.elt.crosshair.update()
................................................................................
			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]
................................................................................
			   -- 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
................................................................................

			if sp < 1.0 and minetest.get_gametime() - u.cooldownTimes.stamina > 5.0 then
				u:statDelta('stamina', (u:phenoTrait('staminaRegen',1) * penaltyFromFatigue) / heatPenalty)
-- 				print('stam', u:effectiveStat 'stamina', u:phenoTrait('staminaRegen',1) / heatPenalty, heatPenalty)
			end

			local morale, mp = u:effectiveStat 'morale'
			local pr = u:phenoTrait 'psiRegen'
			u:statDelta('psi', pr * penaltyFromFatigue * mp)
		end
	end
end)

local cbit = {
	up   = 0x001;
	down = 0x002;








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


>







 







>







 







>
>
>



|







 







|
|







 







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







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







>






|
>







 







|
|







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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
...
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
....
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
....
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
....
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
	persona = {
		key  = 'starlit:persona';
		type = starlit.store.persona;
	};
}

local suitStore = starlit.store.suitMeta

local leds = {
	freeze = {
		icon = lib.image('starlit-ui-alert-temp-cold.png');
		bg = lib.image('starlit-ui-alert-bg-temp-cold.png');
		side = 'left';
	};
	overheat = {
		icon = lib.image('starlit-ui-alert-temp-hot.png');
		bg = lib.image('starlit-ui-alert-bg-temp-hot.png');
		side = 'left';
	};
	hydration = {
		icon = lib.image('starlit-ui-alert-hydration.png');
		bg = lib.image('starlit-ui-alert-bg-hydration.png');
		side = 'left';
	};
	nutrition = {
		icon = lib.image('starlit-ui-alert-nutrition.png');
		bg = lib.image('starlit-ui-alert-bg-nutrition.png');
		side = 'left';
	};

	radiation = {
		icon = lib.image('starlit-ui-alert-rad.png');
		bg = lib.image('starlit-ui-alert-bg-rad.png');
		side = 'right';
	};
	fatigue = {
		icon = lib.image('starlit-ui-alert-fatigue.png');
		bg = lib.image('starlit-ui-alert-bg-fatigue.png');
		side = 'right';
	};
}

starlit.type.user = lib.class {
	name = 'starlit:user';
	leds = leds;
	construct = function(ident)
		local name, luser
		if type(ident) == 'string' then
			name = ident
			luser = minetest.get_player_by_name(name)
		else
			luser = ident
................................................................................
		return {
			entity = luser;
			name = name;
			hud = {
				elt = {};
				bar = {};
				alarm = {};
				led = { left={}, right={}, map={} };
			};
			tree = {};
			action = {
				bits = 0; -- for control deltas
				prog = {}; -- for recording action progress on a node; reset on refocus
				tgt = {type='nothing'};
				sfx = {};
................................................................................
		}
	end;
	__index = {
		--------------
		-- overlays --
		--------------
		updateOverlays = function(self)
			-- minetest: because fuck you, that's why
			local engineGravity = starlit.constant.phys.engineGravity
			local targetGravity = starlit.world.planet.gravity
			local phys = {
				speed = self.pheno:trait('speed',1);
				jump = self.pheno:trait('jump',1);
				gravity = targetGravity / engineGravity;
				speed_climb = 1;
				speed_crouch = 1;
				speed_walk = 1;
				acceleration_default = 1;
				acceleration_air = 1;
			}
			for i, o in ipairs(self.overlays) do o(phys) end
................................................................................
			self.hud.elt.bat = self:attachStatBar {
				name = 'battery', stat = batteryLookup;
				color = C(190,0,.2), size = 100;
				pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-48 - bpad};
				dir = 0;
				align = {x=1, y=-1};
			}
			self.hud.elt.numina = attachBasicStat {
				name = 'numina', stat = 'numina';
				color = C(320,0,.2), size = 100;
				pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-24 - bpad};
				dir = 0;
				align = {x=1, y=-1};
			}
			self.hud.elt.time = self:attachTextBox {
				name = 'time';
................................................................................
				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
			self:updateLEDs()
		end;
		updateLEDs = function(self)
			local time = minetest.get_gametime()
			local function updateSide(name, ofs, tx)
				local del = {}
				for i, l in ipairs(self.hud.led[name]) do
					local idx = 0
					if time - l.origin > 3 then
						if l.elt then self.entity:hud_remove(l.elt.id) end
						self.hud.led.map[l.kind] = nil
						table.insert(del, i)
					else
						local xc = (idx*48 + 400)*ofs
						if l.elt and next(del) then
							l.elt:update('offset', {x=xc, y=1})
						else
							local tex = leds[l.kind].icon:blit(hudAdjustBacklight(leds[l.kind].bg))
							if tx then tex = tex:transform(tx) end
							if not l.elt then
								l.elt = self:attachImage {
									tex = tex:render();
									align = {x=ofs, y=-1};
									pos = {x=.5, y=1};
									scale = {x=1,y=1};
									ofs = {x=xc, y=0};
								}
							end
						end
						idx = idx + 1
					end
				end
				for _, i in ipairs(del) do
					table.remove(self.hud.led[name], i)
				end

			end
			updateSide('left', -1)
			updateSide('right', 1, 'FX')
		end;

		---------------------
		-- actions & modes --
		---------------------
		onModeChange = function(self, oldMode, silent)
			self.hud.elt.crosshair.update()
................................................................................
			if run then
				run(self, ctx)
				return true
			end
			return false
		end;

		alarm = function(self, urgency, kind, minFreq)
			minFreq = minFreq or 1.5
			local time = minetest.get_gametime()
			local led = leds[kind]

			local ul = self.hud.led.map[kind]
			if ul then
				if time - ul.origin > minFreq then
					ul.origin = time
				else return end
			end

			if urgency > 0 then
				local urgencies = {
					[1] = {sound = 'starlit-alarm'};
					[2] = {sound = 'starlit-alarm-urgent'};
				}
			   local urg = urgencies[urgency] or urgencies[#urgencies]

			   if time - self.cooldownTimes.alarm > 1.5 then
				   self.cooldownTimes.alarm = time
				   self:suitSound(urg.sound)
			   end
		   end


			local newLed = {
				kind = kind;
				origin = time;
			}
			self.hud.led.map[kind] = newLed
			table.insert(self.hud.led[led.side], newLed)


		   self:updateLEDs()

		--[[
			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]
................................................................................
			   -- 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()
		u:updateLEDs()
	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
................................................................................

			if sp < 1.0 and minetest.get_gametime() - u.cooldownTimes.stamina > 5.0 then
				u:statDelta('stamina', (u:phenoTrait('staminaRegen',1) * penaltyFromFatigue) / heatPenalty)
-- 				print('stam', u:effectiveStat 'stamina', u:phenoTrait('staminaRegen',1) / heatPenalty, heatPenalty)
			end

			local morale, mp = u:effectiveStat 'morale'
			local pr = u:phenoTrait 'numinaRegen'
			u:statDelta('numina', pr * penaltyFromFatigue * mp)
		end
	end
end)

local cbit = {
	up   = 0x001;
	down = 0x002;