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