]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qc
drawpic_aspect wrapper for drawpic
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
1 /*
2 ==================
3 Misc HUD functions
4 ==================
5 */
6
7 // a border picture is a texture containing nine parts:
8 //   1/4 width: left part
9 //   1/2 width: middle part (stretched)
10 //   1/4 width: right part
11 // divided into
12 //   1/4 height: top part
13 //   1/2 height: middle part (stretched)
14 //   1/4 height: bottom part
15 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
16 {
17         vector dX, dY;
18         vector width, height;
19         vector bW, bH;
20         //pic = draw_UseSkinFor(pic);
21         width = eX * theSize_x;
22         height = eY * theSize_y;
23         if(theSize_x <= theBorderSize_x * 2)
24         {
25                 // not wide enough... draw just left and right then
26                 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
27                 if(theSize_y <= theBorderSize_y * 2)
28                 {
29                         // not high enough... draw just corners
30                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
31                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0 0 0',           bW + bH, theColor, theAlpha, 0);
32                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, eX - bW,           bW + bH, theColor, theAlpha, 0);
33                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, eY - bH,           bW + bH, theColor, theAlpha, 0);
34                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
35                 }
36                 else
37                 {
38                         dY = theBorderSize_x * eY;
39                         drawsubpic(theOrigin,                             width * 0.5          +     dY, pic, '0 0    0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
40                         drawsubpic(theOrigin + width * 0.5,               width * 0.5          +     dY, pic, '0 0    0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
41                         drawsubpic(theOrigin                        + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0',           '0 0.5  0' + bW, theColor, theAlpha, 0);
42                         drawsubpic(theOrigin + width * 0.5          + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0' + eX - bW, '0 0.5  0' + bW, theColor, theAlpha, 0);
43                         drawsubpic(theOrigin               + height - dY, width * 0.5          +     dY, pic, '0 0.75 0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
44                         drawsubpic(theOrigin + width * 0.5 + height - dY, width * 0.5          +     dY, pic, '0 0.75 0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
45                 }
46         }
47         else
48         {
49                 if(theSize_y <= theBorderSize_y * 2)
50                 {
51                         // not high enough... draw just top and bottom then
52                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
53                         dX = theBorderSize_x * eX;
54                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
55                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0 0',           '0.5  0 0' + bH, theColor, theAlpha, 0);
56                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
57                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
58                         drawsubpic(theOrigin + dX         + height * 0.5, width - 2 * dX + height * 0.5, pic, '0.25 0 0' + eY - bH, '0.5  0 0' + bH, theColor, theAlpha, 0);
59                         drawsubpic(theOrigin + width - dX + height * 0.5,             dX + height * 0.5, pic, '0.75 0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
60                 }
61                 else
62                 {
63                         dX = theBorderSize_x * eX;
64                         dY = theBorderSize_x * eY;
65                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
66                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
67                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
68                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
69                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
70                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
71                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
72                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
73                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
74                 }
75         }
76 }
77
78 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
79 void drawpic_aspect(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
80         vector imgsize;
81         imgsize = drawgetimagesize(pic);
82         float imgaspect;
83         imgaspect = imgsize_x/imgsize_y;
84
85         vector oldsz;
86         oldsz = sz;
87         float aspect;
88         aspect = sz_x/sz_y;
89
90         if(aspect > imgaspect) {
91                 sz_x = sz_y * imgaspect;
92                 drawpic(pos + eX * (oldsz_x - sz_x) * 0.5, pic, sz, color, alpha, drawflag);
93         } else {
94                 sz_y = sz_x / imgaspect; 
95                 drawpic(pos + eY * (oldsz_y - sz_y) * 0.5, pic, sz, color, alpha, drawflag);
96         }
97 }
98
99 // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga
100 void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
101         drawpic_aspect(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag);
102 }
103
104 void drawpic_skin_expanding(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
105         drawpic_expanding(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
106 }
107
108 void drawpic_skin_expanding_two(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
109         drawpic_expanding_two(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
110 }
111
112 // return HUD background color
113 vector HUD_GetBgColor()
114 {
115         vector color;
116         if (teamplay)
117                 GetTeamRGB(myteam) * hud_color_bg_team;
118         else {
119                 // allow custom HUD colors in non-teamgames
120                 color_x = cvar("hud_color_bg_r");
121                 color_y = cvar("hud_color_bg_g");
122                 color_z = cvar("hud_color_bg_b");
123         }
124         return color;
125 }
126
127 // return accuracy text color
128 vector HUD_AccuracyColor(float accuracy)
129 {
130         vector rgb;
131         float yellow_accuracy = cvar("hud_weaponicons_accuracy_yellow"); // value at which this function returns yellow
132         if(accuracy >= 100) {
133                 rgb_x = 0;
134                 rgb_y = 1;
135         }
136         else if(accuracy > yellow_accuracy) {
137                 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
138                 rgb_y = 1;
139         }
140         else {
141                 rgb_x = 1;
142                 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
143         }
144         rgb_z = 0;
145         return rgb;
146 }
147
148 // draw number in the XSCALE font
149 void HUD_DrawXNum (vector pos, float num, float digits, float showsign, float lettersize, vector rgb, float highlighted, float stroke, float alpha, float dflags)
150 {
151         float l, i;
152         string str, tmp, l_length;
153         float minus, plus;
154         vector vsize, num_color;
155
156         vsize_x = vsize_y = lettersize;
157         vsize_z = 0;
158
159         // showsign 1: always prefix with minus sign (useful in race distribution display)
160         // showsign 2: always prefix with plus sign (useful in race distribution display)
161         // showsign 3: prefix with minus sign if negative, plus sign if positive (useful in score distribution display)
162
163         if((showsign == 2 && num >= 0) || (num > 0 && showsign == 3))
164         {
165                 plus = true;
166                 pos_x -= lettersize;
167         } else
168                 plus = false;
169
170         if(num < 0 || (num < 0 && showsign == 3) || (showsign == 1 && num <= 0))
171         {
172                 minus = true;
173                 num = -num;
174                 pos_x -= lettersize;
175         } else
176                 minus = false;
177
178         if(digits < 0)
179         {
180                 tmp = ftos(num);
181                 digits = -digits;
182                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
183         } else
184                 str = ftos(num);
185
186         l = strlen(str);
187         l_length = ftos(l);
188
189         if(l > digits)
190         {
191                 str = substring(str, l-digits, 999);
192                 l = strlen(str);
193         } else if(l < digits)
194                 pos_x += (digits-l) * lettersize;
195
196         if (highlighted == 1) {
197                 vector hl_size;
198                 hl_size_x = vsize_x * l + vsize_x * 0.2;
199                 hl_size_y = vsize_y * 1.1;
200                 hl_size_z = 0;
201                 if(minus)
202                         hl_size_x = hl_size_x + vsize_x;
203
204                 vector hl_pos;
205                 hl_pos_x = pos_x - lettersize/10;
206                 hl_pos_y = pos_y - lettersize/20;
207                 hl_pos_z = 0;
208
209                 drawpic_skin(hl_pos, strcat("num_leading_", l_length), hl_size, '1 1 1', alpha, dflags);
210         }
211
212         if (stroke == 1)
213                 num_color = '1 1 1';
214         else
215                 num_color = rgb;
216
217         if(minus)
218         {
219                 if (stroke == 1)
220                         drawpic_skin(pos, "num_minus_stroke", vsize, rgb, alpha, dflags);
221                 drawpic_skin(pos, "num_minus", vsize, num_color, alpha, dflags);
222                 pos_x += lettersize;
223         } else if(plus)
224         {
225                 if (stroke == 1)
226                         drawpic_skin(pos, "num_plus_stroke", vsize, rgb, alpha, dflags);
227                 drawpic_skin(pos, "num_plus", vsize, num_color, alpha, dflags);
228                 pos_x += lettersize;
229         }
230
231         for(i = 0; i < l; ++i)
232         {
233                 tmp = substring(str, i, 1);
234                 if (stroke == 1)
235                         drawpic_skin(pos, strcat("num_", tmp, "_stroke"), vsize, rgb, alpha, dflags);
236                 drawpic_skin(pos, strcat("num_", tmp), vsize, num_color, alpha, dflags);
237                 pos_x += lettersize;
238         }
239 }
240
241 vector HUD_Get_Num_Color (float x, float maxvalue)
242 {
243         vector color;
244         if(x > maxvalue) {
245                 color_x = 0;
246                 color_y = 1;
247                 color_z = 0;
248         }
249         else if(x > maxvalue * 0.75) {
250                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
251                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
252                 color_z = 0;
253         }
254         else if(x > maxvalue * 0.5) {
255                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
256                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
257                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
258         }
259         else if(x > maxvalue * 0.25) {
260                 color_x = 1;
261                 color_y = 1;
262                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
263         }
264         else if(x > maxvalue * 0.1) {
265                 color_x = 1;
266                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
267                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
268         }
269         else {
270                 color_x = 1;
271                 color_y = 0;
272                 color_z = 0;
273         }
274         return color;
275 }
276 // color the number differently based on how big it is (used in the health/armor panel)
277 void HUD_DrawXNum_Colored (vector pos, float x, float digits, float lettersize, float alpha)
278 {
279         vector color;
280         color = HUD_Get_Num_Color (x, 200);
281         HUD_DrawXNum(pos, x, digits, 0, lettersize, color, 0, 0, alpha, DRAWFLAG_NORMAL);
282 }
283
284 float stringwidth_colors(string s, vector theSize)
285 {
286         return stringwidth(s, TRUE, theSize);
287 }
288
289 float stringwidth_nocolors(string s, vector theSize)
290 {
291         return stringwidth(s, FALSE, theSize);
292 }
293
294 #define CENTERPRINT_MAX_LINES 30
295 string centerprint_messages[CENTERPRINT_MAX_LINES];
296 float centerprint_width[CENTERPRINT_MAX_LINES];
297 vector centerprint_start;
298 float centerprint_expire;
299 float centerprint_num;
300 float centerprint_offset_hint;
301 vector centerprint_fontsize;
302
303 void centerprint(string strMessage)
304 {
305         float i, j, n, hcount;
306         string s;
307
308         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
309
310         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
311
312         if(cvar("scr_centertime") <= 0)
313                 return;
314
315         if(strMessage == "")
316                 return;
317
318         // strip trailing newlines
319         j = strlen(strMessage) - 1;
320         while(substring(strMessage, j, 1) == "\n" && j >= 0)
321                 j = j - 1;
322         strMessage = substring(strMessage, 0, j + 1);
323
324         if(strMessage == "")
325                 return;
326
327         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
328         j = 0;
329         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
330                 j = j + 1;
331         strMessage = substring(strMessage, j, strlen(strMessage) - j);
332         centerprint_offset_hint = j;
333
334         if(strMessage == "")
335                 return;
336
337         // if we get here, we have a message. Initialize its height.
338         centerprint_num = 0;
339
340         n = tokenizebyseparator(strMessage, "\n");
341         i = hcount = 0;
342         for(j = 0; j < n; ++j)
343         {
344                 getWrappedLine_remaining = argv(j);
345                 while(getWrappedLine_remaining)
346                 {
347                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
348                         if(centerprint_messages[i])
349                                 strunzone(centerprint_messages[i]);
350                         centerprint_messages[i] = strzone(s);
351                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
352                         ++i;
353
354                         // half height for empty lines looks better
355                         if(s == "")
356                                 hcount += 0.5;
357                         else
358                                 hcount += 1;
359
360                         if(i >= CENTERPRINT_MAX_LINES)
361                                 break;
362                 }
363         }
364
365         float h, havail;
366         h = centerprint_fontsize_y*hcount;
367
368         havail = vid_conheight;
369         if(cvar("con_chatpos") < 0)
370                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
371         if(havail > vid_conheight - 70)
372                 havail = vid_conheight - 70; // avoid overlapping HUD
373
374         centerprint_start_x = 0;
375
376 #if 0
377         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
378
379         // here, the centerprint would cover the crosshair. REALLY BAD.
380         forbiddenmin = vid_conheight * 0.5 - h - 16;
381         forbiddenmax = vid_conheight * 0.5 + 16;
382
383         allowedmin = scoreboard_bottom;
384         allowedmax = havail - h;
385         preferred = (havail - h)/2;
386
387
388         // possible orderings (total: 4! / 4 = 6)
389         //  allowedmin allowedmax forbiddenmin forbiddenmax
390         //  forbiddenmin forbiddenmax allowedmin allowedmax
391         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
392         {
393                 // forbidden doesn't matter in this case
394                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
395         }
396         //  allowedmin forbiddenmin allowedmax forbiddenmax
397         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
398         {
399                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
400         }
401         //  allowedmin forbiddenmin forbiddenmax allowedmax
402         else if(allowedmin < forbiddenmin)
403         {
404                 // make sure the forbidden zone is not covered
405                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
406                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
407                 else
408                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
409         }
410         //  forbiddenmin allowedmin allowedmax forbiddenmax
411         else if(allowedmax < forbiddenmax)
412         {
413                 // it's better to leave the allowed zone (overlap with scoreboard) than
414                 // to cover the forbidden zone (crosshair)
415                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
416                         centerprint_start_y = forbiddenmax;
417                 else
418                         centerprint_start_y = forbiddenmin;
419         }
420         //  forbiddenmin allowedmin forbiddenmax allowedmax
421         else
422         {
423                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
424         }
425 #else
426         centerprint_start_y =
427                 min(
428                         max(
429                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
430                                 (havail - h)/2
431                         ),
432                         havail - h
433                 );
434 #endif
435
436         centerprint_num = i;
437         centerprint_expire = time + cvar("scr_centertime");
438 }
439
440 void HUD_DrawCenterPrint (void)
441 {
442         float i;
443         vector pos;
444         string ts;
445         float a;
446
447         //if(time > centerprint_expire)
448         //      return;
449
450         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
451         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
452         //sz = 1.2 / (a + 0.2);
453
454         if(a <= 0)
455                 return;
456
457         pos = centerprint_start;
458         for (i=0; i<centerprint_num; i = i + 1)
459         {
460                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
461                 ts = centerprint_messages[i];
462                 if (ts != "")
463                 {
464                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
465                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
466                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
467                         pos_y = pos_y + centerprint_fontsize_y;
468                 }
469                 else
470                         // half height for empty lines looks better
471                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
472         }
473 }
474
475 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
476 {
477         position_x -= 2 / 3 * strlen(text) * scale_x;
478         drawstring(position, text, scale, rgb, alpha, flag);
479 }
480
481 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
482 {
483         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
484         drawstring(position, text, scale, rgb, alpha, flag);
485 }
486
487 // return the string of the given race place
488 string race_PlaceName(float pos) {
489         if(pos == 1)
490                 return "1st";
491         else if(pos == 2)
492                 return "2nd";
493         else if(pos == 3)
494                 return "3rd";
495         else
496                 return strcat(ftos(pos), "th");
497 }
498
499 // return the string of the onscreen race timer
500 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
501 {
502         string col;
503         string timestr;
504         string cpname;
505         string lapstr;
506         lapstr = "";
507
508         if(histime == 0) // goal hit
509         {
510                 if(mytime > 0)
511                 {
512                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
513                         col = "^1";
514                 }
515                 else if(mytime == 0)
516                 {
517                         timestr = "+0.0";
518                         col = "^3";
519                 }
520                 else
521                 {
522                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
523                         col = "^2";
524                 }
525
526                 if(lapdelta > 0)
527                 {
528                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
529                         col = "^2";
530                 }
531                 else if(lapdelta < 0)
532                 {
533                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
534                         col = "^1";
535                 }
536         }
537         else if(histime > 0) // anticipation
538         {
539                 if(mytime >= histime)
540                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
541                 else
542                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
543                 col = "^3";
544         }
545         else
546                 col = "^7";
547
548         if(cp == 254)
549                 cpname = "Start line";
550         else if(cp == 255)
551                 cpname = "Finish line";
552         else if(cp)
553                 cpname = strcat("Intermediate ", ftos(cp));
554         else
555                 cpname = "Finish line";
556
557         if(histime < 0)
558                 return strcat(col, cpname);
559         else if(hisname == "")
560                 return strcat(col, cpname, " (", timestr, ")");
561         else
562                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
563 }
564
565 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
566 float race_CheckName(string net_name) {
567         float i;
568         for (i=RANKINGS_CNT-1;i>=0;--i)
569                 if(grecordholder[i] == net_name)
570                         return i+1;
571         return 0;
572 }
573
574 /*
575 ==================
576 HUD panels
577 ==================
578 */
579
580 // Save the config
581 void HUD_Panel_ExportCfg(string cfgname)
582 {
583         float fh;
584         fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
585         if(fh >= 0)
586         {
587                 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
588                 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
589                 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
590                 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
591                 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
592                 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
593                 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
594                 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
595                 fputs(fh, "\n");
596
597                 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
598                 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
599                 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
600                 fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
601                 fputs(fh, "\n");
602
603                 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
604                 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
605                 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
606                 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
607                 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
608                 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
609                 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
610                 fputs(fh, "\n");
611
612                 // common cvars for all panels
613                 float i;
614                 for (i = 0; i < HUD_PANEL_NUM; ++i)
615                 {
616                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
617                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
618                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
619                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
620                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
621                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
622                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
623                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
624                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
625                         switch(i) {
626                                 case 0:
627                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
628                                         break;
629                                 case 1:
630                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
631                                         break;
632                                 case 2:
633                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
634                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
635                                         break;
636                                 case 3:
637                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
638                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
639                                         break;
640                                 case 4:
641                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
642                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_info_top ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_info_top"))), "\n"));
643                                         break;
644                                 case 6:
645                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_foreground_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_foreground_alpha"))), "\n"));
646                                 case 9:
647                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
648                                         break;
649                         }
650                         fputs(fh, "\n");
651                 }
652
653                 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
654         }
655         fclose(fh);
656 }
657
658 vector HUD_Panel_GetMinSize(float id)
659 {
660         vector mySize;
661         // note: please only set mySize_y on aspect ratio forced panels
662         switch(id) {
663                 case 0: 
664                         mySize_x = 1/10; // at least 1/10 * height
665                         mySize_y = 1/26; // at least 1/26 * width
666                         break;
667                 case 1: 
668                         if(cvar("hud_inventory_onlycurrent"))
669                                 mySize_y = 2/5; //  2/5 width
670                         else
671                                 mySize_x = 0.7; // at least 0.7 * height
672                         break;
673                 case 3: 
674                         if(cvar("hud_healtharmor") == 2)
675                         {
676                                 mySize_x = 4.35; // 4.35 * height, trial and error...
677                                 mySize_y = 0.01; // "unlimited" ;)
678                         }
679                         break;
680                 case 4: 
681                         mySize_x = 1.1; // 4/5 * height, trial and error...
682                         mySize_y = 1/3; // 1/3 * width, trial and error...
683                         break;
684                 case 5: 
685                         mySize_y = 1/4.1; // 1/4.1 * width, trial and error...
686                         break;
687                 case 7: 
688                         mySize_y = 1/4; // 1/4 * width
689                         break;
690                 case 8: 
691                         mySize_y = 1/4; // 1/4 * width
692                         break;
693                 case 9: 
694                         mySize_y = 1/4; // 1/4 * width
695                         break;
696                 case 10: 
697                         mySize_y = 1/2; // 1/2 * width
698                         break;
699                 case 11: 
700                         mySize_y = 0.5898; // 0.5898 * width, reason: bg has weird dimensions...
701                         break;
702                 case 13: 
703                         mySize_y = 0.2; // 0.25 * width, trial and error...
704                         break;
705         }
706         return mySize;
707 }
708
709 // return active status of panel
710 float HUD_Panel_CheckActive(float id)
711 {
712         if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
713                 return 1;
714         return 0;
715 }
716
717 // return size of given panel
718 vector HUD_Panel_GetSize(float id)
719 {
720         vector mySize;
721         mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
722
723         mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
724
725         if(disable_menu_alphacheck == 2 && id == highlightedPanel)
726         {
727                 vector menu_enable_maxsize, menu_enable_size;
728                 menu_enable_maxsize = '0 0 0'; // shut up FTEQCC
729                 menu_enable_maxsize_x = 0.3 * vid_conwidth;
730                 menu_enable_maxsize_y = 0.18 * vid_conheight;
731                 if(mySize_x > mySize_y)
732                 {
733                         if(mySize_y > menu_enable_maxsize_y)
734                         {
735                                 menu_enable_size_y = menu_enable_maxsize_y;
736                                 menu_enable_size_x = mySize_x * (menu_enable_maxsize_y/mySize_y);
737                                 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
738                         }
739                 }
740                 else
741                 {
742                         if(mySize_x > menu_enable_maxsize_x)
743                         {
744                                 menu_enable_size_x = menu_enable_maxsize_x;
745                                 menu_enable_size_y = mySize_y * (menu_enable_maxsize_x/mySize_x);
746                                 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
747                         }
748                 }
749         }
750         return mySize;
751 }
752
753 // return pos of given panel
754 vector HUD_Panel_GetPos(float id)
755 {
756         vector pos;
757         pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
758
759         pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
760
761         if(disable_menu_alphacheck == 2 && id == highlightedPanel)
762         {
763                 vector mySize, menu_enable_panelpos;
764                 mySize = HUD_Panel_GetSize(id);
765                 if(mySize_x > mySize_y)
766                         menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * mySize_x + eY * 0.82 * vid_conheight;
767                 else
768                         menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * mySize_y + eX * 0.7 * vid_conwidth;
769                 pos = (1 - cvar("_menu_alpha")) * pos + (cvar("_menu_alpha")) * menu_enable_panelpos;
770         }
771         return pos;
772 }
773
774 float HUD_Panel_GetBorder(float id)
775 {
776         string border;
777         border = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
778         if(border == "")
779                 border = cvar_string("hud_bg_border");
780         return stof(border);
781 }
782
783 vector HUD_Panel_GetColor(float id)
784 {
785         float f;
786         vector color_vec;
787         string color;
788
789         // fetch per-panel color
790         if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
791                 f = stof(getplayerkey(self.sv_entnum, "colors"));
792                 color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
793         }
794         else
795                 color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
796         color_vec = stov(color);
797
798         if(color == "") { // fetch default color
799                 color = cvar_string("hud_bg_color");
800                 color_vec = stov(color);
801                 if(teamplay && cvar(strcat("hud_bg_color_team"))) {
802                         f = stof(getplayerkey(self.sv_entnum, "colors"));
803                         color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
804                 }
805                 else if(color == "shirt") {
806                         f = stof(getplayerkey(self.sv_entnum, "colors"));
807                         color_vec = colormapPaletteColor(floor(f / 16), 0);
808                 }
809                 else if(color == "pants") {
810                         f = stof(getplayerkey(self.sv_entnum, "colors"));
811                         color_vec = colormapPaletteColor(mod(f, 16), 1);
812                 }
813         }
814         else if(color == "shirt") {
815                 f = stof(getplayerkey(self.sv_entnum, "colors"));
816                 color_vec = colormapPaletteColor(floor(f / 16), 0);
817         }
818         else if(color == "pants") {
819                 f = stof(getplayerkey(self.sv_entnum, "colors"));
820                 color_vec = colormapPaletteColor(mod(f, 16), 1);
821         }
822         return color_vec;
823 }
824
825 vector HUD_Panel_Dock_GetColor(void)
826 {
827         float f;
828         vector color_vec;
829         string color;
830         color = cvar_string("hud_dock_color");
831         color_vec = stov(color);
832         if(teamplay && cvar(strcat("hud_dock_color_team"))) {
833                 f = stof(getplayerkey(self.sv_entnum, "colors"));
834                 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
835         }
836         else if(color == "shirt") {
837                 f = stof(getplayerkey(self.sv_entnum, "colors"));
838                 color_vec = colormapPaletteColor(floor(f / 16), 0);
839         }
840         else if(color == "pants") {
841                 f = stof(getplayerkey(self.sv_entnum, "colors"));
842                 color_vec = colormapPaletteColor(mod(f, 16), 1);
843         }
844         return color_vec;
845 }
846
847 float HUD_Panel_GetBgAlpha(float id)
848 {
849         string alpha;
850         alpha = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
851         if(alpha == "")
852                 alpha = cvar_string("hud_bg_alpha");
853
854         if(hud_configure && disable_menu_alphacheck == 2 && highlightedPanel == id) // do not set a minalpha cap when showing the config dialog for this panel
855                 alpha = ftos((1 - cvar("_menu_alpha")) * max(cvar("hud_configure_bg_minalpha"), stof(alpha)) + (cvar("_menu_alpha")) * stof(alpha));
856         else if(hud_configure)
857                 alpha = ftos(max(cvar("hud_configure_bg_minalpha"), stof(alpha)));
858
859         if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
860                 return 0.25;
861
862         if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
863                 return stof(alpha);
864         else
865                 return stof(alpha) * menu_fade_alpha;
866 }
867
868 float HUD_Panel_GetFgAlpha(float id)
869 {
870         float alpha;
871         alpha = hud_fg_alpha;
872
873         if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
874                 return 0.25;
875
876         if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
877                 return alpha;
878         else
879                 return alpha * menu_fade_alpha;
880 }
881
882 float HUD_Panel_GetPadding(float id)
883 {
884         string padding;
885         padding = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_padding"));
886         if(padding == "")
887                 padding = cvar_string("hud_bg_padding");
888
889         vector mySize;
890         mySize = HUD_Panel_GetSize(id);
891         float smallestsize;
892         smallestsize = min(mySize_x, mySize_y);
893         return min(smallestsize/2 - 5, stof(padding));
894 }
895
896 // draw the background/borders
897 void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
898 {
899         if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
900                 return;
901
902         string bg;
903         bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
904         if(bg == "")
905                 bg = cvar_string("hud_bg");
906
907         if(bg == "0" && hud_configure) {
908                 bg = "border"; // we probably want to see a background in config mode at all times...
909         }
910
911         if(bg != "0")
912         {
913                 float border;
914                 border = max(0.0000001, HUD_Panel_GetBorder(id)); // draw_BorderPicture does not like border = 0
915
916                 vector color;
917                 color = HUD_Panel_GetColor(id);
918
919                 if(alpha)
920                         alpha = HUD_Panel_GetBgAlpha(id) * alpha; // allow panels to fade in/out by passing an alpha value
921                 else
922                         alpha = HUD_Panel_GetBgAlpha(id);
923
924                 draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", cvar_string("hud_skin"), "/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
925         }
926 }
927
928 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
929 {
930 //float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag) = #328;
931         string pic;
932         pic = strcat("gfx/hud/", cvar_string("hud_skin"), "/");
933         if(vertical) {
934                 drawsubpic(pos, eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0 0', '1 0.25 0', color, alpha, drawflag);
935                 if(mySize_y/mySize_x > 2)
936                         drawsubpic(pos + eY * mySize_x, eY * (mySize_y - 2 * mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.25 0', '1 0.5 0', color, alpha, drawflag);
937                 drawsubpic(pos + eY * mySize_y - eY * min(mySize_y * 0.5, mySize_x), eY * min(mySize_y * 0.5, mySize_x) + eX * mySize_x, strcat(pic, "statusbar_vertical"), '0 0.75 0', '1 0.25 0', color, alpha, drawflag);
938         } else {
939                 drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0 0 0', '0.25 1 0', color, alpha, drawflag);
940                 if(mySize_x/mySize_y > 2)
941                         drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
942                 drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, strcat(pic, "statusbar"), '0.75 0 0', '0.25 1 0', color, alpha, drawflag);
943         }
944 }
945
946 vector HUD_Panel_GetProgressBarColor(string item)
947 {
948         return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
949 }
950
951 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
952 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
953 {
954         float i;
955
956         vector myTarget;
957         myTarget = myPos;
958
959         vector targPos;
960         vector targSize;
961         vector myCenter;
962         vector targCenter;
963         myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
964         targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
965
966         for (i = 0; i < HUD_PANEL_NUM; ++i) {
967                 if(i == id || !HUD_Panel_CheckActive(i))
968                         continue;
969
970                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
971                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
972
973                 if(myPos_y + mySize_y < targPos_y)
974                         continue;
975                 if(myPos_y > targPos_y + targSize_y)
976                         continue;
977
978                 if(myPos_x + mySize_x < targPos_x)
979                         continue;
980                 if(myPos_x > targPos_x + targSize_x)
981                         continue;
982
983                 // OK, there IS a collision.
984
985                 myCenter_x = myPos_x + 0.5 * mySize_x;
986                 myCenter_y = myPos_y + 0.5 * mySize_y;
987
988                 targCenter_x = targPos_x + 0.5 * targSize_x;
989                 targCenter_y = targPos_y + 0.5 * targSize_y;
990
991                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
992                 {
993                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
994                                 myTarget_x = targPos_x - mySize_x;
995                         else // push it upwards
996                                 myTarget_y = targPos_y - mySize_y;
997                 }
998                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
999                 {
1000                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
1001                                 myTarget_x = targPos_x + targSize_x;
1002                         else // push it upwards
1003                                 myTarget_y = targPos_y - mySize_y;
1004                 }
1005                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
1006                 {
1007                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
1008                                 myTarget_x = targPos_x - mySize_x;
1009                         else // push it downwards
1010                                 myTarget_y = targPos_y + targSize_y;
1011                 }
1012                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
1013                 {
1014                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
1015                                 myTarget_x = targPos_x + targSize_x;
1016                         else // push it downwards
1017                                 myTarget_y = targPos_y + targSize_y;
1018                 }
1019         }
1020
1021         return myTarget;
1022 }
1023
1024 void HUD_Panel_SetPos(float id, vector pos)
1025 {
1026         vector oldPos;
1027         oldPos = HUD_Panel_GetPos(id);
1028
1029         vector mySize;
1030         mySize = HUD_Panel_GetSize(id);
1031
1032         if(cvar("hud_configure_checkcollisions"))
1033                 pos = HUD_Panel_CheckMove(id, pos, mySize);
1034
1035         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
1036         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
1037
1038         if(cvar("hud_configure_grid"))
1039         {
1040                 pos_x = floor((pos_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * cvar("hud_configure_grid_x") * vid_conwidth;
1041                 pos_y = floor((pos_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * cvar("hud_configure_grid_y") * vid_conheight;
1042         }
1043
1044         string s;
1045         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
1046
1047         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1048 }
1049
1050 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
1051 vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin, float ratio) {
1052         float i;
1053
1054         float targBorder;
1055         vector targPos;
1056         vector targSize;
1057         vector targEndPos;
1058         vector dist;
1059
1060         for (i = 0; i < HUD_PANEL_NUM; ++i) {
1061                 if(i == id || !HUD_Panel_CheckActive(i))
1062                         continue;
1063
1064                 targBorder = HUD_Panel_GetBorder(i);
1065                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * targBorder;
1066                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * targBorder;
1067                 targEndPos = targPos + targSize;
1068
1069                 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
1070                 if(resizeorigin_x > targPos_x && resizeorigin_x < targPos_x + targSize_x && resizeorigin_y > targPos_y && resizeorigin_y < targPos_y + targSize_y)
1071                         continue;
1072
1073                 if (resizeCorner == 1)
1074                 {
1075                         // check if this panel is on our way
1076                         if (resizeorigin_x <= targPos_x)
1077                                 continue;
1078                         if (resizeorigin_y <= targPos_y)
1079                                 continue;
1080                         if (targEndPos_x <= resizeorigin_x - mySize_x)
1081                                 continue;
1082                         if (targEndPos_y <= resizeorigin_y - mySize_y)
1083                                 continue;
1084
1085                         // there is a collision:
1086                         // detect which side of the panel we are facing is actually limiting the resizing
1087                         // (which side the resize direction finds for first) and reduce the size up to there
1088                         //
1089                         // dist is the distance between resizeorigin and the "analogous" point of the panel
1090                         // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
1091                         dist_x = resizeorigin_x - targEndPos_x;
1092                         dist_y = resizeorigin_y - targEndPos_y;
1093                         if (dist_y < 0 || dist_x / dist_y > ratio)
1094                                 mySize_x = min(mySize_x, dist_x);
1095                         else
1096                                 mySize_y = min(mySize_y, dist_y);
1097                 }
1098                 else if (resizeCorner == 2)
1099                 {
1100                         if (resizeorigin_x >= targEndPos_x)
1101                                 continue;
1102                         if (resizeorigin_y <= targPos_y)
1103                                 continue;
1104                         if (targPos_x >= resizeorigin_x + mySize_x)
1105                                 continue;
1106                         if (targEndPos_y <= resizeorigin_y - mySize_y)
1107                                 continue;
1108
1109                         dist_x = targPos_x - resizeorigin_x;
1110                         dist_y = resizeorigin_y - targEndPos_y;
1111                         if (dist_y < 0 || dist_x / dist_y > ratio)
1112                                 mySize_x = min(mySize_x, dist_x);
1113                         else
1114                                 mySize_y = min(mySize_y, dist_y);
1115                 }
1116                 else if (resizeCorner == 3)
1117                 {
1118                         if (resizeorigin_x <= targPos_x)
1119                                 continue;
1120                         if (resizeorigin_y >= targEndPos_y)
1121                                 continue;
1122                         if (targEndPos_x <= resizeorigin_x - mySize_x)
1123                                 continue;
1124                         if (targPos_y >= resizeorigin_y + mySize_y)
1125                                 continue;
1126
1127                         dist_x = resizeorigin_x - targEndPos_x;
1128                         dist_y = targPos_y - resizeorigin_y;
1129                         if (dist_y < 0 || dist_x / dist_y > ratio)
1130                                 mySize_x = min(mySize_x, dist_x);
1131                         else
1132                                 mySize_y = min(mySize_y, dist_y);
1133                 }
1134                 else if (resizeCorner == 4)
1135                 {
1136                         if (resizeorigin_x >= targEndPos_x)
1137                                 continue;
1138                         if (resizeorigin_y >= targEndPos_y)
1139                                 continue;
1140                         if (targPos_x >= resizeorigin_x + mySize_x)
1141                                 continue;
1142                         if (targPos_y >= resizeorigin_y + mySize_y)
1143                                 continue;
1144
1145                         dist_x = targPos_x - resizeorigin_x;
1146                         dist_y = targPos_y - resizeorigin_y;
1147                         if (dist_y < 0 || dist_x / dist_y > ratio)
1148                                 mySize_x = min(mySize_x, dist_x);
1149                         else
1150                                 mySize_y = min(mySize_y, dist_y);
1151                 }
1152                 if(cvar("hud_configure_checkcollisions_debug"))
1153                         drawfill(targPos + '1 1 0' * targBorder, targSize - '2 2 0' * targBorder, '1 1 0', .3, DRAWFLAG_NORMAL);
1154         }
1155
1156         return mySize;
1157 }
1158
1159 void HUD_Panel_SetPosSize(float id)
1160 {
1161         vector resizeorigin;
1162         resizeorigin = panel_click_resizeorigin;
1163         vector mySize, myPos;
1164
1165         if(resizeCorner == 1) {
1166                 mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
1167                 mySize_y = resizeorigin_y - (mousepos_y - panel_click_distance_y);
1168         } else if(resizeCorner == 2) {          
1169                 mySize_x = mousepos_x + panel_click_distance_x - resizeorigin_x;
1170                 mySize_y = panel_click_distance_y + resizeorigin_y - mousepos_y;
1171         } else if(resizeCorner == 3) {
1172                 mySize_x = resizeorigin_x + panel_click_distance_x - mousepos_x;
1173                 mySize_y = mousepos_y + panel_click_distance_y - resizeorigin_y;
1174         } else { // resizeCorner == 4
1175                 mySize_x = mousepos_x - (resizeorigin_x - panel_click_distance_x);
1176                 mySize_y = mousepos_y - (resizeorigin_y - panel_click_distance_y);
1177         }
1178
1179         // minimum panel size cap
1180         mySize_x = max(0.025 * vid_conwidth, mySize_x);
1181         mySize_y = max(0.025 * vid_conheight, mySize_y);
1182
1183         if(id == 12) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
1184         {
1185                 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
1186                 mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
1187         }
1188
1189         // cap against panel's own limits
1190         vector minSize;
1191         minSize = HUD_Panel_GetMinSize(id); // mySize_x at least minSize_x * mySize_y, and vice versa
1192         float fixedRatio;
1193         if(!minSize_x && minSize_y) // forced aspect ratio
1194         {
1195                 minSize_x = 1/minSize_y;
1196                 fixedRatio = minSize_x;
1197                 mySize_x = max(minSize_x * mySize_y, mySize_x);
1198                 mySize_y = max(minSize_y * mySize_x, mySize_y);
1199         }
1200         else if(minSize_x && !minSize_y) // hybrid aspect ratio, currently supported only in one dimension
1201         {
1202                 if (mySize_x/mySize_y < minSize_x) // resizing in x direction allows free aspect ratio
1203                 {
1204                         fixedRatio = minSize_x;
1205                         minSize_y = 1/minSize_x;
1206                         mySize_y = max(minSize_y * mySize_x, mySize_y);
1207                         mySize_x = max(minSize_x * mySize_y, mySize_x);
1208                 }
1209                 else
1210                         fixedRatio = -minSize_x; //negative so that it will be used ONLY after checkResize
1211         }
1212
1213         // collision testing|
1214         // -----------------+
1215
1216         // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
1217         if(resizeCorner == 1) {
1218                 myPos_x = resizeorigin_x - mySize_x;
1219                 myPos_y = resizeorigin_y - mySize_y;
1220         } else if(resizeCorner == 2) {
1221                 myPos_x = resizeorigin_x;
1222                 myPos_y = resizeorigin_y - mySize_y;
1223         } else if(resizeCorner == 3) {
1224                 myPos_x = resizeorigin_x - mySize_x;
1225                 myPos_y = resizeorigin_y;
1226         } else { // resizeCorner == 4
1227                 myPos_x = resizeorigin_x;
1228                 myPos_y = resizeorigin_y;
1229         }
1230
1231         // left/top screen edges
1232         if(myPos_x < 0)
1233                 mySize_x = mySize_x + myPos_x;
1234         if(myPos_y < 0)
1235                 mySize_y = mySize_y + myPos_y;
1236
1237         // bottom/right screen edges
1238         if(myPos_x + mySize_x > vid_conwidth)
1239                 mySize_x = vid_conwidth - myPos_x;
1240         if(myPos_y + mySize_y > vid_conheight)
1241                 mySize_y = vid_conheight - myPos_y;
1242
1243         if(cvar("hud_configure_checkcollisions_debug"))
1244                 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
1245
1246         // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
1247         if(cvar("hud_configure_grid"))
1248         {
1249                 mySize_x = floor((mySize_x/vid_conwidth)/bound(0.005, cvar("hud_configure_grid_x"), 0.2) + 0.5) * cvar("hud_configure_grid_x") * vid_conwidth;
1250                 mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * cvar("hud_configure_grid_y") * vid_conheight;
1251         }
1252
1253         if (fixedRatio > 0)
1254         {
1255                 // keep aspect ratio _MAXIMIZING_ the size
1256                 if (mySize_x / mySize_y > fixedRatio)
1257                         mySize_y = mySize_x / fixedRatio;
1258                 else
1259                         mySize_x = mySize_y * fixedRatio;
1260         }
1261
1262         if(cvar("hud_configure_checkcollisions"))
1263         {
1264                 if (fixedRatio > 0)
1265                 {
1266                         mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin, fixedRatio);
1267
1268                         // Make sure once more that we DON'T cross the screen edges
1269                         // left/top screen edges
1270                         if(myPos_x < 0)
1271                                 mySize_x = mySize_x + myPos_x;
1272                         if(myPos_y < 0)
1273                                 mySize_y = mySize_y + myPos_y;
1274
1275                         // bottom/right screen edges
1276                         if(myPos_x + mySize_x > vid_conwidth)
1277                                 mySize_x = vid_conwidth - myPos_x;
1278                         if(myPos_y + mySize_y > vid_conheight)
1279                                 mySize_y = vid_conheight - myPos_y;
1280
1281                         // restore again aspect ratio, _minimizing_ the size
1282                         if (mySize_x / mySize_y < fixedRatio)
1283                                 mySize_y = mySize_x / fixedRatio;
1284                         else
1285                                 mySize_x = mySize_y * fixedRatio;
1286                 }
1287                 else
1288                 {
1289                         mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin, mySize_x / mySize_y);
1290                         if (fixedRatio < 0)
1291                         {
1292                                 fixedRatio = -fixedRatio;
1293                                 // restore again aspect ratio, _minimizing_ the size
1294                                 if (mySize_x / mySize_y < fixedRatio)
1295                                         mySize_y = mySize_x / fixedRatio;
1296                         }
1297                 }
1298         }
1299
1300         // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
1301         mySize_x = max(0.025 * vid_conwidth, mySize_x);
1302         mySize_y = max(0.025 * vid_conheight, mySize_y);
1303
1304         // do another pos check, as size might have changed by now
1305         if(resizeCorner == 1) {
1306                 myPos_x = resizeorigin_x - mySize_x;
1307                 myPos_y = resizeorigin_y - mySize_y;
1308         } else if(resizeCorner == 2) {
1309                 myPos_x = resizeorigin_x;
1310                 myPos_y = resizeorigin_y - mySize_y;
1311         } else if(resizeCorner == 3) {
1312                 myPos_x = resizeorigin_x - mySize_x;
1313                 myPos_y = resizeorigin_y;
1314         } else { // resizeCorner == 4
1315                 myPos_x = resizeorigin_x;
1316                 myPos_y = resizeorigin_y;
1317         }
1318
1319         if(cvar("hud_configure_checkcollisions_debug"))
1320         if(cvar("hud_configure_checkcollisions"))
1321                 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
1322
1323         string s;
1324         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
1325         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
1326
1327         s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
1328         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1329 }
1330
1331 float mouseClicked;
1332 float prevMouseClicked; // previous state
1333 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
1334 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
1335
1336 float menu_enabled;
1337 float menu_enabled_time;
1338 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1339 {
1340         if(!hud_configure)
1341                 return false;
1342
1343         // allow console bind to work
1344         string con_keys;
1345         float keys;
1346         con_keys = findkeysforcommand("toggleconsole");
1347         keys = tokenize(con_keys);
1348
1349         float hit_con_bind, i;
1350         for (i = 0; i < keys; ++i)
1351         {
1352                 if(nPrimary == stof(argv(i)))
1353                         hit_con_bind = 1;
1354         }
1355
1356         if(nPrimary == K_MOUSE1)
1357         {
1358                 if(bInputType == 0) { // key pressed
1359                         mouseClicked = 1;
1360                         return true;
1361                 }
1362                 else if(bInputType == 1) {// key released
1363                         mouseClicked = 0;
1364                         return true;
1365                 }
1366         }
1367         else if(nPrimary == K_ESCAPE)
1368         {
1369                 disable_menu_alphacheck = 1;
1370                 menu_enabled = 1;
1371                 menu_enabled_time = time;
1372                 localcmd("menu_showhudexit\n");
1373         }
1374
1375         else if(hit_con_bind)
1376                 return false;
1377
1378         return true; // Suppress ALL other input
1379 }
1380
1381 void HUD_Panel_Mouse()
1382 {
1383         // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1384         if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1385                 disable_menu_alphacheck = 0;
1386         if (cvar("_menu_alpha") == 0 && time - menu_enabled_time > 0.5)
1387                 menu_enabled = 0;
1388
1389         /*
1390         print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1391         print("Highlighted: ", ftos(highlightedPanel), "\n");
1392         print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1393         */
1394
1395         if(mouseClicked == 0 && disable_menu_alphacheck != 2) { // don't reset these variables in disable_menu_alphacheck mode 2!
1396                 highlightedPanel = -1;
1397                 highlightedAction = 0;
1398         }
1399
1400         mousepos = mousepos + getmousepos();
1401
1402         mousepos_x = bound(0, mousepos_x, vid_conwidth);
1403         mousepos_y = bound(0, mousepos_y, vid_conheight);
1404
1405         drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1406
1407         if(mouseClicked)
1408         {
1409                 float i, border;
1410                 vector panelPos;
1411                 vector panelSize;
1412
1413                 for(i = 0; i < HUD_PANEL_NUM; ++i)
1414                 {
1415                         panelPos = HUD_Panel_GetPos(i);
1416                         panelSize = HUD_Panel_GetSize(i);
1417                         border = HUD_Panel_GetBorder(i);
1418                         if(prevMouseClicked == 0) {
1419                                 // move
1420                                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1421                                 {
1422                                         highlightedPanel = i;
1423                                         highlightedAction = 1;
1424                                 }
1425                                 // resize from topleft border
1426                                 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1427                                 {
1428                                         highlightedPanel = i;
1429                                         highlightedAction = 2;
1430                                         resizeCorner = 1;
1431                                 }
1432                                 // resize from topright border
1433                                 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
1434                                 {
1435                                         highlightedPanel = i;
1436                                         highlightedAction = 2;
1437                                         resizeCorner = 2;
1438                                 }
1439                                 // resize from bottomleft border
1440                                 else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
1441                                 {
1442                                         highlightedPanel = i;
1443                                         highlightedAction = 2;
1444                                         resizeCorner = 3;
1445                                 }
1446                                 // resize from bottomright border
1447                                 else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
1448                                 {
1449                                         highlightedPanel = i;
1450                                         highlightedAction = 2;
1451                                         resizeCorner = 4;
1452                                 }
1453                         }
1454
1455                         if(highlightedPanel == i)
1456                         {
1457                                 if(prevMouseClicked == 0)
1458                                 {
1459                                         if(highlightedAction == 1)
1460                                                 panel_click_distance = mousepos - panelPos;
1461                                         else if(highlightedAction == 2)
1462                                         {
1463                                                 if(resizeCorner == 1) {
1464                                                         panel_click_distance = mousepos - panelPos;
1465                                                         panel_click_resizeorigin = panelPos + panelSize;
1466                                                 } else if(resizeCorner == 2) {
1467                                                         panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1468                                                         panel_click_distance_y = mousepos_y - panelPos_y;
1469                                                         panel_click_resizeorigin = panelPos + eY * panelSize_y;
1470                                                 } else if(resizeCorner == 3) {
1471                                                         panel_click_distance_x = mousepos_x - panelPos_x;
1472                                                         panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1473                                                         panel_click_resizeorigin = panelPos + eX * panelSize_x;
1474                                                 } else if(resizeCorner == 4) {
1475                                                         panel_click_distance = panelSize - mousepos + panelPos;
1476                                                         panel_click_resizeorigin = panelPos;
1477                                                 }
1478                                         }       
1479                                 }
1480
1481                                 if(cvar("hud_configure_checkcollisions_debug"))
1482                                         drawfill(panelPos, panelSize, '1 0 0', .3, DRAWFLAG_NORMAL);
1483
1484                                 if(highlightedAction == 1)
1485                                         HUD_Panel_SetPos(i, mousepos - panel_click_distance);
1486                                 else if(highlightedAction == 2)
1487                                         HUD_Panel_SetPosSize(i);
1488                         }
1489                 }
1490
1491                 // doubleclick check
1492                 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1493                 {
1494                         mouseClicked = 0; // to prevent spam, I guess.
1495                         disable_menu_alphacheck = 2;
1496                         menu_enabled = 1;
1497                         menu_enabled_time = time;
1498                         localcmd("menu_showhudoptions ", ftos(highlightedPanel), "\n");
1499                         return;
1500                 }
1501                 if(prevMouseClicked == 0)
1502                 {
1503                         prevMouseClickedTime = time;
1504                         prevMouseClickedPos = mousepos;
1505                 }
1506         }
1507         prevMouseClicked = mouseClicked;
1508 }
1509
1510 // Weapon icons (#0)
1511 //
1512 float weaponspace[10];
1513 void HUD_WeaponIcons_Clear()
1514 {
1515         float idx;
1516         for(idx = 0; idx < 10; ++idx)
1517                 weaponspace[idx] = 0;
1518 }
1519
1520 entity weaponorder[WEP_MAXCOUNT];
1521
1522 void weaponorder_swap(float i, float j, entity pass)
1523 {
1524         entity h;
1525         h = weaponorder[i];
1526         weaponorder[i] = weaponorder[j];
1527         weaponorder[j] = h;
1528 }
1529
1530 string weaponorder_cmp_str;
1531 float weaponorder_cmp(float i, float j, entity pass)
1532 {
1533         float ai, aj;
1534         ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1535         aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1536         return aj - ai; // the string is in REVERSE order (higher prio at the right is what we want, but higher prio first is the string)
1537 }
1538
1539 void HUD_WeaponIcons(void)
1540 {
1541         float id = HUD_PANEL_WEAPONICONS;
1542         float alpha, stat_weapons; // "constants"
1543         vector pos, mySize, accuracy_color;
1544         float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1545
1546         pos = HUD_Panel_GetPos(id);
1547         mySize = HUD_Panel_GetSize(id);
1548
1549         stat_weapons = getstati(STAT_WEAPONS);
1550         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1551         {
1552                 self = get_weaponinfo(i);
1553                 if(self.impulse >= 0)
1554                 {
1555                         weaponorder[weapon_cnt] = self;
1556                         ++weapon_cnt;
1557                 }
1558         }
1559
1560         // TODO make this configurable
1561         weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1562         heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1563
1564         HUD_Panel_DrawBg(id, pos, mySize, 0);
1565         float padding;
1566         padding = HUD_Panel_GetPadding(id);
1567         if(padding)
1568         {
1569                 pos += '1 1 0' * padding;
1570                 mySize -= '2 2 0' * padding;
1571         }
1572
1573         // hits
1574         weapon_stats = getstati(STAT_DAMAGE_HITS);
1575         weapon_number = weapon_stats & 63;
1576         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1577         // fired
1578         weapon_stats = getstati(STAT_DAMAGE_FIRED);
1579         weapon_number = weapon_stats & 63;
1580         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1581
1582         if(cvar_or("hud_weaponicons_fade", 1))
1583         {
1584                 fade = 3.2 - 2 * (time - weapontime);
1585                 fade = bound(0.7, fade, 1);
1586         }
1587         else
1588                 fade = 1;
1589
1590         HUD_WeaponIcons_Clear();
1591
1592         float rows, columns;
1593         rows = mySize_y/mySize_x;
1594         rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1595         //                               ^^^ weapon icon aspect goes here
1596
1597         columns = ceil(WEP_COUNT/rows);
1598         float row, column;
1599         for(i = 0; i < weapon_cnt; ++i)
1600         {
1601                 self = weaponorder[i];
1602                 weapid = self.impulse;
1603
1604                 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1605
1606                 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1607                 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1608
1609                 // draw background behind currently selected weapon
1610                 if(self.weapon == activeweapon)
1611                         drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_current_bg", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1612
1613                 // draw the weapon accuracy on the HUD
1614                 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1615                 {
1616                         if(weapon_damage)
1617                                 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1618
1619                         accuracy_color = HUD_AccuracyColor(weapon_stats);
1620                         if(weapon_damage)
1621                                 drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), "weapon_accuracy", eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), accuracy_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1622                 }
1623
1624                 // draw the weapon icon
1625                 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1626                 {
1627                         drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '1 1 1', fade * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1628
1629                         if(cvar_or("hud_weaponicons_number", 1))
1630                                 drawstring(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1631                 }
1632                 else
1633                 {
1634                         drawpic_skin(pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows), strcat("weapon", self.netname), eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows), '0 0 0', HUD_Panel_GetFgAlpha(id) * 0.5, DRAWFLAG_NORMAL);
1635                 }
1636
1637                 ++row;
1638                 if(row >= rows)
1639                 {
1640                         row = 0;
1641                         ++column;
1642                 }
1643         }
1644
1645 }
1646
1647 // Inventory (#1)
1648 //
1649 float GetAmmoStat(float i)
1650 {
1651         switch(i)
1652         {
1653                 case 0: return STAT_SHELLS;
1654                 case 1: return STAT_NAILS;
1655                 case 2: return STAT_ROCKETS;
1656                 case 3: return STAT_CELLS;
1657                 case 4: return STAT_FUEL;
1658                 default: return -1;
1659         }
1660 }
1661
1662 float GetAmmoItemCode(float i)
1663 {
1664         switch(i)
1665         {
1666                 case 0: return IT_SHELLS;
1667                 case 1: return IT_NAILS;
1668                 case 2: return IT_ROCKETS;
1669                 case 3: return IT_CELLS;
1670                 case 4: return IT_FUEL;
1671                 default: return -1;
1672         }
1673 }
1674
1675 string GetAmmoPicture(float i)
1676 {
1677         switch(i)
1678         {
1679                 case 0: return "ammo_shells";
1680                 case 1: return "ammo_bullets";
1681                 case 2: return "ammo_rockets";
1682                 case 3: return "ammo_cells";
1683                 case 4: return "ammo_fuel";
1684                 default: return "";
1685         }
1686 }
1687
1688 void HUD_Inventory(void)
1689 {
1690         float id = HUD_PANEL_INVENTORY;
1691         float i;
1692         float stat_items;
1693
1694         vector pos, mySize, mysize, mypos;
1695         pos = HUD_Panel_GetPos(id);
1696         mySize = HUD_Panel_GetSize(id);
1697
1698         HUD_Panel_DrawBg(id, pos, mySize, 0);
1699         float padding;
1700         padding = HUD_Panel_GetPadding(id);
1701         if(padding)
1702         {
1703                 pos += '1 1 0' * padding;
1704                 mySize -= '2 2 0' * padding;
1705         }
1706
1707         // ammo
1708         stat_items = getstati(STAT_ITEMS);
1709         for (i = 0; i < 4; ++i) {
1710                 float a;
1711                 a = getstati(GetAmmoStat(i)); // how much ammo do we have of type i?
1712                 if(hud_configure)
1713                         a = 100;
1714
1715                 if(cvar("hud_inventory_onlycurrent")) {
1716                         if(hud_configure)
1717                                 i = 2;
1718                         if (stat_items & GetAmmoItemCode(i) || hud_configure) {
1719                                 drawpic_skin(pos, GetAmmoPicture(i), '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1720                                 if(a < 10)
1721                                         HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '0.7 0 0', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1722                                 else
1723                                         HUD_DrawXNum(pos + eX * mySize_y + eY * 0.25 * mySize_y, a, strlen(ftos(a)), 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1724                         }
1725                         if(hud_configure)
1726                                 break;
1727                 } else {
1728                         if (a > 0) {
1729                                 if(mySize_x/mySize_y >= 10) { // arrange horizontally
1730                                         switch (i) {
1731                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1732                                                 case 1: mypos_x = pos_x + 0.25 * mySize_x;      mypos_y = pos_y;                        break; // bullets
1733                                                 case 2: mypos_x = pos_x + 0.5  * mySize_x;      mypos_y = pos_y;                        break; // rockets
1734                                                 case 3: mypos_x = pos_x + 0.75 * mySize_x;      mypos_y = pos_y;                        break; // cells
1735                                         }
1736                                         mysize_x = 0.25 * mySize_x;
1737                                         mysize_y = mySize_y;
1738                                 } else if(mySize_x/mySize_y >= 2.5) { // arrange in a 2x2 grid
1739                                         switch (i) {
1740                                                 case 0: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y + 0.5 * mySize_y;       break; // shells
1741                                                 case 1: mypos_x = pos_x + 0.5 * mySize_x;       mypos_y = pos_y;                        break; // bullets
1742                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5 * mySize_y;       break; // rockets
1743                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // cells
1744                                         }
1745                                         mysize_x = 0.5 * mySize_x;
1746                                         mysize_y = 0.5 * mySize_y;
1747                                 } else { // arrange vertically
1748                                         switch (i) {
1749                                                 case 0: mypos_x = pos_x;                        mypos_y = pos_y;                        break; // shells
1750                                                 case 1: mypos_x = pos_x;                        mypos_y = pos_y + 0.25 * mySize_y;      break; // bullets
1751                                                 case 2: mypos_x = pos_x;                        mypos_y = pos_y + 0.5  * mySize_y;      break; // rockets
1752                                                 case 3: mypos_x = pos_x;                        mypos_y = pos_y + 0.75 * mySize_y;      break; // cells
1753                                         }
1754                                         mysize_x = mySize_x;
1755                                         mysize_y = 0.25 * mySize_y;
1756                                 }
1757
1758                                 if (stat_items & GetAmmoItemCode(i))
1759                                         drawpic_skin(mypos, "ammo_current_bg", mysize, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1760                                 drawpic_skin(mypos + eY * 0.05 * mysize_y, GetAmmoPicture(i), '1 1 0' * 0.8 * mysize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1761                                 if (a < 10) {
1762                                         if(stat_items & GetAmmoItemCode(i))
1763                                                 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0 0', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1764                                         else
1765                                                 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0 0', 0, 0, HUD_Panel_GetFgAlpha(id) * 0.7, DRAWFLAG_NORMAL);
1766                                 } else {
1767                                         if(stat_items & GetAmmoItemCode(i))
1768                                                 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1769                                         else
1770                                                 HUD_DrawXNum(mypos + eX * 0.8 * mysize_y + eY * 0.25 * mysize_y, a, strlen(ftos(a)), 0, 0.5 * mysize_y, '0.7 0.7 0.7', 0, 0, HUD_Panel_GetFgAlpha(id) * 0.7, DRAWFLAG_NORMAL);
1771                                 }
1772                         }
1773                 }
1774         }
1775 }
1776
1777
1778 // Powerups (#2)
1779 //
1780 void HUD_Powerups(void) {
1781         float id = HUD_PANEL_POWERUPS;
1782         float stat_items;
1783         stat_items = getstati(STAT_ITEMS);
1784
1785         if(!hud_configure)
1786         {
1787                 if not(stat_items & IT_STRENGTH)
1788                         if not(stat_items & IT_INVINCIBLE)
1789                                 return;
1790
1791                 if (getstati(STAT_HEALTH) <= 0)
1792                         return;
1793         }
1794
1795         vector pos, mySize;
1796         pos = HUD_Panel_GetPos(id);
1797         mySize = HUD_Panel_GetSize(id);
1798
1799         HUD_Panel_DrawBg(id, pos, mySize, 0);
1800         float padding;
1801         padding = HUD_Panel_GetPadding(id);
1802         if(padding)
1803         {
1804                 pos += '1 1 0' * padding;
1805                 mySize -= '2 2 0' * padding;
1806         }
1807
1808         float strength_time, shield_time;
1809
1810         strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1811         shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1812
1813         if(hud_configure)
1814         {
1815                 strength_time = 15;
1816                 shield_time = 27;
1817         }
1818
1819         float len;
1820
1821         vector barpos, barsize;
1822         vector picpos;
1823         vector numpos;
1824
1825         string leftname, rightname;
1826         float leftcnt, rightcnt;
1827         float leftexact, rightexact;
1828         float leftalpha, rightalpha;
1829         if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) {
1830                 leftname = "strength";
1831                 leftcnt = ceil(strength_time);
1832                 leftexact = strength_time;
1833
1834                 rightname = "shield";
1835                 rightcnt = ceil(shield_time);
1836                 rightexact = shield_time;
1837         } else {
1838                 leftname = "shield";
1839                 leftcnt = ceil(shield_time);
1840                 leftexact = shield_time;
1841
1842                 rightname = "strength";
1843                 rightcnt = ceil(strength_time);
1844                 rightexact = strength_time;
1845         }
1846         leftalpha = bound(0, leftexact, 1);
1847         rightalpha = bound(0, rightexact, 1);
1848
1849         if (mySize_x/mySize_y > 4)
1850         {
1851                 if(leftcnt)
1852                 {
1853                         len = strlen(ftos(leftcnt));
1854
1855                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1856                                 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1857                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1858                                 picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1859                                 numpos = picpos - eX * 2 * 0.5 * mySize_y + eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1860                         } else {
1861                                 barpos = pos;
1862                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1863                                 picpos = pos;
1864                                 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1865                         }
1866
1867                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1868                         if(leftcnt <= 5)
1869                                 drawpic_skin_expanding_two(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1870                         else
1871                                 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1872                         HUD_DrawXNum(numpos, leftcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1873                 }
1874
1875                 if(rightcnt)
1876                 {
1877                         len = strlen(ftos(rightcnt));
1878
1879                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1880                                 barpos = pos + eX * 0.5 * mySize_x;
1881                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1882                                 picpos = pos + eX * 0.5 * mySize_x;
1883                                 numpos = picpos + eX * mySize_y - eX * (2-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1884                         } else {
1885                                 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1886                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1887                                 picpos = pos + eX * mySize_x - eX * mySize_y;
1888                                 numpos = picpos - eX * mySize_y + eY * 0.25 * mySize_y;
1889                         }
1890
1891                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1892                         if(rightcnt <= 5)
1893                                 drawpic_skin_expanding_two(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1894                         else
1895                                 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1896                         HUD_DrawXNum(numpos, rightcnt, 2, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1897                 }
1898         }
1899         else if (mySize_x/mySize_y > 1.5)
1900         {
1901                 if(leftcnt)
1902                 {
1903                         len = strlen(ftos(leftcnt));
1904
1905                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1906                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1907                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1908                                 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
1909                                 numpos = picpos - eX * len * 0.5 * mySize_y;
1910                         } else {
1911                                 barpos = pos;
1912                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1913                                 picpos = pos;
1914                                 numpos = picpos + eX * 0.5 * mySize_y;
1915                         }
1916
1917                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1918                         if(leftcnt <= 5)
1919                                 drawpic_skin_expanding_two(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1920                         else
1921                                 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1922                         HUD_DrawXNum(numpos, leftcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1923                 }
1924
1925                 if(rightcnt)
1926                 {
1927                         len = strlen(ftos(rightcnt));
1928
1929                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1930                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1931                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1932                                 picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
1933                                 numpos = picpos - eX * len * 0.5 * mySize_y;
1934                         } else {
1935                                 barpos = pos + eY * 0.5 * mySize_y;
1936                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1937                                 picpos = pos + eY * 0.5 * mySize_y;
1938                                 numpos = picpos + eX * 0.5 * mySize_y;
1939                         }
1940
1941                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1942                         if(rightcnt <= 5)
1943                                 drawpic_skin_expanding_two(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1944                         else
1945                                 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1946                         HUD_DrawXNum(numpos, rightcnt, len, 0, 0.5 * mySize_y, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1947                 }
1948         }
1949         else
1950         {
1951                 if(leftcnt)
1952                 {
1953                         len = strlen(ftos(leftcnt));
1954
1955                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1956                                 barpos = pos;
1957                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1958                                 picpos = pos + eX * 0.05 * mySize_x;
1959                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
1960                         } else {
1961                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1962                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1963                                 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x;
1964                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x;
1965                         }
1966
1967                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1968                         if(leftcnt <= 5)
1969                                 drawpic_skin_expanding_two(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (leftcnt - leftexact) / 0.5, 1));
1970                         else
1971                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1972                         HUD_DrawXNum(numpos, leftcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1973                 }
1974
1975                 if(rightcnt)
1976                 {
1977                         len = strlen(ftos(rightcnt));
1978
1979                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1980                                 barpos = pos + eX * 0.5 * mySize_x;
1981                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1982                                 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1983                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1984                         } else {
1985                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/30) + eX * 0.5 * mySize_x;
1986                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/30);
1987                                 picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.65 * mySize_x + eX * 0.5 * mySize_x;
1988                                 numpos = pos + eX * ((2-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1989                         }
1990
1991                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1992                         if(rightcnt <= 5)
1993                                 drawpic_skin_expanding_two(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE, bound(0, (rightcnt - rightexact) / 0.5, 1));
1994                         else
1995                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1996                         HUD_DrawXNum(numpos, rightcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1997                 }
1998         }
1999 }
2000
2001 // Health/armor (#3)
2002 //
2003 void HUD_HealthArmor(void)
2004 {
2005         float id = HUD_PANEL_HEALTHARMOR;
2006         vector pos, mySize;
2007         pos = HUD_Panel_GetPos(id);
2008         mySize = HUD_Panel_GetSize(id);
2009
2010         HUD_Panel_DrawBg(id, pos, mySize, 0);
2011         float padding;
2012         padding = HUD_Panel_GetPadding(id);
2013         if(padding)
2014         {
2015                 pos += '1 1 0' * padding;
2016                 mySize -= '2 2 0' * padding;
2017         }
2018
2019         float armor, health;
2020         armor = getstati(STAT_ARMOR);
2021         health = getstati(STAT_HEALTH);
2022
2023         float fuel;
2024         fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
2025
2026         if(hud_configure)
2027         {
2028                 armor = 150;
2029                 health = 100;
2030                 fuel = 70;
2031         }
2032
2033         if(health <= 0)
2034                 return;
2035
2036         float len;
2037         vector barpos, barsize;
2038         vector picpos;
2039         vector numpos;
2040
2041         if(cvar("hud_healtharmor") == 2) // combined health and armor display
2042         {
2043                 vector v;
2044                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
2045
2046                 float x;
2047                 x = floor(v_x + 1);
2048
2049                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2050                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
2051                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2052                         picpos = pos;
2053                         numpos = picpos + eX * 1.5 * mySize_y;
2054                 } else {
2055                         barpos = pos;
2056                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
2057                         picpos = pos + eX * 3 * mySize_y;
2058                         numpos = pos;
2059                 }
2060
2061                 if(v_z) // NOT fully armored
2062                 {
2063                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2064                         drawpic_skin(picpos, "health", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2065                         if(armor)
2066                                 drawpic_skin(picpos + eX * mySize_y, "armor", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * armor / health, DRAWFLAG_NORMAL);
2067                 }
2068                 else
2069                 {
2070                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2071                         drawpic_skin(picpos + eX * mySize_y, "health", '0.5 0.5 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * health / armor, DRAWFLAG_NORMAL);
2072                         if(armor)
2073                                 drawpic_skin(picpos, "armor", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2074                 }
2075                 HUD_DrawXNum_Colored(numpos, x, 3, mySize_y, HUD_Panel_GetFgAlpha(id)); // draw the combined health and armor
2076
2077                 // fuel
2078                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2079                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2080                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2081                 } else {
2082                         barpos = pos;
2083                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2084                 }
2085                 if(fuel)
2086                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2087         }
2088
2089         else
2090         {
2091                 string leftname, rightname;
2092                 float leftcnt, rightcnt;
2093                 float leftactive, rightactive;
2094                 float leftalpha, rightalpha;
2095                 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) { // old style layout with armor left/top of health
2096                         leftname = "armor";
2097                         leftcnt = armor;
2098                         if(leftcnt)
2099                                 leftactive = 1;
2100                         leftalpha = min((armor+10)/55, 1);
2101
2102                         rightname = "health";
2103                         rightcnt = health;
2104                         rightactive = 1;
2105                         rightalpha = 1;
2106                 } else {
2107                         leftname = "health";
2108                         leftcnt = health;
2109                         leftactive = 1;
2110                         leftalpha = 1;
2111
2112                         rightname = "armor";
2113                         rightcnt = armor;
2114                         if(rightcnt)
2115                                 rightactive = 1;
2116                         rightalpha = min((armor+10)/55, 1);
2117                 }
2118
2119                 if (mySize_x/mySize_y > 5)
2120                 {
2121                         if(leftactive)
2122                         {
2123                                 len = strlen(ftos(leftcnt));
2124
2125                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2126                                         barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
2127                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2128                                         picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
2129                                         numpos = picpos - eX * 3 * 0.5 * mySize_y + eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
2130                                 } else {
2131                                         barpos = pos;
2132                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
2133                                         picpos = pos;
2134                                         numpos = picpos + eX * mySize_y + eY * 0.25 * mySize_y;
2135                                 }
2136
2137                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2138                                 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2139                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2140                         }
2141
2142                         if(rightactive)
2143                         {
2144                                 len = strlen(ftos(rightcnt));
2145
2146                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2147                                         barpos = pos + eX * 0.5 * mySize_x;
2148                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2149                                         picpos = pos + eX * 0.5 * mySize_x;
2150                                         numpos = picpos + eX * mySize_y - eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
2151                                 } else {
2152                                         barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
2153                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
2154                                         picpos = pos + eX * mySize_x - eX * mySize_y;
2155                                         numpos = picpos - eX * 1.5 * mySize_y + eY * 0.25 * mySize_y;
2156                                 }
2157
2158                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2159                                 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2160                                 HUD_DrawXNum_Colored(numpos, rightcnt, 3, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2161                         }
2162
2163                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2164                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2165                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2166                         } else {
2167                                 barpos = pos;
2168                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
2169                         }
2170                         if(fuel)
2171                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2172                 }
2173                 else if (mySize_x/mySize_y > 2)
2174                 {
2175                         if(leftactive)
2176                         {
2177                                 len = strlen(ftos(leftcnt));
2178
2179                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2180                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
2181                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2182                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
2183                                         numpos = picpos - eX * len * 0.5 * mySize_y;
2184                                 } else {
2185                                         barpos = pos;
2186                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2187                                         picpos = pos;
2188                                         numpos = picpos + eX * 0.5 * mySize_y;
2189                                 }
2190
2191                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2192                                 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2193                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2194                         }
2195
2196                         if(rightactive)
2197                         {
2198                                 len = strlen(ftos(rightcnt));
2199
2200                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2201                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2202                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2203                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
2204                                         numpos = picpos - eX * len * 0.5 * mySize_y;
2205                                 } else {
2206                                         barpos = pos + eY * 0.5 * mySize_y;
2207                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2208                                         picpos = pos + eY * 0.5 * mySize_y;
2209                                         numpos = picpos + eX * 0.5 * mySize_y;
2210                                 }
2211
2212                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2213                                 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2214                                 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2215                         }
2216
2217                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2218                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2219                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2220                         } else {
2221                                 barpos = pos;
2222                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2223                         }
2224                         if(fuel)
2225                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2226                 }
2227                 else
2228                 {
2229                         if(leftactive)
2230                         {
2231                                 len = strlen(ftos(leftcnt));
2232
2233                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2234                                         barpos = pos;
2235                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2236                                         picpos = pos + eX * 0.05 * mySize_x;
2237                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
2238                                 } else {
2239                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2240                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2241                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x;
2242                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x;
2243                                 }
2244
2245                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2246                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2247                                 HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2248                         }
2249
2250                         if(rightactive)
2251                         {
2252                                 len = strlen(ftos(rightcnt));
2253
2254                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2255                                         barpos = pos + eX * 0.5 * mySize_x;
2256                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2257                                         picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2258                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2259                                 } else {
2260                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2261                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2262                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x + eX * 0.5 * mySize_x;
2263                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x + eX * 0.5 * mySize_x;
2264                                 }
2265
2266                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2267                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2268                                 HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2269                         }
2270
2271                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2272                                 barpos = pos;
2273                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2274                         } else {
2275                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2276                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2277                         }
2278                         if(fuel)
2279                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2280                 }
2281         }
2282 }
2283
2284 // ___TODO___ !!!
2285 // Notification area (#4)
2286 //
2287
2288 string Weapon_SuicideMessage(float deathtype)
2289 {
2290         w_deathtype = deathtype;
2291         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2292         return w_deathtypestring;
2293 }
2294
2295 string Weapon_KillMessage(float deathtype)
2296 {
2297         w_deathtype = deathtype;
2298         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2299         return w_deathtypestring;
2300 }
2301
2302 float killnotify_times[10];
2303 float killnotify_deathtype[10];
2304 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2305 string killnotify_attackers[10];
2306 string killnotify_victims[10];
2307 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2308 {
2309         float i;
2310         for (i = 9; i > 0; --i) {
2311                 killnotify_times[i] = killnotify_times[i-1];
2312                 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2313                 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2314                 if(killnotify_attackers[i])
2315                         strunzone(killnotify_attackers[i]);
2316                 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2317                 if(killnotify_victims[i])
2318                         strunzone(killnotify_victims[i]);
2319                 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2320         }
2321         killnotify_times[0] = time;
2322         killnotify_deathtype[0] = wpn;
2323         killnotify_actiontype[0] = actiontype;
2324         if(killnotify_attackers[0])
2325                 strunzone(killnotify_attackers[0]);
2326         killnotify_attackers[0] = strzone(attacker);
2327         if(killnotify_victims[0])
2328                 strunzone(killnotify_victims[0]);
2329         killnotify_victims[0] = strzone(victim);
2330 }
2331
2332 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2333 {
2334         float w;
2335         float alsoprint;
2336         alsoprint = (cvar("hud_notify_print") || !HUD_Panel_CheckActive(4)); // print message to console if: notify panel disabled, or cvar to do so enabled
2337         
2338         if(msg == MSG_SUICIDE) {
2339                 // TODO: cl_gentle
2340                 w = DEATH_WEAPONOF(type);
2341                 if(WEP_VALID(w)) {
2342                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2343                         if (alsoprint)
2344                                 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2345                 } else if (type == DEATH_KILL) {
2346                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2347                         if (alsoprint)
2348                                 print ("^1",s1, "^1 couldn't take it anymore\n");
2349                 } else if (type == DEATH_ROT) {
2350                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2351                         if (alsoprint)
2352                                 print ("^1",s1, "^1 died\n");
2353                 } else if (type == DEATH_NOAMMO) {
2354                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2355                         if (alsoprint)
2356                                 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2357                 } else if (type == DEATH_CAMP) {
2358                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2359                         if (alsoprint)
2360                                 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2361                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2362                         HUD_KillNotify_Push(s1, "", 0, type);
2363                         if (alsoprint)
2364                                 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2365                 } else if (type == DEATH_CHEAT) {
2366                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2367                         if (alsoprint)
2368                                 print ("^1",s1, "^1 unfairly eliminated themself\n");
2369                 } else if (type == DEATH_FIRE) {
2370                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2371                         if (alsoprint)
2372                                 print ("^1",s1, "^1 burned to death\n");
2373                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2374                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2375                         if (alsoprint)
2376                                 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2377                 } 
2378                 
2379                 if (stof(s2) > 2) // killcount > 2
2380                         print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2381         } else if(msg == MSG_KILL) {
2382                 w = DEATH_WEAPONOF(type);
2383                 if(WEP_VALID(w)) {
2384                         HUD_KillNotify_Push(s2, s1, 1, w);
2385                         if (alsoprint)
2386                                 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2387                 }
2388                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2389                         HUD_KillNotify_Push(s1, s2, 1, type);
2390                         if(alsoprint)
2391                         {
2392                                 if(cvar("cl_gentle")) {
2393                                         print ("^1", s1, "^1 took action against a team mate\n");
2394                                 } else {
2395                                         print ("^1", s1, "^1 mows down a team mate\n");
2396                                 }
2397                         }
2398                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2399                                 if(cvar("cl_gentle"))
2400                                         print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2401                                 else
2402                                         print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2403                         }
2404                         else if (stof(s2) > 2) {
2405                                 if(cvar("cl_gentle"))
2406                                         print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2407                                 else
2408                                         print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2409                         }
2410                 }
2411                 else if(type == KILL_FIRST_BLOOD)
2412                         print("^1",s1, "^1 drew first blood", "\n");
2413                 // TODO: icon!
2414                 else if (type == DEATH_TELEFRAG)
2415                         print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2416                 else if (type == DEATH_DROWN) {
2417                         HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2418                         if(alsoprint)
2419                                 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2420                 }
2421                 else if (type == DEATH_SLIME) {
2422                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2423                         if(alsoprint)
2424                                 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2425                 }
2426                 else if (type == DEATH_LAVA) {
2427                         HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2428                         if(alsoprint)
2429                                 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2430                 }
2431                 else if (type == DEATH_FALL) {
2432                         HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2433                         if(alsoprint)
2434                                 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2435                 }
2436                 else if (type == DEATH_SHOOTING_STAR) {
2437                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2438                         if(alsoprint)
2439                                 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2440                 }
2441                 else if (type == DEATH_SWAMP) {
2442                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2443                         if(alsoprint)
2444                                 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2445                 }
2446                 else if (type == DEATH_HURTTRIGGER)
2447                 {
2448                         HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2449                         if(alsoprint)
2450                                 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2451                 } else if(type == DEATH_SBCRUSH) {
2452                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2453                         if(alsoprint)
2454                                 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2455                 } else if(type == DEATH_SBMINIGUN) {
2456                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2457                         if(alsoprint)
2458                                 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2459                 } else if(type == DEATH_SBROCKET) {
2460                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2461                         if(alsoprint)
2462                                 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2463                 } else if(type == DEATH_SBBLOWUP) {
2464                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2465                         if(alsoprint)
2466                                 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2467                 } else if(type == DEATH_WAKIGUN) {
2468                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2469                         if(alsoprint)
2470                                 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2471                 } else if(type == DEATH_WAKIROCKET) {
2472                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2473                         if(alsoprint)
2474                                 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2475                 } else if(type == DEATH_WAKIBLOWUP) {
2476                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2477                         if(alsoprint)
2478                                 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2479                 } else if(type == DEATH_TURRET) {
2480                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2481                         if(alsoprint)
2482                                 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2483                 } else if(type == DEATH_TOUCHEXPLODE) {
2484                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2485                         if(alsoprint)
2486                                 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2487                 } else if(type == DEATH_CHEAT) {
2488                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2489                         if(alsoprint)
2490                                 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2491                 } else if (type == DEATH_FIRE) {
2492                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2493                         if(alsoprint)
2494                                 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2495                 } else if (type == DEATH_CUSTOM) {
2496                         HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2497                         if(alsoprint)
2498                                 print ("^1",s1, "^1 ", s2, "\n");
2499                 } else {
2500                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2501                         if(alsoprint)
2502                                 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2503                 }
2504         } else if(msg == MSG_SPREE) {
2505                 if(type == KILL_END_SPREE) {
2506                         if(cvar("cl_gentle"))
2507                                 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2508                         else
2509                                 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2510                 } else if(type == KILL_SPREE) {
2511                         if(cvar("cl_gentle"))
2512                                 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2513                         else
2514                                 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2515                 } else if(type == KILL_SPREE_3) {
2516                         if(cvar("cl_gentle"))
2517                                 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2518                         else
2519                                 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2520                 } else if(type == KILL_SPREE_5) {
2521                         if(cvar("cl_gentle"))
2522                                 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2523                         else
2524                                 print (s1,"^7 unleashes ^1RAGE\n");
2525                 } else if(type == KILL_SPREE_10) {
2526                         if(cvar("cl_gentle"))
2527                                 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2528                         else
2529                                 print (s1,"^7 starts the ^1MASSACRE!\n");
2530                 } else if(type == KILL_SPREE_15) {
2531                         if(cvar("cl_gentle"))
2532                                 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2533                         else
2534                                 print (s1,"^7 executes ^1MAYHEM!\n");
2535                 } else if(type == KILL_SPREE_20) {
2536                         if(cvar("cl_gentle"))
2537                                 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2538                         else
2539                                 print (s1,"^7 is a ^1BERSERKER!\n");
2540                 } else if(type == KILL_SPREE_25) {
2541                         if(cvar("cl_gentle"))
2542                                 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2543                         else
2544                                 print (s1,"^7 inflicts ^1CARNAGE!\n");
2545                 } else if(type == KILL_SPREE_30) {
2546                         if(cvar("cl_gentle"))
2547                                 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2548                         else
2549                                 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2550                 }
2551         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2552                 if (type == DEATH_DROWN) {
2553                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2554                         if(alsoprint)
2555                         {
2556                                 if(cvar("cl_gentle"))
2557                                         print ("^1",s1, "^1 was in the water for too long\n");
2558                                 else
2559                                         print ("^1",s1, "^1 drowned\n");
2560                         }
2561                 } else if (type == DEATH_SLIME) {
2562                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2563                         if(alsoprint)
2564                                 print ("^1",s1, "^1 was slimed\n");
2565                 } else if (type == DEATH_LAVA) {
2566                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2567                         if(alsoprint)
2568                         {
2569                                 if(cvar("cl_gentle"))
2570                                         print ("^1",s1, "^1 found a hot place\n");
2571                                 else
2572                                         print ("^1",s1, "^1 turned into hot slag\n");
2573                         }
2574                 } else if (type == DEATH_FALL) {
2575                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2576                         if(alsoprint)
2577                         {
2578                                 if(cvar("cl_gentle"))
2579                                         print ("^1",s1, "^1 tested gravity (and it worked)\n");
2580                                 else
2581                                         print ("^1",s1, "^1 hit the ground with a crunch\n");
2582                         }
2583                 } else if (type == DEATH_SHOOTING_STAR) {
2584                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2585                         if(alsoprint)
2586                                 print ("^1",s1, "^1 became a shooting star\n");
2587                 } else if (type == DEATH_SWAMP) {
2588                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2589                         if(alsoprint)
2590                         {
2591                                 if(cvar("cl_gentle"))
2592                                         print ("^1",s1, "^1 discovered a swamp\n");
2593                                 else
2594                                         print ("^1",s1, "^1 is now conserved for centuries to come\n");
2595                         }
2596                 } else if(type == DEATH_TURRET) {
2597                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2598                         if(alsoprint)
2599                                 print ("^1",s1, "^1 was mowed down by a turret \n");
2600                 } else if (type == DEATH_CUSTOM) {
2601                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2602                         if(alsoprint)
2603                                 print ("^1",s1, "^1 ", s2, "\n");
2604                 } else if (type == DEATH_HURTTRIGGER) {
2605                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2606                         if(alsoprint)
2607                                 print ("^1",s1, "^1 was in the wrong place\n");
2608                 } else if(type == DEATH_TOUCHEXPLODE) {
2609                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2610                         if(alsoprint)
2611                                 print ("^1",s1, "^1 died in an accident\n");
2612                 } else if(type == DEATH_CHEAT) {
2613                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2614                         if(alsoprint)
2615                                 print ("^1",s1, "^1 was unfairly eliminated\n");
2616                 } else if(type == DEATH_FIRE) {
2617                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2618                         if(alsoprint)
2619                         {
2620                                 if(cvar("cl_gentle"))
2621                                         print ("^1",s1, "^1 felt a little hot\n");
2622                                 else
2623                                         print ("^1",s1, "^1 burnt to death\n");
2624                                 }
2625                 } else {
2626                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2627                         if(alsoprint)
2628                         {
2629                                 if(cvar("cl_gentle"))
2630                                         print ("^1",s1, "^1 needs a restart\n");
2631                                 else
2632                                         print ("^1",s1, "^1 died\n");
2633                         }
2634                 }
2635         } else if(msg == MSG_KILL_ACTION_SPREE) {
2636                 if(cvar("cl_gentle"))
2637                         print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2638                 else
2639                         print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2640         } else if(msg == MSG_INFO) {
2641                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2642                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2643                         print(s1, "^7 got the ", s2, "\n");
2644                 } else if(type == INFO_LOSTFLAG) {
2645                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2646                         print(s1, "^7 lost the ", s2, "\n");
2647                 } else if(type == INFO_PICKUPFLAG) {
2648                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2649                         print(s1, "^7 picked up the ", s2, "\n");
2650                 } else if(type == INFO_RETURNFLAG) {
2651                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2652                         print(s1, "^7 returned the ", s2, "\n");
2653                 }
2654         }
2655 }
2656
2657 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2658
2659 void HUD_Centerprint(string s1, string s2, float type, float msg)
2660 {
2661         if(msg == MSG_SUICIDE) {
2662                 if (type == DEATH_TEAMCHANGE) {
2663                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2664                 } else if (type == DEATH_AUTOTEAMCHANGE) {
2665                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2666                 } else if (type == DEATH_CAMP) {
2667                         if(cvar("cl_gentle"))
2668                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2669                         else
2670                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2671                 } else if (type == DEATH_NOAMMO) {
2672                         if(cvar("cl_gentle"))
2673                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2674                         else
2675                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2676                 } else if (type == DEATH_ROT) {
2677                         if(cvar("cl_gentle"))
2678                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2679                         else
2680                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2681                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2682                         if(cvar("cl_gentle"))
2683                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2684                         else
2685                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2686                 } else if (type == DEATH_QUIET) {
2687                         // do nothing
2688                 } else if (type == DEATH_KILL) {
2689                         if(cvar("cl_gentle"))
2690                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2691                         else
2692                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2693                 }
2694         } else if(msg == MSG_KILL) {
2695                 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2696                         if(cvar("cl_gentle")) {
2697                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2698                         } else {
2699                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2700                         }
2701                 } else if (type == KILL_FIRST_BLOOD) {
2702                         if(cvar("cl_gentle")) {
2703                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2704                         } else {
2705                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2706                         }
2707                 } else if (type == KILL_FIRST_VICTIM) {
2708                         if(cvar("cl_gentle")) {
2709                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2710                         } else {
2711                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2712                         }
2713                 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2714                         if(cvar("cl_gentle")) {
2715                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2716                         } else {
2717                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2718                         }
2719                 } else if (type == KILL_TYPEFRAGGED) {
2720                         if(cvar("cl_gentle")) {
2721                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2722                         } else {
2723                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2724                         }
2725                 } else if (type == KILL_FRAG) {
2726                         if(cvar("cl_gentle")) {
2727                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2728                         } else {
2729                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2730                         }
2731                 } else if (type == KILL_FRAGGED) {
2732                         if(cvar("cl_gentle")) {
2733                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2734                         } else {
2735                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2736                         }
2737                 }
2738         } else if(msg == MSG_KILL_ACTION) {
2739                 // TODO: invent more centerprints here?
2740                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2741         }
2742 }
2743
2744 void HUD_Notify (void)
2745 {
2746         float id = HUD_PANEL_NOTIFY;
2747         vector pos, mySize;
2748         pos = HUD_Panel_GetPos(id);
2749         mySize = HUD_Panel_GetSize(id);
2750
2751         HUD_Panel_DrawBg(id, pos, mySize, 0);
2752         float padding;
2753         padding = HUD_Panel_GetPadding(id);
2754         if(padding)
2755         {
2756                 pos += '1 1 0' * padding;
2757                 mySize -= '2 2 0' * padding;
2758         }
2759
2760         float entries, height;
2761         entries = bound(1, floor(14 * mySize_y/mySize_x), 12);
2762         height = mySize_y/entries;
2763         entries -= 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2764         
2765         vector fontsize;
2766         fontsize = '0.5 0.5 0' * height;
2767
2768         float a;
2769         float when;
2770         when = cvar("hud_notify_time");
2771         float fadetime;
2772         fadetime = cvar("hud_notify_fadetime");
2773
2774         string s;
2775
2776         vector pos_attacker, pos_victim;
2777         vector weap_pos;
2778         float width_attacker, width_victim;
2779         string attacker, victim;
2780
2781         float i, j;
2782         for(j = 0; j < entries; ++j)
2783         {
2784                 if(cvar("hud_notify_flip"))
2785                         i = j;
2786                 else // rather nasty hack for ordering items from the bottom up
2787                         i = entries - j - 1;
2788                 if(cvar("hud_notify_info_top"))
2789                         i += 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2790
2791                 if(fadetime)
2792                 {
2793                         if(killnotify_times[j] + when > time)
2794                                 a = 1;
2795                         else
2796                                 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2797                 }
2798                 else
2799                 {
2800                         if(killnotify_times[j] + when > time)
2801                                 a = 1;
2802                         else
2803                                 a = 0;
2804                 }
2805
2806                 // TODO: maybe print in team colors?
2807                 // TODO: maybe this could be cleaned up somehow...
2808                 // TODO: less copypaste code below
2809                 //
2810                 // Y [used by] X
2811                 if(killnotify_actiontype[j] == 0 && !hud_configure) 
2812                 {
2813                         attacker = textShortenToWidth(killnotify_attackers[j], mySize_x - 2 * height, fontsize, stringwidth_colors);
2814
2815                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2816                         pos_attacker = pos + eX * 0.5 * (mySize_x - width_attacker + 2 * height) + eY * 0.5 * fontsize_y + eY * i * height;
2817
2818                         weap_pos = pos + eX * 0.5 * (mySize_x - width_attacker) - eX * height + eY * i * height;
2819                         if(killnotify_deathtype[j] == DEATH_GENERIC)
2820                         {
2821                                 drawpic_skin(weap_pos, "notify_death", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2822                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2823                         }
2824                         else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2825                         {
2826                                 drawpic_skin(weap_pos, "notify_outofammo", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2827                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2828                         }
2829                         else if(killnotify_deathtype[j] == DEATH_KILL)
2830                         {
2831                                 drawpic_skin(weap_pos, "notify_selfkill", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2832                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2833                         }
2834                         else if(killnotify_deathtype[j] == DEATH_CAMP)
2835                         {
2836                                 drawpic_skin(weap_pos, "notify_camping", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2837                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2838                         }
2839                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2840                         {
2841                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2842                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2843                         }
2844                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2845                         {
2846                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2847                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2848                         }
2849                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2850                         {
2851                                 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2852                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2853                         }
2854                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2855                         {
2856                                 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2857                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2858                         }
2859                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2860                         {
2861                                 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2862                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2863                         }
2864                         else if(killnotify_deathtype[j] == DEATH_FALL)
2865                         {
2866                                 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2867                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2868                         }
2869                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2870                         {
2871                                 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2872                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2873                         }
2874                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2875                         {
2876                                 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2877                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2878                         }
2879                         else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2880                         {
2881                                 if(killnotify_victims[j] == "^1RED^7 flag")
2882                                         s = "red";
2883                                 else
2884                                         s = "blue";
2885                                 drawpic_skin(weap_pos, strcat("flag_", s, "_carrying"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2886                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2887                         }
2888                         else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2889                         {
2890                                 if(killnotify_victims[j] == "^1RED^7 flag")
2891                                         s = "red";
2892                                 else
2893                                         s = "blue";
2894                                 drawpic_skin(weap_pos, strcat("flag_", s, "_taken"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2895                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2896                         }
2897                         else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2898                         {
2899                                 if(killnotify_victims[j] == "^1RED^7 flag")
2900                                         s = "red";
2901                                 else
2902                                         s = "blue";
2903                                 drawpic_skin(weap_pos, strcat("flag_", s, "_lost"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2904                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2905                         }
2906                 }
2907                 // X [did action to] Y
2908                 else
2909                 {
2910                         if(hud_configure)
2911                         {
2912                                 attacker = textShortenToWidth("Player1", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2913                                 victim = textShortenToWidth("Player2", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2914                                 a = bound(0, (when - j) / 4, 1);
2915                         }
2916                         else
2917                         {
2918                                 attacker = textShortenToWidth(killnotify_attackers[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2919                                 victim = textShortenToWidth(killnotify_victims[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2920                         }
2921                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2922                         width_victim = stringwidth(victim, TRUE, fontsize);
2923                         pos_attacker = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_attacker) + eY * 0.5 * fontsize_y + eY * i * height;
2924                         pos_victim = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_victim) + eY * 0.5 * fontsize_y + eX * 0.5 * mySize_x + eX * height + eY * i * height;
2925                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2926
2927                         if(hud_configure) // example actions for config mode
2928                         {
2929                                 drawpic_skin(weap_pos, strcat("weapon", "electro"), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2930                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2931                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2932                         }
2933                         else if(WEP_VALID(killnotify_deathtype[j]))
2934                         {
2935                                 self = get_weaponinfo(killnotify_deathtype[j]);
2936                                 drawpic_skin(weap_pos, strcat("weapon", self.netname), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2937                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2938                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2939                         }
2940                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2941                         {
2942                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2943                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2944                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2945                         }
2946                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2947                         {
2948                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2949                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2950                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2951                         }
2952                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2953                         {
2954                                 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2955                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2956                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2957                         }
2958                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2959                         {
2960                                 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2961                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2962                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2963                         }
2964                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2965                         {
2966                                 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2967                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2968                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2969                         }
2970                         else if(killnotify_deathtype[j] == DEATH_FALL)
2971                         {
2972                                 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2973                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2974                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2975                         }
2976                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2977                         {
2978                                 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2979                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2980                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2981                         }
2982                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2983                         {
2984                                 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2985                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2986                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2987                         }
2988                 }
2989
2990         }
2991
2992         // Info messages
2993         //
2994         entity tm;
2995         vector o;
2996         o = pos;
2997         if(cvar("hud_notify_info_top"))
2998                 o = pos + eY;
2999         else
3000                 o = pos + eY * mySize_y - eY * 2 * height;
3001         
3002         if(spectatee_status && !intermission)
3003         {
3004                 //drawfont = hud_bigfont;
3005                 if(spectatee_status == -1)
3006                         s = "^1Observing";
3007                 else
3008                         s = GetPlayerName(spectatee_status - 1);
3009
3010                 //s = textShortenToWidth(s, mySize_y, 0.5 * height, stringwidth_colors);
3011                 //drawcolorcodedstring(pos + eY * 0.25 * height, s, 0.5 * height, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3012                 //drawfont = hud_font;
3013
3014                 // spectator text in the upper right corner
3015                 if(spectatee_status == -1)
3016                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
3017                 else
3018                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
3019                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3020                 o += eY * fontsize_y;
3021
3022                 if(spectatee_status == -1)
3023                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
3024                 else
3025                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
3026                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3027                 o += eY * fontsize_y;
3028
3029                 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
3030                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3031                 o += eY * fontsize_y;
3032
3033                 if(gametype == GAME_ARENA)
3034                         s = "^1Wait for your turn to join";
3035                 else if(gametype == GAME_LMS)
3036                 {
3037                         entity sk;
3038                         sk = playerslots[player_localentnum - 1];
3039                         if(sk.(scores[ps_primary]) >= 666)
3040                                 s = "^1Match has already begun";
3041                         else if(sk.(scores[ps_primary]) > 0)
3042                                 s = "^1You have no more lives left";
3043                         else
3044                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
3045                 }
3046                 else
3047                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
3048                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3049                 o += eY * fontsize_y;
3050
3051                 //show restart countdown:
3052                 if (time < getstatf(STAT_GAMESTARTTIME)) {
3053                         float countdown;
3054                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
3055                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
3056                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
3057                         drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3058                         o += eY * fontsize_y;
3059                 }
3060         }
3061         if(warmup_stage && !intermission)
3062         {
3063                 s = "^2Currently in ^1warmup^2 stage!";
3064                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3065                 o += eY * fontsize_y;
3066         }
3067
3068         string blinkcolor;
3069         if(mod(time, 1) >= 0.5)
3070                 blinkcolor = "^1";
3071         else
3072                 blinkcolor = "^3";
3073
3074         if(ready_waiting && !intermission && !spectatee_status)
3075         {
3076                 if(ready_waiting_for_me)
3077                 {
3078                         if(warmup_stage)
3079                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
3080                         else
3081                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
3082                 }
3083                 else
3084                 {
3085                         if(warmup_stage)
3086                                 s = strcat("^2Waiting for others to ready up to end warmup...");
3087                         else
3088                                 s = strcat("^2Waiting for others to ready up...");
3089                 }
3090                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3091                 o += eY * fontsize_y;
3092         }
3093         else if(warmup_stage && !intermission && !spectatee_status)
3094         {
3095                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
3096                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3097                 o += eY * fontsize_y;
3098         }
3099
3100         if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
3101         {
3102                 float ts_min, ts_max;
3103                 tm = teams.sort_next;
3104                 if (tm)
3105                 {
3106                         for(; tm.sort_next; tm = tm.sort_next)
3107                         {
3108                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
3109                                         continue;
3110                                 if(!ts_min) ts_min = tm.team_size;
3111                                 else ts_min = min(ts_min, tm.team_size);
3112                                 if(!ts_max) ts_max = tm.team_size;
3113                                 else ts_max = max(ts_max, tm.team_size);
3114                         }
3115                         if ((ts_max - ts_min) > 1)
3116                         {
3117                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
3118                                 tm = GetTeam(myteam, false);
3119                                 if (tm)
3120                                 if (tm.team != COLOR_SPECTATOR)
3121                                 if (tm.team_size == ts_max)
3122                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
3123
3124                                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3125                                 o += eY * fontsize_y;
3126                         }
3127                 }
3128         }
3129         if(hud_configure)
3130         {
3131                 s = "^7Press ^3ESC ^7to show HUD options.";
3132                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3133                 o += eY * fontsize_y;
3134                 s = "^3Doubleclick a panel for panel-specific options.";
3135                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3136                 o += eY * fontsize_y;
3137         }
3138 }
3139
3140 // Timer (#5)
3141 //
3142 void HUD_Timer(void)
3143 {
3144         float id = HUD_PANEL_TIMER;
3145         vector pos, mySize;
3146         pos = HUD_Panel_GetPos(id);
3147         mySize = HUD_Panel_GetSize(id);
3148
3149         HUD_Panel_DrawBg(id, pos, mySize, 0);
3150         float padding;
3151         padding = HUD_Panel_GetPadding(id);
3152         if(padding)
3153         {
3154                 pos += '1 1 0' * padding;
3155                 mySize -= '2 2 0' * padding;
3156         }
3157
3158         float timelimit, elapsedTime, minutes, seconds, timeleft, minutesLeft, secondsLeft;
3159
3160         timelimit = getstatf(STAT_TIMELIMIT);
3161
3162         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
3163         timeleft = ceil(timeleft);
3164         minutesLeft = floor(timeleft / 60);
3165         secondsLeft = timeleft - minutesLeft*60;
3166
3167         vector timer_color;
3168         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3169                 timer_color = '1 1 1'; //white
3170         else if(minutesLeft >= 1)
3171                 timer_color = '1 1 0'; //yellow
3172         else
3173                 timer_color = '1 0 0'; //red
3174
3175         if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
3176                 if (time < getstatf(STAT_GAMESTARTTIME)) {
3177                         //while restart is still active, show 00:00
3178                         minutes = seconds = 0;
3179                 } else {
3180                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3181                         minutes = floor(elapsedTime / 60);
3182                         seconds = elapsedTime - minutes*60;
3183                 }
3184         } else {
3185                 minutes = minutesLeft;
3186                 seconds = secondsLeft;
3187         }
3188
3189         if(minutes > 999)
3190                 seconds = 99;
3191         minutes = min(minutes, 999);
3192         if(minutesLeft >= 1 || cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
3193                 HUD_DrawXNum(pos + eX * mySize_x - eX * 5.1 * mySize_y, minutes, 3, 0, mySize_y, timer_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3194                 drawpic_skin(pos + eX * mySize_x - eX * 2.57 * mySize_y, "num_colon", '1 1 0' * mySize_y, timer_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3195         }
3196         HUD_DrawXNum(pos + eX * mySize_x - eX * 2 * mySize_y, seconds, -2, 0, mySize_y, timer_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3197 }
3198
3199 // Radar (#6)
3200 //
3201 void HUD_Radar(void)
3202 {
3203         float id = HUD_PANEL_RADAR;
3204         vector pos, mySize;
3205         pos = HUD_Panel_GetPos(id);
3206         mySize = HUD_Panel_GetSize(id);
3207
3208         HUD_Panel_DrawBg(id, pos, mySize, 0);
3209         float padding;
3210         padding = HUD_Panel_GetPadding(id);
3211         if(padding)
3212         {
3213                 pos += '1 1 0' * padding;
3214                 mySize -= '2 2 0' * padding;
3215         }
3216
3217         local float color1, color2; // color already declared as a global in hud.qc
3218         local vector rgb;
3219         local entity tm;
3220         float scale2d, normalsize, bigsize;
3221         float f;
3222
3223         teamradar_origin2d = pos + 0.5 * mySize;
3224         teamradar_size2d = mySize;
3225
3226         if(minimapname == "")
3227                 return;
3228
3229         teamradar_loadcvars();
3230
3231         switch(hud_radar_zoommode)
3232         {
3233                 default:
3234                 case 0:
3235                         f = current_zoomfraction;
3236                         break;
3237                 case 1:
3238                         f = 1 - current_zoomfraction;
3239                         break;
3240                 case 2:
3241                         f = 0;
3242                         break;
3243                 case 3:
3244                         f = 1;
3245                         break;
3246         }
3247
3248         switch(hud_radar_rotation)
3249         {
3250                 case 0:
3251                         teamradar_angle = view_angles_y - 90;
3252                         break;
3253                 default:
3254                         teamradar_angle = 90 * hud_radar_rotation;
3255                         break;
3256         }
3257
3258         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3259         teamradar_size2d = mySize;
3260
3261         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3262
3263         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3264         if(hud_radar_rotation == 0)
3265         {
3266                 // max-min distance must fit the radar in any rotation
3267                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3268         }
3269         else
3270         {
3271                 vector c0, c1, c2, c3, span;
3272                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3273                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3274                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3275                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3276                 span = '0 0 0';
3277                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3278                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3279
3280                 // max-min distance must fit the radar in x=x, y=y
3281                 bigsize = min(
3282                         teamradar_size2d_x * scale2d / (1.05 * span_x),
3283                         teamradar_size2d_y * scale2d / (1.05 * span_y)
3284                 );
3285         }
3286
3287         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
3288         if(bigsize > normalsize)
3289                 normalsize = bigsize;
3290
3291         teamradar_size =
3292                   f * bigsize
3293                 + (1 - f) * normalsize;
3294         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3295                   f * (mi_min + mi_max) * 0.5
3296                 + (1 - f) * view_origin);
3297
3298         color1 = GetPlayerColor(player_localentnum-1);
3299         rgb = GetTeamRGB(color1);
3300
3301         drawsetcliparea(
3302                 pos_x,
3303                 pos_y,
3304                 mySize_x,
3305                 mySize_y
3306         );
3307
3308         draw_teamradar_background(hud_radar_background_alpha, hud_radar_foreground_alpha);
3309
3310         for(tm = world; (tm = find(tm, classname, "radarlink")); )
3311                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
3312         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
3313                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, HUD_Panel_GetFgAlpha(id));
3314         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
3315         {
3316                 color2 = GetPlayerColor(tm.sv_entnum);
3317                 //if(color == COLOR_SPECTATOR || color == color2)
3318                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
3319         }
3320         draw_teamradar_player(view_origin, view_angles, '1 1 1');
3321
3322         drawresetcliparea();
3323 };
3324
3325 // Score (#7)
3326 //
3327 void HUD_Score(void)
3328 {
3329         float id = HUD_PANEL_SCORE;
3330         vector pos, mySize;
3331         pos = HUD_Panel_GetPos(id);
3332         mySize = HUD_Panel_GetSize(id);
3333
3334         HUD_Panel_DrawBg(id, pos, mySize, 0);
3335         float padding;
3336         padding = HUD_Panel_GetPadding(id);
3337         if(padding)
3338         {
3339                 pos += '1 1 0' * padding;
3340                 mySize -= '2 2 0' * padding;
3341         }
3342
3343         float score, distribution, leader;
3344         float score_len, distr_len;
3345         vector distribution_color;
3346         entity tm, pl, me;
3347         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
3348
3349         // TODO... this (race part) still uses constant coordinates :/
3350         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
3351                 /*pl = players.sort_next;
3352                 if(pl == me)
3353                         pl = pl.sort_next;
3354                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
3355                         if(pl.scores[ps_primary] == 0)
3356                                 pl = world;
3357
3358                 score = me.(scores[ps_primary]);
3359
3360                 float racemin, racesec, racemsec;
3361                 float distsec, distmsec, minusplus;
3362
3363                 racemin = floor(score/(60 * TIME_FACTOR));
3364                 racesec = floor((score - racemin*(60 * TIME_FACTOR))/TIME_FACTOR);
3365                 racemsec = score - racemin*60*TIME_FACTOR - racesec*TIME_FACTOR;
3366
3367                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
3368                         // distribution display
3369                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3370
3371                         if (distribution < TIME_FACTOR && distribution > -TIME_FACTOR)
3372                                 distmsec = fabs(distribution);
3373                         else {
3374                                 distsec = floor(fabs(distribution)/TIME_FACTOR);
3375                                 distmsec = fabs(distribution) - distsec*TIME_FACTOR;
3376                                 if (distribution < 0)
3377                                         distsec = -distsec;
3378                         }
3379
3380                         if (distribution <= 0) {
3381                                 distribution_color = eY;
3382                                 minusplus = 1; // minusplus 1: always prefix with minus sign
3383                         }
3384                         else {
3385                                 distribution_color = eX;
3386                                 minusplus = 2; // minusplus 1: always prefix with plus sign
3387                         }
3388                         HUD_DrawXNum(bottomright - '0 48 0' - '16 0 0' * TIME_DECIMALS, distmsec, -TIME_DECIMALS, 0, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3389                         HUD_DrawXNum(bottomright - '68 48 0' - '16 0 0' * TIME_DECIMALS, distsec, 4, minusplus, 16, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3390                         drawpic_skin(bottomright - '10 48 0' - '16 0 0' * TIME_DECIMALS, "num_dot", '16 16 0', distribution_color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3391                 }
3392                 // race record display
3393                 if (distribution <= 0 || distribution == score) // draw the highlight background behind the timer if we have the lead
3394                         drawpic_skin(bottomright - '0 32 0' - '32 0 0' * (4 + TIME_DECIMALS), "num_leading_4", '0 28 0' + '32 0 0' * (4 + TIME_DECIMALS), '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3395
3396                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0', racemsec, -TIME_DECIMALS, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3397                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0'  - '66 0 0', racesec, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3398                 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '18 0 0', "num_dot", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3399
3400                 HUD_DrawXNum(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '132 0 0', racemin, -2, 0, 30, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3401                 drawpic_skin(bottomright - '0 32 0' - TIME_DECIMALS * '30 0 0' - '84 0 0', "num_colon", '30 30 0', '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_ADDITIVE);
3402                 */
3403         } else if (!teamplay) { // non-teamgames
3404                 // me vector := [team/connected frags id]
3405                 pl = players.sort_next;
3406                 if(pl == me)
3407                         pl = pl.sort_next;
3408
3409                 if(hud_configure)
3410                         distribution = 42;
3411                 else if(pl)
3412                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
3413                 else
3414                         distribution = 0;
3415
3416                 score = me.(scores[ps_primary]);
3417                 if(hud_configure)
3418                         score = 123;
3419
3420                 if(distribution >= 5) {
3421                         distribution_color = eY;
3422                         leader = 1;
3423                 } else if(distribution >= 0) {
3424                         distribution_color = '1 1 1';
3425                         leader = 1;
3426                 } else if(distribution >= -5)
3427                         distribution_color = '1 1 0';
3428                 else
3429                         distribution_color = eX;
3430
3431                 score_len = strlen(ftos(score));
3432                 distr_len = strlen(ftos(distribution));
3433
3434                 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y, distribution, 3, 3, 0.33 * mySize_y, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3435                 if (leader)
3436                         drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("num_leading_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3437                 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, distribution_color, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3438         } else { // teamgames
3439                 float max_fragcount;
3440                 max_fragcount = -99;
3441
3442                 float teamnum;
3443                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
3444                         if(tm.team == COLOR_SPECTATOR || (!tm.team_size && !hud_configure)) // no players? don't display
3445                                 continue;
3446                         score = tm.(teamscores[ts_primary]);
3447                         if(hud_configure)
3448                                 score = 123;
3449                         leader = 0;
3450                         
3451                         score_len = strlen(ftos(score));
3452
3453                         if (score > max_fragcount)
3454                                 max_fragcount = score;
3455
3456                         if(tm.team == myteam) {
3457                                 if (max_fragcount == score)
3458                                         leader = 1;
3459                                 if (leader)
3460                                         drawpic_skin(pos + eX * mySize_x - eX * score_len * mySize_y - eX * 3 * 0.33 * mySize_y, strcat("num_leading_", ftos(score_len)), eX * score_len * mySize_y + eY * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3461                                 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * mySize_y - eX * 3 * 0.33 * mySize_y, score, 3, 0, mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3462                         } else {
3463                                 if (max_fragcount == score)
3464                                         leader = 1;
3465                                 if (leader)
3466                                         drawpic_skin(pos + eX * mySize_x - eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y * teamnum, strcat("num_leading_", ftos(score_len)), eX * 0.33 * score_len * mySize_y + eY * 0.33 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3467                                 HUD_DrawXNum(pos + eX * mySize_x - eX * 3 * 0.33 * mySize_y + eY * 0.33 * mySize_y * teamnum, score, 3, 0, 0.33 * mySize_y, GetTeamRGB(tm.team) * 0.8, 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3468                                 teamnum += 1;
3469                         }
3470                 }
3471         }
3472 }
3473
3474 // Race timer (#8)
3475 //
3476 void HUD_RaceTimer (void) {
3477         float id = HUD_PANEL_RACETIMER;
3478         vector pos, mySize;
3479         pos = HUD_Panel_GetPos(id);
3480         mySize = HUD_Panel_GetSize(id);
3481
3482         HUD_Panel_DrawBg(id, pos, mySize, 0);
3483         float padding;
3484         padding = HUD_Panel_GetPadding(id);
3485         if(padding)
3486         {
3487                 pos += '1 1 0' * padding;
3488                 mySize -= '2 2 0' * padding;
3489         }
3490
3491         drawfont = hud_bigfont;
3492         float a, t;
3493         string s, forcetime;
3494
3495         if(hud_configure)
3496         {
3497                 s = "0:13:37";
3498                 drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.60 0.60 0' * mySize_y), s, '0.60 0.60 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3499                 s = "^1Intermediate 1 (+15.42)";
3500                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.60 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3501                 s = strcat("^1PENALTY: ", ftos_decimals(20 * 0.1, 1), " (missing a checkpoint)");
3502                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.20 * mySize_y) + eY * 0.80 * mySize_y, s, '1 1 0' * 0.20 * mySize_y, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3503         }
3504         else if(race_checkpointtime)
3505         {
3506                 a = bound(0, 2 - (time - race_checkpointtime), 1);
3507                 s = "";
3508                 forcetime = "";
3509                 if(a > 0) // just hit a checkpoint?
3510                 {
3511                         if(race_checkpoint != 254)
3512                         {
3513                                 if(race_time && race_previousbesttime)
3514                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
3515                                 else
3516                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
3517                                 if(race_time)
3518                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
3519                         }
3520                 }
3521                 else
3522                 {
3523                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
3524                         {
3525                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
3526                                 if(a > 0) // next one?
3527                                 {
3528                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
3529                                 }
3530                         }
3531                 }
3532
3533                 if(s != "" && a > 0)
3534                 {
3535                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3536                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3537                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3538                 }
3539
3540                 if(race_penaltytime)
3541                 {
3542                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
3543                         if(a > 0)
3544                         {
3545                                 s = strcat("^1PENALTY: ", ftos_decimals(race_penaltytime * 0.1, 1), " (", race_penaltyreason, ")");
3546                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3547                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3548                                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.8 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3549                         }
3550                 }
3551
3552                 if(forcetime != "")
3553                 {
3554                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
3555                         //drawstring_expanding(m - '16 0 0' * stringwidth(forcetime, FALSE), forcetime, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id), 0, a);
3556                         drawstring_expanding(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(forcetime, FALSE, '1 1 0' * 0.6 * mySize_y), forcetime, '1 1 0' * 0.6 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), 0, a);
3557                 }
3558                 else
3559                         a = 1;
3560
3561                 if(race_laptime && race_checkpoint != 255)
3562                 {
3563                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
3564                         //drawstring(m - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3565                         drawstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, FALSE, '0.6 0.6 0' * mySize_y), s, '0.6 0.6 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3566                 }
3567         }
3568         else
3569         {
3570                 if(race_mycheckpointtime)
3571                 {
3572                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
3573                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
3574                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3575                         //drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3576                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3577                 }
3578                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
3579                 {
3580                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
3581                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
3582                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3583                         //drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3584                         drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3585                 }
3586
3587                 if(race_penaltytime && !race_penaltyaccumulator)
3588                 {
3589                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
3590                         a = bound(0, (1 + t - time), 1);
3591                         if(a > 0)
3592                         {
3593                                 if(time < t)
3594                                         s = strcat("^1PENALTY: ", ftos_decimals(t - time, 1), " (", race_penaltyreason, ")");
3595                                 else
3596                                         s = strcat("^2PENALTY: 0.0 (", race_penaltyreason, ")");
3597                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
3598                                 //drawcolorcodedstring(m - '0 32 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3599                                 drawcolorcodedstring(pos + eX * 0.5 * mySize_x - '0.5 0 0' * stringwidth(s, TRUE, '1 1 0' * 0.2 * mySize_y) + eY * 0.6 * mySize_y, s, '1 1 0' * 0.2 * mySize_y, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
3600                         }
3601                 }
3602         }
3603
3604         drawfont = hud_font;
3605 }
3606
3607 // Vote window (#9)
3608 //
3609 float vote_yescount;
3610 float vote_nocount;
3611 float vote_needed;
3612 float vote_highlighted; // currently selected vote
3613
3614 float vote_active; // is there an active vote?
3615 float vote_prev; // previous state of vote_active to check for a change
3616 float vote_alpha;
3617 float vote_change; // "time" when vote_active changed
3618
3619 void HUD_VoteWindow(void) 
3620 {
3621         float id = HUD_PANEL_VOTE;
3622         vector pos, mySize;
3623         pos = HUD_Panel_GetPos(id);
3624         mySize = HUD_Panel_GetSize(id);
3625
3626         string s;
3627         float a;
3628         if(vote_active != vote_prev) {
3629                 vote_change = time;
3630                 vote_prev = vote_active;
3631         }
3632
3633         if(vote_active || hud_configure)
3634                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3635         else
3636                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3637
3638         if(hud_configure)
3639         {
3640                 vote_yescount = 3;
3641                 vote_nocount = 2;
3642                 vote_needed = 4;
3643         }
3644
3645         if(!vote_alpha)
3646                 return;
3647
3648         a = vote_alpha * bound(cvar_or("hud_vote_alreadyvoted_alpha", 0.75), 1 - vote_highlighted, 1);
3649
3650         HUD_Panel_DrawBg(id, pos, mySize, a);
3651         float padding;
3652         padding = HUD_Panel_GetPadding(id);
3653         if(padding)
3654         {
3655                 pos += '1 1 0' * padding;
3656                 mySize -= '2 2 0' * padding;
3657         }
3658
3659         drawpic_skin(pos, "voteprogress_back", mySize, '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3660
3661         s = "A vote has been called for: ";
3662         drawstring(pos + '0.5 0 0' * mySize_x + '0 0.1 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/5)), s, '1 1 0' * mySize_y*(1/5), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3663         s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '1 1 0' * mySize_y*(1/5), stringwidth_colors); // TODO: broken?
3664         if(hud_configure)
3665                 s = "Configure the HUD";
3666         drawcolorcodedstring(pos + '0.52 0 0' * mySize_x + '0 0.3 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3667
3668         // print the yes/no counts
3669         s = strcat("Yes: ", ftos(vote_yescount));
3670         drawstring(pos + '0 0.6 0' * mySize_y + '0.02 0 0' * mySize_x, s, '1 1 0' * mySize_y*(1/6) , eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3671         s = strcat("No: ", ftos(vote_nocount));
3672         drawstring(pos + '0 0.6 0' * mySize_y + '0.98 0 0' * mySize_x - eX * stringwidth(s, FALSE, '1 1 0' * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3673
3674         // draw the progress bars
3675         drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3676         drawpic_skin(pos, "voteprogress_prog", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3677
3678         drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3679         drawpic_skin(pos, "voteprogress_prog", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3680
3681         // draw the highlights
3682         if(vote_highlighted == 1) {
3683                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3684                 drawpic_skin(pos, "voteprogress_voted", mySize, eY, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3685         }
3686         else if(vote_highlighted == 2) {
3687                 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3688                 drawpic_skin(pos, "voteprogress_voted", mySize, eX, a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
3689         }
3690
3691         drawresetcliparea();
3692
3693         if(!vote_active) {
3694                 vote_highlighted = 0;
3695         }
3696 }
3697
3698 // Mod icons panel (#10)
3699 //
3700
3701 float mod_active; // is there any active mod icon?
3702
3703 // CTF HUD modicon section
3704 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3705 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3706 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3707
3708 void HUD_Mod_CTF_Reset(void)
3709 {
3710         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3711 }
3712
3713 void HUD_Mod_CTF(vector pos, vector mySize)
3714 {
3715         vector redflag_pos, blueflag_pos;
3716         float f; // every function should have that
3717
3718         float redflag, blueflag; // current status
3719         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3720         float stat_items;
3721
3722         stat_items = getstati(STAT_ITEMS);
3723         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3724         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3725         
3726         if(redflag || blueflag)
3727                 mod_active = 1;
3728         else
3729                 mod_active = 0;
3730
3731         if(hud_configure)
3732         {
3733                 redflag = 1;
3734                 blueflag = 2;
3735         }
3736
3737         // when status CHANGES, set old status into prevstatus and current status into status
3738         if (redflag != redflag_prevframe)
3739         {
3740                 redflag_statuschange_time = time;
3741                 redflag_prevstatus = redflag_prevframe;
3742                 redflag_prevframe = redflag;
3743         }
3744
3745         if (blueflag != blueflag_prevframe)
3746         {
3747                 blueflag_statuschange_time = time;
3748                 blueflag_prevstatus = blueflag_prevframe;
3749                 blueflag_prevframe = blueflag;
3750         }
3751
3752         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3753         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3754
3755         float BLINK_FACTOR = 0.15;
3756         float BLINK_BASE = 0.85;
3757         // note:
3758         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3759         // thus
3760         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3761         // ensure RMS == 1
3762         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3763
3764         string red_icon, red_icon_prevstatus;
3765         float red_alpha, red_alpha_prevstatus;
3766         red_alpha = red_alpha_prevstatus = 1;
3767         switch(redflag) {
3768                 case 1: red_icon = "flag_red_taken"; break;
3769                 case 2: red_icon = "flag_red_lost"; break;
3770                 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3771                 default:
3772                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3773                                 red_icon = "flag_red_shielded";
3774                         else
3775                                 red_icon = string_null;
3776                         break;
3777         }
3778         switch(redflag_prevstatus) {
3779                 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3780                 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3781                 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3782                 default:
3783                         if(redflag == 3)
3784                                 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3785                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3786                                 red_icon_prevstatus = "flag_red_shielded";
3787                         else
3788                                 red_icon_prevstatus = string_null;
3789                         break;
3790         }
3791
3792         string blue_icon, blue_icon_prevstatus;
3793         float blue_alpha, blue_alpha_prevstatus;
3794         blue_alpha = blue_alpha_prevstatus = 1;
3795         switch(blueflag) {
3796                 case 1: blue_icon = "flag_blue_taken"; break;
3797                 case 2: blue_icon = "flag_blue_lost"; break;
3798                 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3799                 default:
3800                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3801                                 blue_icon = "flag_blue_shielded";
3802                         else
3803                                 blue_icon = string_null;
3804                         break;
3805         }
3806         switch(blueflag_prevstatus) {
3807                 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3808                 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3809                 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3810                 default:
3811                         if(blueflag == 3)
3812                                 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3813                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3814                                 blue_icon_prevstatus = "flag_blue_shielded";
3815                         else
3816                                 blue_icon_prevstatus = string_null;
3817                         break;
3818         }
3819
3820         if (myteam == COLOR_TEAM1) { // always draw own flag on left
3821                 redflag_pos = pos;
3822                 blueflag_pos = pos + eX * mySize_y;
3823         } else {
3824                 blueflag_pos = pos;
3825                 redflag_pos = pos + eX * mySize_y;
3826         }
3827
3828         f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3829         if(red_icon_prevstatus && f < 1)
3830                 drawpic_skin_expanding(redflag_pos, red_icon_prevstatus, '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3831         if(red_icon)
3832                 drawpic_skin(redflag_pos, red_icon, '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * red_alpha * f, DRAWFLAG_NORMAL);
3833
3834         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3835         if(blue_icon_prevstatus && f < 1)
3836                 drawpic_skin_expanding(blueflag_pos, blue_icon_prevstatus, '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3837         if(blue_icon)
3838                 drawpic_skin(blueflag_pos, blue_icon, '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * blue_alpha * f, DRAWFLAG_NORMAL);
3839 }
3840
3841 // Keyhunt HUD modicon section
3842 float kh_runheretime;
3843
3844 void HUD_Mod_KH_Reset(void)
3845 {
3846         kh_runheretime = 0;
3847 }
3848
3849 void HUD_Mod_KH(vector pos, vector mySize)
3850 {
3851         mod_active = 1; // keyhunt should never hide the mod icons panel
3852         float kh_keys;
3853         float keyteam;
3854         float a, aa;
3855         vector p, pa, kh_size, kh_asize;
3856
3857         p_x = pos_x;
3858         p_y = pos_y + 0.25 * mySize_y;
3859
3860         kh_keys = getstati(STAT_KH_KEYS);
3861
3862         kh_size_x = mySize_x * 0.25;
3863         kh_size_y = 0.75 * mySize_y;
3864
3865         pa = p - eY * 0.25 * mySize_y;
3866
3867         kh_asize_x = mySize_x * 0.25;
3868         kh_asize_y = mySize_y * 0.25;
3869
3870         float i, key;
3871
3872         float keycount;
3873         keycount = 0;
3874         for(i = 0; i < 4; ++i)
3875         {
3876                 key = floor(kh_keys / pow(32, i)) & 31;
3877                 keyteam = key - 1;
3878                 if(keyteam == 30 && keycount <= 4)
3879                         keycount += 4;
3880                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3881                         keycount += 1;
3882         }
3883
3884         // this yields 8 exactly if "RUN HERE" shows
3885
3886         if(keycount == 8)
3887         {
3888                 if(!kh_runheretime)
3889                         kh_runheretime = time;
3890                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3891         }
3892         else
3893                 kh_runheretime = 0;
3894
3895         for(i = 0; i < 4; ++i)
3896         {
3897                 key = floor(kh_keys / pow(32, i)) & 31;
3898                 keyteam = key - 1;
3899                 switch(keyteam)
3900                 {
3901                         case 30: // my key
3902                                 keyteam = myteam;
3903                                 a = 1;
3904                                 aa = 1;
3905                                 break;
3906                         case -1: // no key
3907                                 a = 0;
3908                                 aa = 0;
3909                                 break;
3910                         default: // owned or dropped
3911                                 a = 0.2;
3912                                 aa = 0.5;
3913                                 break;
3914                 }
3915                 a = a * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3916                 aa = aa * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS);
3917                 if(a > 0)
3918                 {
3919                         switch(keyteam)
3920                         {
3921                                 case COLOR_TEAM1:
3922                                         drawpic_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3923                                         break;
3924                                 case COLOR_TEAM2:
3925                                         drawpic_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3926                                         break;
3927                                 case COLOR_TEAM3:
3928                                         drawpic_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3929                                         break;
3930                                 case COLOR_TEAM4:
3931                                         drawpic_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3932                                         break;
3933                                 default:
3934                                         break;
3935                         }
3936                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3937                         {
3938                                 case 0:
3939                                         drawpic_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3940                                         break;
3941                                 case 1:
3942                                         drawpic_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3943                                         break;
3944                                 case 2:
3945                                         drawpic_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3946                                         break;
3947                                 case 3:
3948                                         drawpic_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3949                                         break;
3950                         }
3951                 }
3952                 p_x += 0.25 * mySize_x;
3953                 pa_x += 0.25 * mySize_x;
3954         }
3955 }
3956
3957 // Nexball HUD mod icon
3958 void HUD_Mod_NexBall(vector pos, vector mySize)
3959 {
3960         float stat_items, nb_pb_starttime, dt, p;
3961
3962         stat_items = getstati(STAT_ITEMS);
3963         nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3964
3965         if (stat_items & IT_KEY1)
3966                 mod_active = 1;
3967         else
3968                 mod_active = 0;
3969
3970         //Manage the progress bar if any
3971         if (nb_pb_starttime > 0)
3972         {
3973                 dt = mod(time - nb_pb_starttime, nb_pb_period);
3974                 // one period of positive triangle
3975                 p = 2 * dt / nb_pb_period;
3976                 if (p > 1)
3977                         p = 2 - p;
3978
3979                 //Draw the filling
3980                 HUD_Panel_DrawProgressBar(pos, 0, eX * p * mySize_x + eY * mySize_y, HUD_Panel_GetProgressBarColor("nexball"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3981         }
3982
3983         pos_x += 0.5 * mySize_x - 0.5 * mySize_y; //horizontal margin to the picture
3984
3985         if (stat_items & IT_KEY1)
3986                 drawpic_skin(pos, "nexball_carrying", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
3987 }
3988
3989 // Race/CTS HUD mod icons
3990 float crecordtime_prev; // last remembered crecordtime
3991 float crecordtime_change_time; // time when crecordtime last changed
3992 float srecordtime_prev; // last remembered srecordtime
3993 float srecordtime_change_time; // time when srecordtime last changed
3994
3995 float race_status_time;
3996 float race_status_prev;
3997 string race_status_name_prev;
3998 void HUD_Mod_Race(vector pos, vector mySize)
3999 {
4000         mod_active = 1; // race should never hide the mod icons panel
4001         entity me;
4002         me = playerslots[player_localentnum - 1];
4003         float t, score;
4004         float f; // yet another function has this
4005         score = me.(scores[ps_primary]);
4006
4007         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
4008                 return; // no records in the actual race
4009
4010         drawfont = hud_bigfont;
4011
4012         // clientside personal record
4013         string rr;
4014         if(gametype == GAME_CTS)
4015                 rr = CTS_RECORD;
4016         else
4017                 rr = RACE_RECORD;
4018         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
4019
4020         if(score && (score < t || !t)) {
4021                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
4022                 if(cvar("cl_autodemo_delete_keeprecords"))
4023                 {
4024                         f = cvar("cl_autodemo_delete");
4025                         f &~= 1;
4026                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
4027                 }
4028         }
4029
4030         if(t != crecordtime_prev) {
4031                 crecordtime_prev = t;
4032                 crecordtime_change_time = time;
4033         }
4034         f = time - crecordtime_change_time;
4035
4036         if (f > 1) {
4037                 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4038                 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4039         } else {
4040                 drawstring(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4041                 drawstring(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4042                 drawstring_expanding(pos, "Personal best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4043                 drawstring_expanding(pos + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4044         }
4045
4046         // server record
4047         t = race_server_record;
4048         if(t != srecordtime_prev) {
4049                 srecordtime_prev = t;
4050                 srecordtime_change_time = time;
4051         }
4052         f = time - srecordtime_change_time;
4053
4054         if (f > 1) {
4055                 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4056                 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4057         } else {
4058                 drawstring(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4059                 drawstring(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL);
4060                 drawstring_expanding(pos + eY * 0.5 * mySize_y, "Server best ", '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4061                 drawstring_expanding(pos + eY * 0.5 * mySize_y + eY * 0.2 * mySize_y, TIME_ENCODED_TOSTRING(t),'1 1 0' * 0.2 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS), DRAWFLAG_NORMAL, f);
4062         }
4063
4064         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
4065                 race_status_time = time + 5;
4066                 race_status_prev = race_status;
4067                 if (race_status_name_prev)
4068                         strunzone(race_status_name_prev);
4069                 race_status_name_prev = strzone(race_status_name);
4070         }
4071
4072         pos_x += mySize_x/2;
4073         // race "awards"
4074         float a;
4075         a = bound(0, race_status_time - time, 1);
4076
4077         string s;
4078         s = textShortenToWidth(race_status_name, mySize_y, '1 1 0' * 0.1 * mySize_y, stringwidth_colors);
4079
4080         float rank;
4081         if(race_status > 0)
4082                 rank = race_CheckName(race_status_name);
4083         string rankname;
4084         rankname = race_PlaceName(rank);
4085
4086         vector namepos;
4087         namepos = pos + '0.5 0.9 0' * mySize_y - eX * stringwidth(s, TRUE, '1 1 0' * 0.1 * mySize_y);
4088         vector rankpos;
4089         rankpos = pos + '0.5 0.25 0' * mySize_y - eX * stringwidth(rankname, TRUE, '1 1 0' * 0.15 * mySize_y);
4090
4091         if(race_status == 0)
4092                 drawpic_skin(pos, "race_newfail", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4093         else if(race_status == 1) {
4094                 drawpic_skin(pos, "race_newtime", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4095                 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4096                 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4097         } else if(race_status == 2) {
4098                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
4099                         drawpic_skin(pos, "race_newrankgreen", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4100                 else
4101                         drawpic_skin(pos, "race_newrankyellow", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4102                 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4103                 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4104         } else if(race_status == 3) {
4105                 drawpic_skin(pos, "race_newrecordserver", '1 1 0' * 0.9 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4106                 drawcolorcodedstring(namepos, s, '1 1 0' * 0.1 * mySize_y, HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4107                 drawstring(rankpos, rankname, '1 1 0' * 0.15 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_MODICONS) * a, DRAWFLAG_NORMAL);
4108         }
4109
4110         if (race_status_time - time <= 0) {
4111                 race_status_prev = -1;
4112                 race_status = -1;
4113                 if(race_status_name)
4114                         strunzone(race_status_name);
4115                 race_status_name = string_null;
4116                 if(race_status_name_prev)
4117                         strunzone(race_status_name_prev);
4118                 race_status_name_prev = string_null;
4119         }
4120         drawfont = hud_font;
4121 }
4122
4123 float mod_prev; // previous state of mod_active to check for a change
4124 float mod_alpha;
4125 float mod_change; // "time" when mod_active changed
4126
4127 void HUD_ModIcons(void)
4128 {
4129         if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && !hud_configure)
4130                 return;
4131
4132         float id = HUD_PANEL_MODICONS;
4133         vector pos, mySize;
4134         pos = HUD_Panel_GetPos(id);
4135         mySize = HUD_Panel_GetSize(id);
4136
4137         if(mod_active != mod_prev) {
4138                 mod_change = time;
4139                 mod_prev = mod_active;
4140         }
4141
4142         if(mod_active || hud_configure)
4143                 mod_alpha = bound(0, (time - mod_change) * 2, 1);
4144         else
4145                 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
4146
4147         if(mod_alpha)
4148                 HUD_Panel_DrawBg(id, pos, mySize, mod_alpha);
4149
4150         float padding;
4151         padding = HUD_Panel_GetPadding(id);
4152         if(padding)
4153         {
4154                 pos += '1 1 0' * padding;
4155                 mySize -= '2 2 0' * padding;
4156         }
4157
4158         // these MUST be ran in order to update mod_active
4159         if(gametype == GAME_KEYHUNT)
4160                 HUD_Mod_KH(pos, mySize);
4161         else if(gametype == GAME_CTF || hud_configure)
4162                 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
4163         else if(gametype == GAME_NEXBALL)
4164                 HUD_Mod_NexBall(pos, mySize);
4165         else if(gametype == GAME_CTS || gametype == GAME_RACE)
4166                 HUD_Mod_Race(pos, mySize);
4167 }
4168
4169 // Draw pressed keys (#11)
4170 //
4171 void HUD_DrawPressedKeys(void)
4172 {
4173         float id = HUD_PANEL_PRESSEDKEYS;
4174         vector pos, mySize;
4175         pos = HUD_Panel_GetPos(id);
4176         mySize = HUD_Panel_GetSize(id);
4177
4178         HUD_Panel_DrawBg(id, pos, mySize, 0);
4179         float padding;
4180         padding = HUD_Panel_GetPadding(id);
4181         if(padding)
4182         {
4183                 pos += '1 1 0' * padding;
4184                 mySize -= '2 2 0' * padding;
4185         }
4186
4187         float pressedkeys;
4188
4189         pressedkeys = getstatf(STAT_PRESSED_KEYS);
4190         drawpic_skin(pos, "key_bg.tga",           mySize, '1 1 1', 0.1 * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4191         drawpic_skin(pos + eX * mySize_x - eX * 0.22 * mySize_x +       eY * 0.195 * mySize_y, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"),        '1 1 0' * (1/3) * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4192         drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.040 * mySize_y, ((pressedkeys & KEY_FORWARD) ? "key_forward_inv.tga" : "key_forward.tga"),     '1 1 0' * 0.46 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4193         drawpic_skin(pos + eX * 0.023 * mySize_x +                      eY * 0.195 * mySize_y, ((pressedkeys & KEY_JUMP) ? "key_jump_inv.tga" : "key_jump.tga"),              '1 1 0' * (1/3) * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4194         drawpic_skin(pos + eX * 0.1 * mySize_x +                        eY * 0.486 * mySize_y, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"),              '1 1 0' * 0.46 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4195         drawpic_skin(pos + eX * 0.5 * mySize_x - eX * 0.23 * mySize_y + eY * 0.486 * mySize_y, ((pressedkeys & KEY_BACKWARD) ? "key_backward_inv.tga" : "key_backward.tga"),  '1 1 0' * 0.46 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4196         drawpic_skin(pos + eX * mySize_x - eX * 0.372 * mySize_x +      eY * 0.486 * mySize_y, ((pressedkeys & KEY_RIGHT) ? "key_right_inv.tga" : "key_right.tga"),           '1 1 0' * 0.46 * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4197 }
4198
4199 // Handle chat as a panel (#12)
4200 //
4201 void HUD_Chat(void)
4202 {
4203         float id = HUD_PANEL_CHAT;
4204         vector pos, mySize;
4205         pos = HUD_Panel_GetPos(id);
4206         mySize = HUD_Panel_GetSize(id);
4207
4208         HUD_Panel_DrawBg(id, pos, mySize, 0);
4209         float padding;
4210         padding = HUD_Panel_GetPadding(id);
4211         if(padding)
4212         {
4213                 pos += '1 1 0' * padding;
4214                 mySize -= '2 2 0' * padding;
4215         }
4216
4217         cvar_set("con_chatrect", "1");
4218
4219         cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
4220         cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
4221
4222         cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
4223         cvar_set("con_chat", ftos(floor(mySize_y/cvar("con_chatsize") - 0.5)));
4224
4225         if(hud_configure)
4226         {
4227                 float chatsize;
4228                 chatsize = cvar("con_chatsize");
4229                 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
4230                 float i, a;
4231                 for(i = 0; i < cvar("con_chat"); ++i)
4232                 {
4233                         if(i == cvar("con_chat") - 1)
4234                                 a = HUD_Panel_GetFgAlpha(id);
4235                         else
4236                                 a = HUD_Panel_GetFgAlpha(id) * floor(((i + 1) * 7 + cvar("con_chattime"))/45);
4237                         drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
4238                 }
4239         }
4240 }
4241
4242 // Engine info panel (#13)
4243 //
4244 float prevfps;
4245 float prevfps_time;
4246 float framecounter;
4247
4248 float frametimeavg;
4249 float frametimeavg1; // 1 frame ago
4250 float frametimeavg2; // 2 frames ago
4251 void HUD_EngineInfo(void)
4252 {
4253         float id = HUD_PANEL_ENGINEINFO;
4254         vector pos, mySize;
4255         pos = HUD_Panel_GetPos(id);
4256         mySize = HUD_Panel_GetSize(id);
4257
4258         HUD_Panel_DrawBg(id, pos, mySize, 0);
4259         float padding;
4260         padding = HUD_Panel_GetPadding(id);
4261         if(padding)
4262         {
4263                 pos += '1 1 0' * padding;
4264                 mySize -= '2 2 0' * padding;
4265         }
4266
4267         if(cvar("hud_engineinfo_framecounter_exponentialmovingaverage"))
4268         {
4269                 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + frametime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
4270                 frametimeavg2 = frametimeavg1;
4271                 frametimeavg1 = frametimeavg;
4272                 
4273                 float weight;
4274                 weight = cvar("hud_engineinfo_framecounter_exponentialmovingaverage_new_weight");
4275                 if(frametime > 0.0001) // filter out insane values which sometimes seem to occur and throw off the average? If you are getting 10,000 fps or more, then you don't need a framerate counter.
4276                 {
4277                         if(fabs(prevfps - (1/frametimeavg)) > prevfps * cvar("hud_engineinfo_framecounter_exponentialmovingaverage_instantupdate_change_threshold")) // if there was a big jump in fps, just force prevfps at current (1/frametime) to make big updates instant
4278                                 prevfps = (1/frametime);
4279                         prevfps = (1 - weight) * prevfps + weight * (1/frametimeavg); // framecounter just used so there's no need for a new variable, think of it as "frametime average"
4280                 }
4281         }
4282         else
4283         {
4284                 framecounter += 1;
4285                 if(time - prevfps_time > cvar("hud_engineinfo_framecounter_time"))
4286                 {
4287                         prevfps = framecounter/cvar("hud_engineinfo_framecounter_time");
4288                         framecounter = 0;
4289                         prevfps_time = time;
4290                 }
4291         }
4292
4293         vector color;
4294         color = HUD_Get_Num_Color (prevfps, 100);
4295         drawstring(pos, strcat("FPS: ", ftos_decimals(prevfps, cvar("hud_engineinfo_framecounter_decimals"))), '1 1 0' * mySize_y, color, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
4296 }
4297 /*
4298 ==================
4299 Main HUD system
4300 ==================
4301 */
4302
4303 void HUD_ShowSpeed(void)
4304 {
4305         vector numsize;
4306         float pos, conversion_factor;
4307         string speed, zspeed, unit;
4308
4309         switch(cvar("cl_showspeed_unit"))
4310         {
4311                 default:
4312                 case 0:
4313                         unit = "";
4314                         conversion_factor = 1.0;
4315                         break;
4316                 case 1:
4317                         unit = " qu/s";
4318                         conversion_factor = 1.0;
4319                         break;
4320                 case 2:
4321                         unit = " m/s";
4322                         conversion_factor = 0.0254;
4323                         break;
4324                 case 3:
4325                         unit = " km/h";
4326                         conversion_factor = 0.0254 * 3.6;
4327                         break;
4328                 case 4:
4329                         unit = " mph";
4330                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4331                         break;
4332                 case 5:
4333                         unit = " knots";
4334                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4335                         break;
4336         }
4337
4338         speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
4339
4340         numsize_x = numsize_y = cvar("cl_showspeed_size");
4341         pos = (vid_conheight - numsize_y) * cvar("cl_showspeed_position");
4342
4343         drawfont = hud_bigfont;
4344         drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4345
4346         if (cvar("cl_showspeed_z") == 1) {
4347                 zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
4348                 drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', hud_fg_alpha, DRAWFLAG_NORMAL);
4349         }
4350
4351         drawfont = hud_font;
4352 }
4353
4354 vector acc_prevspeed;
4355 float acc_prevtime;
4356 float acc_avg;
4357
4358 void HUD_ShowAcceleration(void)
4359 {
4360         float acceleration, sz, scale, alpha, f;
4361         vector pos, top, rgb;
4362         top_x = vid_conwidth/2;
4363         top_y = 0;
4364
4365         f = time - acc_prevtime;
4366         if(cvar("cl_showacceleration_z"))
4367                 acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
4368         else
4369                 acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
4370         acc_prevspeed = pmove_vel;
4371         acc_prevtime = time;
4372
4373         f = bound(0, f * 10, 1);
4374         acc_avg = acc_avg * (1 - f) + acceleration * f;
4375         acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
4376
4377         pos = top - sz/2 * eY + (cvar("cl_showacceleration_position") * vid_conheight) * eY;
4378
4379         sz = cvar("cl_showacceleration_size");
4380         scale = cvar("cl_showacceleration_scale");
4381         alpha = cvar("cl_showacceleration_alpha");
4382         if (cvar("cl_showacceleration_color_custom"))
4383                 rgb = stov(cvar_string("cl_showacceleration_color"));
4384         else {
4385                 rgb = '1 1 1';
4386                 if (acceleration < 0) {
4387                         rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
4388                 } else if (acceleration > 0) {
4389                         rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
4390                 }
4391         }
4392
4393         if (acceleration > 0)
4394                 HUD_Panel_DrawProgressBar(pos, 0, acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4395         else if (acceleration < 0)
4396                 HUD_Panel_DrawProgressBar(pos + acceleration * scale * '40 0 0', 0, -acceleration * scale * '40 0 0' + sz * eY, rgb, alpha * hud_fg_alpha, DRAWFLAG_NORMAL);
4397 }
4398
4399 void HUD_Reset (void)
4400 {
4401         // reset gametype specific icons
4402         if(gametype == GAME_KEYHUNT)
4403                 HUD_Mod_KH_Reset();
4404         else if(gametype == GAME_CTF)
4405                 HUD_Mod_CTF_Reset();
4406 }
4407
4408 void HUD_Main (void)
4409 {
4410         if(disable_menu_alphacheck == 1)
4411                 menu_fade_alpha = 1;
4412         else
4413                 menu_fade_alpha = (1 - cvar("_menu_alpha"));
4414         hud_fg_alpha = cvar("hud_fg_alpha");
4415
4416         hud_border_thickness = bound(0, cvar("hud_border_thickness"), 5);
4417         hud_accuracy_border_thickness = bound(0, cvar_or("hud_accuracy_border_thickness", 1), 5);
4418         hud_color_bg_team = cvar("hud_color_bg_team");
4419
4420         hud_fontsize = HUD_GetFontsize("hud_fontsize");
4421         hud_fontsize_spec = HUD_GetFontsize("hud_fontsize_spec");
4422
4423         hud_configure = cvar("_hud_configure");
4424
4425         // Drawing stuff
4426
4427         // HUD configure visible grid
4428         if(hud_configure && cvar("hud_configure_grid") && cvar("hud_configure_grid_alpha"))
4429         {
4430                 float i;
4431                 // x-axis
4432                 for(i = 0; i < 1/bound(0.005, bound(0.005, cvar("hud_configure_grid_x"), 0.2), 0.2); ++i)
4433                 {
4434                         drawfill(eX * i * vid_conwidth * bound(0.005, bound(0.005, cvar("hud_configure_grid_x"), 0.2), 0.2), eX + eY * vid_conheight, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4435                 }
4436                 // y-axis
4437                 for(i = 0; i < 1/bound(0.005, bound(0.005, cvar("hud_configure_grid_y"), 0.2), 0.2); ++i)
4438                 {
4439                         drawfill(eY * i * vid_conheight * bound(0.005, bound(0.005, cvar("hud_configure_grid_y"), 0.2), 0.2), eY + eX * vid_conwidth, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
4440                 }
4441         }
4442
4443         if(cvar_string("hud_dock") != "")
4444                 drawpic_skin('0 0 0', cvar_string("hud_dock"), eX * vid_conwidth + eY * vid_conheight, HUD_Panel_Dock_GetColor(), cvar("hud_dock_alpha") * menu_fade_alpha, DRAWFLAG_NORMAL);
4445
4446         if(HUD_Panel_CheckActive(HUD_PANEL_RADAR) || hud_configure)
4447                 if(cvar_string("hud_radar") != "0" && (cvar("hud_radar") == 2 || teamplay))
4448                         HUD_Radar();
4449         if(HUD_Panel_CheckActive(HUD_PANEL_WEAPONICONS) || hud_configure)
4450                 HUD_WeaponIcons();
4451         if(HUD_Panel_CheckActive(HUD_PANEL_INVENTORY) || hud_configure)
4452                 HUD_Inventory();
4453         if(HUD_Panel_CheckActive(HUD_PANEL_POWERUPS) || hud_configure)
4454                 HUD_Powerups();
4455         if(HUD_Panel_CheckActive(HUD_PANEL_HEALTHARMOR) || hud_configure)
4456                 HUD_HealthArmor();
4457         if(HUD_Panel_CheckActive(HUD_PANEL_NOTIFY) || hud_configure)
4458                 HUD_Notify();
4459         if(HUD_Panel_CheckActive(HUD_PANEL_TIMER) || hud_configure)
4460                 HUD_Timer();
4461         if(HUD_Panel_CheckActive(HUD_PANEL_SCORE) || hud_configure)
4462                 HUD_Score();
4463         if(HUD_Panel_CheckActive(HUD_PANEL_RACETIMER) || hud_configure)
4464                 if(gametype == GAME_RACE || gametype == GAME_CTS || hud_configure)
4465                         HUD_RaceTimer();
4466         if(HUD_Panel_CheckActive(HUD_PANEL_VOTE) || hud_configure)
4467                 HUD_VoteWindow();
4468         if(HUD_Panel_CheckActive(HUD_PANEL_MODICONS) || hud_configure)
4469                 HUD_ModIcons();
4470         // TODO hud'ify
4471         if(HUD_Panel_CheckActive(HUD_PANEL_PRESSEDKEYS) || hud_configure)
4472                 if(spectatee_status > 0 || cvar("hud_pressedkeys") >= 2 || hud_configure)
4473                         HUD_DrawPressedKeys();
4474         if(HUD_Panel_CheckActive(HUD_PANEL_CHAT) || hud_configure)
4475                 HUD_Chat();
4476         else
4477                 cvar_set("con_chatrect", "0");
4478         if(HUD_Panel_CheckActive(HUD_PANEL_ENGINEINFO) || hud_configure)
4479                 HUD_EngineInfo();
4480
4481         // TODO hud_'ify these
4482         if (cvar("cl_showspeed"))
4483                 HUD_ShowSpeed();
4484         if (cvar("cl_showacceleration"))
4485                 HUD_ShowAcceleration();
4486
4487         if (hud_configure && spectatee_status) // try to join if we are in hud_configure mode, but still spectating (in order to get rid of motd and such)
4488                 localcmd("cmd selectteam auto; cmd join\n");
4489
4490         if (!hud_configure) // hud config mode disabled, enable normal alpha stuff again
4491                 disable_menu_alphacheck = 0;
4492 }