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