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