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