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