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