Differences From
Artifact [788077fd8e]:
37 37 end
38 38 return {
39 39 entity = luser;
40 40 name = name;
41 41 hud = {
42 42 elt = {};
43 43 bar = {};
44 + alarm = {};
44 45 };
45 46 tree = {};
46 47 action = {
47 48 bits = 0; -- for control deltas
48 49 prog = {}; -- for recording action progress on a node; reset on refocus
49 50 tgt = {type='nothing'};
50 51 sfx = {};
................................................................................
59 60 };
60 61 pref = {
61 62 calendar = 'commune';
62 63 };
63 64 overlays = {};
64 65 cooldownTimes = {
65 66 stamina = 0;
67 + alarm = 0;
66 68 };
67 69 }
68 70 end;
69 71 __index = {
70 72 --------------
71 73 -- overlays --
72 74 --------------
................................................................................
188 190 end;
189 191
190 192 ---------
191 193 -- HUD --
192 194 ---------
193 195 attachImage = function(self, def)
194 196 local user = self.entity
195 - local img = {}
197 + local img = {def = def}
196 198 img.id = user:hud_add {
197 199 type = 'image';
198 200 text = def.tex;
199 201 scale = def.scale;
200 202 alignment = def.align;
201 203 position = def.pos;
202 204 offset = def.ofs;
................................................................................
209 211 end, def)
210 212 end
211 213 end
212 214 return img
213 215 end;
214 216 attachMeter = function(self, def)
215 217 local luser = self.entity
216 - local m = {}
218 + local m = {def = def}
217 219 local w = def.size or 80
218 220 local szf = w / 80
219 221 local h = szf * 260
220 222 m.meter = luser:hud_add {
221 223 type = 'image';
222 224 scale = {x = szf, y = szf};
223 225 alignment = def.align;
................................................................................
263 265 luser:hud_change(m.readout, 'number', txtcolor:hex())
264 266 end
265 267 end
266 268 return m
267 269 end;
268 270 attachTextBox = function(self, def)
269 271 local luser = self.entity
270 - local box = {}
272 + local box = {def = def}
271 273 box.id = luser:hud_add {
272 274 type = 'text';
273 275 text = '';
274 276 alignment = def.align;
275 277 number = def.color and def.color:int24() or 0xFFffFF;
276 278 scale = def.bound;
277 279 size = {x = def.size, y=0};
................................................................................
286 288 luser:hud_change(box.id, 'number', color:int24())
287 289 end
288 290 end
289 291 return box
290 292 end;
291 293 attachStatBar = function(self, def)
292 294 local luser = self.entity
293 - local bar = {}
295 + local bar = {def = def}
294 296 local img = lib.image 'starlit-ui-bar.png'
295 297 local colorized = img
296 298 if type(def.color) ~= 'function' then
297 299 colorized = colorized:shift(def.color)
298 300 end
299 301
300 302 bar.id = luser:hud_add {
................................................................................
446 448 set('text', hudAdjustBacklight(hudCenterBG):render())
447 449 end;
448 450 };
449 451 self:updateHUD()
450 452 end;
451 453 deleteHUD = function(self)
452 454 for name, e in pairs(self.hud.elt) do
453 - self:hud_delete(e.id)
455 + self.entity:hud_remove(e.id)
454 456 end
455 457 end;
456 458 updateHUD = function(self)
457 459 for name, e in pairs(self.hud.elt) do
458 460 if e.update then e.update() end
459 461 end
460 462 end;
................................................................................
499 501 -- intel-gathering --
500 502 ---------------------
501 503 clientInfo = function(self)
502 504 return minetest.get_player_information(self.name)
503 505 end;
504 506 species = function(self)
505 507 return starlit.world.species.index[self.persona.species]
508 + end;
509 + -- can the suit heater sustain its current internal temperature in an area of t°C
510 + tempCanSustain = function(self, t)
511 + if self:naked() then return false end
512 + local s = self:getSuit()
513 + if s:powerState() == 'off' then return false end
514 + local sd = s:def()
515 + local w = self:effectiveStat 'warmth'
516 + local kappa = starlit.constant.heat.thermalConductivity
517 + local insul = sd.temp.insulation
518 + local dt = (kappa * (1-insul)) * (t - w)
519 + print('dt', dt, dump(sd.temp))
520 + if (dt > 0 and dt > sd.temp.maxCool)
521 + or (dt < 0 and math.abs(dt) > sd.temp.maxHeat) then return false end
522 + return true
523 + end;
524 + -- will exposure to temperature t cause the player eventual harm
525 + tempHazard = function(self, t)
526 + local tr = self:species().tempRange.survivable
527 + if t >= tr[1] and t <= tr[2] then return nil end
528 + if self:tempCanSustain(t) then return nil end
529 +
530 + if t < tr[1] then return 'cold' end
531 + return 'hot'
506 532 end;
507 533
508 534 --------------------
509 535 -- event handlers --
510 536 --------------------
511 537 onSignup = function(self)
512 538 local meta = self.entity:get_meta()
................................................................................
872 898 end
873 899 if run then
874 900 run(self, ctx)
875 901 return true
876 902 end
877 903 return false
878 904 end;
905 +
906 + alarm = function(self, urgency, kind, freq, where)
907 + freq = freq or 3
908 + local urgencies = {
909 + [1] = {sound = 'starlit-alarm'};
910 + [2] = {sound = 'starlit-alarm-urgent'};
911 + }
912 + local gt = minetest.get_gametime()
913 + local urg = urgencies[urgency] or urgencies[#urgencies]
914 +
915 + if gt - self.cooldownTimes.alarm < freq then return end
916 +
917 + self.cooldownTimes.alarm = gt
918 + self:suitSound(urg.sound)
919 +
920 + if where then
921 + local elt = {
922 + tex = where.tex or 'starlit-ui-alert.png';
923 + scale = {x=1, y=1};
924 + align = table.copy(where.elt.def.align);
925 + pos = table.copy(where.elt.def.pos);
926 + ofs = table.copy(where.elt.def.ofs);
927 + }
928 + elt.ofs.x = elt.ofs.x + where.ofs.x
929 + elt.ofs.y = elt.ofs.y + where.ofs.y
930 + local attached = self:attachImage(elt)
931 + table.insert(self.hud.alarm, attached)
932 +
933 + -- HATE. HATE. HAAAAAAAAAAATE
934 + minetest.after(freq/2, function()
935 + for k,v in pairs(self.hud.alarm) do
936 + self.entity:hud_remove(v.id)
937 + end
938 + self.hud.alarm={}
939 + end)
940 + end
941 + end;
879 942
880 943 -------------
881 944 -- weather --
882 945 -------------
883 946 updateWeather = function(self)
884 947 end;
885 948
................................................................................
933 996
934 997 local clockInterval = 1.0
935 998 starlit.startJob('starlit:clock', clockInterval, function(delta)
936 999 for id, u in pairs(starlit.activeUsers) do
937 1000 u.hud.elt.time:update()
938 1001 end
939 1002 end)
1003 +
1004 +-- performs a general HUD refresh, mainly to update the HUD backlight brightness
1005 +local hudInterval = 10
1006 +starlit.startJob('starlit:hud-refresh', hudInterval, function(delta)
1007 + for id, u in pairs(starlit.activeUsers) do u:updateHUD() end
1008 +end)
940 1009
941 1010 local biointerval = 1.0
942 1011 starlit.startJob('starlit:bio', biointerval, function(delta)
943 1012 for id, u in pairs(starlit.activeUsers) do
944 1013 if u:effectiveStat 'health' ~= 0 then
945 1014 local bmr = u:phenoTrait 'metabolism' * biointerval
946 1015 -- TODO apply modifiers