]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud.qc
Merge remote-tracking branch 'origin/master' into fruitiex/borken_shownames
[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, 0, 0, a/autocvar_hud_panel_ammo_maxammo, 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 float health_time, prev_health;
1304 float armor_time, prev_armor;
1305 var float saved_health = -2;
1306 var float saved_armor = -2;
1307 void HUD_HealthArmor(void)
1308 {
1309         float armor, health, fuel;
1310         if(!autocvar__hud_configure)
1311         {
1312                 if(!autocvar_hud_panel_healtharmor) return;
1313                 if(spectatee_status == -1) return;
1314
1315                 health = getstati(STAT_HEALTH);
1316                 if(health <= 0)
1317                 {
1318                         health_time = -1;
1319                         return;
1320                 }
1321                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1322                 {
1323                         if ( (prev_spectatee_status == -1 && spectatee_status > 0) //before observing, now spectating
1324                           || (prev_spectatee_status > 0 && spectatee_status > 0 && prev_spectatee_status != spectatee_status) //changed spectated player
1325                         )
1326                         {
1327                                 //no effect
1328                                 saved_health = 0;
1329                                 saved_armor = 0;
1330                                 health_time = 0;
1331                                 armor_time = 0;
1332                         }
1333                         else if(prev_spectatee_status == -1 || (prev_spectatee_status > 0 && !spectatee_status)) //before spectating/observing, now playing
1334                                 health_time = -1;
1335
1336                         if (health_time == -1)
1337                         {
1338                                 //start the load effect
1339                                 saved_health = -2;
1340                                 saved_armor = -2;
1341                                 health_time = time;
1342                                 armor_time = time;
1343                                 prev_health = 0;
1344                                 prev_armor = 0;
1345                         }
1346                 }
1347                 armor = getstati(STAT_ARMOR);
1348                 fuel = getstati(STAT_FUEL);
1349         }
1350         else
1351         {
1352                 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1353
1354                 health = 150;
1355                 armor = 75;
1356                 fuel = 20;
1357         }
1358
1359         HUD_Panel_UpdateCvars(healtharmor);
1360         vector pos, mySize;
1361         pos = panel_pos;
1362         mySize = panel_size;
1363
1364         HUD_Panel_DrawBg(1);
1365         if(panel_bg_padding)
1366         {
1367                 pos += '1 1 0' * panel_bg_padding;
1368                 mySize -= '2 2 0' * panel_bg_padding;
1369         }
1370
1371         float baralign = autocvar_hud_panel_healtharmor_baralign;
1372         float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1373
1374     float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1375     float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1376         if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1377         {
1378                 vector v;
1379                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1380
1381                 float x;
1382                 x = floor(v_x + 1);
1383
1384         float maxtotal = maxhealth + maxarmor;
1385                 string biggercount;
1386                 if(v_z) // NOT fully armored
1387                 {
1388                         biggercount = "health";
1389                         if(autocvar_hud_panel_healtharmor_progressbar)
1390                         {
1391                                 HUD_Panel_GetProgressBarColor(health);
1392                                 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);
1393                         }
1394                         if(armor)
1395             if(autocvar_hud_panel_healtharmor_text)
1396                                 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);
1397                 }
1398                 else
1399                 {
1400                         biggercount = "armor";
1401                         if(autocvar_hud_panel_healtharmor_progressbar)
1402                         {
1403                                 HUD_Panel_GetProgressBarColor(armor);
1404                                 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);
1405                         }
1406                         if(health)
1407             if(autocvar_hud_panel_healtharmor_text)
1408                                 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);
1409                 }
1410         if(autocvar_hud_panel_healtharmor_text)
1411                         DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1412
1413                 if(fuel)
1414                 {
1415                         HUD_Panel_GetProgressBarColor(fuel);
1416                         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);
1417                 }
1418         }
1419         else
1420         {
1421                 float panel_ar = mySize_x/mySize_y;
1422                 float is_vertical = (panel_ar < 1);
1423                 vector health_offset, armor_offset;
1424                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1425                 {
1426                         mySize_x *= 0.5;
1427                         if (autocvar_hud_panel_healtharmor_flip)
1428                                 health_offset_x = mySize_x;
1429                         else
1430                                 armor_offset_x = mySize_x;
1431                 }
1432                 else
1433                 {
1434                         mySize_y *= 0.5;
1435                         if (autocvar_hud_panel_healtharmor_flip)
1436                                 health_offset_y = mySize_y;
1437                         else
1438                                 armor_offset_y = mySize_y;
1439                 }
1440
1441                 float health_baralign, armor_baralign, fuel_baralign;
1442                 float health_iconalign, armor_iconalign;
1443                 if (autocvar_hud_panel_healtharmor_flip)
1444                 {
1445                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1446                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1447                         fuel_baralign = health_baralign;
1448                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1449                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1450                 }
1451                 else
1452                 {
1453                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1454                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1455                         fuel_baralign = armor_baralign;
1456                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1457                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1458                 }
1459
1460                 //if(health)
1461                 {
1462                         if(autocvar_hud_panel_healtharmor_progressbar)
1463                         {
1464                                 HUD_Panel_GetProgressBarColor(health);
1465                                 float p_health, pain_health_alpha;
1466                                 p_health = health;
1467                                 pain_health_alpha = 1;
1468                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1469                                 {
1470                                         if (saved_health == -1)
1471                                         {
1472                                                 if (prev_health == 0 || prev_health - health >= 3)
1473                                                 {
1474                                                         health_time = time;
1475                                                         saved_health = prev_health;
1476                                                 }
1477                                         }
1478                                         if (saved_health != -1)
1479                                         {
1480                                                 float d = time - health_time;
1481                                                 if (d < 1)
1482                                                 {
1483                                                         if (saved_health == -2)
1484                                                                 p_health *= sqrt(d);
1485                                                         else
1486                                                         {
1487                                                                 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, saved_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
1488                                                                 if (prev_health - health >= 1) //refresh the effect if repeatedly damaged
1489                                                                         health_time = time;
1490                                                         }
1491                                                 }
1492                                                 else
1493                                                         saved_health = -1; //damage effect ended
1494                                         }
1495                                         prev_health = health;
1496
1497                                         if (health <= 40 && saved_health != -2)
1498                                         {
1499                                                 float BLINK_FACTOR = 0.15;
1500                                                 float BLINK_BASE = 0.85;
1501                                                 float BLINK_FREQ = 9; 
1502                                                 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1503                                         }
1504                                 }
1505                                 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);
1506                         }
1507                         if(autocvar_hud_panel_healtharmor_text)
1508                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1509                 }
1510
1511                 if(armor)
1512                 {
1513                         if(autocvar_hud_panel_healtharmor_progressbar)
1514                         {
1515                                 HUD_Panel_GetProgressBarColor(armor);
1516                                 float p_armor;
1517                                 p_armor = armor;
1518                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1519                                 {
1520                                         if (saved_armor == -1)
1521                                         {
1522                                                 if (prev_armor == 0 || prev_armor - armor >= 3)
1523                                                 {
1524                                                         armor_time = time;
1525                                                         saved_armor = prev_armor;
1526                                                 }
1527                                         }
1528                                         if (saved_armor != -1)
1529                                         {
1530                                                 float d = time - armor_time;
1531                                                 if (d < 1)
1532                                                 {
1533                                                         if (saved_armor == -2)
1534                                                                 p_armor *= sqrt(d);
1535                                                         else
1536                                                         {
1537                                                                 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, saved_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
1538                                                                 if (prev_armor - armor >= 1) //refresh the effect if repeatedly damaged
1539                                                                         armor_time = time;
1540                                                         }
1541                                                 }
1542                                                 else
1543                                                         saved_armor = -1; //damage effect ended
1544                                         }
1545                                         prev_armor = armor;
1546                                 }
1547                                 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);
1548                         }
1549                         if(autocvar_hud_panel_healtharmor_text)
1550                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1551                 }
1552
1553                 if(fuel)
1554                 {
1555                         if (is_vertical)
1556                                 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1557                         else
1558                                 mySize_y *= 0.2;
1559                         if (panel_ar >= 4)
1560                                 mySize_x *= 2; //restore full panel size
1561                         else if (panel_ar < 1/4)
1562                                 mySize_y *= 2; //restore full panel size
1563                         HUD_Panel_GetProgressBarColor(fuel);
1564                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1565                 }
1566         }
1567 }
1568
1569 // Notification area (#4)
1570 //
1571
1572 string Weapon_SuicideMessage(float deathtype)
1573 {
1574         w_deathtype = deathtype;
1575         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1576         return w_deathtypestring;
1577 }
1578
1579 string Weapon_KillMessage(float deathtype)
1580 {
1581         w_deathtype = deathtype;
1582         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1583         return w_deathtypestring;
1584 }
1585
1586 #define KN_MAX_ENTRIES 10
1587 float kn_index;
1588 float killnotify_times[KN_MAX_ENTRIES];
1589 float killnotify_deathtype[KN_MAX_ENTRIES];
1590 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
1591 string killnotify_attackers[KN_MAX_ENTRIES];
1592 string killnotify_victims[KN_MAX_ENTRIES];
1593 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
1594 {
1595         --kn_index;
1596         if (kn_index == -1)
1597                 kn_index = KN_MAX_ENTRIES-1;
1598         killnotify_times[kn_index] = time;
1599         killnotify_deathtype[kn_index] = wpn;
1600         killnotify_actiontype[kn_index] = actiontype;
1601         if(killnotify_attackers[kn_index])
1602                 strunzone(killnotify_attackers[kn_index]);
1603         killnotify_attackers[kn_index] = strzone(attacker);
1604         if(killnotify_victims[kn_index])
1605                 strunzone(killnotify_victims[kn_index]);
1606         killnotify_victims[kn_index] = strzone(victim);
1607 }
1608
1609 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1610 {
1611         float w;
1612         float alsoprint, gentle;
1613         alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1614         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1615         
1616         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
1617                 return;
1618
1619         if(msg == MSG_SUICIDE) {
1620                 w = DEATH_WEAPONOF(type);
1621                 if(WEP_VALID(w)) {
1622                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1623                         if (alsoprint)
1624                                 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1625                 } else if (type == DEATH_KILL) {
1626                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1627                         if (alsoprint)
1628                                 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1629                 } else if (type == DEATH_ROT) {
1630                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1631                         if (alsoprint)
1632                                 print (sprintf(_("^1%s^1 died\n"), s1));
1633                 } else if (type == DEATH_NOAMMO) {
1634                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1635                         if (alsoprint)
1636                                 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1637                 } else if (type == DEATH_CAMP) {
1638                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1639                         if (alsoprint)
1640                                 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1641                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1642                         HUD_KillNotify_Push(s1, "", 0, type);
1643                         if (alsoprint)
1644                                 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1645                 } else if (type == DEATH_CHEAT) {
1646                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1647                         if (alsoprint)
1648                                 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1649                 } else if (type == DEATH_FIRE) {
1650                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1651                         if (alsoprint)
1652                                 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1653                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1654                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1655                         if (alsoprint)
1656                                 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1657                 } 
1658                 
1659                 if (stof(s2) > 2) // killcount > 2
1660                         print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1661         } else if(msg == MSG_KILL) {
1662                 w = DEATH_WEAPONOF(type);
1663                 if(WEP_VALID(w)) {
1664                         if((w == WEP_SNIPERRIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
1665                                 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
1666                         else
1667                                 HUD_KillNotify_Push(s1, s2, 1, type);
1668
1669                         if (alsoprint)
1670                                 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1671                 }
1672                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1673                         HUD_KillNotify_Push(s1, s2, 1, type);
1674                         if(alsoprint)
1675                         {
1676                                 if(gentle) {
1677                                         print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1678                                 } else {
1679                                         print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1680                                 }
1681                         }
1682                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1683                                 if(gentle)
1684                                         print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1685                                 else
1686                                         print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1687                         }
1688                         else if (stof(s2) > 2) {
1689                                 if(gentle)
1690                                         print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1691                                 else
1692                                         print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1693                         }
1694                 }
1695                 else if(type == KILL_FIRST_BLOOD)
1696                         print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1697                 else if (type == DEATH_TELEFRAG) {
1698                         HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1699                         if(gentle)
1700                                 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1701                         else
1702                                 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1703                 }
1704                 else if (type == DEATH_DROWN) {
1705                         HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1706                         if(alsoprint)
1707                                 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1708                 }
1709                 else if (type == DEATH_SLIME) {
1710                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1711                         if(alsoprint)
1712                                 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1713                 }
1714                 else if (type == DEATH_LAVA) {
1715                         HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1716                         if(alsoprint)
1717                                 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1718                 }
1719                 else if (type == DEATH_FALL) {
1720                         HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1721                         if(alsoprint)
1722                                 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1723                 }
1724                 else if (type == DEATH_SHOOTING_STAR) {
1725                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1726                         if(alsoprint)
1727                                 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1728                 }
1729                 else if (type == DEATH_SWAMP) {
1730                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1731                         if(alsoprint)
1732                                 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1733                 }
1734                 else if (type == DEATH_HURTTRIGGER)
1735                 {
1736                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1737                         if(alsoprint)
1738                                 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1739                 } else if(type == DEATH_SBCRUSH) {
1740                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1741                         if(alsoprint)
1742                                 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1743                 } else if(type == DEATH_SBMINIGUN) {
1744                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1745                         if(alsoprint)
1746                                 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1747                 } else if(type == DEATH_SBROCKET) {
1748                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1749                         if(alsoprint)
1750                                 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1751                 } else if(type == DEATH_SBBLOWUP) {
1752                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1753                         if(alsoprint)
1754                                 print (sprintf(_("^1%s^1 got caught in the destruction of %s^1's vehicle\n"), s2, s1));
1755                 } else if(type == DEATH_WAKIGUN) {
1756                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1757                         if(alsoprint)
1758                                 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1759                 } else if(type == DEATH_WAKIROCKET) {
1760                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1761                         if(alsoprint)
1762                                 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1763                 } else if(type == DEATH_WAKIBLOWUP) {
1764                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1765                         if(alsoprint)
1766                                 print (sprintf(_("^1%s^1 dies when %s^1's wakizashi dies.\n"), s2, s1));
1767                 } else if(type == DEATH_TURRET) {
1768                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1769                         if(alsoprint)
1770                                 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1771                 } else if(type == DEATH_TOUCHEXPLODE) {
1772                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1773                         if(alsoprint)
1774                                 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1775                 } else if(type == DEATH_CHEAT) {
1776                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1777                         if(alsoprint)
1778                                 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1779                 } else if (type == DEATH_FIRE) {
1780                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1781                         if(alsoprint)
1782                                 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1783                 } else if (type == DEATH_CUSTOM) {
1784                         HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1785                         if(alsoprint)
1786                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1787                 } else if (type == DEATH_HURTTRIGGER) {
1788                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1789                         if(alsoprint)
1790                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1791                 } else {
1792                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1793                         if(alsoprint)
1794                                 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1795                 }
1796         } else if(msg == MSG_SPREE) {
1797                 if(type == KILL_END_SPREE) {
1798                         if(gentle)
1799                                 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1800                         else
1801                                 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1802                 } else if(type == KILL_SPREE) {
1803                         if(gentle)
1804                                 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1805                         else
1806                                 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1807                 } else if(type == KILL_SPREE_3) {
1808                         if(gentle)
1809                                 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1810                         else
1811                                 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1812                 } else if(type == KILL_SPREE_5) {
1813                         if(gentle)
1814                                 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1815                         else
1816                                 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1817                 } else if(type == KILL_SPREE_10) {
1818                         if(gentle)
1819                                 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1820                         else
1821                                 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1822                 } else if(type == KILL_SPREE_15) {
1823                         if(gentle)
1824                                 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1825                         else
1826                                 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1827                 } else if(type == KILL_SPREE_20) {
1828                         if(gentle)
1829                                 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1830                         else
1831                                 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1832                 } else if(type == KILL_SPREE_25) {
1833                         if(gentle)
1834                                 print (sprintf(_("%s^7 made ^1TWENTY FIFE SCORES IN A ROW!\n"), s1));
1835                         else
1836                                 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1837                 } else if(type == KILL_SPREE_30) {
1838                         if(gentle)
1839                                 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1840                         else
1841                                 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1842                 }
1843         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1844                 if (type == DEATH_DROWN) {
1845                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1846                         if(alsoprint)
1847                         {
1848                                 if(gentle)
1849                                         print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1850                                 else
1851                                         print (sprintf(_("^1%s^1 drowned\n"), s1));
1852                         }
1853                 } else if (type == DEATH_SLIME) {
1854                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1855                         if(alsoprint)
1856                                 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1857                 } else if (type == DEATH_LAVA) {
1858                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1859                         if(alsoprint)
1860                         {
1861                                 if(gentle)
1862                                         print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1863                                 else
1864                                         print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1865                         }
1866                 } else if (type == DEATH_FALL) {
1867                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1868                         if(alsoprint)
1869                         {
1870                                 if(gentle)
1871                                         print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1872                                 else
1873                                         print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1874                         }
1875                 } else if (type == DEATH_SHOOTING_STAR) {
1876                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1877                         if(alsoprint)
1878                                 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1879                 } else if (type == DEATH_SWAMP) {
1880                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1881                         if(alsoprint)
1882                         {
1883                                 if(gentle)
1884                                         print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1885                                 else
1886                                         print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1887                         }
1888                 } else if(type == DEATH_TURRET) {
1889                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1890                         if(alsoprint)
1891                                 print (sprintf(_("^1%s^1 was mowed down by a turret \n"), s1));
1892                 } else if (type == DEATH_CUSTOM) {
1893                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1894                         if(alsoprint)
1895                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1896                 } else if (type == DEATH_HURTTRIGGER) {
1897                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1898                         if(alsoprint)
1899                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1900                 } else if(type == DEATH_TOUCHEXPLODE) {
1901                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1902                         if(alsoprint)
1903                                 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1904                 } else if(type == DEATH_CHEAT) {
1905                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1906                         if(alsoprint)
1907                                 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
1908                 } else if(type == DEATH_FIRE) {
1909                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1910                         if(alsoprint)
1911                         {
1912                                 if(gentle)
1913                                         print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
1914                                 else
1915                                         print (sprintf(_("^1%s^1 burnt to death\n"), s1));
1916                                 }
1917                 } else {
1918                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1919                         if(alsoprint)
1920                         {
1921                                 if(gentle)
1922                                         print (sprintf(_("^1%s^1 needs a restart\n"), s1));
1923                                 else
1924                                         print (sprintf(_("^1%s^1 died\n"), s1));
1925                         }
1926                 }
1927         } else if(msg == MSG_KILL_ACTION_SPREE) {
1928                 if(gentle)
1929                         print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
1930                 else
1931                         print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
1932         } else if(msg == MSG_INFO) {
1933                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
1934                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1935                         print(sprintf(_("%s^7 got the %s\n"), s1, s2));
1936                 } else if(type == INFO_LOSTFLAG) {
1937                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
1938                         print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
1939                 } else if(type == INFO_PICKUPFLAG) {
1940                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1941                         print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
1942                 } else if(type == INFO_RETURNFLAG) {
1943                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
1944                         print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
1945                 } else if(type == INFO_CAPTUREFLAG) {
1946                         HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
1947                         print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
1948                 }
1949         } else if(msg == MSG_RACE) {
1950                 if(type == RACE_SERVER_RECORD) {
1951                         HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
1952                 }
1953                 else if(type == RACE_NEW_RANK) {
1954                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
1955                 }
1956                 else if(type == RACE_NEW_TIME) {
1957                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
1958                 }
1959                 else if(type == RACE_FAIL) {
1960                         HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
1961                 }
1962         } else if(msg == MSG_KA) {
1963                 if(type == KA_PICKUPBALL) {
1964                         HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
1965                         if(alsoprint)
1966                                 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
1967                 }
1968                 else if(type == KA_DROPBALL) {
1969                         HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
1970                         if(alsoprint)
1971                                 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
1972                 }
1973         }
1974 }
1975
1976 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
1977
1978 void HUD_Centerprint(string s1, string s2, float type, float msg)
1979 {
1980         float gentle;
1981         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1982         if(msg == MSG_SUICIDE) {
1983                 if (type == DEATH_TEAMCHANGE) {
1984                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("You are now on: %s"), s1)));
1985                 } else if (type == DEATH_AUTOTEAMCHANGE) {
1986                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("You have been moved into a different team to improve team balance\nYou are now on: %s"), s1)));
1987                 } else if (type == DEATH_CAMP) {
1988                         if(gentle)
1989                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Reconsider your tactics, camper!")));
1990                         else
1991                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Die camper!")));
1992                 } else if (type == DEATH_NOAMMO) {
1993                         if(gentle)
1994                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You are reinserted into the game for running out of ammo...")));
1995                         else
1996                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You were killed for running out of ammo...")));
1997                 } else if (type == DEATH_ROT) {
1998                         if(gentle)
1999                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You need to preserve your health")));
2000                         else
2001                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You grew too old without taking your medicine")));
2002                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2003                         if(gentle)
2004                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Don't go against team mates!")));
2005                         else
2006                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Don't shoot your team mates!")));
2007                 } else if (type == DEATH_QUIET) {
2008                         // do nothing
2009                 } else { // generic message
2010                         if(gentle)
2011                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You need to be more careful!")));
2012                         else
2013                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You killed your own dumb self!")));
2014                 }
2015         } else if(msg == MSG_KILL) {
2016                 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2017                         if(gentle) {
2018                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1Moron! You went against %s, a team mate!"), s1)));
2019                         } else {
2020                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1Moron! You fragged %s, a team mate!"), s1)));
2021                         }
2022                 } else if (type == KILL_FIRST_BLOOD) {
2023                         if(gentle) {
2024                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First score")));
2025                         } else {
2026                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First blood")));
2027                         }
2028                 } else if (type == KILL_FIRST_VICTIM) {
2029                         if(gentle) {
2030                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First casualty")));
2031                         } else {
2032                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First victim")));
2033                         }
2034                 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2035                         if(gentle) {
2036                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You scored against ^7%s^1 who was typing!"), s1), s2));
2037                         } else {
2038                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You typefragged ^7%s"), s1), s2));
2039                         }
2040                 } else if (type == KILL_TYPEFRAGGED) {
2041                         if(gentle) {
2042                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were scored against by ^7%s^1 while you were typing!"), s1), s2));
2043                         } else {
2044                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were typefragged by ^7%s"), s1), s2));
2045                         }
2046                 } else if (type == KILL_FRAG) {
2047                         if(gentle) {
2048                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^4You scored against ^7%s"), s1), s2));
2049                         } else {
2050                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^4You fragged ^7%s"), s1), s2));
2051                         }
2052                 } else { // generic message
2053                         if(gentle) {
2054                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were scored against by ^7%s"), s1), s2));
2055                         } else {
2056                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were fragged by ^7%s"), s1), s2));
2057                         }
2058                 }
2059         } else if(msg == MSG_KILL_ACTION) {
2060                 // TODO: invent more centerprints here?
2061                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Watch your step!")));
2062         }
2063 }
2064
2065 void HUD_Notify (void)
2066 {
2067         if(!autocvar__hud_configure)
2068         {
2069                 if(!autocvar_hud_panel_notify) return;
2070         }
2071         else
2072                 hud_configure_active_panel = HUD_PANEL_NOTIFY;
2073
2074         HUD_Panel_UpdateCvars(notify);
2075         vector pos, mySize;
2076         pos = panel_pos;
2077         mySize = panel_size;
2078
2079         HUD_Panel_DrawBg(1);
2080         if(panel_bg_padding)
2081         {
2082                 pos += '1 1 0' * panel_bg_padding;
2083                 mySize -= '2 2 0' * panel_bg_padding;
2084         }
2085
2086         float entries, height;
2087         entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2088         height = mySize_y/entries;
2089         
2090         vector fontsize;
2091         float fontheight = height * autocvar_hud_panel_notify_fontsize;
2092         fontsize = '0.5 0.5 0' * fontheight;
2093
2094         float a;
2095         float when;
2096         when = autocvar_hud_panel_notify_time;
2097         float fadetime;
2098         fadetime = autocvar_hud_panel_notify_fadetime;
2099
2100         string s;
2101
2102         vector pos_attacker, pos_victim;
2103         vector weap_pos;
2104         float width_attacker;
2105         string attacker, victim;
2106
2107         float i, j, w, step, limit;
2108         if(autocvar_hud_panel_notify_flip) //order items from the top down
2109         {
2110                 i = 0;
2111                 step = +1;
2112                 limit = entries;
2113         }
2114         else //order items from the bottom up
2115         {
2116                 i = entries - 1;
2117                 step = -1;
2118                 limit = -1;
2119         }
2120
2121         for(j = kn_index;  i != limit;  i += step, ++j)
2122         {
2123                 if(autocvar__hud_configure)
2124                 {
2125                         if (step == +1)
2126                                 a = i;
2127                         else // inverse order
2128                                 a = entries - 1 - i;
2129                         attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2130                         victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2131                         s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2132                         a = bound(0, (when - a) / 4, 1);
2133                         goto hud_config_notifyprint;
2134                 }
2135
2136                 if (j == KN_MAX_ENTRIES)
2137                         j = 0;
2138
2139                 if(killnotify_times[j] + when > time)
2140                         a = 1;
2141                 else if(fadetime)
2142                 {
2143                         a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2144                         if(!a)
2145                         {
2146                                 break;
2147                         }
2148                 }
2149                 else
2150                 {
2151                         break;
2152                 }
2153
2154                 s = "";
2155
2156                 w = -1;
2157                 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
2158
2159                 // TODO: maybe print in team colors?
2160                 //
2161                 // Y [used by] X
2162                 if(killnotify_actiontype[j] == 0) 
2163                 {
2164                         if(killnotify_deathtype[j] == DEATH_GENERIC)
2165                         {
2166                                 s = "notify_death";
2167                         }
2168                         else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2169                         {
2170                                 s = "notify_outofammo";
2171                         }
2172                         else if(killnotify_deathtype[j] == DEATH_KILL)
2173                         {
2174                                 s = "notify_selfkill";
2175                         }
2176                         else if(killnotify_deathtype[j] == DEATH_CAMP)
2177                         {
2178                                 s = "notify_camping";
2179                         }
2180                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2181                         {
2182                                 s = "notify_teamkill_red";
2183                         }
2184                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2185                         {
2186                                 s = "notify_teamkill_blue";
2187                         }
2188                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2189                         {
2190                                 s = "notify_water";
2191                         }
2192                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2193                         {
2194                                 s = "notify_slime";
2195                         }
2196                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2197                         {
2198                                 s = "notify_lava";
2199                         }
2200                         else if(killnotify_deathtype[j] == DEATH_FALL)
2201                         {
2202                                 s = "notify_fall";
2203                         }
2204                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2205                         {
2206                                 s = "notify_shootingstar";
2207                         }
2208                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2209                         {
2210                                 s = "notify_death";
2211                         }
2212                         else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2213                         {
2214                                 if(killnotify_victims[j] == "^1RED^7 flag")
2215                                 {
2216                                         s = "notify_red_taken";
2217                                 }
2218                                 else
2219                                 {
2220                                         s = "notify_blue_taken";
2221                                 }
2222                         }
2223                         else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2224                         {
2225                                 if(killnotify_victims[j] == "^1RED^7 flag")
2226                                 {
2227                                         s = "notify_red_returned";
2228                                 }
2229                                 else
2230                                 {
2231                                         s = "notify_blue_returned";
2232                                 }
2233                         }
2234                         else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2235                         {
2236                                 if(killnotify_victims[j] == "^1RED^7 flag")
2237                                 {
2238                                         s = "notify_red_lost";
2239                                 }
2240                                 else
2241                                 {
2242                                         s = "notify_blue_lost";
2243                                 }
2244                         }
2245                         else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
2246                         {
2247                                 if(killnotify_victims[j] == "^1RED^7 flag")
2248                                 {
2249                                         s = "notify_red_captured";
2250                                 }
2251                                 else
2252                                 {
2253                                         s = "notify_blue_captured";
2254                                 }
2255                         }
2256                         else if(killnotify_deathtype[j] == KA_DROPBALL)
2257                         {
2258                                 s = "notify_balldropped";
2259                         }
2260                         else if(killnotify_deathtype[j] == KA_PICKUPBALL)
2261                         {
2262                                 s = "notify_ballpickedup";
2263                         }
2264                         
2265                         attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2266                         pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2267                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2268
2269                         if(s != "")
2270                         {
2271                                 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2272                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2273                         }
2274                 }
2275                 // X [did action to] Y
2276                 else
2277                 {
2278                         if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
2279                         {
2280                                 s = "notify_melee_laser";
2281                         }
2282                         else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
2283                         {
2284                                 s = "notify_melee_shotgun";
2285                         }
2286                         else if(WEP_VALID(w))
2287                         {
2288                                 self = get_weaponinfo(w);
2289                                 s = strcat("weapon", self.netname);
2290                         }
2291                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2292                         {
2293                                 s = "notify_teamkill_red";
2294                         }
2295                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2296                         {
2297                                 s = "notify_teamkill_red";
2298                         }
2299                         else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
2300                         {
2301                                 s = "notify_telefrag";
2302                         }
2303                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2304                         {
2305                                 s = "notify_water";
2306                         }
2307                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2308                         {
2309                                 s = "notify_slime";
2310                         }
2311                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2312                         {
2313                                 s = "notify_lava";
2314                         }
2315                         else if(killnotify_deathtype[j] == DEATH_FALL)
2316                         {
2317                                 s = "notify_fall";
2318                         }
2319                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2320                         {
2321                                 s = "notify_shootingstar";
2322                         }
2323                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2324                         {
2325                                 s = "notify_void";
2326                         }
2327                         else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
2328                         {
2329                                 s = "notify_headshot";
2330                         }
2331                         else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
2332                         {
2333                                 s = "race_newrecordserver";
2334                         }
2335                         else if(killnotify_deathtype[j] == RACE_NEW_RANK)
2336                         {
2337                                 s = "race_newrankyellow";
2338                         }
2339                         else if(killnotify_deathtype[j] == RACE_NEW_TIME)
2340                         {
2341                                 s = "race_newtime";
2342                         }
2343                         else if(killnotify_deathtype[j] == RACE_FAIL)
2344                         {
2345                                 s = "race_newfail";
2346                         }
2347
2348                         attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2349                         victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2350 :hud_config_notifyprint
2351                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2352                         pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2353                         pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2354                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2355
2356                         if(s != "")
2357                         {
2358                                 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2359                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2360                                 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2361                         }
2362                 }
2363         }
2364 }
2365
2366 // Timer (#5)
2367 //
2368 // TODO: macro
2369 string seconds_tostring(float sec)
2370 {
2371         float minutes;
2372         minutes = floor(sec / 60);
2373
2374         sec -= minutes * 60;
2375         return sprintf("%d:%02d", minutes, sec);
2376 }
2377
2378 void HUD_Timer(void)
2379 {
2380         if(!autocvar__hud_configure)
2381         {
2382                 if(!autocvar_hud_panel_timer) return;
2383         }
2384         else
2385                 hud_configure_active_panel = HUD_PANEL_TIMER;
2386
2387         HUD_Panel_UpdateCvars(timer);
2388         vector pos, mySize;
2389         pos = panel_pos;
2390         mySize = panel_size;
2391
2392         HUD_Panel_DrawBg(1);
2393         if(panel_bg_padding)
2394         {
2395                 pos += '1 1 0' * panel_bg_padding;
2396                 mySize -= '2 2 0' * panel_bg_padding;
2397         }
2398
2399         string timer;
2400         float timelimit, elapsedTime, timeleft, minutesLeft;
2401
2402         timelimit = getstatf(STAT_TIMELIMIT);
2403
2404         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2405         timeleft = ceil(timeleft);
2406
2407         minutesLeft = floor(timeleft / 60);
2408
2409         vector timer_color;
2410         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2411                 timer_color = '1 1 1'; //white
2412         else if(minutesLeft >= 1)
2413                 timer_color = '1 1 0'; //yellow
2414         else
2415                 timer_color = '1 0 0'; //red
2416
2417         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2418                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2419                         //while restart is still active, show 00:00
2420                         timer = seconds_tostring(0);
2421                 } else {
2422                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2423                         timer = seconds_tostring(elapsedTime);
2424                 }
2425         } else {
2426                 timer = seconds_tostring(timeleft);
2427         }
2428
2429         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2430 }
2431
2432 // Radar (#6)
2433 //
2434 void HUD_Radar(void)
2435 {
2436         if (!autocvar__hud_configure)
2437         {
2438                 if (autocvar_hud_panel_radar == 0) return;
2439                 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2440         }
2441         else
2442                 hud_configure_active_panel = HUD_PANEL_RADAR;
2443
2444         HUD_Panel_UpdateCvars(radar);
2445         vector pos, mySize;
2446         pos = panel_pos;
2447         mySize = panel_size;
2448
2449         HUD_Panel_DrawBg(1);
2450         if(panel_bg_padding)
2451         {
2452                 pos += '1 1 0' * panel_bg_padding;
2453                 mySize -= '2 2 0' * panel_bg_padding;
2454         }
2455
2456         local float color2;
2457         local entity tm;
2458         float scale2d, normalsize, bigsize;
2459         float f;
2460
2461         teamradar_origin2d = pos + 0.5 * mySize;
2462         teamradar_size2d = mySize;
2463
2464         if(minimapname == "")
2465                 return;
2466
2467         teamradar_loadcvars();
2468
2469         switch(hud_panel_radar_zoommode)
2470         {
2471                 default:
2472                 case 0:
2473                         f = current_zoomfraction;
2474                         break;
2475                 case 1:
2476                         f = 1 - current_zoomfraction;
2477                         break;
2478                 case 2:
2479                         f = 0;
2480                         break;
2481                 case 3:
2482                         f = 1;
2483                         break;
2484         }
2485
2486         switch(hud_panel_radar_rotation)
2487         {
2488                 case 0:
2489                         teamradar_angle = view_angles_y - 90;
2490                         break;
2491                 default:
2492                         teamradar_angle = 90 * hud_panel_radar_rotation;
2493                         break;
2494         }
2495
2496         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2497         teamradar_size2d = mySize;
2498
2499         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2500
2501         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2502         if(hud_panel_radar_rotation == 0)
2503         {
2504                 // max-min distance must fit the radar in any rotation
2505                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2506         }
2507         else
2508         {
2509                 vector c0, c1, c2, c3, span;
2510                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2511                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2512                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2513                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2514                 span = '0 0 0';
2515                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2516                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2517
2518                 // max-min distance must fit the radar in x=x, y=y
2519                 bigsize = min(
2520                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2521                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2522                 );
2523         }
2524
2525         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2526         if(bigsize > normalsize)
2527                 normalsize = bigsize;
2528
2529         teamradar_size =
2530                   f * bigsize
2531                 + (1 - f) * normalsize;
2532         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2533                   f * mi_center
2534                 + (1 - f) * view_origin);
2535
2536         drawsetcliparea(
2537                 pos_x,
2538                 pos_y,
2539                 mySize_x,
2540                 mySize_y
2541         );
2542
2543         draw_teamradar_background(hud_panel_radar_foreground_alpha);
2544
2545         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2546                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2547         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2548                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2549         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2550         {
2551                 color2 = GetPlayerColor(tm.sv_entnum);
2552                 //if(color == COLOR_SPECTATOR || color == color2)
2553                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2554         }
2555         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2556
2557         drawresetcliparea();
2558 };
2559
2560 // Score (#7)
2561 //
2562 void HUD_UpdatePlayerTeams();
2563 void HUD_Score(void)
2564 {
2565         if(!autocvar__hud_configure)
2566         {
2567                 if(!autocvar_hud_panel_score) return;
2568                 if(spectatee_status == -1 && (gametype == GAME_RACE || gametype == GAME_CTS)) return;
2569         }
2570         else
2571                 hud_configure_active_panel = HUD_PANEL_SCORE;
2572
2573         HUD_Panel_UpdateCvars(score);
2574         vector pos, mySize;
2575         pos = panel_pos;
2576         mySize = panel_size;
2577
2578         HUD_Panel_DrawBg(1);
2579         if(panel_bg_padding)
2580         {
2581                 pos += '1 1 0' * panel_bg_padding;
2582                 mySize -= '2 2 0' * panel_bg_padding;
2583         }
2584
2585         float score, distribution;
2586         string sign;
2587         vector distribution_color;
2588         entity tm, pl, me;
2589         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2590
2591         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2592                 string timer, distrtimer;
2593
2594                 pl = players.sort_next;
2595                 if(pl == me)
2596                         pl = pl.sort_next;
2597                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2598                         if(pl.scores[ps_primary] == 0)
2599                                 pl = world;
2600
2601                 score = me.(scores[ps_primary]);
2602                 timer = TIME_ENCODED_TOSTRING(score);
2603
2604                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2605                         // distribution display
2606                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2607
2608                         distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2609
2610                         if (distribution <= 0) {
2611                                 distribution_color = '0 1 0';
2612                                 sign = "-";
2613                         }
2614                         else {
2615                                 distribution_color = '1 0 0';
2616                                 sign = "+";
2617                         }
2618                         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);
2619                 }
2620                 // race record display
2621                 if (distribution <= 0)
2622                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2623                 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2624         } else if (!teamplay) { // non-teamgames
2625                 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2626                 {
2627 #define SCOREPANEL_MAX_ENTRIES 6
2628 #define SCOREPANEL_ASPECTRATIO 2
2629                         const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2630                         const float height = mySize_y/entries;
2631                         const vector fontsize = '0.9 0.9 0' * height;
2632                         pos_y += height * (1 - 0.9) / 2;
2633
2634                         vector rgb;
2635                         rgb = '1 1 1';
2636
2637                         const float name_size = mySize_x*0.75;
2638                         const float highlight_alpha = 0.2;
2639                         float i, me_printed;
2640                         string s;
2641                         if (autocvar__hud_configure)
2642                         {
2643                                 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2644                                 for (i=0; i<entries; ++i)
2645                                 {
2646                                         //simulate my score is lower than all displayed players,
2647                                         //so that I don't appear at all showing pure rankings.
2648                                         //This is to better show the difference between the 2 ranking views
2649                                         if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2650                                         {
2651                                                 rgb = '1 1 0';
2652                                                 drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2653                                                 s = GetPlayerName(pl.sv_entnum);
2654                                                 score = 7;
2655                                         }
2656                                         else
2657                                         {
2658                                                 s = sprintf(_("Player %d"), ftos(i+1));
2659                                                 score -= 3;
2660                                         }
2661
2662                                         s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2663                                         drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2664                                         drawstring(pos + eX * mySize_x*0.79, ftos(score), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2665                                         pos_y += height;
2666                                 }
2667                                 return;
2668                         }
2669
2670                         if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2671                                 HUD_UpdatePlayerTeams();
2672
2673                         for (pl = players.sort_next, i=0; pl && i<entries; pl = pl.sort_next, ++i)
2674                         {
2675                                 if (pl.team == COLOR_SPECTATOR)
2676                                         continue;
2677
2678                                 if (i == entries-1 && !me_printed && pl != me)
2679                                 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2680                                 {
2681                                         for (pl = me.sort_next; pl; pl = pl.sort_next)
2682                                                 if (pl.team != COLOR_SPECTATOR)
2683                                                         break;
2684
2685                                         if (pl)
2686                                                 rgb = '1 1 0'; //not last but not among the leading players: yellow
2687                                         else
2688                                                 rgb = '1 0 0'; //last: red
2689                                         pl = me;
2690                                 }
2691
2692                                 if (pl == me)
2693                                 {
2694                                         if (i == 0)
2695                                                 rgb = '0 1 0'; //first: green
2696                                         me_printed = 1;
2697                                         drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2698                                 }
2699                                 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2700                                 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2701                                 drawstring(pos + eX * mySize_x*0.79, ftos(pl.(scores[ps_primary])), fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2702                                 pos_y += height;
2703                         }
2704                         return;
2705                 }
2706                 // me vector := [team/connected frags id]
2707                 pl = players.sort_next;
2708                 if(pl == me)
2709                         pl = pl.sort_next;
2710
2711                 if(autocvar__hud_configure)
2712                         distribution = 42;
2713                 else if(pl)
2714                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2715                 else
2716                         distribution = 0;
2717
2718                 score = me.(scores[ps_primary]);
2719                 if(autocvar__hud_configure)
2720                         score = 123;
2721
2722                 if(distribution >= 5)
2723                         distribution_color = eY;
2724                 else if(distribution >= 0)
2725                         distribution_color = '1 1 1';
2726                 else if(distribution >= -5)
2727                         distribution_color = '1 1 0';
2728                 else
2729                         distribution_color = eX;
2730
2731                 string distribution_str;
2732                 distribution_str = ftos(distribution);
2733                 if (distribution >= 0)
2734                 {
2735                         if (distribution > 0)
2736                                 distribution_str = strcat("+", distribution_str);
2737                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2738                 }
2739                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2740                 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);
2741         } else { // teamgames
2742                 float max_fragcount;
2743                 max_fragcount = -99;
2744
2745                 float scores_count, row, column, rows, columns;
2746                 vector offset;
2747                 vector score_pos, score_size; //for scores other than myteam
2748                 if (spectatee_status == -1)
2749                 {
2750                         if (autocvar__hud_configure)
2751                                 scores_count = 4;
2752                         else for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2753                                 if(tm.team == COLOR_SPECTATOR)
2754                                         continue;
2755                                 ++scores_count;
2756                         }
2757                         rows = mySize_y/mySize_x;
2758                         rows = bound(1, floor((sqrt(4 * (3/1) * rows * scores_count + rows * rows) + rows + 0.5) / 2), scores_count);
2759                         //                               ^^^ ammo item aspect goes here
2760
2761                         columns = ceil(scores_count/rows);
2762
2763                         score_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
2764
2765                         float newSize;
2766                         if(score_size_x/score_size_y > 3)
2767                         {
2768                                 newSize = 3 * score_size_y;
2769                                 offset_x = score_size_x - newSize;
2770                                 pos_x += offset_x/2;
2771                                 score_size_x = newSize;
2772                         }
2773                         else
2774                         {
2775                                 newSize = 1/3 * score_size_x;
2776                                 offset_y = score_size_y - newSize;
2777                                 pos_y += offset_y/2;
2778                                 score_size_y = newSize;
2779                         }
2780                 }
2781                 else
2782                         score_size = eX * mySize_x*(1/4) + eY * mySize_y*(1/3);
2783                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2784                         if(tm.team == COLOR_SPECTATOR)
2785                                 continue;
2786                         score = tm.(teamscores[ts_primary]);
2787                         if(autocvar__hud_configure)
2788                                 score = 123;
2789                         
2790                         if (score > max_fragcount)
2791                                 max_fragcount = score;
2792
2793                         if (spectatee_status == -1)
2794                         {
2795                                 score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
2796                                 if (max_fragcount == score)
2797                                         HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2798                                 drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2799                                 ++row;
2800                                 if(row >= rows)
2801                                 {
2802                                         row = 0;
2803                                         ++column;
2804                                 }
2805                         }
2806                         else if(tm.team == myteam) {
2807                                 if (max_fragcount == score)
2808                                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2809                                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2810                         } else {
2811                                 if (max_fragcount == score)
2812                                         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);
2813                                 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);
2814                                 ++rows;
2815                         }
2816                 }
2817         }
2818 }
2819
2820 // Race timer (#8)
2821 //
2822 void HUD_RaceTimer (void)
2823 {
2824         if(!autocvar__hud_configure)
2825         {
2826                 if(!autocvar_hud_panel_racetimer) return;
2827                 if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
2828                 if(spectatee_status == -1) return;
2829         }
2830         else
2831                 hud_configure_active_panel = HUD_PANEL_RACETIMER;
2832
2833         HUD_Panel_UpdateCvars(racetimer);
2834         vector pos, mySize;
2835         pos = panel_pos;
2836         mySize = panel_size;
2837
2838         HUD_Panel_DrawBg(1);
2839         if(panel_bg_padding)
2840         {
2841                 pos += '1 1 0' * panel_bg_padding;
2842                 mySize -= '2 2 0' * panel_bg_padding;
2843         }
2844
2845         // always force 4:1 aspect
2846         vector newSize;
2847         if(mySize_x/mySize_y > 4)
2848         {
2849                 newSize_x = 4 * mySize_y;
2850                 newSize_y = mySize_y;
2851
2852                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
2853         }
2854         else
2855         {
2856                 newSize_y = 1/4 * mySize_x;
2857                 newSize_x = mySize_x;
2858
2859                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
2860         }
2861         mySize = newSize;
2862
2863         float a, t;
2864         string s, forcetime;
2865
2866         if(autocvar__hud_configure)
2867         {
2868                 s = "0:13:37";
2869                 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);
2870                 s = _("^1Intermediate 1 (+15.42)");
2871                 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);
2872                 s = sprintf(_("^1PENALTY: %.1f (%s)"), 2, "missing a checkpoint");
2873                 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);
2874         }
2875         else if(race_checkpointtime)
2876         {
2877                 a = bound(0, 2 - (time - race_checkpointtime), 1);
2878                 s = "";
2879                 forcetime = "";
2880                 if(a > 0) // just hit a checkpoint?
2881                 {
2882                         if(race_checkpoint != 254)
2883                         {
2884                                 if(race_time && race_previousbesttime)
2885                                         s = MakeRaceString(race_checkpoint, TIME_DECODE(race_time) - TIME_DECODE(race_previousbesttime), 0, 0, race_previousbestname);
2886                                 else
2887                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
2888                                 if(race_time)
2889                                         forcetime = TIME_ENCODED_TOSTRING(race_time);
2890                         }
2891                 }
2892                 else
2893                 {
2894                         if(race_laptime && race_nextbesttime && race_nextcheckpoint != 254)
2895                         {
2896                                 a = bound(0, 2 - ((race_laptime + TIME_DECODE(race_nextbesttime)) - (time + TIME_DECODE(race_penaltyaccumulator))), 1);
2897                                 if(a > 0) // next one?
2898                                 {
2899                                         s = MakeRaceString(race_nextcheckpoint, (time + TIME_DECODE(race_penaltyaccumulator)) - race_laptime, TIME_DECODE(race_nextbesttime), 0, race_nextbestname);
2900                                 }
2901                         }
2902                 }
2903
2904                 if(s != "" && a > 0)
2905                 {
2906                         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);
2907                 }
2908
2909                 if(race_penaltytime)
2910                 {
2911                         a = bound(0, 2 - (time - race_penaltyeventtime), 1);
2912                         if(a > 0)
2913                         {
2914                                 s = sprintf(_("^1PENALTY: %.1f (%s)"), race_penaltytime * 0.1, race_penaltyreason);
2915                                 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);
2916                         }
2917                 }
2918
2919                 if(forcetime != "")
2920                 {
2921                         a = bound(0, (time - race_checkpointtime) / 0.5, 1);
2922                         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);
2923                 }
2924                 else
2925                         a = 1;
2926
2927                 if(race_laptime && race_checkpoint != 255)
2928                 {
2929                         s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
2930                         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);
2931                 }
2932         }
2933         else
2934         {
2935                 if(race_mycheckpointtime)
2936                 {
2937                         a = bound(0, 2 - (time - race_mycheckpointtime), 1);
2938                         s = MakeRaceString(race_mycheckpoint, TIME_DECODE(race_mycheckpointdelta), -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
2939                         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);
2940                 }
2941                 if(race_othercheckpointtime && race_othercheckpointenemy != "")
2942                 {
2943                         a = bound(0, 2 - (time - race_othercheckpointtime), 1);
2944                         s = MakeRaceString(race_othercheckpoint, -TIME_DECODE(race_othercheckpointdelta), -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
2945                         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);
2946                 }
2947
2948                 if(race_penaltytime && !race_penaltyaccumulator)
2949                 {
2950                         t = race_penaltytime * 0.1 + race_penaltyeventtime;
2951                         a = bound(0, (1 + t - time), 1);
2952                         if(a > 0)
2953                         {
2954                                 if(time < t)
2955                                         s = sprintf(_("^1PENALTY: %.1f (%s)"), (t - time) * 0.1, race_penaltyreason);
2956                                 else
2957                                         s = sprintf(_("^2PENALTY: %.1f (%s)"), 0, race_penaltyreason);
2958                                 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);
2959                         }
2960                 }
2961         }
2962 }
2963
2964 // Vote window (#9)
2965 //
2966 float vote_yescount;
2967 float vote_nocount;
2968 float vote_needed;
2969 float vote_highlighted; // currently selected vote
2970
2971 float vote_active; // is there an active vote?
2972 float vote_prev; // previous state of vote_active to check for a change
2973 float vote_alpha;
2974 float vote_change; // "time" when vote_active changed
2975
2976 void HUD_VoteWindow(void) 
2977 {
2978         if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
2979         {
2980                 vote_active = 1;
2981                 if (autocvar__hud_configure)
2982                 {
2983                         vote_yescount = 0;
2984                         vote_nocount = 0;
2985                         print(_("^1You must answer before entering hud configure mode\n"));
2986                         cvar_set("_hud_configure", "0");
2987                 }
2988                 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Unregistered player^7\" in stats"));
2989                 uid2name_dialog = 1;
2990         }
2991
2992         if(!autocvar__hud_configure)
2993         {
2994                 if(!autocvar_hud_panel_vote) return;
2995
2996                 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
2997                 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
2998
2999                 if(panel_bg_alpha_str == "") {
3000                         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
3001                 }
3002                 panel_bg_alpha = stof(panel_bg_alpha_str);
3003         }
3004         else
3005         {
3006                 hud_configure_active_panel = HUD_PANEL_VOTE;
3007
3008                 vote_yescount = 3;
3009                 vote_nocount = 2;
3010                 vote_needed = 4;
3011         }
3012
3013         string s;
3014         float a;
3015         if(vote_active != vote_prev) {
3016                 vote_change = time;
3017                 vote_prev = vote_active;
3018         }
3019
3020         if(vote_active || autocvar__hud_configure)
3021                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
3022         else
3023                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
3024
3025         if(!vote_alpha)
3026                 return;
3027
3028         HUD_Panel_UpdateCvars(vote);
3029
3030         if(uid2name_dialog)
3031         {
3032                 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
3033                 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
3034         }
3035
3036     // these must be below above block
3037         vector pos, mySize;
3038         pos = panel_pos;
3039         mySize = panel_size;
3040
3041         a = vote_alpha * bound(autocvar_hud_panel_vote_alreadyvoted_alpha, 1 - vote_highlighted, 1);
3042         HUD_Panel_DrawBg(a);
3043         a = panel_fg_alpha * a;
3044
3045         if(panel_bg_padding)
3046         {
3047                 pos += '1 1 0' * panel_bg_padding;
3048                 mySize -= '2 2 0' * panel_bg_padding;
3049         }
3050
3051         // always force 3:1 aspect
3052         vector newSize;
3053         if(mySize_x/mySize_y > 3)
3054         {
3055                 newSize_x = 3 * mySize_y;
3056                 newSize_y = mySize_y;
3057
3058                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
3059         }
3060         else
3061         {
3062                 newSize_y = 1/3 * mySize_x;
3063                 newSize_x = mySize_x;
3064
3065                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
3066         }
3067         mySize = newSize;
3068
3069         s = _("A vote has been called for:");
3070         if(uid2name_dialog)
3071                 s = _("Allow servers to store and display your name?");
3072         drawstring_aspect(pos, s, eX * mySize_x + eY * (2/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3073         s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (1/8), stringwidth_colors);
3074         if(autocvar__hud_configure)
3075                 s = _("^1Configure the HUD");
3076         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize_y, s, eX * mySize_x + eY * (1.75/8) * mySize_y, a, DRAWFLAG_NORMAL);
3077
3078         // print the yes/no counts
3079     s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
3080         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);
3081     s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
3082         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);
3083
3084         // draw the progress bar backgrounds
3085         drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_back", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3086
3087         // draw the highlights
3088         if(vote_highlighted == 1) {
3089                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5, mySize_y);
3090                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3091         }
3092         else if(vote_highlighted == 2) {
3093                 drawsetcliparea(pos_x + 0.5 * mySize_x, pos_y, mySize_x * 0.5, mySize_y);
3094                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_voted", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3095         }
3096
3097         // draw the progress bars
3098         if(vote_yescount && vote_needed)
3099         {
3100                 drawsetcliparea(pos_x, pos_y, mySize_x * 0.5 * (vote_yescount/vote_needed), mySize_y);
3101                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3102         }
3103
3104         if(vote_nocount && vote_needed)
3105         {
3106                 drawsetcliparea(pos_x + mySize_x - mySize_x * 0.5 * (vote_nocount/vote_needed), pos_y, mySize_x * 0.5, mySize_y);
3107                 drawpic_skin(pos + eY * (5/8) * mySize_y, "voteprogress_prog", eX * mySize_x + eY * (3/8) * mySize_y, '1 1 1', a, DRAWFLAG_NORMAL);
3108         }
3109
3110         drawresetcliparea();
3111
3112         if(!vote_active) {
3113                 vote_highlighted = 0;
3114         }
3115 }
3116
3117 // Mod icons panel (#10)
3118 //
3119
3120 float mod_active; // is there any active mod icon?
3121
3122 // Clan Arena HUD modicons
3123 void HUD_Mod_CA(vector pos, vector mySize)
3124 {
3125         mod_active = 1; // CA should never hide the mod icons panel
3126         float redalive, bluealive;
3127         redalive = getstati(STAT_REDALIVE);
3128         bluealive = getstati(STAT_BLUEALIVE);
3129
3130         vector redpos, bluepos;
3131         if(mySize_x > mySize_y)
3132         {
3133                 redpos = pos;
3134                 bluepos = pos + eY * 0.5 * mySize_y;
3135                 drawpic_aspect_skin(redpos, "player_red.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3136                 drawstring_aspect(redpos + eX * 0.5 * mySize_x, ftos(redalive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3137                 drawpic_aspect_skin(bluepos, "player_blue.tga", 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3138                 drawstring_aspect(bluepos + eX * 0.5 * mySize_x, ftos(bluealive), 0.5 * mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3139         }
3140         else
3141         {
3142                 redpos = pos;
3143                 bluepos = pos + eY * 0.5 * mySize_y;
3144                 drawpic_aspect_skin(redpos, "player_red.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3145                 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);
3146                 drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3147                 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);
3148         }
3149 }
3150
3151 // CTF HUD modicon section
3152 float redflag_prevframe, blueflag_prevframe; // status during previous frame
3153 float redflag_prevstatus, blueflag_prevstatus; // last remembered status
3154 float redflag_statuschange_time, blueflag_statuschange_time; // time when the status changed
3155
3156 void HUD_Mod_CTF_Reset(void)
3157 {
3158         redflag_prevstatus = blueflag_prevstatus = redflag_prevframe = blueflag_prevframe = redflag_statuschange_time = blueflag_statuschange_time = 0;
3159 }
3160
3161 void HUD_Mod_CTF(vector pos, vector mySize)
3162 {
3163         vector redflag_pos, blueflag_pos;
3164         vector flag_size;
3165         float f; // every function should have that
3166
3167         float redflag, blueflag; // current status
3168         float redflag_statuschange_elapsedtime, blueflag_statuschange_elapsedtime; // time since the status changed
3169         float stat_items;
3170
3171         stat_items = getstati(STAT_ITEMS);
3172         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
3173         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
3174         
3175         if(redflag || blueflag)
3176                 mod_active = 1;
3177         else
3178                 mod_active = 0;
3179
3180         if(autocvar__hud_configure)
3181         {
3182                 redflag = 1;
3183                 blueflag = 2;
3184         }
3185
3186         // when status CHANGES, set old status into prevstatus and current status into status
3187         if (redflag != redflag_prevframe)
3188         {
3189                 redflag_statuschange_time = time;
3190                 redflag_prevstatus = redflag_prevframe;
3191                 redflag_prevframe = redflag;
3192         }
3193
3194         if (blueflag != blueflag_prevframe)
3195         {
3196                 blueflag_statuschange_time = time;
3197                 blueflag_prevstatus = blueflag_prevframe;
3198                 blueflag_prevframe = blueflag;
3199         }
3200
3201         redflag_statuschange_elapsedtime = time - redflag_statuschange_time;
3202         blueflag_statuschange_elapsedtime = time - blueflag_statuschange_time;
3203
3204         float BLINK_FACTOR = 0.15;
3205         float BLINK_BASE = 0.85;
3206         // note:
3207         //   RMS = sqrt(BLINK_BASE^2 + 0.5 * BLINK_FACTOR^2)
3208         // thus
3209         //   BLINK_BASE = sqrt(RMS^2 - 0.5 * BLINK_FACTOR^2)
3210         // ensure RMS == 1
3211         float BLINK_FREQ = 5; // circle frequency, = 2*pi*frequency in hertz
3212
3213         string red_icon, red_icon_prevstatus;
3214         float red_alpha, red_alpha_prevstatus;
3215         red_alpha = red_alpha_prevstatus = 1;
3216         switch(redflag) {
3217                 case 1: red_icon = "flag_red_taken"; break;
3218                 case 2: red_icon = "flag_red_lost"; break;
3219                 case 3: red_icon = "flag_red_carrying"; red_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3220                 default:
3221                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3222                                 red_icon = "flag_red_shielded";
3223                         else
3224                                 red_icon = string_null;
3225                         break;
3226         }
3227         switch(redflag_prevstatus) {
3228                 case 1: red_icon_prevstatus = "flag_red_taken"; break;
3229                 case 2: red_icon_prevstatus = "flag_red_lost"; break;
3230                 case 3: red_icon_prevstatus = "flag_red_carrying"; red_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3231                 default:
3232                         if(redflag == 3)
3233                                 red_icon_prevstatus = "flag_red_carrying"; // make it more visible
3234                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM2))
3235                                 red_icon_prevstatus = "flag_red_shielded";
3236                         else
3237                                 red_icon_prevstatus = string_null;
3238                         break;
3239         }
3240
3241         string blue_icon, blue_icon_prevstatus;
3242         float blue_alpha, blue_alpha_prevstatus;
3243         blue_alpha = blue_alpha_prevstatus = 1;
3244         switch(blueflag) {
3245                 case 1: blue_icon = "flag_blue_taken"; break;
3246                 case 2: blue_icon = "flag_blue_lost"; break;
3247                 case 3: blue_icon = "flag_blue_carrying"; blue_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3248                 default:
3249                         if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3250                                 blue_icon = "flag_blue_shielded";
3251                         else
3252                                 blue_icon = string_null;
3253                         break;
3254         }
3255         switch(blueflag_prevstatus) {
3256                 case 1: blue_icon_prevstatus = "flag_blue_taken"; break;
3257                 case 2: blue_icon_prevstatus = "flag_blue_lost"; break;
3258                 case 3: blue_icon_prevstatus = "flag_blue_carrying"; blue_alpha_prevstatus = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ); break;
3259                 default:
3260                         if(blueflag == 3)
3261                                 blue_icon_prevstatus = "flag_blue_carrying"; // make it more visible
3262                         else if((stat_items & IT_CTF_SHIELDED) && (myteam == COLOR_TEAM1))
3263                                 blue_icon_prevstatus = "flag_blue_shielded";
3264                         else
3265                                 blue_icon_prevstatus = string_null;
3266                         break;
3267         }
3268
3269         if(mySize_x > mySize_y) {
3270                 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3271                         redflag_pos = pos;
3272                         blueflag_pos = pos + eX * 0.5 * mySize_x;
3273                 } else {
3274                         blueflag_pos = pos;
3275                         redflag_pos = pos + eX * 0.5 * mySize_x;
3276                 }
3277                 flag_size = eX * 0.5 * mySize_x + eY * mySize_y;
3278         } else {
3279                 if (myteam == COLOR_TEAM1) { // always draw own flag on left
3280                         redflag_pos = pos;
3281                         blueflag_pos = pos + eY * 0.5 * mySize_y;
3282                 } else {
3283                         blueflag_pos = pos;
3284                         redflag_pos = pos + eY * 0.5 * mySize_y;
3285                 }
3286                 flag_size = eY * 0.5 * mySize_y + eX * mySize_x;
3287         }
3288
3289         f = bound(0, redflag_statuschange_elapsedtime*2, 1);
3290         if(red_icon_prevstatus && f < 1)
3291                 drawpic_aspect_skin_expanding(redflag_pos, red_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * red_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3292         if(red_icon)
3293                 drawpic_aspect_skin(redflag_pos, red_icon, flag_size, '1 1 1', panel_fg_alpha * red_alpha * f, DRAWFLAG_NORMAL);
3294
3295         f = bound(0, blueflag_statuschange_elapsedtime*2, 1);
3296         if(blue_icon_prevstatus && f < 1)
3297                 drawpic_aspect_skin_expanding(blueflag_pos, blue_icon_prevstatus, flag_size, '1 1 1', panel_fg_alpha * blue_alpha_prevstatus, DRAWFLAG_NORMAL, f);
3298         if(blue_icon)
3299                 drawpic_aspect_skin(blueflag_pos, blue_icon, flag_size, '1 1 1', panel_fg_alpha * blue_alpha * f, DRAWFLAG_NORMAL);
3300 }
3301
3302 // Keyhunt HUD modicon section
3303 float kh_runheretime;
3304
3305 void HUD_Mod_KH_Reset(void)
3306 {
3307         kh_runheretime = 0;
3308 }
3309
3310 void HUD_Mod_KH(vector pos, vector mySize)
3311 {
3312         mod_active = 1; // keyhunt should never hide the mod icons panel
3313         float kh_keys;
3314         float keyteam;
3315         float a, aa;
3316         vector p, pa, kh_size, kh_asize;
3317
3318         kh_keys = getstati(STAT_KH_KEYS);
3319
3320         p_x = pos_x;
3321         if(mySize_x > mySize_y)
3322         {
3323                 p_y = pos_y + 0.25 * mySize_y;
3324                 pa = p - eY * 0.25 * mySize_y;
3325
3326                 kh_size_x = mySize_x * 0.25;
3327                 kh_size_y = 0.75 * mySize_y;
3328                 kh_asize_x = mySize_x * 0.25;
3329                 kh_asize_y = mySize_y * 0.25;
3330         }
3331         else
3332         {
3333                 p_y = pos_y + 0.125 * mySize_y;
3334                 pa = p - eY * 0.125 * mySize_y;
3335
3336                 kh_size_x = mySize_x * 0.5;
3337                 kh_size_y = 0.375 * mySize_y;
3338                 kh_asize_x = mySize_x * 0.5;
3339                 kh_asize_y = mySize_y * 0.125;
3340         }
3341
3342         float i, key;
3343
3344         float keycount;
3345         keycount = 0;
3346         for(i = 0; i < 4; ++i)
3347         {
3348                 key = floor(kh_keys / pow(32, i)) & 31;
3349                 keyteam = key - 1;
3350                 if(keyteam == 30 && keycount <= 4)
3351                         keycount += 4;
3352                 if(keyteam == myteam || keyteam == -1 || keyteam == 30)
3353                         keycount += 1;
3354         }
3355
3356         // this yields 8 exactly if "RUN HERE" shows
3357
3358         if(keycount == 8)
3359         {
3360                 if(!kh_runheretime)
3361                         kh_runheretime = time;
3362                 pa_y -= fabs(sin((time - kh_runheretime) * 3.5)) * 6; // make the arrows jump in case of RUN HERE
3363         }
3364         else
3365                 kh_runheretime = 0;
3366
3367         for(i = 0; i < 4; ++i)
3368         {
3369                 key = floor(kh_keys / pow(32, i)) & 31;
3370                 keyteam = key - 1;
3371                 switch(keyteam)
3372                 {
3373                         case 30: // my key
3374                                 keyteam = myteam;
3375                                 a = 1;
3376                                 aa = 1;
3377                                 break;
3378                         case -1: // no key
3379                                 a = 0;
3380                                 aa = 0;
3381                                 break;
3382                         default: // owned or dropped
3383                                 a = 0.2;
3384                                 aa = 0.5;
3385                                 break;
3386                 }
3387                 a = a * panel_fg_alpha;
3388                 aa = aa * panel_fg_alpha;
3389                 if(a > 0)
3390                 {
3391                         switch(keyteam)
3392                         {
3393                                 case COLOR_TEAM1:
3394                                         drawpic_aspect_skin(pa, "kh_redarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3395                                         break;
3396                                 case COLOR_TEAM2:
3397                                         drawpic_aspect_skin(pa, "kh_bluearrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3398                                         break;
3399                                 case COLOR_TEAM3:
3400                                         drawpic_aspect_skin(pa, "kh_yellowarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3401                                         break;
3402                                 case COLOR_TEAM4:
3403                                         drawpic_aspect_skin(pa, "kh_pinkarrow", kh_asize, '1 1 1', aa, DRAWFLAG_NORMAL);  // show 30% alpha key
3404                                         break;
3405                                 default:
3406                                         break;
3407                         }
3408                         switch(i) // YAY! switch(i) inside a for loop for i. DailyWTF, here we come!
3409                         {
3410                                 case 0:
3411                                         drawpic_aspect_skin(p, "kh_red", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3412                                         break;
3413                                 case 1:
3414                                         drawpic_aspect_skin(p, "kh_blue", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3415                                         break;
3416                                 case 2:
3417                                         drawpic_aspect_skin(p, "kh_yellow", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3418                                         break;
3419                                 case 3:
3420                                         drawpic_aspect_skin(p, "kh_pink", kh_size, '1 1 1', a, DRAWFLAG_NORMAL);  // show 30% alpha key
3421                                         break;
3422                         }
3423                 }
3424                 if(mySize_x > mySize_y)
3425                 {
3426                         p_x += 0.25 * mySize_x;
3427                         pa_x += 0.25 * mySize_x;
3428                 }
3429                 else
3430                 {
3431                         if(i == 1)
3432                         {
3433                                 p_y = pos_y + 0.625 * mySize_y;
3434                                 pa_y = pos_y + 0.5 * mySize_y;
3435                                 p_x = pos_x;
3436                                 pa_x = pos_x;
3437                         }
3438                         else
3439                         {
3440                                 p_x += 0.5 * mySize_x;
3441                                 pa_x += 0.5 * mySize_x;
3442                         }
3443                 }
3444         }
3445 }
3446
3447 // Keepaway HUD mod icon
3448 float kaball_prevstatus; // last remembered status
3449 float kaball_statuschange_time; // time when the status changed
3450
3451 // we don't need to reset for keepaway since it immediately 
3452 // autocorrects prevstatus as to if the player has the ball or not
3453
3454 void HUD_Mod_Keepaway(vector pos, vector mySize)
3455 {
3456         mod_active = 1; // keepaway should always show the mod HUD
3457         
3458         float BLINK_FACTOR = 0.15;
3459         float BLINK_BASE = 0.85;
3460         float BLINK_FREQ = 5; 
3461         float kaball_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
3462         
3463         float stat_items = getstati(STAT_ITEMS);
3464         float kaball = (stat_items/IT_KEY1) & 1;
3465         
3466         if(kaball != kaball_prevstatus)
3467         {
3468                 kaball_statuschange_time = time;
3469                 kaball_prevstatus = kaball;
3470         }
3471         
3472         vector kaball_pos, kaball_size;
3473         
3474         if(mySize_x > mySize_y) {
3475                 kaball_pos = pos + eX * 0.25 * mySize_x;
3476                 kaball_size = eX * 0.5 * mySize_x + eY * mySize_y;
3477         } else {
3478                 kaball_pos = pos + eY * 0.25 * mySize_y;
3479                 kaball_size = eY * 0.5 * mySize_y + eX * mySize_x;
3480         }
3481         
3482         float kaball_statuschange_elapsedtime = time - kaball_statuschange_time;
3483         float f = bound(0, kaball_statuschange_elapsedtime*2, 1);
3484         
3485         if(kaball_prevstatus && f < 1)
3486                 drawpic_aspect_skin_expanding(kaball_pos, "keepawayball_carrying", kaball_size, '1 1 1', panel_fg_alpha * kaball_alpha, DRAWFLAG_NORMAL, f);
3487         
3488         if(kaball)
3489                 drawpic_aspect_skin(pos, "keepawayball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha * kaball_alpha * f, DRAWFLAG_NORMAL);
3490 }
3491
3492
3493 // Nexball HUD mod icon
3494 void HUD_Mod_NexBall(vector pos, vector mySize)
3495 {
3496         float stat_items, nb_pb_starttime, dt, p;
3497
3498         stat_items = getstati(STAT_ITEMS);
3499         nb_pb_starttime = getstatf(STAT_NB_METERSTART);
3500
3501         if (stat_items & IT_KEY1)
3502                 mod_active = 1;
3503         else
3504                 mod_active = 0;
3505
3506         //Manage the progress bar if any
3507         if (nb_pb_starttime > 0)
3508         {
3509                 dt = mod(time - nb_pb_starttime, nb_pb_period);
3510                 // one period of positive triangle
3511                 p = 2 * dt / nb_pb_period;
3512                 if (p > 1)
3513                         p = 2 - p;
3514
3515                 //Draw the filling
3516                 HUD_Panel_GetProgressBarColor(nexball);
3517                 if(mySize_x > mySize_y)
3518                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 0, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3519                 else
3520                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", p, 1, 0, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
3521         }
3522
3523         if (stat_items & IT_KEY1)
3524                 drawpic_aspect_skin(pos, "nexball_carrying", eX * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3525 }
3526
3527 // Race/CTS HUD mod icons
3528 float crecordtime_prev; // last remembered crecordtime
3529 float crecordtime_change_time; // time when crecordtime last changed
3530 float srecordtime_prev; // last remembered srecordtime
3531 float srecordtime_change_time; // time when srecordtime last changed
3532
3533 float race_status_time;
3534 float race_status_prev;
3535 string race_status_name_prev;
3536 void HUD_Mod_Race(vector pos, vector mySize)
3537 {
3538         mod_active = 1; // race should never hide the mod icons panel
3539         entity me;
3540         me = playerslots[player_localentnum - 1];
3541         float t, score;
3542         float f; // yet another function has this
3543         score = me.(scores[ps_primary]);
3544
3545         if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
3546                 return; // no records in the actual race
3547
3548         // clientside personal record
3549         string rr;
3550         if(gametype == GAME_CTS)
3551                 rr = CTS_RECORD;
3552         else
3553                 rr = RACE_RECORD;
3554         t = stof(db_get(ClientProgsDB, strcat(shortmapname, rr, "time")));
3555
3556         if(score && (score < t || !t)) {
3557                 db_put(ClientProgsDB, strcat(shortmapname, rr, "time"), ftos(score));
3558                 if(autocvar_cl_autodemo_delete_keeprecords)
3559                 {
3560                         f = autocvar_cl_autodemo_delete;
3561                         f &~= 1;
3562                         cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
3563                 }
3564         }
3565
3566         if(t != crecordtime_prev) {
3567                 crecordtime_prev = t;
3568                 crecordtime_change_time = time;
3569         }
3570
3571         vector textPos, medalPos;
3572         float squareSize;
3573         if(mySize_x > mySize_y) {
3574                 // text on left side
3575                 squareSize = min(mySize_y, mySize_x/2);
3576                 textPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eY * 0.5 * (mySize_y - squareSize);
3577                 medalPos = pos + eX * 0.5 * max(0, mySize_x/2 - squareSize) + eX * 0.5 * mySize_x + eY * 0.5 * (mySize_y - squareSize);
3578         } else {
3579                 // text on top
3580                 squareSize = min(mySize_x, mySize_y/2);
3581                 textPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eX * 0.5 * (mySize_x - squareSize);
3582                 medalPos = pos + eY * 0.5 * max(0, mySize_y/2 - squareSize) + eY * 0.5 * mySize_y + eX * 0.5 * (mySize_x - squareSize);
3583         }
3584
3585         f = time - crecordtime_change_time;
3586
3587         if (f > 1) {
3588                 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3589                 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);
3590         } else {
3591                 drawstring_aspect(textPos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3592                 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);
3593                 drawstring_aspect_expanding(pos, _("Personal best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
3594                 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);
3595         }
3596
3597         // server record
3598         t = race_server_record;
3599         if(t != srecordtime_prev) {
3600                 srecordtime_prev = t;
3601                 srecordtime_change_time = time;
3602         }
3603         f = time - srecordtime_change_time;
3604
3605         if (f > 1) {
3606                 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3607                 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);
3608         } else {
3609                 drawstring_aspect(textPos + eY * 0.5 * squareSize, _("Server best"), eX * squareSize + eY * 0.25 * squareSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3610                 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);
3611                 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);
3612                 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);
3613         }
3614
3615         if (race_status != race_status_prev || race_status_name != race_status_name_prev) {
3616                 race_status_time = time + 5;
3617                 race_status_prev = race_status;
3618                 if (race_status_name_prev)
3619                         strunzone(race_status_name_prev);
3620                 race_status_name_prev = strzone(race_status_name);
3621         }
3622
3623         // race "awards"
3624         float a;
3625         a = bound(0, race_status_time - time, 1);
3626
3627         string s;
3628         s = textShortenToWidth(race_status_name, squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
3629
3630         float rank;
3631         if(race_status > 0)
3632                 rank = race_CheckName(race_status_name);
3633         string rankname;
3634         rankname = race_PlaceName(rank);
3635
3636         vector namepos;
3637         namepos = medalPos + '0 0.8 0' * squareSize;
3638         vector rankpos;
3639         rankpos = medalPos + '0 0.15 0' * squareSize;
3640
3641         if(race_status == 0)
3642                 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3643         else if(race_status == 1) {
3644                 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);
3645                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3646                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3647         } else if(race_status == 2) {
3648                 if(race_status_name == GetPlayerName(player_localentnum -1) || !race_myrank || race_myrank < rank)
3649                         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);
3650                 else
3651                         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);
3652                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3653                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3654         } else if(race_status == 3) {
3655                 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);
3656                 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
3657                 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
3658         }
3659
3660         if (race_status_time - time <= 0) {
3661                 race_status_prev = -1;
3662                 race_status = -1;
3663                 if(race_status_name)
3664                         strunzone(race_status_name);
3665                 race_status_name = string_null;
3666                 if(race_status_name_prev)
3667                         strunzone(race_status_name_prev);
3668                 race_status_name_prev = string_null;
3669         }
3670 }
3671
3672 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
3673 {
3674         float stat, pps_ratio;
3675         string pic;
3676         vector color;
3677         switch(i)
3678         {
3679                 case 0:
3680                         stat = getstatf(STAT_DOM_PPS_RED);
3681                         pic = "dom_icon_red";
3682                         color = '1 0 0';
3683                         break;
3684                 case 1:
3685                         stat = getstatf(STAT_DOM_PPS_BLUE);
3686                         pic = "dom_icon_blue";
3687                         color = '0 0 1';
3688                         break;
3689                 case 2:
3690                         stat = getstatf(STAT_DOM_PPS_YELLOW);
3691                         pic = "dom_icon_yellow";
3692                         color = '1 1 0';
3693                         break;
3694                 case 3:
3695                         stat = getstatf(STAT_DOM_PPS_PINK);
3696                         pic = "dom_icon_pink";
3697                         color = '1 0 1';
3698         }
3699         pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
3700
3701         if(mySize_x/mySize_y > aspect_ratio)
3702         {
3703                 i = aspect_ratio * mySize_y;
3704                 myPos_x = myPos_x + (mySize_x - i) / 2;
3705                 mySize_x = i;
3706         }
3707         else
3708         {
3709                 i = 1/aspect_ratio * mySize_x;
3710                 myPos_y = myPos_y + (mySize_y - i) / 2;
3711                 mySize_y = i;
3712         }
3713
3714         if (layout) // show text too
3715         {
3716                 //draw the text
3717                 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
3718                 if (layout == 2) // average pps
3719                         drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(stat, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
3720                 else // percentage of average pps
3721                         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);
3722         }
3723
3724         //draw the icon
3725         drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3726         if (stat > 0)
3727         {
3728                 drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - pps_ratio), mySize_y, mySize_y * pps_ratio);
3729                 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3730                 drawresetcliparea();
3731         }
3732 }
3733
3734 void HUD_Mod_Dom(vector myPos, vector mySize)
3735 {
3736         mod_active = 1; // required in each mod function that always shows something
3737         entity tm;
3738         float teams_count;
3739         for(tm = teams.sort_next; tm; tm = tm.sort_next)
3740                 if(tm.team != COLOR_SPECTATOR)
3741                         ++teams_count;
3742
3743         float layout = autocvar_hud_panel_modicons_dom_layout;
3744         float rows, columns, aspect_ratio;
3745         rows = mySize_y/mySize_x;
3746         aspect_ratio = (layout) ? 3 : 1;
3747         rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
3748         columns = ceil(teams_count/rows);
3749
3750         int i;
3751         float row, column;
3752         for(i=0; i<teams_count; ++i)
3753         {
3754                 vector pos, itemSize;
3755                 pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
3756                 itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
3757
3758                 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
3759
3760                 ++row;
3761                 if(row >= rows)
3762                 {
3763                         row = 0;
3764                         ++column;
3765                 }
3766         }
3767 }
3768
3769 float mod_prev; // previous state of mod_active to check for a change
3770 float mod_alpha;
3771 float mod_change; // "time" when mod_active changed
3772
3773 void HUD_ModIcons(void)
3774 {
3775         if(!autocvar__hud_configure)
3776         {
3777                 if(!autocvar_hud_panel_modicons) return;
3778                 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;
3779         }
3780         else
3781                 hud_configure_active_panel = HUD_PANEL_MODICONS;
3782
3783         HUD_Panel_UpdateCvars(modicons);
3784         vector pos, mySize;
3785         pos = panel_pos;
3786         mySize = panel_size;
3787
3788         if(mod_active != mod_prev) {
3789                 mod_change = time;
3790                 mod_prev = mod_active;
3791         }
3792
3793         if(mod_active || autocvar__hud_configure)
3794                 mod_alpha = bound(0, (time - mod_change) * 2, 1);
3795         else
3796                 mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
3797
3798         if(mod_alpha)
3799                 HUD_Panel_DrawBg(mod_alpha);
3800
3801         if(panel_bg_padding)
3802         {
3803                 pos += '1 1 0' * panel_bg_padding;
3804                 mySize -= '2 2 0' * panel_bg_padding;
3805         }
3806
3807         // these MUST be ran in order to update mod_active
3808         if(gametype == GAME_KEYHUNT)
3809                 HUD_Mod_KH(pos, mySize);
3810         else if(gametype == GAME_CTF || autocvar__hud_configure)
3811                 HUD_Mod_CTF(pos, mySize); // forcealpha only needed for ctf icons, as only they are shown in config mode
3812         else if(gametype == GAME_NEXBALL)
3813                 HUD_Mod_NexBall(pos, mySize);
3814         else if(gametype == GAME_CTS || gametype == GAME_RACE)
3815                 HUD_Mod_Race(pos, mySize);
3816         else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
3817                 HUD_Mod_CA(pos, mySize);
3818         else if(gametype == GAME_DOMINATION)
3819                 HUD_Mod_Dom(pos, mySize);
3820         else if(gametype == GAME_KEEPAWAY)
3821                 HUD_Mod_Keepaway(pos, mySize);
3822 }
3823
3824 // Draw pressed keys (#11)
3825 //
3826 void HUD_DrawPressedKeys(void)
3827 {
3828         if(!autocvar__hud_configure)
3829         {
3830                 if(!autocvar_hud_panel_pressedkeys) return;
3831                 if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
3832         }
3833         else
3834                 hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
3835
3836
3837         HUD_Panel_UpdateCvars(pressedkeys);
3838         vector pos, mySize;
3839         pos = panel_pos;
3840         mySize = panel_size;
3841
3842         HUD_Panel_DrawBg(1);
3843         if(panel_bg_padding)
3844         {
3845                 pos += '1 1 0' * panel_bg_padding;
3846                 mySize -= '2 2 0' * panel_bg_padding;
3847         }
3848
3849         // force custom aspect
3850         float aspect = autocvar_hud_panel_pressedkeys_aspect;
3851         if(aspect)
3852         {
3853                 vector newSize;
3854                 if(mySize_x/mySize_y > aspect)
3855                 {
3856                         newSize_x = aspect * mySize_y;
3857                         newSize_y = mySize_y;
3858
3859                         pos_x = pos_x + (mySize_x - newSize_x) / 2;
3860                 }
3861                 else
3862                 {
3863                         newSize_y = 1/aspect * mySize_x;
3864                         newSize_x = mySize_x;
3865
3866                         pos_y = pos_y + (mySize_y - newSize_y) / 2;
3867                 }
3868                 mySize = newSize;
3869         }
3870
3871         vector keysize;
3872         keysize = eX * mySize_x * (1/3) + eY * mySize_y * 0.5;
3873         float pressedkeys;
3874         pressedkeys = getstatf(STAT_PRESSED_KEYS);
3875
3876         drawpic_aspect_skin(pos, ((pressedkeys & KEY_CROUCH) ? "key_crouch_inv.tga" : "key_crouch.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3877         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);
3878         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);
3879         pos_y += keysize_y;
3880         drawpic_aspect_skin(pos, ((pressedkeys & KEY_LEFT) ? "key_left_inv.tga" : "key_left.tga"), keysize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
3881         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);
3882         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);
3883 }
3884
3885 // Handle chat as a panel (#12)
3886 //
3887 void HUD_Chat(void)
3888 {
3889         if(!autocvar__hud_configure)
3890         {
3891                 if (!autocvar_hud_panel_chat)
3892                 {
3893                         if (!autocvar_con_chatrect)
3894                                 cvar_set("con_chatrect", "0");
3895                         return;
3896                 }
3897         }
3898         else
3899                 hud_configure_active_panel = HUD_PANEL_CHAT;
3900
3901         HUD_Panel_UpdateCvars(chat);
3902
3903         if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
3904         {
3905                 panel_pos_y = panel_bg_border;
3906                 panel_size_y = vid_conheight - panel_bg_border * 2;
3907                 if(panel_bg == "0") // force a border when maximized
3908                 {
3909                         if(precache_pic(panel_bg) == "") {
3910                                 panel_bg = strcat(hud_skin_path, "/border_default");
3911                                 if(precache_pic(panel_bg) == "") {
3912                                         panel_bg = "gfx/hud/default/border_default";
3913                                 }
3914                         }
3915                 }
3916                 panel_bg_alpha = max(0.75, panel_bg_alpha); // force an alpha of at least 0.75
3917         }
3918
3919         vector pos, mySize;
3920         pos = panel_pos;
3921         mySize = panel_size;
3922
3923         HUD_Panel_DrawBg(1);
3924
3925         if(panel_bg_padding)
3926         {
3927                 pos += '1 1 0' * panel_bg_padding;
3928                 mySize -= '2 2 0' * panel_bg_padding;
3929         }
3930
3931         if (!autocvar_con_chatrect)
3932                 cvar_set("con_chatrect", "1");
3933
3934         cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
3935         cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
3936
3937         cvar_set("con_chatwidth", ftos(mySize_x/vid_conwidth));
3938         cvar_set("con_chat", ftos(floor(mySize_y/autocvar_con_chatsize - 0.5)));
3939
3940         if(autocvar__hud_configure)
3941         {
3942                 vector chatsize;
3943                 chatsize = '1 1 0' * autocvar_con_chatsize;
3944                 cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
3945                 float i, a;
3946                 for(i = 0; i < autocvar_con_chat; ++i)
3947                 {
3948                         if(i == autocvar_con_chat - 1)
3949                                 a = panel_fg_alpha;
3950                         else
3951                                 a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
3952                         drawcolorcodedstring(pos, textShortenToWidth(_("^3Player^7: This is the chat area."), mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
3953                         pos_y += chatsize_y;
3954                 }
3955         }
3956 }
3957
3958 // Engine info panel (#13)
3959 //
3960 float prevfps;
3961 float prevfps_time;
3962 float framecounter;
3963
3964 float frametimeavg;
3965 float frametimeavg1; // 1 frame ago
3966 float frametimeavg2; // 2 frames ago
3967 void HUD_EngineInfo(void)
3968 {
3969         if(!autocvar__hud_configure)
3970         {
3971                 if(!autocvar_hud_panel_engineinfo) return;
3972         }
3973         else
3974                 hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
3975
3976         HUD_Panel_UpdateCvars(engineinfo);
3977         vector pos, mySize;
3978         pos = panel_pos;
3979         mySize = panel_size;
3980
3981         HUD_Panel_DrawBg(1);
3982         if(panel_bg_padding)
3983         {
3984                 pos += '1 1 0' * panel_bg_padding;
3985                 mySize -= '2 2 0' * panel_bg_padding;
3986         }
3987
3988         float currentTime = gettime(GETTIME_REALTIME);
3989         if(cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage"))
3990         {
3991                 float currentframetime = currentTime - prevfps_time;
3992                 frametimeavg = (frametimeavg + frametimeavg1 + frametimeavg2 + currentframetime)/4; // average three frametimes into framecounter for slightly more stable fps readings :P
3993                 frametimeavg2 = frametimeavg1;
3994                 frametimeavg1 = frametimeavg;
3995                 
3996                 float weight;
3997                 weight = cvar("hud_panel_engineinfo_framecounter_exponentialmovingaverage_new_weight");
3998                 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.
3999                 {
4000                         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
4001                                 prevfps = (1/currentframetime);
4002                         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"
4003                 }
4004                 prevfps_time = currentTime;
4005         }
4006         else
4007         {
4008                 framecounter += 1;
4009                 if(currentTime - prevfps_time > autocvar_hud_panel_engineinfo_framecounter_time)
4010                 {
4011                         prevfps = framecounter/(currentTime - prevfps_time);
4012                         framecounter = 0;
4013                         prevfps_time = currentTime;
4014                 }
4015         }
4016
4017         vector color;
4018         color = HUD_Get_Num_Color (prevfps, 100);
4019         drawstring_aspect(pos, sprintf(_("FPS: %.*f"), autocvar_hud_panel_engineinfo_framecounter_decimals, prevfps), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
4020 }
4021
4022 // Info messages panel (#14)
4023 //
4024 #define drawInfoMessage(s)\
4025         if(autocvar_hud_panel_infomessages_flip)\
4026                 o_x = pos_x + mySize_x - stringwidth(s, TRUE, fontsize);\
4027         drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);\
4028         o_y += fontsize_y;
4029 void HUD_InfoMessages(void)
4030 {
4031         if(!autocvar__hud_configure)
4032         {
4033                 if(!autocvar_hud_panel_infomessages) return;
4034         }
4035         else
4036                 hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
4037
4038         HUD_Panel_UpdateCvars(infomessages);
4039         vector pos, mySize;
4040         pos = panel_pos;
4041         mySize = panel_size;
4042
4043         HUD_Panel_DrawBg(1);
4044         if(panel_bg_padding)
4045         {
4046                 pos += '1 1 0' * panel_bg_padding;
4047                 mySize -= '2 2 0' * panel_bg_padding;
4048         }
4049
4050         // always force 5:1 aspect
4051         vector newSize;
4052         if(mySize_x/mySize_y > 5)
4053         {
4054                 newSize_x = 5 * mySize_y;
4055                 newSize_y = mySize_y;
4056
4057                 pos_x = pos_x + (mySize_x - newSize_x) / 2;
4058         }
4059         else
4060         {
4061                 newSize_y = 1/5 * mySize_x;
4062                 newSize_x = mySize_x;
4063
4064                 pos_y = pos_y + (mySize_y - newSize_y) / 2;
4065         }
4066
4067         mySize = newSize;
4068         entity tm;
4069         vector o;
4070         o = pos;
4071
4072         vector fontsize;
4073         fontsize = '0.20 0.20 0' * mySize_y;
4074         
4075         float a;
4076         if(spectatee_status != 0)
4077                 a = 1;
4078         else
4079                 a = panel_fg_alpha;
4080
4081         string s;
4082         if(!autocvar__hud_configure)
4083         {
4084                 if(spectatee_status && !intermission)
4085                 {
4086                         if(spectatee_status == -1)
4087                                 s = _("^1Observing");
4088                         else
4089                                 s = sprintf(_("^1Spectating: ^7%s"), GetPlayerName(spectatee_status - 1));
4090                         drawInfoMessage(s)
4091
4092                         if(spectatee_status == -1)
4093                                 s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
4094                         else
4095                                 s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
4096                         drawInfoMessage(s)
4097
4098                         if(spectatee_status == -1)
4099                                 s = sprintf(_("^1Use ^3%s^1 or ^3%s^1 to change the speed"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
4100                         else
4101                                 s = sprintf(_("^1Press ^3%s^1 to observe"), getcommandkey("secondary fire", "+fire2"));
4102                         drawInfoMessage(s)
4103
4104                         s = sprintf(_("^1Press ^3%s^1 for gamemode info"), getcommandkey("server info", "+show_info"));
4105                         drawInfoMessage(s)
4106
4107                         if(gametype == GAME_ARENA)
4108                                 s = _("^1Wait for your turn to join");
4109                         else if(gametype == GAME_LMS)
4110                         {
4111                                 entity sk;
4112                                 sk = playerslots[player_localentnum - 1];
4113                                 if(sk.(scores[ps_primary]) >= 666)
4114                                         s = _("^1Match has already begun");
4115                                 else if(sk.(scores[ps_primary]) > 0)
4116                                         s = _("^1You have no more lives left");
4117                                 else
4118                                         s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4119                         }
4120                         else
4121                                 s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
4122                         drawInfoMessage(s)
4123
4124                         //show restart countdown:
4125                         if (time < getstatf(STAT_GAMESTARTTIME)) {
4126                                 float countdown;
4127                                 //we need to ceil, otherwise the countdown would be off by .5 when using round()
4128                                 countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
4129                                 s = sprintf(_("^1Game starts in ^3%d^1 seconds"), countdown);
4130                                 drawcolorcodedstring(o, s, fontsize, a, DRAWFLAG_NORMAL);
4131                                 o_y += fontsize_y;
4132                         }
4133                 }
4134                 if(warmup_stage && !intermission)
4135                 {
4136                         s = _("^2Currently in ^1warmup^2 stage!");
4137                         drawInfoMessage(s)
4138                 }
4139
4140                 string blinkcolor;
4141                 if(mod(time, 1) >= 0.5)
4142                         blinkcolor = "^1";
4143                 else
4144                         blinkcolor = "^3";
4145
4146                 if(ready_waiting && !intermission && !spectatee_status)
4147                 {
4148                         if(ready_waiting_for_me)
4149                         {
4150                                 if(warmup_stage)
4151                                         s = sprintf(_("%sPress ^3%s%s to end warmup"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4152                                 else
4153                                         s = sprintf(_("%sPress ^3%s%s once you are ready"), blinkcolor, getcommandkey("ready", "ready"), blinkcolor);
4154                         }
4155                         else
4156                         {
4157                                 if(warmup_stage)
4158                                         s = _("^2Waiting for others to ready up to end warmup...");
4159                                 else
4160                                         s = _("^2Waiting for others to ready up...");
4161                         }
4162                         drawInfoMessage(s)
4163                 }
4164                 else if(warmup_stage && !intermission && !spectatee_status)
4165                 {
4166                         s = sprintf(_("^2Press ^3%s^2 to end warmup"), getcommandkey("ready", "ready"));
4167                         drawInfoMessage(s)
4168                 }
4169
4170                 if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
4171                 {
4172                         float ts_min, ts_max;
4173                         tm = teams.sort_next;
4174                         if (tm)
4175                         {
4176                                 for(; tm.sort_next; tm = tm.sort_next)
4177                                 {
4178                                         if(!tm.team_size || tm.team == COLOR_SPECTATOR)
4179                                                 continue;
4180                                         if(!ts_min) ts_min = tm.team_size;
4181                                         else ts_min = min(ts_min, tm.team_size);
4182                                         if(!ts_max) ts_max = tm.team_size;
4183                                         else ts_max = max(ts_max, tm.team_size);
4184                                 }
4185                                 if ((ts_max - ts_min) > 1)
4186                                 {
4187                                         s = strcat(blinkcolor, _("Teamnumbers are unbalanced!"));
4188                                         tm = GetTeam(myteam, false);
4189                                         if (tm)
4190                                         if (tm.team != COLOR_SPECTATOR)
4191                                         if (tm.team_size == ts_max)
4192                                                 s = strcat(s, sprintf(_(" Press ^3%s%s to adjust"), getcommandkey("team menu", "menu_showteamselect"), blinkcolor));
4193                                         drawInfoMessage(s)
4194                                 }
4195                         }
4196                 }
4197         }
4198         else 
4199         {
4200                 s = _("^7Press ^3ESC ^7to show HUD options.");
4201                 drawInfoMessage(s)
4202                 s = _("^3Doubleclick ^7a panel for panel-specific options.");
4203                 drawInfoMessage(s)
4204                 s = _("^3CTRL ^7to disable collision testing, ^3SHIFT ^7and");
4205                 drawInfoMessage(s)
4206                 s = _("^3ALT ^7+ ^3ARROW KEYS ^7for fine adjustments.");
4207                 drawInfoMessage(s)
4208         }
4209 }
4210
4211 // ShowNames (#15)
4212 //
4213 float shownames_alpha;
4214 void HUD_ShowNames(void)
4215 {
4216     if(shownames_time < time && shownames_alpha == 0 && !autocvar__hud_configure)
4217         return;
4218
4219     if(autocvar__hud_configure)
4220     {
4221         shownames_alpha = 1;
4222     }
4223     else
4224     {
4225         if(shownames_time < time)
4226             shownames_alpha = bound(0, shownames_alpha - 2 * frametime, 1);
4227         else
4228             shownames_alpha = bound(0, shownames_alpha + 4 * frametime, 1);
4229     }
4230
4231         if(!autocvar_hud_panel_shownames && !autocvar__hud_configure)
4232                 return;
4233
4234         hud_configure_active_panel = HUD_PANEL_SHOWNAMES;
4235         HUD_Panel_UpdateCvars(shownames);
4236     panel_fg_alpha *= shownames_alpha;
4237         vector myPos, mySize;
4238         myPos = panel_pos;
4239         mySize = panel_size;
4240
4241         HUD_Panel_DrawBg(shownames_alpha);
4242         if(panel_bg_padding)
4243         {
4244                 myPos += '1 1 0' * panel_bg_padding;
4245                 mySize -= '2 2 0' * panel_bg_padding;
4246         }
4247
4248     vector iconpos, iconsize;
4249     vector namepos, namesize;
4250     if(mySize_x/mySize_y > 6)
4251     {
4252         iconpos = myPos;
4253         iconsize = eX * 2 * mySize_y + eY * mySize_y;
4254
4255         namepos = myPos + eX * 2 * mySize_y;
4256         namesize = eX * mySize_x - eX * 2 * mySize_y + eY * mySize_y;
4257     }
4258     else
4259     {
4260         iconpos = myPos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_y;
4261         iconsize = eX * mySize_y + eY * 0.5 * mySize_y;
4262
4263         namepos = myPos + eY * 0.5 * mySize_y;
4264         namesize = eX * mySize_x + eY * 0.5 * mySize_y;
4265     }
4266
4267     if(shownames_health > 0) // otherwise player is an enemy
4268     {
4269         // "ghost" backgrounds
4270         drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
4271         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
4272
4273         drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, shownames_health/autocvar_hud_panel_healtharmor_maxhealth), vid_conwidth, myPos_y + iconsize_y);
4274         drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4275
4276         drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, shownames_armor/autocvar_hud_panel_healtharmor_maxarmor), vid_conwidth, myPos_y + iconsize_y);
4277         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4278         drawresetcliparea();
4279     }
4280     else
4281     {
4282         drawpic_aspect_skin(iconpos, "health_unknown", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
4283         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor_unknown", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
4284     }
4285
4286     if(autocvar__hud_configure)
4287         drawcolorcodedstring_aspect(namepos, "Player1234", namesize, panel_fg_alpha, DRAWFLAG_NORMAL);
4288     else
4289         drawcolorcodedstring_aspect(namepos, shownames_netname, namesize, panel_fg_alpha, DRAWFLAG_NORMAL);
4290 }
4291
4292 // Physics panel (#16)
4293 //
4294 vector acc_prevspeed;
4295 float acc_prevtime, acc_avg, top_speed, top_speed_time;
4296 void HUD_Physics(void)
4297 {
4298         if(!autocvar__hud_configure)
4299         {
4300                 if(!autocvar_hud_panel_physics) return;
4301                 if(spectatee_status == -1 && autocvar_hud_panel_physics < 2) return;
4302         }
4303         else
4304                 hud_configure_active_panel = HUD_PANEL_PHYSICS;
4305
4306         HUD_Panel_UpdateCvars(physics);
4307
4308         HUD_Panel_DrawBg(1);
4309         if(panel_bg_padding)
4310         {
4311                 panel_pos += '1 1 0' * panel_bg_padding;
4312                 panel_size -= '2 2 0' * panel_bg_padding;
4313         }
4314
4315         //compute speed
4316         float speed, conversion_factor;
4317         string unit;
4318
4319         switch(autocvar_hud_panel_physics_speed_unit)
4320         {
4321                 default:
4322                 case 1:
4323                         unit = _(" qu/s");
4324                         conversion_factor = 1.0;
4325                         break;
4326                 case 2:
4327                         unit = _(" m/s");
4328                         conversion_factor = 0.0254;
4329                         break;
4330                 case 3:
4331                         unit = _(" km/h");
4332                         conversion_factor = 0.0254 * 3.6;
4333                         break;
4334                 case 4:
4335                         unit = _(" mph");
4336                         conversion_factor = 0.0254 * 3.6 * 0.6213711922;
4337                         break;
4338                 case 5:
4339                         unit = _(" knots");
4340                         conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
4341                         break;
4342         }
4343
4344         float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
4345         if (autocvar__hud_configure)
4346                 speed = floor( max_speed * 0.65 + 0.5 );
4347         else if(autocvar_hud_panel_physics_speed_vertical)
4348                 speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
4349         else
4350                 speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
4351
4352         //compute acceleration
4353         float acceleration, f;
4354         if (autocvar__hud_configure)
4355                 acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
4356         else
4357         {
4358                 // 1 m/s = 0.0254 qu/s; 1 g = 9.80665 m/s^2
4359                 f = time - acc_prevtime;
4360                 if(autocvar_hud_panel_physics_acceleration_vertical)
4361                         acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f) * (0.0254 / 9.80665);
4362                 else
4363                         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);
4364                 acc_prevspeed = pmove_vel;
4365                 acc_prevtime = time;
4366
4367                 f = bound(0, f * 10, 1);
4368                 acc_avg = acc_avg * (1 - f) + acceleration * f;
4369         }
4370
4371         //compute layout
4372         float panel_ar = panel_size_x/panel_size_y;
4373         vector speed_offset, acceleration_offset;
4374         if (panel_ar >= 5)
4375         {
4376                 panel_size_x *= 0.5;
4377                 if (autocvar_hud_panel_physics_flip)
4378                         speed_offset_x = panel_size_x;
4379                 else
4380                         acceleration_offset_x = panel_size_x;
4381         }
4382         else
4383         {
4384                 panel_size_y *= 0.5;
4385                 if (autocvar_hud_panel_physics_flip)
4386                         speed_offset_y = panel_size_y;
4387                 else
4388                         acceleration_offset_y = panel_size_y;
4389         }
4390         float speed_baralign, acceleration_baralign;
4391         if (autocvar_hud_panel_physics_baralign == 1)
4392                 acceleration_baralign = speed_baralign = 1;
4393     else if(autocvar_hud_panel_physics_baralign == 4)
4394                 acceleration_baralign = speed_baralign = 2;
4395         else if (autocvar_hud_panel_physics_flip)
4396         {
4397                 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
4398                 speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
4399         }
4400         else
4401         {
4402                 speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
4403                 acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
4404         }
4405         if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
4406                 acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
4407
4408         //draw speed
4409         if(speed)
4410         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4411         {
4412                 HUD_Panel_GetProgressBarColor(speed);
4413                 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);
4414         }
4415         vector tmp_offset, tmp_size;
4416         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4417         {
4418                 tmp_size_x = panel_size_x * 0.75;
4419                 tmp_size_y = panel_size_y;
4420                 if (speed_baralign)
4421                         tmp_offset_x = panel_size_x - tmp_size_x;
4422                 //else
4423                         //tmp_offset_x = 0;
4424                 drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4425
4426                 //draw speed unit
4427                 if (speed_baralign)
4428                         tmp_offset_x = 0;
4429                 else
4430                         tmp_offset_x = tmp_size_x;
4431                 if (autocvar_hud_panel_physics_speed_unit_show)
4432                 {
4433                         //tmp_offset_y = 0;
4434                         tmp_size_x = panel_size_x * (1 - 0.75);
4435                         tmp_size_y = panel_size_y * 0.4;
4436                         drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4437                 }
4438         }
4439
4440         //compute and draw top speed
4441         if (autocvar_hud_panel_physics_topspeed)
4442         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
4443         {
4444                 if (autocvar__hud_configure)
4445                 {
4446                         top_speed = floor( max_speed * 0.75 + 0.5 );
4447                         f = 1;
4448                 }
4449                 else
4450                 {
4451                         if (speed >= top_speed)
4452                         {
4453                                 top_speed = speed;
4454                                 top_speed_time = time;
4455                         }
4456                         if (top_speed != 0)
4457                         {
4458                                 f = max(1, autocvar_hud_panel_physics_topspeed_time);
4459                                 // divide by f to make it start from 1
4460                                 f = cos( ((time - top_speed_time) / f) * PI/2 );
4461                         }
4462             else //hide top speed 0, it would be stupid
4463                                 f = 0;
4464                 }
4465                 if (f > 0)
4466                 {
4467                         //top speed progressbar peak
4468                         if(speed < top_speed)
4469                         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
4470                         {
4471                                 float peak_offset_x;
4472                                 vector peak_size;
4473                                 if (speed_baralign == 0)
4474                                         peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
4475                 else if (speed_baralign == 1)
4476                                         peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
4477                 else if (speed_baralign == 2)
4478                     peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5;
4479                                 //if speed is not 0 the speed progressbar already fetched the color
4480                                 if (speed == 0)
4481                                         HUD_Panel_GetProgressBarColor(speed);
4482                                 peak_size_x = floor(panel_size_x * 0.01 + 1.5);
4483                 peak_size_y = panel_size_y;
4484                 if (speed_baralign == 2) // draw two peaks, on both sides
4485                 {
4486                     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);
4487                     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);
4488                 }
4489                 else
4490                     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);
4491                         }
4492
4493                         //top speed
4494                         tmp_offset_y = panel_size_y * 0.4;
4495                         tmp_size_x = panel_size_x * (1 - 0.75);
4496                         tmp_size_y = panel_size_y - tmp_offset_y;
4497                         drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
4498                 }
4499                 else
4500                         top_speed = 0;
4501         }
4502
4503         //draw acceleration
4504         if(acceleration)
4505         if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 3)
4506         {
4507                 if (acceleration < 0)
4508                         HUD_Panel_GetProgressBarColor(acceleration_neg);
4509                 else
4510                         HUD_Panel_GetProgressBarColor(acceleration);
4511                 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);
4512         }
4513         if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 3)
4514                 drawstring_aspect(panel_pos + acceleration_offset, strcat(ftos_decimals(acceleration, 2), "g"), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
4515 }
4516
4517 /*
4518 ==================
4519 Main HUD system
4520 ==================
4521 */
4522
4523 void HUD_Reset (void)
4524 {
4525         // reset gametype specific icons
4526         if(gametype == GAME_KEYHUNT)
4527                 HUD_Mod_KH_Reset();
4528         else if(gametype == GAME_CTF)
4529                 HUD_Mod_CTF_Reset();
4530 }
4531
4532 #define HUD_DrawPanel(id)\
4533 switch (id) {\
4534         case (HUD_PANEL_RADAR):\
4535                 HUD_Radar(); break;\
4536         case (HUD_PANEL_WEAPONS):\
4537                 HUD_Weapons(); break;\
4538         case (HUD_PANEL_AMMO):\
4539                 HUD_Ammo(); break;\
4540         case (HUD_PANEL_POWERUPS):\
4541                 HUD_Powerups(); break;\
4542         case (HUD_PANEL_HEALTHARMOR):\
4543                 HUD_HealthArmor(); break;\
4544         case (HUD_PANEL_NOTIFY):\
4545                 HUD_Notify(); break;\
4546         case (HUD_PANEL_TIMER):\
4547                 HUD_Timer(); break;\
4548         case (HUD_PANEL_SCORE):\
4549                 HUD_Score(); break;\
4550         case (HUD_PANEL_RACETIMER):\
4551                 HUD_RaceTimer(); break;\
4552         case (HUD_PANEL_VOTE):\
4553                 HUD_VoteWindow(); break;\
4554         case (HUD_PANEL_MODICONS):\
4555                 HUD_ModIcons(); break;\
4556         case (HUD_PANEL_PRESSEDKEYS):\
4557                 HUD_DrawPressedKeys(); break;\
4558         case (HUD_PANEL_CHAT):\
4559                 HUD_Chat(); break;\
4560         case (HUD_PANEL_ENGINEINFO):\
4561                 HUD_EngineInfo(); break;\
4562         case (HUD_PANEL_INFOMESSAGES):\
4563                  HUD_InfoMessages(); break;\
4564         case (HUD_PANEL_PHYSICS):\
4565                  HUD_Physics(); break;\
4566         case (HUD_PANEL_SHOWNAMES):\
4567                  HUD_ShowNames(); break;\
4568 } ENDS_WITH_CURLY_BRACE
4569
4570 void HUD_Main (void)
4571 {
4572         float i;
4573         // global hud alpha fade
4574         if(menu_enabled == 1)
4575                 hud_fade_alpha = 1;
4576         else
4577                 hud_fade_alpha = (1 - autocvar__menu_alpha);
4578
4579         if(scoreboard_fade_alpha)
4580                 hud_fade_alpha = (1 - scoreboard_fade_alpha);
4581
4582         if(intermission == 2) // no hud during mapvote
4583                 hud_fade_alpha = 0;
4584         else if(autocvar__menu_alpha == 0 && scoreboard_fade_alpha == 0)
4585                 hud_fade_alpha = 1;
4586
4587         if(!autocvar__hud_configure && !hud_fade_alpha)
4588                 return;
4589
4590         // Drawing stuff
4591         if (hud_skin_path != autocvar_hud_skin)
4592         {
4593                 if (hud_skin_path)
4594                         strunzone(hud_skin_path);
4595                 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
4596         }
4597
4598         // HUD configure visible grid
4599         if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
4600         {
4601                 hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
4602                 hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
4603                 hud_configure_realGridSize_x = hud_configure_gridSize_x * vid_conwidth;
4604                 hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
4605                 // x-axis
4606                 for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
4607                         drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4608                 // y-axis
4609                 for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
4610                         drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
4611         }
4612
4613     current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum;
4614
4615         // draw the dock
4616         if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
4617         {
4618                 float f;
4619                 vector color;
4620                 float hud_dock_color_team = autocvar_hud_dock_color_team;
4621                 if((teamplay) && hud_dock_color_team) {
4622                         f = stof(getplayerkey(current_player - 1, "colors"));
4623                         color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
4624                 }
4625                 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
4626                         color = '1 0 0' * hud_dock_color_team;
4627                 }
4628                 else
4629                 {
4630                         string hud_dock_color = autocvar_hud_dock_color;
4631                         if(hud_dock_color == "shirt") {
4632                                 f = stof(getplayerkey(current_player - 1, "colors"));
4633                                 color = colormapPaletteColor(floor(f / 16), 0);
4634                         }
4635                         else if(hud_dock_color == "pants") {
4636                                 f = stof(getplayerkey(current_player - 1, "colors"));
4637                                 color = colormapPaletteColor(mod(f, 16), 1);
4638                         }
4639                         else
4640                                 color = stov(hud_dock_color);
4641                 }
4642
4643                 string pic;
4644                 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
4645                 if(precache_pic(pic) == "") {
4646                         pic = strcat(hud_skin_path, "/dock_medium");
4647                         if(precache_pic(pic) == "") {
4648                                 pic = "gfx/hud/default/dock_medium";
4649                         }
4650                 }
4651                 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...
4652         }
4653
4654         // cache the panel order into the panel_order array
4655         if(autocvar__hud_panelorder != hud_panelorder_prev) {
4656                 for(i = 0; i < HUD_PANEL_NUM; ++i)
4657                         panel_order[i] = -1;
4658                 string s;
4659                 float p_num, warning;
4660                 float argc = tokenize_console(autocvar__hud_panelorder);
4661                 if (argc > HUD_PANEL_NUM)
4662                         warning = true;
4663                 //first detect wrong/missing panel numbers
4664                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4665                         p_num = stof(argv(i));
4666                         if (p_num >= 0 && p_num < HUD_PANEL_NUM) { //correct panel number?
4667                                 if (panel_order[p_num] == -1) //found for the first time?
4668                                         s = strcat(s, ftos(p_num), " ");
4669                                 panel_order[p_num] = 1; //mark as found
4670                         }
4671                         else
4672                                 warning = true;
4673                 }
4674                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4675                         if (panel_order[i] == -1) {
4676                                 warning = true;
4677                                 s = strcat(s, ftos(i), " "); //add missing panel number
4678                         }
4679                 }
4680                 if (warning)
4681                         print(_("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n"));
4682
4683                 cvar_set("_hud_panelorder", s);
4684                 if(hud_panelorder_prev)
4685                         strunzone(hud_panelorder_prev);
4686                 hud_panelorder_prev = strzone(s);
4687
4688                 //now properly set panel_order
4689                 tokenize_console(s);
4690                 for(i = 0; i < HUD_PANEL_NUM; ++i) {
4691                         panel_order[i] = stof(argv(i));
4692                 }
4693         }
4694
4695         // draw panels in order specified by panel_order array
4696         for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
4697                 if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
4698                         HUD_DrawPanel(panel_order[i]);
4699         }
4700
4701         // draw chat panel on top if it is maximized
4702         if(autocvar__con_chat_maximized)
4703                 HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
4704
4705         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)
4706                 localcmd("cmd selectteam auto; cmd join\n");
4707
4708         if(autocvar__hud_configure && tab_panel != -1)
4709         {
4710                 HUD_Panel_UpdatePosSizeForId(tab_panel)
4711                 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .2, DRAWFLAG_NORMAL);
4712         }
4713
4714         hud_configure_prev = autocvar__hud_configure;
4715
4716         if (!autocvar__hud_configure) // hud config mode disabled, enable normal alpha stuff again
4717                 if (menu_enabled)
4718                         menu_enabled = 0;
4719 }