Differences From
Artifact [b2784a81d4]:
- File
mods/starlit/user.lua
— part of check-in
[953151446f]
at
2024-05-05 19:31:39
on branch trunk
— better alarm LEDs, continue work on matter compiler UI, hack around gravitational horrorscape (i.e. stop shitting all over the server's `minetest.conf`), better stat interface, tweak some compute stats, be more generous with starting battery loadout, mercilessly squash numberless bugs beneath my jackbooted heel
(user:
lexi,
size: 37789)
[annotate]
[blame]
[check-ins using]
19 19 persona = {
20 20 key = 'starlit:persona';
21 21 type = starlit.store.persona;
22 22 };
23 23 }
24 24
25 25 local suitStore = starlit.store.suitMeta
26 +
27 +local leds = {
28 + freeze = {
29 + icon = lib.image('starlit-ui-alert-temp-cold.png');
30 + bg = lib.image('starlit-ui-alert-bg-temp-cold.png');
31 + side = 'left';
32 + };
33 + overheat = {
34 + icon = lib.image('starlit-ui-alert-temp-hot.png');
35 + bg = lib.image('starlit-ui-alert-bg-temp-hot.png');
36 + side = 'left';
37 + };
38 + hydration = {
39 + icon = lib.image('starlit-ui-alert-hydration.png');
40 + bg = lib.image('starlit-ui-alert-bg-hydration.png');
41 + side = 'left';
42 + };
43 + nutrition = {
44 + icon = lib.image('starlit-ui-alert-nutrition.png');
45 + bg = lib.image('starlit-ui-alert-bg-nutrition.png');
46 + side = 'left';
47 + };
48 +
49 + radiation = {
50 + icon = lib.image('starlit-ui-alert-rad.png');
51 + bg = lib.image('starlit-ui-alert-bg-rad.png');
52 + side = 'right';
53 + };
54 + fatigue = {
55 + icon = lib.image('starlit-ui-alert-fatigue.png');
56 + bg = lib.image('starlit-ui-alert-bg-fatigue.png');
57 + side = 'right';
58 + };
59 +}
26 60
27 61 starlit.type.user = lib.class {
28 62 name = 'starlit:user';
63 + leds = leds;
29 64 construct = function(ident)
30 65 local name, luser
31 66 if type(ident) == 'string' then
32 67 name = ident
33 68 luser = minetest.get_player_by_name(name)
34 69 else
35 70 luser = ident
................................................................................
38 73 return {
39 74 entity = luser;
40 75 name = name;
41 76 hud = {
42 77 elt = {};
43 78 bar = {};
44 79 alarm = {};
80 + led = { left={}, right={}, map={} };
45 81 };
46 82 tree = {};
47 83 action = {
48 84 bits = 0; -- for control deltas
49 85 prog = {}; -- for recording action progress on a node; reset on refocus
50 86 tgt = {type='nothing'};
51 87 sfx = {};
................................................................................
69 105 }
70 106 end;
71 107 __index = {
72 108 --------------
73 109 -- overlays --
74 110 --------------
75 111 updateOverlays = function(self)
112 + -- minetest: because fuck you, that's why
113 + local engineGravity = starlit.constant.phys.engineGravity
114 + local targetGravity = starlit.world.planet.gravity
76 115 local phys = {
77 116 speed = self.pheno:trait('speed',1);
78 117 jump = self.pheno:trait('jump',1);
79 - gravity = 1;
118 + gravity = targetGravity / engineGravity;
80 119 speed_climb = 1;
81 120 speed_crouch = 1;
82 121 speed_walk = 1;
83 122 acceleration_default = 1;
84 123 acceleration_air = 1;
85 124 }
86 125 for i, o in ipairs(self.overlays) do o(phys) end
................................................................................
372 411 self.hud.elt.bat = self:attachStatBar {
373 412 name = 'battery', stat = batteryLookup;
374 413 color = C(190,0,.2), size = 100;
375 414 pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-48 - bpad};
376 415 dir = 0;
377 416 align = {x=1, y=-1};
378 417 }
379 - self.hud.elt.psi = attachBasicStat {
380 - name = 'psi', stat = 'psi';
418 + self.hud.elt.numina = attachBasicStat {
419 + name = 'numina', stat = 'numina';
381 420 color = C(320,0,.2), size = 100;
382 421 pos = {x=0.5, y=1}, ofs = {x = hbofs - 4, y=-24 - bpad};
383 422 dir = 0;
384 423 align = {x=1, y=-1};
385 424 }
386 425 self.hud.elt.time = self:attachTextBox {
387 426 name = 'time';
................................................................................
477 516 self.entity:hud_remove(e.id)
478 517 end
479 518 end;
480 519 updateHUD = function(self)
481 520 for name, e in pairs(self.hud.elt) do
482 521 if e.update then e.update() end
483 522 end
523 + self:updateLEDs()
524 + end;
525 + updateLEDs = function(self)
526 + local time = minetest.get_gametime()
527 + local function updateSide(name, ofs, tx)
528 + local del = {}
529 + for i, l in ipairs(self.hud.led[name]) do
530 + local idx = 0
531 + if time - l.origin > 3 then
532 + if l.elt then self.entity:hud_remove(l.elt.id) end
533 + self.hud.led.map[l.kind] = nil
534 + table.insert(del, i)
535 + else
536 + local xc = (idx*48 + 400)*ofs
537 + if l.elt and next(del) then
538 + l.elt:update('offset', {x=xc, y=1})
539 + else
540 + local tex = leds[l.kind].icon:blit(hudAdjustBacklight(leds[l.kind].bg))
541 + if tx then tex = tex:transform(tx) end
542 + if not l.elt then
543 + l.elt = self:attachImage {
544 + tex = tex:render();
545 + align = {x=ofs, y=-1};
546 + pos = {x=.5, y=1};
547 + scale = {x=1,y=1};
548 + ofs = {x=xc, y=0};
549 + }
550 + end
551 + end
552 + idx = idx + 1
553 + end
554 + end
555 + for _, i in ipairs(del) do
556 + table.remove(self.hud.led[name], i)
557 + end
558 +
559 + end
560 + updateSide('left', -1)
561 + updateSide('right', 1, 'FX')
484 562 end;
485 563
486 564 ---------------------
487 565 -- actions & modes --
488 566 ---------------------
489 567 onModeChange = function(self, oldMode, silent)
490 568 self.hud.elt.crosshair.update()
................................................................................
920 998 if run then
921 999 run(self, ctx)
922 1000 return true
923 1001 end
924 1002 return false
925 1003 end;
926 1004
927 - alarm = function(self, urgency, kind, freq, where)
1005 + alarm = function(self, urgency, kind, minFreq)
1006 + minFreq = minFreq or 1.5
1007 + local time = minetest.get_gametime()
1008 + local led = leds[kind]
1009 +
1010 + local ul = self.hud.led.map[kind]
1011 + if ul then
1012 + if time - ul.origin > minFreq then
1013 + ul.origin = time
1014 + else return end
1015 + end
1016 +
1017 + if urgency > 0 then
1018 + local urgencies = {
1019 + [1] = {sound = 'starlit-alarm'};
1020 + [2] = {sound = 'starlit-alarm-urgent'};
1021 + }
1022 + local urg = urgencies[urgency] or urgencies[#urgencies]
1023 +
1024 + if time - self.cooldownTimes.alarm > 1.5 then
1025 + self.cooldownTimes.alarm = time
1026 + self:suitSound(urg.sound)
1027 + end
1028 + end
1029 +
1030 +
1031 + local newLed = {
1032 + kind = kind;
1033 + origin = time;
1034 + }
1035 + self.hud.led.map[kind] = newLed
1036 + table.insert(self.hud.led[led.side], newLed)
1037 +
1038 +
1039 + self:updateLEDs()
1040 +
1041 + --[[
928 1042 freq = freq or 3
929 1043 local urgencies = {
930 1044 [1] = {sound = 'starlit-alarm'};
931 1045 [2] = {sound = 'starlit-alarm-urgent'};
932 1046 }
933 1047 local gt = minetest.get_gametime()
934 1048 local urg = urgencies[urgency] or urgencies[#urgencies]
................................................................................
954 1068 -- HATE. HATE. HAAAAAAAAAAATE
955 1069 minetest.after(freq/2, function()
956 1070 for k,v in pairs(self.hud.alarm) do
957 1071 self.entity:hud_remove(v.id)
958 1072 end
959 1073 self.hud.alarm={}
960 1074 end)
961 - end
1075 + end]]
962 1076 end;
963 1077
964 1078 -------------
965 1079 -- weather --
966 1080 -------------
967 1081 updateWeather = function(self)
968 1082 end;
................................................................................
1015 1129 };
1016 1130 }
1017 1131
1018 1132 local clockInterval = 1.0
1019 1133 starlit.startJob('starlit:clock', clockInterval, function(delta)
1020 1134 for id, u in pairs(starlit.activeUsers) do
1021 1135 u.hud.elt.time:update()
1136 + u:updateLEDs()
1022 1137 end
1023 1138 end)
1024 1139
1025 1140 -- performs a general HUD refresh, mainly to update the HUD backlight brightness
1026 1141 local hudInterval = 10
1027 1142 starlit.startJob('starlit:hud-refresh', hudInterval, function(delta)
1028 - for id, u in pairs(starlit.activeUsers) do u:updateHUD() end
1143 + for id, u in pairs(starlit.activeUsers) do
1144 + u:updateHUD() end
1029 1145 end)
1030 1146
1031 1147 local biointerval = 1.0
1032 1148 starlit.startJob('starlit:bio', biointerval, function(delta)
1033 1149 for id, u in pairs(starlit.activeUsers) do
1034 1150 if u:effectiveStat 'health' ~= 0 then
1035 1151 local bmr = u:phenoTrait 'metabolism' * biointerval
................................................................................
1092 1208
1093 1209 if sp < 1.0 and minetest.get_gametime() - u.cooldownTimes.stamina > 5.0 then
1094 1210 u:statDelta('stamina', (u:phenoTrait('staminaRegen',1) * penaltyFromFatigue) / heatPenalty)
1095 1211 -- print('stam', u:effectiveStat 'stamina', u:phenoTrait('staminaRegen',1) / heatPenalty, heatPenalty)
1096 1212 end
1097 1213
1098 1214 local morale, mp = u:effectiveStat 'morale'
1099 - local pr = u:phenoTrait 'psiRegen'
1100 - u:statDelta('psi', pr * penaltyFromFatigue * mp)
1215 + local pr = u:phenoTrait 'numinaRegen'
1216 + u:statDelta('numina', pr * penaltyFromFatigue * mp)
1101 1217 end
1102 1218 end
1103 1219 end)
1104 1220
1105 1221 local cbit = {
1106 1222 up = 0x001;
1107 1223 down = 0x002;