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