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