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