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