dda9f6069ed64ba17fb9764801f17b38b7b59916
[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 // TODO: make a default skin, and fallback to these!
101 void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) {
102         drawpic_aspect(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag);
103 }
104
105 // TODO: aspect!
106 void drawpic_skin_expanding(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
107         return;
108         //drawpic_aspect_expanding(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
109 }
110
111 void drawpic_skin_expanding_two(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) {
112         return;
113         //drawpic_aspect_expanding_two(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, rgb, alpha, flag, fadelerp);
114 }
115
116 // return HUD background color
117 vector HUD_GetBgColor()
118 {
119         vector color;
120         if (teamplay)
121                 GetTeamRGB(myteam) * hud_color_bg_team;
122         else {
123                 // allow custom HUD colors in non-teamgames
124                 color_x = cvar("hud_color_bg_r");
125                 color_y = cvar("hud_color_bg_g");
126                 color_z = cvar("hud_color_bg_b");
127         }
128         return color;
129 }
130
131 // return accuracy text color
132 vector HUD_AccuracyColor(float accuracy)
133 {
134         vector rgb;
135         float yellow_accuracy = cvar("hud_weaponicons_accuracy_yellow"); // value at which this function returns yellow
136         if(accuracy >= 100) {
137                 rgb_x = 0;
138                 rgb_y = 1;
139         }
140         else if(accuracy > yellow_accuracy) {
141                 rgb_x = 1 - (accuracy-yellow_accuracy)/(100-yellow_accuracy); // red value between 1 -> 0
142                 rgb_y = 1;
143         }
144         else {
145                 rgb_x = 1;
146                 rgb_y = accuracy/yellow_accuracy; // green value between 0 -> 1
147         }
148         rgb_z = 0;
149         return rgb;
150 }
151
152 vector HUD_Get_Num_Color (float x, float maxvalue)
153 {
154         vector color;
155         if(x > maxvalue) {
156                 color_x = 0;
157                 color_y = 1;
158                 color_z = 0;
159         }
160         else if(x > maxvalue * 0.75) {
161                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
162                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
163                 color_z = 0;
164         }
165         else if(x > maxvalue * 0.5) {
166                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
167                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
168                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
169         }
170         else if(x > maxvalue * 0.25) {
171                 color_x = 1;
172                 color_y = 1;
173                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
174         }
175         else if(x > maxvalue * 0.1) {
176                 color_x = 1;
177                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
178                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
179         }
180         else {
181                 color_x = 1;
182                 color_y = 0;
183                 color_z = 0;
184         }
185         return color;
186 }
187
188 float stringwidth_colors(string s, vector theSize)
189 {
190         return stringwidth(s, TRUE, theSize);
191 }
192
193 float stringwidth_nocolors(string s, vector theSize)
194 {
195         return stringwidth(s, FALSE, theSize);
196 }
197
198 #define CENTERPRINT_MAX_LINES 30
199 string centerprint_messages[CENTERPRINT_MAX_LINES];
200 float centerprint_width[CENTERPRINT_MAX_LINES];
201 vector centerprint_start;
202 float centerprint_expire;
203 float centerprint_num;
204 float centerprint_offset_hint;
205 vector centerprint_fontsize;
206
207 void centerprint(string strMessage)
208 {
209         float i, j, n, hcount;
210         string s;
211
212         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
213
214         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
215
216         if(cvar("scr_centertime") <= 0)
217                 return;
218
219         if(strMessage == "")
220                 return;
221
222         // strip trailing newlines
223         j = strlen(strMessage) - 1;
224         while(substring(strMessage, j, 1) == "\n" && j >= 0)
225                 j = j - 1;
226         strMessage = substring(strMessage, 0, j + 1);
227
228         if(strMessage == "")
229                 return;
230
231         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
232         j = 0;
233         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
234                 j = j + 1;
235         strMessage = substring(strMessage, j, strlen(strMessage) - j);
236         centerprint_offset_hint = j;
237
238         if(strMessage == "")
239                 return;
240
241         // if we get here, we have a message. Initialize its height.
242         centerprint_num = 0;
243
244         n = tokenizebyseparator(strMessage, "\n");
245         i = hcount = 0;
246         for(j = 0; j < n; ++j)
247         {
248                 getWrappedLine_remaining = argv(j);
249                 while(getWrappedLine_remaining)
250                 {
251                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
252                         if(centerprint_messages[i])
253                                 strunzone(centerprint_messages[i]);
254                         centerprint_messages[i] = strzone(s);
255                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
256                         ++i;
257
258                         // half height for empty lines looks better
259                         if(s == "")
260                                 hcount += 0.5;
261                         else
262                                 hcount += 1;
263
264                         if(i >= CENTERPRINT_MAX_LINES)
265                                 break;
266                 }
267         }
268
269         float h, havail;
270         h = centerprint_fontsize_y*hcount;
271
272         havail = vid_conheight;
273         if(cvar("con_chatpos") < 0)
274                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
275         if(havail > vid_conheight - 70)
276                 havail = vid_conheight - 70; // avoid overlapping HUD
277
278         centerprint_start_x = 0;
279
280 #if 0
281         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
282
283         // here, the centerprint would cover the crosshair. REALLY BAD.
284         forbiddenmin = vid_conheight * 0.5 - h - 16;
285         forbiddenmax = vid_conheight * 0.5 + 16;
286
287         allowedmin = scoreboard_bottom;
288         allowedmax = havail - h;
289         preferred = (havail - h)/2;
290
291
292         // possible orderings (total: 4! / 4 = 6)
293         //  allowedmin allowedmax forbiddenmin forbiddenmax
294         //  forbiddenmin forbiddenmax allowedmin allowedmax
295         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
296         {
297                 // forbidden doesn't matter in this case
298                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
299         }
300         //  allowedmin forbiddenmin allowedmax forbiddenmax
301         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
302         {
303                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
304         }
305         //  allowedmin forbiddenmin forbiddenmax allowedmax
306         else if(allowedmin < forbiddenmin)
307         {
308                 // make sure the forbidden zone is not covered
309                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
310                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
311                 else
312                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
313         }
314         //  forbiddenmin allowedmin allowedmax forbiddenmax
315         else if(allowedmax < forbiddenmax)
316         {
317                 // it's better to leave the allowed zone (overlap with scoreboard) than
318                 // to cover the forbidden zone (crosshair)
319                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
320                         centerprint_start_y = forbiddenmax;
321                 else
322                         centerprint_start_y = forbiddenmin;
323         }
324         //  forbiddenmin allowedmin forbiddenmax allowedmax
325         else
326         {
327                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
328         }
329 #else
330         centerprint_start_y =
331                 min(
332                         max(
333                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
334                                 (havail - h)/2
335                         ),
336                         havail - h
337                 );
338 #endif
339
340         centerprint_num = i;
341         centerprint_expire = time + cvar("scr_centertime");
342 }
343
344 void HUD_DrawCenterPrint (void)
345 {
346         float i;
347         vector pos;
348         string ts;
349         float a;
350
351         //if(time > centerprint_expire)
352         //      return;
353
354         //a = bound(0, 1 - 2 * (time - centerprint_expire), 1);
355         a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
356         //sz = 1.2 / (a + 0.2);
357
358         if(a <= 0)
359                 return;
360
361         pos = centerprint_start;
362         for (i=0; i<centerprint_num; i = i + 1)
363         {
364                 pos_x = (vid_conwidth - centerprint_width[i]) * 0.5;
365                 ts = centerprint_messages[i];
366                 if (ts != "")
367                 {
368                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
369                         drawcolorcodedstring(pos, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
370                         //  - '0 0.5 0' * (sz - 1) * centerprint_fontsize_x - '0.5 0 0' * (sz - 1) * centerprint_width[i] * centerprint_fontsize_y, centerprint_fontsize * sz
371                         pos_y = pos_y + centerprint_fontsize_y;
372                 }
373                 else
374                         // half height for empty lines looks better
375                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
376         }
377 }
378
379 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
380 {
381         position_x -= 2 / 3 * strlen(text) * scale_x;
382         drawstring(position, text, scale, rgb, alpha, flag);
383 }
384
385 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
386 {
387         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
388         drawstring(position, text, scale, rgb, alpha, flag);
389 }
390
391 // return the string of the given race place
392 string race_PlaceName(float pos) {
393         if(pos == 1)
394                 return "1st";
395         else if(pos == 2)
396                 return "2nd";
397         else if(pos == 3)
398                 return "3rd";
399         else
400                 return strcat(ftos(pos), "th");
401 }
402
403 // return the string of the onscreen race timer
404 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
405 {
406         string col;
407         string timestr;
408         string cpname;
409         string lapstr;
410         lapstr = "";
411
412         if(histime == 0) // goal hit
413         {
414                 if(mytime > 0)
415                 {
416                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
417                         col = "^1";
418                 }
419                 else if(mytime == 0)
420                 {
421                         timestr = "+0.0";
422                         col = "^3";
423                 }
424                 else
425                 {
426                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
427                         col = "^2";
428                 }
429
430                 if(lapdelta > 0)
431                 {
432                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
433                         col = "^2";
434                 }
435                 else if(lapdelta < 0)
436                 {
437                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
438                         col = "^1";
439                 }
440         }
441         else if(histime > 0) // anticipation
442         {
443                 if(mytime >= histime)
444                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
445                 else
446                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
447                 col = "^3";
448         }
449         else
450                 col = "^7";
451
452         if(cp == 254)
453                 cpname = "Start line";
454         else if(cp == 255)
455                 cpname = "Finish line";
456         else if(cp)
457                 cpname = strcat("Intermediate ", ftos(cp));
458         else
459                 cpname = "Finish line";
460
461         if(histime < 0)
462                 return strcat(col, cpname);
463         else if(hisname == "")
464                 return strcat(col, cpname, " (", timestr, ")");
465         else
466                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
467 }
468
469 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
470 float race_CheckName(string net_name) {
471         float i;
472         for (i=RANKINGS_CNT-1;i>=0;--i)
473                 if(grecordholder[i] == net_name)
474                         return i+1;
475         return 0;
476 }
477
478 /*
479 ==================
480 HUD panels
481 ==================
482 */
483
484 // Save the config
485 void HUD_Panel_ExportCfg(string cfgname)
486 {
487         float fh;
488         fh = fopen(strcat("hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg"), FILE_WRITE);
489         if(fh >= 0)
490         {
491                 fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
492                 fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
493                 fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
494                 fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
495                 fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
496                 fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
497                 fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
498                 fputs(fh, strcat("seta hud_fg_alpha \"", cvar_string("hud_fg_alpha"), "\"", "\n"));
499                 fputs(fh, "\n");
500
501                 fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
502                 fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
503                 fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
504                 fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
505                 fputs(fh, "\n");
506
507                 fputs(fh, strcat("seta hud_progressbar_alpha ", ftos(cvar("hud_progressbar_alpha")), "\n"));
508                 fputs(fh, strcat("seta hud_progressbar_strength_color \"", cvar_string("hud_progressbar_strength_color"), "\"", "\n"));
509                 fputs(fh, strcat("seta hud_progressbar_shield_color \"", cvar_string("hud_progressbar_shield_color"), "\"", "\n"));
510                 fputs(fh, strcat("seta hud_progressbar_health_color \"", cvar_string("hud_progressbar_health_color"), "\"", "\n"));
511                 fputs(fh, strcat("seta hud_progressbar_armor_color \"", cvar_string("hud_progressbar_armor_color"), "\"", "\n"));
512                 fputs(fh, strcat("seta hud_progressbar_fuel_color \"", cvar_string("hud_progressbar_fuel_color"), "\"", "\n"));
513                 fputs(fh, strcat("seta hud_progressbar_nexball_color \"", cvar_string("hud_progressbar_nexball_color"), "\"", "\n"));
514                 fputs(fh, "\n");
515
516                 // common cvars for all panels
517                 float i;
518                 for (i = 0; i < HUD_PANEL_NUM; ++i)
519                 {
520                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), " ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i)))), "\n"));
521                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_pos \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_pos")), "\"", "\n"));
522                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
523                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
524                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
525                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
526                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
527                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
528                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
529                         switch(i) {
530                                 case 0:
531                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
532                                         break;
533                                 case 1:
534                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
535                                         break;
536                                 case 2:
537                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
538                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
539                                         break;
540                                 case 3:
541                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
542                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
543                                         break;
544                                 case 4:
545                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
546                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_info_top ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_info_top"))), "\n"));
547                                         break;
548                                 case 6:
549                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_foreground_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_foreground_alpha"))), "\n"));
550                                 case 9:
551                                         fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
552                                         break;
553                         }
554                         fputs(fh, "\n");
555                 }
556
557                 print("^2Successfully exported to hud_", cvar_string("hud_skin"), "_", cfgname, ".cfg! (Note: It's saved in data/data/)\n");
558         }
559         fclose(fh);
560 }
561
562 // return active status of panel
563 float HUD_Panel_CheckActive(float id)
564 {
565         if (cvar_or(strcat("hud_", HUD_Panel_GetName(id)), 1))
566                 return 1;
567         return 0;
568 }
569
570 // return size of given panel
571 vector HUD_Panel_GetSize(float id)
572 {
573         vector mySize;
574         mySize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
575
576         mySize = eX * mySize_x * vid_conwidth + eY * mySize_y * vid_conheight;
577
578         if(disable_menu_alphacheck == 2 && id == highlightedPanel)
579         {
580                 vector menu_enable_maxsize, menu_enable_size;
581                 menu_enable_maxsize = '0 0 0'; // shut up FTEQCC
582                 menu_enable_maxsize_x = 0.3 * vid_conwidth;
583                 menu_enable_maxsize_y = 0.18 * vid_conheight;
584                 if(mySize_x > mySize_y)
585                 {
586                         if(mySize_y > menu_enable_maxsize_y)
587                         {
588                                 menu_enable_size_y = menu_enable_maxsize_y;
589                                 menu_enable_size_x = mySize_x * (menu_enable_maxsize_y/mySize_y);
590                                 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
591                         }
592                 }
593                 else
594                 {
595                         if(mySize_x > menu_enable_maxsize_x)
596                         {
597                                 menu_enable_size_x = menu_enable_maxsize_x;
598                                 menu_enable_size_y = mySize_y * (menu_enable_maxsize_x/mySize_x);
599                                 mySize = (1 - cvar("_menu_alpha")) * mySize + (cvar("_menu_alpha")) * menu_enable_size;
600                         }
601                 }
602         }
603         return mySize;
604 }
605
606 // return pos of given panel
607 vector HUD_Panel_GetPos(float id)
608 {
609         vector pos;
610         pos = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_pos")));
611
612         pos = eX * pos_x * vid_conwidth + eY * pos_y * vid_conheight;
613
614         if(disable_menu_alphacheck == 2 && id == highlightedPanel)
615         {
616                 vector mySize, menu_enable_panelpos;
617                 mySize = HUD_Panel_GetSize(id);
618                 if(mySize_x > mySize_y)
619                         menu_enable_panelpos = eX * 0.5 * vid_conwidth - eX * 0.5 * mySize_x + eY * 0.82 * vid_conheight;
620                 else
621                         menu_enable_panelpos = eY * 0.5 * vid_conheight - eY * 0.5 * mySize_y + eX * 0.7 * vid_conwidth;
622                 pos = (1 - cvar("_menu_alpha")) * pos + (cvar("_menu_alpha")) * menu_enable_panelpos;
623         }
624         return pos;
625 }
626
627 float HUD_Panel_GetBorder(float id)
628 {
629         string border;
630         border = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_border"));
631         if(border == "")
632                 border = cvar_string("hud_bg_border");
633         return stof(border);
634 }
635
636 vector HUD_Panel_GetColor(float id)
637 {
638         float f;
639         vector color_vec;
640         string color;
641
642         // fetch per-panel color
643         if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
644                 f = stof(getplayerkey(self.sv_entnum, "colors"));
645                 color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
646         }
647         else
648                 color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
649         color_vec = stov(color);
650
651         if(color == "") { // fetch default color
652                 color = cvar_string("hud_bg_color");
653                 color_vec = stov(color);
654                 if(teamplay && cvar(strcat("hud_bg_color_team"))) {
655                         f = stof(getplayerkey(self.sv_entnum, "colors"));
656                         color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
657                 }
658                 else if(color == "shirt") {
659                         f = stof(getplayerkey(self.sv_entnum, "colors"));
660                         color_vec = colormapPaletteColor(floor(f / 16), 0);
661                 }
662                 else if(color == "pants") {
663                         f = stof(getplayerkey(self.sv_entnum, "colors"));
664                         color_vec = colormapPaletteColor(mod(f, 16), 1);
665                 }
666         }
667         else if(color == "shirt") {
668                 f = stof(getplayerkey(self.sv_entnum, "colors"));
669                 color_vec = colormapPaletteColor(floor(f / 16), 0);
670         }
671         else if(color == "pants") {
672                 f = stof(getplayerkey(self.sv_entnum, "colors"));
673                 color_vec = colormapPaletteColor(mod(f, 16), 1);
674         }
675         return color_vec;
676 }
677
678 vector HUD_Panel_Dock_GetColor(void)
679 {
680         float f;
681         vector color_vec;
682         string color;
683         color = cvar_string("hud_dock_color");
684         color_vec = stov(color);
685         if(teamplay && cvar(strcat("hud_dock_color_team"))) {
686                 f = stof(getplayerkey(self.sv_entnum, "colors"));
687                 color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
688         }
689         else if(color == "shirt") {
690                 f = stof(getplayerkey(self.sv_entnum, "colors"));
691                 color_vec = colormapPaletteColor(floor(f / 16), 0);
692         }
693         else if(color == "pants") {
694                 f = stof(getplayerkey(self.sv_entnum, "colors"));
695                 color_vec = colormapPaletteColor(mod(f, 16), 1);
696         }
697         return color_vec;
698 }
699
700 float HUD_Panel_GetBgAlpha(float id)
701 {
702         string alpha;
703         alpha = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_alpha"));
704         if(alpha == "")
705                 alpha = cvar_string("hud_bg_alpha");
706
707         if(hud_configure && disable_menu_alphacheck == 2 && highlightedPanel == id) // do not set a minalpha cap when showing the config dialog for this panel
708                 alpha = ftos((1 - cvar("_menu_alpha")) * max(cvar("hud_configure_bg_minalpha"), stof(alpha)) + (cvar("_menu_alpha")) * stof(alpha));
709         else if(hud_configure)
710                 alpha = ftos(max(cvar("hud_configure_bg_minalpha"), stof(alpha)));
711
712         if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
713                 return 0.25;
714
715         if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
716                 return stof(alpha);
717         else
718                 return stof(alpha) * menu_fade_alpha;
719 }
720
721 float HUD_Panel_GetFgAlpha(float id)
722 {
723         float alpha;
724         alpha = hud_fg_alpha;
725
726         if(hud_configure && !cvar(strcat("hud_", HUD_Panel_GetName(id)))) // ALWAYS show disabled panels at 0.25 alpha when in config mode
727                 return 0.25;
728
729         if(disable_menu_alphacheck == 2 && highlightedPanel == id) // don't fade this panel when showing the panel-specific menu dialog
730                 return alpha;
731         else
732                 return alpha * menu_fade_alpha;
733 }
734
735 float HUD_Panel_GetPadding(float id)
736 {
737         string padding;
738         padding = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_padding"));
739         if(padding == "")
740                 padding = cvar_string("hud_bg_padding");
741
742         vector mySize;
743         mySize = HUD_Panel_GetSize(id);
744         float smallestsize;
745         smallestsize = min(mySize_x, mySize_y);
746         return min(smallestsize/2 - 5, stof(padding));
747 }
748
749 // draw the background/borders
750 void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
751 {
752         if(!hud_configure && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg")) == "0")
753                 return;
754
755         string bg;
756         bg = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg"));
757         if(bg == "")
758                 bg = cvar_string("hud_bg");
759
760         if(bg == "0" && hud_configure) {
761                 bg = "border"; // we probably want to see a background in config mode at all times...
762         }
763
764         if(bg != "0")
765         {
766                 float border;
767                 border = max(0.0000001, HUD_Panel_GetBorder(id)); // draw_BorderPicture does not like border = 0
768
769                 vector color;
770                 color = HUD_Panel_GetColor(id);
771
772                 if(alpha)
773                         alpha = HUD_Panel_GetBgAlpha(id) * alpha; // allow panels to fade in/out by passing an alpha value
774                 else
775                         alpha = HUD_Panel_GetBgAlpha(id);
776
777                 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));
778         }
779 }
780
781 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
782 {
783         if(!alpha)
784                 return;
785
786         string pic;
787         pic = strcat("gfx/hud/", cvar_string("hud_skin"), "/");
788         if(vertical) {
789                 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);
790                 if(mySize_y/mySize_x > 2)
791                         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);
792                 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);
793         } else {
794                 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);
795                 if(mySize_x/mySize_y > 2)
796                         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);
797                 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);
798         }
799 }
800
801 vector HUD_Panel_GetProgressBarColor(string item)
802 {
803         return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
804 }
805
806 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
807 vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
808 {
809         float i;
810
811         vector myTarget;
812         myTarget = myPos;
813
814         vector targPos;
815         vector targSize;
816         vector myCenter;
817         vector targCenter;
818         myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
819         targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
820
821         for (i = 0; i < HUD_PANEL_NUM; ++i) {
822                 if(i == id || !HUD_Panel_CheckActive(i))
823                         continue;
824
825                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
826                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
827
828                 if(myPos_y + mySize_y < targPos_y)
829                         continue;
830                 if(myPos_y > targPos_y + targSize_y)
831                         continue;
832
833                 if(myPos_x + mySize_x < targPos_x)
834                         continue;
835                 if(myPos_x > targPos_x + targSize_x)
836                         continue;
837
838                 // OK, there IS a collision.
839
840                 myCenter_x = myPos_x + 0.5 * mySize_x;
841                 myCenter_y = myPos_y + 0.5 * mySize_y;
842
843                 targCenter_x = targPos_x + 0.5 * targSize_x;
844                 targCenter_y = targPos_y + 0.5 * targSize_y;
845
846                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
847                 {
848                         if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
849                                 myTarget_x = targPos_x - mySize_x;
850                         else // push it upwards
851                                 myTarget_y = targPos_y - mySize_y;
852                 }
853                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
854                 {
855                         if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
856                                 myTarget_x = targPos_x + targSize_x;
857                         else // push it upwards
858                                 myTarget_y = targPos_y - mySize_y;
859                 }
860                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
861                 {
862                         if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
863                                 myTarget_x = targPos_x - mySize_x;
864                         else // push it downwards
865                                 myTarget_y = targPos_y + targSize_y;
866                 }
867                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
868                 {
869                         if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
870                                 myTarget_x = targPos_x + targSize_x;
871                         else // push it downwards
872                                 myTarget_y = targPos_y + targSize_y;
873                 }
874         }
875
876         return myTarget;
877 }
878
879 void HUD_Panel_SetPos(float id, vector pos)
880 {
881         vector oldPos;
882         oldPos = HUD_Panel_GetPos(id);
883
884         vector mySize;
885         mySize = HUD_Panel_GetSize(id);
886
887         if(cvar("hud_configure_checkcollisions"))
888                 pos = HUD_Panel_CheckMove(id, pos, mySize);
889
890         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
891         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
892
893         if(cvar("hud_configure_grid"))
894         {
895                 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;
896                 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;
897         }
898
899         string s;
900         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
901
902         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
903 }
904
905 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
906 vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
907         float i;
908
909         float targBorder;
910         vector targPos;
911         vector targSize;
912         vector targEndPos;
913         vector dist;
914
915         for (i = 0; i < HUD_PANEL_NUM; ++i) {
916                 if(i == id || !HUD_Panel_CheckActive(i))
917                         continue;
918
919                 targBorder = HUD_Panel_GetBorder(i);
920                 targPos = HUD_Panel_GetPos(i) - '1 1 0' * targBorder;
921                 targSize = HUD_Panel_GetSize(i) + '2 2 0' * targBorder;
922                 targEndPos = targPos + targSize;
923
924                 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
925                 if(resizeorigin_x > targPos_x && resizeorigin_x < targPos_x + targSize_x && resizeorigin_y > targPos_y && resizeorigin_y < targPos_y + targSize_y)
926                         continue;
927
928                 if (resizeCorner == 1)
929                 {
930                         // check if this panel is on our way
931                         if (resizeorigin_x <= targPos_x)
932                                 continue;
933                         if (resizeorigin_y <= targPos_y)
934                                 continue;
935                         if (targEndPos_x <= resizeorigin_x - mySize_x)
936                                 continue;
937                         if (targEndPos_y <= resizeorigin_y - mySize_y)
938                                 continue;
939
940                         // there is a collision:
941                         // detect which side of the panel we are facing is actually limiting the resizing
942                         // (which side the resize direction finds for first) and reduce the size up to there
943                         //
944                         // dist is the distance between resizeorigin and the "analogous" point of the panel
945                         // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
946                         dist_x = resizeorigin_x - targEndPos_x;
947                         dist_y = resizeorigin_y - targEndPos_y;
948                         if (dist_y < 0)
949                                 mySize_x = min(mySize_x, dist_x);
950                         else
951                                 mySize_y = min(mySize_y, dist_y);
952                 }
953                 else if (resizeCorner == 2)
954                 {
955                         if (resizeorigin_x >= targEndPos_x)
956                                 continue;
957                         if (resizeorigin_y <= targPos_y)
958                                 continue;
959                         if (targPos_x >= resizeorigin_x + mySize_x)
960                                 continue;
961                         if (targEndPos_y <= resizeorigin_y - mySize_y)
962                                 continue;
963
964                         dist_x = targPos_x - resizeorigin_x;
965                         dist_y = resizeorigin_y - targEndPos_y;
966                         if (dist_y < 0)
967                                 mySize_x = min(mySize_x, dist_x);
968                         else
969                                 mySize_y = min(mySize_y, dist_y);
970                 }
971                 else if (resizeCorner == 3)
972                 {
973                         if (resizeorigin_x <= targPos_x)
974                                 continue;
975                         if (resizeorigin_y >= targEndPos_y)
976                                 continue;
977                         if (targEndPos_x <= resizeorigin_x - mySize_x)
978                                 continue;
979                         if (targPos_y >= resizeorigin_y + mySize_y)
980                                 continue;
981
982                         dist_x = resizeorigin_x - targEndPos_x;
983                         dist_y = targPos_y - resizeorigin_y;
984                         if (dist_y < 0)
985                                 mySize_x = min(mySize_x, dist_x);
986                         else
987                                 mySize_y = min(mySize_y, dist_y);
988                 }
989                 else if (resizeCorner == 4)
990                 {
991                         if (resizeorigin_x >= targEndPos_x)
992                                 continue;
993                         if (resizeorigin_y >= targEndPos_y)
994                                 continue;
995                         if (targPos_x >= resizeorigin_x + mySize_x)
996                                 continue;
997                         if (targPos_y >= resizeorigin_y + mySize_y)
998                                 continue;
999
1000                         dist_x = targPos_x - resizeorigin_x;
1001                         dist_y = targPos_y - resizeorigin_y;
1002                         if (dist_y < 0)
1003                                 mySize_x = min(mySize_x, dist_x);
1004                         else
1005                                 mySize_y = min(mySize_y, dist_y);
1006                 }
1007                 if(cvar("hud_configure_checkcollisions_debug"))
1008                         drawfill(targPos + '1 1 0' * targBorder, targSize - '2 2 0' * targBorder, '1 1 0', .3, DRAWFLAG_NORMAL);
1009         }
1010
1011         return mySize;
1012 }
1013
1014 void HUD_Panel_SetPosSize(float id)
1015 {
1016         vector resizeorigin;
1017         resizeorigin = panel_click_resizeorigin;
1018         vector mySize, myPos;
1019
1020         if(resizeCorner == 1) {
1021                 mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
1022                 mySize_y = resizeorigin_y - (mousepos_y - panel_click_distance_y);
1023         } else if(resizeCorner == 2) {          
1024                 mySize_x = mousepos_x + panel_click_distance_x - resizeorigin_x;
1025                 mySize_y = panel_click_distance_y + resizeorigin_y - mousepos_y;
1026         } else if(resizeCorner == 3) {
1027                 mySize_x = resizeorigin_x + panel_click_distance_x - mousepos_x;
1028                 mySize_y = mousepos_y + panel_click_distance_y - resizeorigin_y;
1029         } else { // resizeCorner == 4
1030                 mySize_x = mousepos_x - (resizeorigin_x - panel_click_distance_x);
1031                 mySize_y = mousepos_y - (resizeorigin_y - panel_click_distance_y);
1032         }
1033
1034         // minimum panel size cap
1035         mySize_x = max(0.025 * vid_conwidth, mySize_x);
1036         mySize_y = max(0.025 * vid_conheight, mySize_y);
1037
1038         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.
1039         {
1040                 mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
1041                 mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
1042         }
1043
1044         // collision testing|
1045         // -----------------+
1046
1047         // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
1048         if(resizeCorner == 1) {
1049                 myPos_x = resizeorigin_x - mySize_x;
1050                 myPos_y = resizeorigin_y - mySize_y;
1051         } else if(resizeCorner == 2) {
1052                 myPos_x = resizeorigin_x;
1053                 myPos_y = resizeorigin_y - mySize_y;
1054         } else if(resizeCorner == 3) {
1055                 myPos_x = resizeorigin_x - mySize_x;
1056                 myPos_y = resizeorigin_y;
1057         } else { // resizeCorner == 4
1058                 myPos_x = resizeorigin_x;
1059                 myPos_y = resizeorigin_y;
1060         }
1061
1062         // left/top screen edges
1063         if(myPos_x < 0)
1064                 mySize_x = mySize_x + myPos_x;
1065         if(myPos_y < 0)
1066                 mySize_y = mySize_y + myPos_y;
1067
1068         // bottom/right screen edges
1069         if(myPos_x + mySize_x > vid_conwidth)
1070                 mySize_x = vid_conwidth - myPos_x;
1071         if(myPos_y + mySize_y > vid_conheight)
1072                 mySize_y = vid_conheight - myPos_y;
1073
1074         if(cvar("hud_configure_checkcollisions_debug"))
1075                 drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
1076
1077         // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
1078         if(cvar("hud_configure_grid"))
1079         {
1080                 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;
1081                 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;
1082         }
1083
1084         if(cvar("hud_configure_checkcollisions"))
1085         {
1086                 mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin);
1087         }
1088
1089         // 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)
1090         mySize_x = max(0.025 * vid_conwidth, mySize_x);
1091         mySize_y = max(0.025 * vid_conheight, mySize_y);
1092
1093         // do another pos check, as size might have changed by now
1094         if(resizeCorner == 1) {
1095                 myPos_x = resizeorigin_x - mySize_x;
1096                 myPos_y = resizeorigin_y - mySize_y;
1097         } else if(resizeCorner == 2) {
1098                 myPos_x = resizeorigin_x;
1099                 myPos_y = resizeorigin_y - mySize_y;
1100         } else if(resizeCorner == 3) {
1101                 myPos_x = resizeorigin_x - mySize_x;
1102                 myPos_y = resizeorigin_y;
1103         } else { // resizeCorner == 4
1104                 myPos_x = resizeorigin_x;
1105                 myPos_y = resizeorigin_y;
1106         }
1107
1108         if(cvar("hud_configure_checkcollisions_debug"))
1109         if(cvar("hud_configure_checkcollisions"))
1110                 drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
1111
1112         string s;
1113         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
1114         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
1115
1116         s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
1117         cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
1118 }
1119
1120 float mouseClicked;
1121 float prevMouseClicked; // previous state
1122 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
1123 vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
1124
1125 float menu_enabled;
1126 float menu_enabled_time;
1127 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
1128 {
1129         if(!hud_configure)
1130                 return false;
1131
1132         // allow console bind to work
1133         string con_keys;
1134         float keys;
1135         con_keys = findkeysforcommand("toggleconsole");
1136         keys = tokenize(con_keys);
1137
1138         float hit_con_bind, i;
1139         for (i = 0; i < keys; ++i)
1140         {
1141                 if(nPrimary == stof(argv(i)))
1142                         hit_con_bind = 1;
1143         }
1144
1145         if(nPrimary == K_MOUSE1)
1146         {
1147                 if(bInputType == 0) { // key pressed
1148                         mouseClicked = 1;
1149                         return true;
1150                 }
1151                 else if(bInputType == 1) {// key released
1152                         mouseClicked = 0;
1153                         return true;
1154                 }
1155         }
1156         else if(nPrimary == K_ESCAPE)
1157         {
1158                 disable_menu_alphacheck = 1;
1159                 menu_enabled = 1;
1160                 menu_enabled_time = time;
1161                 localcmd("menu_showhudexit\n");
1162         }
1163
1164         else if(hit_con_bind)
1165                 return false;
1166
1167         return true; // Suppress ALL other input
1168 }
1169
1170 void HUD_Panel_Mouse()
1171 {
1172         // 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
1173         if (menu_enabled == 0) // menu dialog closed, enable normal alpha stuff again
1174                 disable_menu_alphacheck = 0;
1175         if (cvar("_menu_alpha") == 0 && time - menu_enabled_time > 0.5)
1176                 menu_enabled = 0;
1177
1178         /*
1179         print("Disable menu_alphacheck: ", ftos(disable_menu_alphacheck), "\n");
1180         print("Highlighted: ", ftos(highlightedPanel), "\n");
1181         print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
1182         */
1183
1184         if(mouseClicked == 0 && disable_menu_alphacheck != 2) { // don't reset these variables in disable_menu_alphacheck mode 2!
1185                 highlightedPanel = -1;
1186                 highlightedAction = 0;
1187         }
1188
1189         mousepos = mousepos + getmousepos();
1190
1191         mousepos_x = bound(0, mousepos_x, vid_conwidth);
1192         mousepos_y = bound(0, mousepos_y, vid_conheight);
1193
1194         drawpic(mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1195
1196         if(mouseClicked)
1197         {
1198                 float i, border;
1199                 vector panelPos;
1200                 vector panelSize;
1201
1202                 for(i = 0; i < HUD_PANEL_NUM; ++i)
1203                 {
1204                         panelPos = HUD_Panel_GetPos(i);
1205                         panelSize = HUD_Panel_GetSize(i);
1206                         border = HUD_Panel_GetBorder(i);
1207                         if(prevMouseClicked == 0) {
1208                                 // move
1209                                 if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
1210                                 {
1211                                         highlightedPanel = i;
1212                                         highlightedAction = 1;
1213                                 }
1214                                 // resize from topleft border
1215                                 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)
1216                                 {
1217                                         highlightedPanel = i;
1218                                         highlightedAction = 2;
1219                                         resizeCorner = 1;
1220                                 }
1221                                 // resize from topright border
1222                                 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)
1223                                 {
1224                                         highlightedPanel = i;
1225                                         highlightedAction = 2;
1226                                         resizeCorner = 2;
1227                                 }
1228                                 // resize from bottomleft border
1229                                 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)
1230                                 {
1231                                         highlightedPanel = i;
1232                                         highlightedAction = 2;
1233                                         resizeCorner = 3;
1234                                 }
1235                                 // resize from bottomright border
1236                                 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)
1237                                 {
1238                                         highlightedPanel = i;
1239                                         highlightedAction = 2;
1240                                         resizeCorner = 4;
1241                                 }
1242                         }
1243
1244                         if(highlightedPanel == i)
1245                         {
1246                                 if(prevMouseClicked == 0)
1247                                 {
1248                                         if(highlightedAction == 1)
1249                                                 panel_click_distance = mousepos - panelPos;
1250                                         else if(highlightedAction == 2)
1251                                         {
1252                                                 if(resizeCorner == 1) {
1253                                                         panel_click_distance = mousepos - panelPos;
1254                                                         panel_click_resizeorigin = panelPos + panelSize;
1255                                                 } else if(resizeCorner == 2) {
1256                                                         panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
1257                                                         panel_click_distance_y = mousepos_y - panelPos_y;
1258                                                         panel_click_resizeorigin = panelPos + eY * panelSize_y;
1259                                                 } else if(resizeCorner == 3) {
1260                                                         panel_click_distance_x = mousepos_x - panelPos_x;
1261                                                         panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
1262                                                         panel_click_resizeorigin = panelPos + eX * panelSize_x;
1263                                                 } else if(resizeCorner == 4) {
1264                                                         panel_click_distance = panelSize - mousepos + panelPos;
1265                                                         panel_click_resizeorigin = panelPos;
1266                                                 }
1267                                         }       
1268                                 }
1269
1270                                 if(cvar("hud_configure_checkcollisions_debug"))
1271                                         drawfill(panelPos, panelSize, '1 0 0', .3, DRAWFLAG_NORMAL);
1272
1273                                 if(highlightedAction == 1)
1274                                         HUD_Panel_SetPos(i, mousepos - panel_click_distance);
1275                                 else if(highlightedAction == 2)
1276                                         HUD_Panel_SetPosSize(i);
1277                         }
1278                 }
1279
1280                 // doubleclick check
1281                 if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
1282                 {
1283                         mouseClicked = 0; // to prevent spam, I guess.
1284                         disable_menu_alphacheck = 2;
1285                         menu_enabled = 1;
1286                         menu_enabled_time = time;
1287                         localcmd("menu_showhudoptions ", ftos(highlightedPanel), "\n");
1288                         return;
1289                 }
1290                 if(prevMouseClicked == 0)
1291                 {
1292                         prevMouseClickedTime = time;
1293                         prevMouseClickedPos = mousepos;
1294                 }
1295         }
1296         prevMouseClicked = mouseClicked;
1297 }
1298
1299 // Weapon icons (#0)
1300 //
1301 float weaponspace[10];
1302 void HUD_WeaponIcons_Clear()
1303 {
1304         float idx;
1305         for(idx = 0; idx < 10; ++idx)
1306                 weaponspace[idx] = 0;
1307 }
1308
1309 entity weaponorder[WEP_MAXCOUNT];
1310
1311 void weaponorder_swap(float i, float j, entity pass)
1312 {
1313         entity h;
1314         h = weaponorder[i];
1315         weaponorder[i] = weaponorder[j];
1316         weaponorder[j] = h;
1317 }
1318
1319 string weaponorder_cmp_str;
1320 float weaponorder_cmp(float i, float j, entity pass)
1321 {
1322         float ai, aj;
1323         ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
1324         aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
1325         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)
1326 }
1327
1328 void HUD_WeaponIcons(void)
1329 {
1330         float id = HUD_PANEL_WEAPONICONS;
1331         float alpha, stat_weapons; // "constants"
1332         vector pos, mySize, accuracy_color;
1333         float i, weapid, fade, weapon_stats, weapon_hit, weapon_damage, weapon_cnt; // variables
1334
1335         pos = HUD_Panel_GetPos(id);
1336         mySize = HUD_Panel_GetSize(id);
1337
1338         stat_weapons = getstati(STAT_WEAPONS);
1339         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
1340         {
1341                 self = get_weaponinfo(i);
1342                 if(self.impulse >= 0)
1343                 {
1344                         weaponorder[weapon_cnt] = self;
1345                         ++weapon_cnt;
1346                 }
1347         }
1348
1349         // TODO make this configurable
1350         weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
1351         heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
1352
1353         HUD_Panel_DrawBg(id, pos, mySize, 0);
1354         float padding;
1355         padding = HUD_Panel_GetPadding(id);
1356         if(padding)
1357         {
1358                 pos += '1 1 0' * padding;
1359                 mySize -= '2 2 0' * padding;
1360         }
1361
1362         // hits
1363         weapon_stats = getstati(STAT_DAMAGE_HITS);
1364         weapon_number = weapon_stats & 63;
1365         weapon_hits[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1366         // fired
1367         weapon_stats = getstati(STAT_DAMAGE_FIRED);
1368         weapon_number = weapon_stats & 63;
1369         weapon_fired[weapon_number-WEP_FIRST] = floor(weapon_stats / 64);
1370
1371         if(cvar_or("hud_weaponicons_fade", 1))
1372         {
1373                 fade = 3.2 - 2 * (time - weapontime);
1374                 fade = bound(0.7, fade, 1);
1375         }
1376         else
1377                 fade = 1;
1378
1379         HUD_WeaponIcons_Clear();
1380
1381         float rows, columns;
1382         rows = mySize_y/mySize_x;
1383         rows = bound(1, floor((sqrt(4 * (2/1) * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
1384         //                               ^^^ weapon icon aspect goes here
1385
1386         columns = ceil(WEP_COUNT/rows);
1387         float row, column;
1388         for(i = 0; i < weapon_cnt; ++i)
1389         {
1390                 self = weaponorder[i];
1391                 weapid = self.impulse;
1392
1393                 alpha = (self.weapon == activeweapon) ? 1 : 0.6;
1394
1395                 weapon_hit = weapon_hits[self.weapon-WEP_FIRST];
1396                 weapon_damage = weapon_fired[self.weapon-WEP_FIRST];
1397
1398                 // draw background behind currently selected weapon
1399                 if(self.weapon == activeweapon)
1400                         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);
1401
1402                 // draw the weapon accuracy on the HUD
1403                 if(hud_accuracy_hud && !(gametype == GAME_RACE || gametype == GAME_CTS))
1404                 {
1405                         if(weapon_damage)
1406                                 weapon_stats = floor(100 * weapon_hit / weapon_damage);
1407
1408                         accuracy_color = HUD_AccuracyColor(weapon_stats);
1409                         if(weapon_damage)
1410                                 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);
1411                 }
1412
1413                 // draw the weapon icon
1414                 if((self.impulse >= 0) && (stat_weapons & self.weapons))
1415                 {
1416                         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);
1417
1418                         if(cvar_or("hud_weaponicons_number", 1))
1419                                 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);
1420                 }
1421                 // draw a "ghost weapon icon" if you don't have the weapon
1422                 else
1423                 {
1424                         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);
1425                 }
1426
1427                 ++row;
1428                 if(row >= rows)
1429                 {
1430                         row = 0;
1431                         ++column;
1432                 }
1433         }
1434
1435 }
1436
1437 // Inventory (#1)
1438 //
1439 float GetAmmoStat(float i)
1440 {
1441         switch(i)
1442         {
1443                 case 0: return STAT_SHELLS;
1444                 case 1: return STAT_NAILS;
1445                 case 2: return STAT_ROCKETS;
1446                 case 3: return STAT_CELLS;
1447                 case 4: return STAT_FUEL;
1448                 default: return -1;
1449         }
1450 }
1451
1452 float GetAmmoItemCode(float i)
1453 {
1454         switch(i)
1455         {
1456                 case 0: return IT_SHELLS;
1457                 case 1: return IT_NAILS;
1458                 case 2: return IT_ROCKETS;
1459                 case 3: return IT_CELLS;
1460                 case 4: return IT_FUEL;
1461                 default: return -1;
1462         }
1463 }
1464
1465 string GetAmmoPicture(float i)
1466 {
1467         switch(i)
1468         {
1469                 case 0: return "ammo_shells";
1470                 case 1: return "ammo_bullets";
1471                 case 2: return "ammo_rockets";
1472                 case 3: return "ammo_cells";
1473                 case 4: return "ammo_fuel";
1474                 default: return "";
1475         }
1476 }
1477
1478 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
1479 {
1480         float a;
1481         a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
1482         if(hud_configure)
1483                 a = 100;
1484
1485         vector color;
1486         if(a < 10)
1487                 color = '0.7 0 0';
1488         else
1489                 color = '1 1 1';
1490
1491         float alpha;
1492         if(currently_selected)
1493                 alpha = 1;
1494         else
1495                 alpha = 0.7;
1496
1497         vector newSize, newPos;
1498         if(mySize_x/mySize_y > 3)
1499         {
1500                 newSize_x = 3 * mySize_y;
1501                 newSize_y = mySize_y;
1502
1503                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1504                 newPos_y = myPos_y;
1505         }
1506         else
1507         {
1508                 newSize_y = 1/3 * mySize_x;
1509                 newSize_x = mySize_x;
1510
1511                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1512                 newPos_x = myPos_x;
1513         }
1514
1515         vector picpos, numpos;
1516         if(cvar("hud_inventory_iconalign"))
1517         {
1518                 numpos = newPos;
1519                 picpos = newPos + eX * 2 * newSize_y;
1520         }
1521         else
1522         {
1523                 numpos = newPos + eX * newSize_y;
1524                 picpos = newPos;
1525         }
1526
1527         if (currently_selected)
1528                 drawpic_skin(newPos, "ammo_current_bg", newSize, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY), DRAWFLAG_NORMAL);
1529
1530         drawstring_aspect(numpos, ftos(a), eX * (2/3) * newSize_x + eY * newSize_y, newSize_y, color, HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY) * alpha, DRAWFLAG_NORMAL);
1531         drawpic_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * newSize_y, '1 1 1', HUD_Panel_GetFgAlpha(HUD_PANEL_INVENTORY) * alpha, DRAWFLAG_NORMAL);
1532 }
1533
1534 void HUD_Inventory(void)
1535 {
1536         float id = HUD_PANEL_INVENTORY;
1537         float i, currently_selected;
1538
1539         vector pos, mySize;
1540         pos = HUD_Panel_GetPos(id);
1541         mySize = HUD_Panel_GetSize(id);
1542
1543         HUD_Panel_DrawBg(id, pos, mySize, 0);
1544         float padding;
1545         padding = HUD_Panel_GetPadding(id);
1546         if(padding)
1547         {
1548                 pos += '1 1 0' * padding;
1549                 mySize -= '2 2 0' * padding;
1550         }
1551
1552         float rows, columns;
1553         rows = mySize_y/mySize_x;
1554         rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1555         //                               ^^^ ammo item aspect goes here
1556
1557         columns = ceil(AMMO_COUNT/rows);
1558
1559         float row, column;
1560         // ammo
1561         for (i = 0; i < AMMO_COUNT; ++i) {
1562                 currently_selected = getstati(STAT_ITEMS) & GetAmmoItemCode(i);
1563                 if(cvar("hud_inventory_onlycurrent")) {
1564                         if(hud_configure)
1565                                 i = 2;
1566                         if (currently_selected || hud_configure)
1567                                 DrawAmmoItem(pos, mySize, i, currently_selected);
1568                         break;
1569                 } else {
1570                         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);
1571                         ++row;
1572                         if(row >= rows)
1573                         {
1574                                 row = 0;
1575                                 column = column + 1;
1576                         }
1577                 }
1578         }
1579 }
1580
1581 // Powerups (#2)
1582 //
1583 void HUD_Powerups(void) {
1584         float id = HUD_PANEL_POWERUPS;
1585         float stat_items;
1586         stat_items = getstati(STAT_ITEMS);
1587
1588         if(!hud_configure)
1589         {
1590                 if not(stat_items & IT_STRENGTH)
1591                         if not(stat_items & IT_INVINCIBLE)
1592                                 return;
1593
1594                 if (getstati(STAT_HEALTH) <= 0)
1595                         return;
1596         }
1597
1598         vector pos, mySize;
1599         pos = HUD_Panel_GetPos(id);
1600         mySize = HUD_Panel_GetSize(id);
1601
1602         HUD_Panel_DrawBg(id, pos, mySize, 0);
1603         float padding;
1604         padding = HUD_Panel_GetPadding(id);
1605         if(padding)
1606         {
1607                 pos += '1 1 0' * padding;
1608                 mySize -= '2 2 0' * padding;
1609         }
1610
1611         float strength_time, shield_time;
1612
1613         strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1614         shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1615
1616         if(hud_configure)
1617         {
1618                 strength_time = 15;
1619                 shield_time = 27;
1620         }
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         float baralign, iconalign;
1651         baralign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_baralign"));
1652         iconalign = cvar(strcat("hud_", HUD_Panel_GetName(id), "_iconalign"));
1653
1654         if (mySize_x/mySize_y > 4)
1655         {
1656                 if(leftcnt)
1657                 {
1658                         if(baralign == 1 || baralign == 3) { // right align
1659                                 barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/30);
1660                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1661                         } else { // left align
1662                                 barpos = pos;
1663                                 barsize = eX * 0.5 * mySize_x * min(1, leftcnt/30) + eY * mySize_y;
1664                         }
1665
1666                         if(iconalign == 1 || iconalign == 3) { // right align
1667                                 picpos = pos + eX * (2/6) * mySize_x;
1668                                 numpos = pos;
1669                         } else { // left align
1670                                 picpos = pos;
1671                                 numpos = pos + eX * (1/6) * mySize_x;
1672                         }
1673
1674                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1675                         if(leftcnt <= 5)
1676                                 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));
1677                         else
1678                                 drawpic_skin(picpos, leftname, eX * (1/6) * mySize_x + eY * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1679                         drawstring_aspect(numpos, ftos(leftcnt), eX * (2/6) * mySize_x + eY * mySize_y, mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1680                 }
1681
1682                 if(rightcnt)
1683                 {
1684                         if(baralign == 0 || baralign == 3) { // left align
1685                                 barpos = pos + eX * 0.5 * mySize_x;
1686                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1687                         } else { // right align
1688                                 barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/30);
1689                                 barsize = eX * 0.5 * mySize_x * min(1, rightcnt/30) + eY * mySize_y;
1690                         }
1691
1692                         if(iconalign == 0 || iconalign == 3) { // left align
1693                                 picpos = pos + eX * (3/6) * mySize_x;
1694                                 numpos = pos + eX * (4/6) * mySize_x;
1695                         } else { // right align
1696                                 picpos = pos + eX * (5/6) * mySize_x;
1697                                 numpos = pos + eX * (3/6) * mySize_x;
1698                         }
1699
1700                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1701                         if(rightcnt <= 5)
1702                                 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));
1703                         else
1704                                 drawpic_skin(picpos, rightname, eX * (1/6) * mySize_x + eY * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1705                         drawstring_aspect(numpos, ftos(rightcnt), eX * (2/6) * mySize_x + eY * mySize_y, mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1706                 }
1707         }
1708         else if (mySize_x/mySize_y > 1.5)
1709         {
1710                 if(leftcnt)
1711                 {
1712                         if(baralign == 1 || baralign == 3) { // right align
1713                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/30);
1714                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1715                         } else { // left align
1716                                 barpos = pos;
1717                                 barsize = eX * mySize_x * min(1, leftcnt/30) + eY * 0.5 * mySize_y;
1718                         }
1719
1720                         if(iconalign == 1 || iconalign == 3) { // right align
1721                                 picpos = pos + eX * (2/3) * mySize_x;
1722                                 numpos = pos;
1723                         } else { // left align
1724                                 picpos = pos;
1725                                 numpos = pos + eX * (1/3) * mySize_x;
1726                         }
1727
1728                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1729                         if(leftcnt <= 5)
1730                                 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));
1731                         else
1732                                 drawpic_skin(picpos, leftname, eX * (1/3) * mySize_x + eY * 0.5 * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1733                         drawstring_aspect(numpos, ftos(leftcnt), eX * (2/3) * mySize_x + eY * 0.5 * mySize_y, mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1734                 }
1735
1736                 if(rightcnt)
1737                 {
1738                         if(baralign == 0 || baralign == 3) { // left align
1739                                 barpos = pos + eY * 0.5 * mySize_y;
1740                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1741                         } else { // right align
1742                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1743                                 barsize = eX * mySize_x * min(1, rightcnt/30) + eY * 0.5 * mySize_y;
1744                         }
1745
1746                         if(iconalign == 0 || iconalign == 3) { // left align
1747                                 picpos = pos + eY * 0.5 * mySize_y;
1748                                 numpos = pos + eX * (1/3) * mySize_x + eY * 0.5 * mySize_y;
1749                         } else { // right align
1750                                 picpos = pos + eX * (2/3) * mySize_x + eY * 0.5 * mySize_y;
1751                                 numpos = pos + eY * 0.5 * mySize_y;
1752                         }
1753
1754                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1755                         if(rightcnt <= 5)
1756                                 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));
1757                         else
1758                                 drawpic_skin(picpos, rightname, eX * (1/3) * mySize_x + eY * 0.5 * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1759                         drawstring_aspect(numpos, ftos(rightcnt), eX * (2/3) * mySize_x + eY * 0.5 * mySize_y, mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1760                 }
1761         }
1762         else
1763         {
1764                 if(leftcnt)
1765                 {
1766                         if(baralign == 1 || baralign == 3) { // down align
1767                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30);
1768                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1769                         } else { // up align
1770                                 barpos = pos;
1771                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1772                         }
1773
1774                         if(iconalign == 1 || iconalign == 3) { // down align
1775                                 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x);
1776                                 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x;
1777                         } else { // up align
1778                                 picpos = pos + eX * 0.05 * mySize_x;
1779                                 numpos = pos + eY * 0.4 * mySize_x;
1780                         }
1781
1782                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1783                         if(leftcnt <= 5)
1784                                 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));
1785                         else
1786                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1787                         drawstring_aspect(numpos, ftos(leftcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1788                 }
1789
1790                 if(rightcnt)
1791                 {
1792                         if(baralign == 0 || baralign == 3) { // up align
1793                                 barpos = pos + eX * 0.5 * mySize_x;
1794                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1795                         } else { // down align
1796                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/30) + eX * 0.5 * mySize_x;
1797                                 barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/30);
1798                         }
1799
1800                         if(iconalign == 0 || iconalign == 3) { // up align
1801                                 picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
1802                                 numpos = pos + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
1803                         } else { // down align
1804                                 picpos = pos + eX * 0.05 * mySize_x + eY * (mySize_y - 0.65 * mySize_x) + eX * 0.5 * mySize_x;
1805                                 numpos = pos + eY * mySize_y - eY * 0.25 * mySize_x + eX * 0.5 * mySize_x;
1806                         }
1807
1808                         HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1809                         if(rightcnt <= 5)
1810                                 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));
1811                         else
1812                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1813                         drawstring_aspect(numpos, ftos(rightcnt), eX * 0.5 * mySize_x + eY * 0.25 * mySize_x, 0.25 * mySize_x, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1814                         //HUD_DrawXNum(numpos, rightcnt, len, 0, 0.25 * mySize_x, '1 1 1', 0, 0, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1815                 }
1816         }
1817 }
1818
1819 // Health/armor (#3)
1820 //
1821 void HUD_HealthArmor(void)
1822 {
1823         float id = HUD_PANEL_HEALTHARMOR;
1824         vector pos, mySize;
1825         pos = HUD_Panel_GetPos(id);
1826         mySize = HUD_Panel_GetSize(id);
1827
1828         HUD_Panel_DrawBg(id, pos, mySize, 0);
1829         float padding;
1830         padding = HUD_Panel_GetPadding(id);
1831         if(padding)
1832         {
1833                 pos += '1 1 0' * padding;
1834                 mySize -= '2 2 0' * padding;
1835         }
1836
1837         float armor, health;
1838         armor = getstati(STAT_ARMOR);
1839         health = getstati(STAT_HEALTH);
1840
1841         float fuel;
1842         fuel = getstati(GetAmmoStat(4)); // how much fuel do we have?
1843
1844         if(hud_configure)
1845         {
1846                 armor = 150;
1847                 health = 100;
1848                 fuel = 70;
1849         }
1850
1851         if(health <= 0)
1852                 return;
1853
1854         float len;
1855         vector barpos, barsize;
1856         vector picpos;
1857         vector numpos;
1858
1859         if(cvar("hud_healtharmor") == 2) // combined health and armor display
1860         {
1861                 vector v;
1862                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1863
1864                 float x;
1865                 x = floor(v_x + 1);
1866
1867                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1868                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, x/400);
1869                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1870                         picpos = pos;
1871                         numpos = picpos + eX * 1.5 * mySize_y;
1872                 } else {
1873                         barpos = pos;
1874                         barsize = eX * mySize_x * min(1, x/400) + eY * mySize_y;
1875                         picpos = pos + eX * 3 * mySize_y;
1876                         numpos = pos;
1877                 }
1878
1879                 if(v_z) // NOT fully armored
1880                 {
1881                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("health"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1882                         drawpic_skin(picpos, "health", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1883                         if(armor)
1884                                 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);
1885                 }
1886                 else
1887                 {
1888                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("armor"), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1889                         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);
1890                         if(armor)
1891                                 drawpic_skin(picpos, "armor", '1 1 0' * mySize_y, '1 1 1', HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1892                 }
1893                 //HUD_DrawXNum_Colored(numpos, x, 3, mySize_y, HUD_Panel_GetFgAlpha(id)); // draw the combined health and armor
1894
1895                 // fuel
1896                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1897                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
1898                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1899                 } else {
1900                         barpos = pos;
1901                         barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1902                 }
1903                 if(fuel)
1904                         HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
1905         }
1906
1907         else
1908         {
1909                 string leftname, rightname;
1910                 float leftcnt, rightcnt;
1911                 float leftactive, rightactive;
1912                 float leftalpha, rightalpha;
1913                 if (cvar(strcat("hud_", HUD_Panel_GetName(id), "_flip"))) { // old style layout with armor left/top of health
1914                         leftname = "armor";
1915                         leftcnt = armor;
1916                         if(leftcnt)
1917                                 leftactive = 1;
1918                         leftalpha = min((armor+10)/55, 1);
1919
1920                         rightname = "health";
1921                         rightcnt = health;
1922                         rightactive = 1;
1923                         rightalpha = 1;
1924                 } else {
1925                         leftname = "health";
1926                         leftcnt = health;
1927                         leftactive = 1;
1928                         leftalpha = 1;
1929
1930                         rightname = "armor";
1931                         rightcnt = armor;
1932                         if(rightcnt)
1933                                 rightactive = 1;
1934                         rightalpha = min((armor+10)/55, 1);
1935                 }
1936
1937                 if (mySize_x/mySize_y > 5)
1938                 {
1939                         if(leftactive)
1940                         {
1941                                 len = strlen(ftos(leftcnt));
1942
1943                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1944                                         barpos = pos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_x * min(1, leftcnt/200);
1945                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1946                                         picpos = pos + eX * 0.5 * mySize_x - eX * mySize_y;
1947                                         numpos = picpos - eX * 3 * 0.5 * mySize_y + eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1948                                 } else {
1949                                         barpos = pos;
1950                                         barsize = eX * 0.5 * mySize_x * min(1, leftcnt/200) + eY * mySize_y;
1951                                         picpos = pos;
1952                                         numpos = picpos + eX * mySize_y + eY * 0.25 * mySize_y;
1953                                 }
1954
1955                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1956                                 drawpic_skin(picpos, leftname, '1 1 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1957                                 //HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
1958                         }
1959
1960                         if(rightactive)
1961                         {
1962                                 len = strlen(ftos(rightcnt));
1963
1964                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1965                                         barpos = pos + eX * 0.5 * mySize_x;
1966                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1967                                         picpos = pos + eX * 0.5 * mySize_x;
1968                                         numpos = picpos + eX * mySize_y - eX * (3-len) * 0.5 * mySize_y + eY * 0.25 * mySize_y;
1969                                 } else {
1970                                         barpos = pos + eX * mySize_x - eX * 0.5 * mySize_x * min(1, rightcnt/200);
1971                                         barsize = eX * 0.5 * mySize_x * min(1, rightcnt/200) + eY * mySize_y;
1972                                         picpos = pos + eX * mySize_x - eX * mySize_y;
1973                                         numpos = picpos - eX * 1.5 * mySize_y + eY * 0.25 * mySize_y;
1974                                 }
1975
1976                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1977                                 drawpic_skin(picpos, rightname, '1 1 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
1978                                 //HUD_DrawXNum_Colored(numpos, rightcnt, 3, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
1979                         }
1980
1981                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1982                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
1983                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1984                         } else {
1985                                 barpos = pos;
1986                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.2 * mySize_y;
1987                         }
1988                         if(fuel)
1989                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
1990                 }
1991                 else if (mySize_x/mySize_y > 2)
1992                 {
1993                         if(leftactive)
1994                         {
1995                                 len = strlen(ftos(leftcnt));
1996
1997                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
1998                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, leftcnt/200);
1999                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2000                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y;
2001                                         numpos = picpos - eX * len * 0.5 * mySize_y;
2002                                 } else {
2003                                         barpos = pos;
2004                                         barsize = eX * mySize_x * min(1, leftcnt/200) + eY * 0.5 * mySize_y;
2005                                         picpos = pos;
2006                                         numpos = picpos + eX * 0.5 * mySize_y;
2007                                 }
2008
2009                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2010                                 drawpic_skin(picpos, leftname, '0.5 0.5 0' * mySize_y, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2011                                 //HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2012                         }
2013
2014                         if(rightactive)
2015                         {
2016                                 len = strlen(ftos(rightcnt));
2017
2018                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2019                                         barpos = pos + eX * mySize_x - eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2020                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2021                                         picpos = pos + eX * mySize_x - eX * 0.5 * mySize_y + eY * 0.5 * mySize_y;
2022                                         numpos = picpos - eX * len * 0.5 * mySize_y;
2023                                 } else {
2024                                         barpos = pos + eY * 0.5 * mySize_y;
2025                                         barsize = eX * mySize_x * min(1, rightcnt/200) + eY * 0.5 * mySize_y;
2026                                         picpos = pos + eY * 0.5 * mySize_y;
2027                                         numpos = picpos + eX * 0.5 * mySize_y;
2028                                 }
2029
2030                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2031                                 drawpic_skin(picpos, rightname, '0.5 0.5 0' * mySize_y, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2032                                 //HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.5 * mySize_y, HUD_Panel_GetFgAlpha(id));
2033                         }
2034
2035                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2036                                 barpos = pos + eX * mySize_x - eX * mySize_x * min(1, fuel/100);
2037                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2038                         } else {
2039                                 barpos = pos;
2040                                 barsize = eX * mySize_x * min(1, fuel/100) + eY * 0.1 * mySize_y;
2041                         }
2042                         if(fuel)
2043                                 HUD_Panel_DrawProgressBar(barpos, 0, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2044                 }
2045                 else
2046                 {
2047                         if(leftactive)
2048                         {
2049                                 len = strlen(ftos(leftcnt));
2050
2051                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2052                                         barpos = pos;
2053                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2054                                         picpos = pos + eX * 0.05 * mySize_x;
2055                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x;
2056                                 } else {
2057                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, leftcnt/200);
2058                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, leftcnt/200);
2059                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x;
2060                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x;
2061                                 }
2062
2063                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(leftname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2064                                 drawpic_skin(picpos, leftname, '0.4 0.4 0' * mySize_x, '1 1 1', leftalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2065                                 //HUD_DrawXNum_Colored(numpos, leftcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2066                         }
2067
2068                         if(rightactive)
2069                         {
2070                                 len = strlen(ftos(rightcnt));
2071
2072                                 if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2073                                         barpos = pos + eX * 0.5 * mySize_x;
2074                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2075                                         picpos = pos + eX * 0.05 * mySize_x + eX * 0.5 * mySize_x;
2076                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * 0.4 * mySize_x + eX * 0.5 * mySize_x;
2077                                 } else {
2078                                         barpos = pos + eY * mySize_y - eY * mySize_y * min(1, rightcnt/200) + eX * 0.5 * mySize_x;
2079                                         barsize = eX * 0.5 * mySize_x + eY * mySize_y * min(1, rightcnt/200);
2080                                         picpos = pos + eX * 0.05 * mySize_x + eY * mySize_y - eY * 0.566 * mySize_x + eX * 0.5 * mySize_x;
2081                                         numpos = pos + eX * ((3-len)/2) * 0.25 * mySize_x + eY * mySize_y - eY * 0.166 * mySize_x + eX * 0.5 * mySize_x;
2082                                 }
2083
2084                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor(rightname), cvar("hud_progressbar_alpha") * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2085                                 drawpic_skin(picpos, rightname, '0.4 0.4 0' * mySize_x, '1 1 1', rightalpha * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2086                                 //HUD_DrawXNum_Colored(numpos, rightcnt, len, 0.166 * mySize_x, HUD_Panel_GetFgAlpha(id));
2087                         }
2088
2089                         if(cvar(strcat("hud_", HUD_Panel_GetName(id), "_mirror"))) {
2090                                 barpos = pos;
2091                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2092                         } else {
2093                                 barpos = pos + eY * mySize_y - eY * mySize_y * min(1, fuel/100);
2094                                 barsize = eX * 0.05 * mySize_x + eY * mySize_y * min(1, fuel/100);
2095                         }
2096                         if(fuel)
2097                                 HUD_Panel_DrawProgressBar(barpos, 1, barsize, HUD_Panel_GetProgressBarColor("fuel"), HUD_Panel_GetFgAlpha(id) * 0.8, DRAWFLAG_NORMAL);
2098                 }
2099         }
2100 }
2101
2102 // ___TODO___ !!!
2103 // Notification area (#4)
2104 //
2105
2106 string Weapon_SuicideMessage(float deathtype)
2107 {
2108         w_deathtype = deathtype;
2109         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
2110         return w_deathtypestring;
2111 }
2112
2113 string Weapon_KillMessage(float deathtype)
2114 {
2115         w_deathtype = deathtype;
2116         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
2117         return w_deathtypestring;
2118 }
2119
2120 float killnotify_times[10];
2121 float killnotify_deathtype[10];
2122 float killnotify_actiontype[10]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
2123 string killnotify_attackers[10];
2124 string killnotify_victims[10];
2125 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
2126 {
2127         float i;
2128         for (i = 9; i > 0; --i) {
2129                 killnotify_times[i] = killnotify_times[i-1];
2130                 killnotify_deathtype[i] = killnotify_deathtype[i-1];
2131                 killnotify_actiontype[i] = killnotify_actiontype[i-1];
2132                 if(killnotify_attackers[i])
2133                         strunzone(killnotify_attackers[i]);
2134                 killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
2135                 if(killnotify_victims[i])
2136                         strunzone(killnotify_victims[i]);
2137                 killnotify_victims[i] = strzone(killnotify_victims[i-1]);
2138         }
2139         killnotify_times[0] = time;
2140         killnotify_deathtype[0] = wpn;
2141         killnotify_actiontype[0] = actiontype;
2142         if(killnotify_attackers[0])
2143                 strunzone(killnotify_attackers[0]);
2144         killnotify_attackers[0] = strzone(attacker);
2145         if(killnotify_victims[0])
2146                 strunzone(killnotify_victims[0]);
2147         killnotify_victims[0] = strzone(victim);
2148 }
2149
2150 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
2151 {
2152         float w;
2153         float alsoprint;
2154         alsoprint = (cvar("hud_notify_print") || !HUD_Panel_CheckActive(4)); // print message to console if: notify panel disabled, or cvar to do so enabled
2155         
2156         if(msg == MSG_SUICIDE) {
2157                 // TODO: cl_gentle
2158                 w = DEATH_WEAPONOF(type);
2159                 if(WEP_VALID(w)) {
2160                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2161                         if (alsoprint)
2162                                 print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
2163                 } else if (type == DEATH_KILL) {
2164                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
2165                         if (alsoprint)
2166                                 print ("^1",s1, "^1 couldn't take it anymore\n");
2167                 } else if (type == DEATH_ROT) {
2168                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2169                         if (alsoprint)
2170                                 print ("^1",s1, "^1 died\n");
2171                 } else if (type == DEATH_NOAMMO) {
2172                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
2173                         if (alsoprint)
2174                                 print ("^7",s1, "^7 committed suicide. What's the point of living without ammo?\n");
2175                 } else if (type == DEATH_CAMP) {
2176                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
2177                         if (alsoprint)
2178                                 print ("^1",s1, "^1 thought they found a nice camping ground\n");
2179                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2180                         HUD_KillNotify_Push(s1, "", 0, type);
2181                         if (alsoprint)
2182                                 print ("^1",s1, "^1 didn't become friends with the Lord of Teamplay\n");
2183                 } else if (type == DEATH_CHEAT) {
2184                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2185                         if (alsoprint)
2186                                 print ("^1",s1, "^1 unfairly eliminated themself\n");
2187                 } else if (type == DEATH_FIRE) {
2188                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2189                         if (alsoprint)
2190                                 print ("^1",s1, "^1 burned to death\n");
2191                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
2192                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2193                         if (alsoprint)
2194                                 print ("^1",s1, "^1 couldn't resist the urge to self-destruct\n");
2195                 } 
2196                 
2197                 if (stof(s2) > 2) // killcount > 2
2198                         print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
2199         } else if(msg == MSG_KILL) {
2200                 w = DEATH_WEAPONOF(type);
2201                 if(WEP_VALID(w)) {
2202                         HUD_KillNotify_Push(s2, s1, 1, w);
2203                         if (alsoprint)
2204                                 print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
2205                 }
2206                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
2207                         HUD_KillNotify_Push(s1, s2, 1, type);
2208                         if(alsoprint)
2209                         {
2210                                 if(cvar("cl_gentle")) {
2211                                         print ("^1", s1, "^1 took action against a team mate\n");
2212                                 } else {
2213                                         print ("^1", s1, "^1 mows down a team mate\n");
2214                                 }
2215                         }
2216                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
2217                                 if(cvar("cl_gentle"))
2218                                         print ("^1",s1,"^1 ended a ",s3," scoring spree by going against a team mate\n");
2219                                 else
2220                                         print ("^1",s1,"^1 ended a ",s3," kill spree by killing a team mate\n");
2221                         }
2222                         else if (stof(s2) > 2) {
2223                                 if(cvar("cl_gentle"))
2224                                         print ("^1",s1,"'s ^1",s3," scoring spree was ended by a team mate!\n");
2225                                 else
2226                                         print ("^1",s1,"'s ^1",s3," kill spree was ended by a team mate!\n");
2227                         }
2228                 }
2229                 else if(type == KILL_FIRST_BLOOD)
2230                         print("^1",s1, "^1 drew first blood", "\n");
2231                 // TODO: icon!
2232                 else if (type == DEATH_TELEFRAG)
2233                         print ("^1",s1, "^1 was telefragged by ", s2, "\n");
2234                 else if (type == DEATH_DROWN) {
2235                         HUD_KillNotify_Push(s2, s1, 1, DEATH_DROWN);
2236                         if(alsoprint)
2237                                 print ("^1",s1, "^1 was drowned by ", s2, "\n");
2238                 }
2239                 else if (type == DEATH_SLIME) {
2240                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SLIME);
2241                         if(alsoprint)
2242                                 print ("^1",s1, "^1 was slimed by ", s2, "\n");
2243                 }
2244                 else if (type == DEATH_LAVA) {
2245                         HUD_KillNotify_Push(s2, s1, 1, DEATH_LAVA);
2246                         if(alsoprint)
2247                                 print ("^1",s1, "^1 was cooked by ", s2, "\n");
2248                 }
2249                 else if (type == DEATH_FALL) {
2250                         HUD_KillNotify_Push(s2, s1, 1, DEATH_FALL);
2251                         if(alsoprint)
2252                                 print ("^1",s1, "^1 was grounded by ", s2, "\n");
2253                 }
2254                 else if (type == DEATH_SHOOTING_STAR) {
2255                         HUD_KillNotify_Push(s2, s1, 1, DEATH_SHOOTING_STAR);
2256                         if(alsoprint)
2257                                 print ("^1",s1, "^1 was shot into space by ", s2, "\n");
2258                 }
2259                 else if (type == DEATH_SWAMP) {
2260                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2261                         if(alsoprint)
2262                                 print ("^1",s1, "^1 was conserved by ", s2, "\n");
2263                 }
2264                 else if (type == DEATH_HURTTRIGGER)
2265                 {
2266                         HUD_KillNotify_Push(s2, s1, 1, DEATH_HURTTRIGGER);
2267                         if(alsoprint)
2268                                 print("^1",s1, "^1 was thrown into a world of hurt by ", s2, "\n");
2269                 } else if(type == DEATH_SBCRUSH) {
2270                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2271                         if(alsoprint)
2272                                 print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
2273                 } else if(type == DEATH_SBMINIGUN) {
2274                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2275                         if(alsoprint)
2276                                 print ("^1",s1, "^1 got shredded by ^1", s2, "\n");
2277                 } else if(type == DEATH_SBROCKET) {
2278                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2279                         if(alsoprint)
2280                                 print ("^1",s1, "^1 was blased to bits by ^1", s2, "\n");
2281                 } else if(type == DEATH_SBBLOWUP) {
2282                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2283                         if(alsoprint)
2284                                 print ("^1",s1, "^1 got caught in the destruction of ^1", s2, "'s vehicle\n");
2285                 } else if(type == DEATH_WAKIGUN) {
2286                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2287                         if(alsoprint)
2288                                 print ("^1",s1, "^1 was bolted down by ^1", s2, "\n");
2289                 } else if(type == DEATH_WAKIROCKET) {
2290                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2291                         if(alsoprint)
2292                                 print ("^1",s1, "^1 could find no shelter from ^1", s2, "'s rockets\n");
2293                 } else if(type == DEATH_WAKIBLOWUP) {
2294                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2295                         if(alsoprint)
2296                                 print ("^1",s1, "^1 dies when ^1", s2, "'s wakizashi dies.\n");
2297                 } else if(type == DEATH_TURRET) {
2298                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2299                         if(alsoprint)
2300                                 print ("^1",s1, "^1 was pushed into the line of fire by ^1", s2, "\n");
2301                 } else if(type == DEATH_TOUCHEXPLODE) {
2302                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2303                         if(alsoprint)
2304                                 print ("^1",s1, "^1 was pushed into an accident by ^1", s2, "\n");
2305                 } else if(type == DEATH_CHEAT) {
2306                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2307                         if(alsoprint)
2308                                 print ("^1",s1, "^1 was unfairly eliminated by ^1", s2, "\n");
2309                 } else if (type == DEATH_FIRE) {
2310                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2311                         if(alsoprint)
2312                                 print ("^1",s1, "^1 was burnt to death by ^1", s2, "\n");
2313                 } else if (type == DEATH_CUSTOM) {
2314                         HUD_KillNotify_Push(s2, s1, 1, DEATH_CUSTOM);
2315                         if(alsoprint)
2316                                 print ("^1",s1, "^1 ", s2, "\n");
2317                 } else {
2318                         HUD_KillNotify_Push(s2, s1, 1, DEATH_GENERIC);
2319                         if(alsoprint)
2320                                 print ("^1",s1, "^1 was fragged by ", s2, "\n");
2321                 }
2322         } else if(msg == MSG_SPREE) {
2323                 if(type == KILL_END_SPREE) {
2324                         if(cvar("cl_gentle"))
2325                                 print ("^1",s1,"'s ^1", s2, " scoring spree was ended by ", s3, "\n");
2326                         else
2327                                 print ("^1",s1,"'s ^1", s2, " kill spree was ended by ", s3, "\n");
2328                 } else if(type == KILL_SPREE) {
2329                         if(cvar("cl_gentle"))
2330                                 print ("^1",s1,"^1 made ",s2," scores in a row\n");
2331                         else
2332                                 print ("^1",s1,"^1 has ",s2," frags in a row\n");
2333                 } else if(type == KILL_SPREE_3) {
2334                         if(cvar("cl_gentle"))
2335                                 print (s1,"^7 made a ^1TRIPLE SCORE\n");
2336                         else
2337                                 print (s1,"^7 made a ^1TRIPLE FRAG\n");
2338                 } else if(type == KILL_SPREE_5) {
2339                         if(cvar("cl_gentle"))
2340                                 print (s1,"^7 unleashes ^1SCORING RAGE\n");
2341                         else
2342                                 print (s1,"^7 unleashes ^1RAGE\n");
2343                 } else if(type == KILL_SPREE_10) {
2344                         if(cvar("cl_gentle"))
2345                                 print (s1,"^7 made ^1TEN SCORES IN A ROW!\n");
2346                         else
2347                                 print (s1,"^7 starts the ^1MASSACRE!\n");
2348                 } else if(type == KILL_SPREE_15) {
2349                         if(cvar("cl_gentle"))
2350                                 print (s1,"^7 made ^1FIFTEEN SCORES IN A ROW!\n");
2351                         else
2352                                 print (s1,"^7 executes ^1MAYHEM!\n");
2353                 } else if(type == KILL_SPREE_20) {
2354                         if(cvar("cl_gentle"))
2355                                 print (s1,"^7 made ^1TWENTY SCORES IN A ROW!\n");
2356                         else
2357                                 print (s1,"^7 is a ^1BERSERKER!\n");
2358                 } else if(type == KILL_SPREE_25) {
2359                         if(cvar("cl_gentle"))
2360                                 print (s1,"^7 made ^1TWENTY FIFE SCORES IN A ROW!\n");
2361                         else
2362                                 print (s1,"^7 inflicts ^1CARNAGE!\n");
2363                 } else if(type == KILL_SPREE_30) {
2364                         if(cvar("cl_gentle"))
2365                                 print (s1,"^7 made ^1THIRTY SCORES IN A ROW!\n");
2366                         else
2367                                 print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
2368                 }
2369         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
2370                 if (type == DEATH_DROWN) {
2371                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
2372                         if(alsoprint)
2373                         {
2374                                 if(cvar("cl_gentle"))
2375                                         print ("^1",s1, "^1 was in the water for too long\n");
2376                                 else
2377                                         print ("^1",s1, "^1 drowned\n");
2378                         }
2379                 } else if (type == DEATH_SLIME) {
2380                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
2381                         if(alsoprint)
2382                                 print ("^1",s1, "^1 was slimed\n");
2383                 } else if (type == DEATH_LAVA) {
2384                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
2385                         if(alsoprint)
2386                         {
2387                                 if(cvar("cl_gentle"))
2388                                         print ("^1",s1, "^1 found a hot place\n");
2389                                 else
2390                                         print ("^1",s1, "^1 turned into hot slag\n");
2391                         }
2392                 } else if (type == DEATH_FALL) {
2393                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2394                         if(alsoprint)
2395                         {
2396                                 if(cvar("cl_gentle"))
2397                                         print ("^1",s1, "^1 tested gravity (and it worked)\n");
2398                                 else
2399                                         print ("^1",s1, "^1 hit the ground with a crunch\n");
2400                         }
2401                 } else if (type == DEATH_SHOOTING_STAR) {
2402                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
2403                         if(alsoprint)
2404                                 print ("^1",s1, "^1 became a shooting star\n");
2405                 } else if (type == DEATH_SWAMP) {
2406                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2407                         if(alsoprint)
2408                         {
2409                                 if(cvar("cl_gentle"))
2410                                         print ("^1",s1, "^1 discovered a swamp\n");
2411                                 else
2412                                         print ("^1",s1, "^1 is now conserved for centuries to come\n");
2413                         }
2414                 } else if(type == DEATH_TURRET) {
2415                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2416                         if(alsoprint)
2417                                 print ("^1",s1, "^1 was mowed down by a turret \n");
2418                 } else if (type == DEATH_CUSTOM) {
2419                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
2420                         if(alsoprint)
2421                                 print ("^1",s1, "^1 ", s2, "\n");
2422                 } else if (type == DEATH_HURTTRIGGER) {
2423                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
2424                         if(alsoprint)
2425                                 print ("^1",s1, "^1 was in the wrong place\n");
2426                 } else if(type == DEATH_TOUCHEXPLODE) {
2427                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2428                         if(alsoprint)
2429                                 print ("^1",s1, "^1 died in an accident\n");
2430                 } else if(type == DEATH_CHEAT) {
2431                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2432                         if(alsoprint)
2433                                 print ("^1",s1, "^1 was unfairly eliminated\n");
2434                 } else if(type == DEATH_FIRE) {
2435                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2436                         if(alsoprint)
2437                         {
2438                                 if(cvar("cl_gentle"))
2439                                         print ("^1",s1, "^1 felt a little hot\n");
2440                                 else
2441                                         print ("^1",s1, "^1 burnt to death\n");
2442                                 }
2443                 } else {
2444                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
2445                         if(alsoprint)
2446                         {
2447                                 if(cvar("cl_gentle"))
2448                                         print ("^1",s1, "^1 needs a restart\n");
2449                                 else
2450                                         print ("^1",s1, "^1 died\n");
2451                         }
2452                 }
2453         } else if(msg == MSG_KILL_ACTION_SPREE) {
2454                 if(cvar("cl_gentle"))
2455                         print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
2456                 else
2457                         print ("^1",s1,"^1 died with a ",s2," kill spree\n");
2458         } else if(msg == MSG_INFO) {
2459                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
2460                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2461                         print(s1, "^7 got the ", s2, "\n");
2462                 } else if(type == INFO_LOSTFLAG) {
2463                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
2464                         print(s1, "^7 lost the ", s2, "\n");
2465                 } else if(type == INFO_PICKUPFLAG) {
2466                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
2467                         print(s1, "^7 picked up the ", s2, "\n");
2468                 } else if(type == INFO_RETURNFLAG) {
2469                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
2470                         print(s1, "^7 returned the ", s2, "\n");
2471                 }
2472         }
2473 }
2474
2475 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2476
2477 void HUD_Centerprint(string s1, string s2, float type, float msg)
2478 {
2479         if(msg == MSG_SUICIDE) {
2480                 if (type == DEATH_TEAMCHANGE) {
2481                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You are now on: ", s1));
2482                 } else if (type == DEATH_AUTOTEAMCHANGE) {
2483                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "You have been moved into a different team to improve team balance\nYou are now on: ", s1));
2484                 } else if (type == DEATH_CAMP) {
2485                         if(cvar("cl_gentle"))
2486                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Reconsider your tactics, camper!"));
2487                         else
2488                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Die camper!"));
2489                 } else if (type == DEATH_NOAMMO) {
2490                         if(cvar("cl_gentle"))
2491                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You are reinserted into the game for running out of ammo..."));
2492                         else
2493                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were killed for running out of ammo..."));
2494                 } else if (type == DEATH_ROT) {
2495                         if(cvar("cl_gentle"))
2496                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to preserve your health"));
2497                         else
2498                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You grew too old without taking your medicine"));
2499                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2500                         if(cvar("cl_gentle"))
2501                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't go against team mates!"));
2502                         else
2503                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Don't shoot your team mates!"));
2504                 } else if (type == DEATH_QUIET) {
2505                         // do nothing
2506                 } else if (type == DEATH_KILL) {
2507                         if(cvar("cl_gentle"))
2508                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You need to be more careful!"));
2509                         else
2510                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You killed your own dumb self!"));
2511                 }
2512         } else if(msg == MSG_KILL) {
2513                 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2514                         if(cvar("cl_gentle")) {
2515                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You went against", s1, ",a team mate!"));
2516                         } else {
2517                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Moron! You fragged ", s1, ", a team mate!"));
2518                         }
2519                 } else if (type == KILL_FIRST_BLOOD) {
2520                         if(cvar("cl_gentle")) {
2521                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First score"));
2522                         } else {
2523                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First blood"));
2524                         }
2525                 } else if (type == KILL_FIRST_VICTIM) {
2526                         if(cvar("cl_gentle")) {
2527                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First casualty"));
2528                         } else {
2529                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1First victim"));
2530                         }
2531                 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2532                         if(cvar("cl_gentle")) {
2533                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You scored against ^7", s1, "^1 who was typing!", s2));
2534                         } else {
2535                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You typefragged ^7", s1, s2));
2536                         }
2537                 } else if (type == KILL_TYPEFRAGGED) {
2538                         if(cvar("cl_gentle")) {
2539                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, "^1 while you were typing!", s2));
2540                         } else {
2541                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were typefragged by ^7", s1, s2));
2542                         }
2543                 } else if (type == KILL_FRAG) {
2544                         if(cvar("cl_gentle")) {
2545                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You scored against ^7", s1, s2));
2546                         } else {
2547                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^4You fragged ^7", s1, s2));
2548                         }
2549                 } else if (type == KILL_FRAGGED) {
2550                         if(cvar("cl_gentle")) {
2551                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were scored against by ^7", s1, s2));
2552                         } else {
2553                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1You were fragged by ^7", s1, s2));
2554                         }
2555                 }
2556         } else if(msg == MSG_KILL_ACTION) {
2557                 // TODO: invent more centerprints here?
2558                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, "^1Watch your step!"));
2559         }
2560 }
2561
2562 void HUD_Notify (void)
2563 {
2564         float id = HUD_PANEL_NOTIFY;
2565         vector pos, mySize;
2566         pos = HUD_Panel_GetPos(id);
2567         mySize = HUD_Panel_GetSize(id);
2568
2569         HUD_Panel_DrawBg(id, pos, mySize, 0);
2570         float padding;
2571         padding = HUD_Panel_GetPadding(id);
2572         if(padding)
2573         {
2574                 pos += '1 1 0' * padding;
2575                 mySize -= '2 2 0' * padding;
2576         }
2577
2578         float entries, height;
2579         entries = bound(1, floor(14 * mySize_y/mySize_x), 12);
2580         height = mySize_y/entries;
2581         entries -= 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2582         
2583         vector fontsize;
2584         fontsize = '0.5 0.5 0' * height;
2585
2586         float a;
2587         float when;
2588         when = cvar("hud_notify_time");
2589         float fadetime;
2590         fadetime = cvar("hud_notify_fadetime");
2591
2592         string s;
2593
2594         vector pos_attacker, pos_victim;
2595         vector weap_pos;
2596         float width_attacker, width_victim;
2597         string attacker, victim;
2598
2599         float i, j;
2600         for(j = 0; j < entries; ++j)
2601         {
2602                 if(cvar("hud_notify_flip"))
2603                         i = j;
2604                 else // rather nasty hack for ordering items from the bottom up
2605                         i = entries - j - 1;
2606                 if(cvar("hud_notify_info_top"))
2607                         i += 2; // top/bottom two lines reserved for info messaged, such as spec instructions
2608
2609                 if(fadetime)
2610                 {
2611                         if(killnotify_times[j] + when > time)
2612                                 a = 1;
2613                         else
2614                                 a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2615                 }
2616                 else
2617                 {
2618                         if(killnotify_times[j] + when > time)
2619                                 a = 1;
2620                         else
2621                                 a = 0;
2622                 }
2623
2624                 // TODO: maybe print in team colors?
2625                 // TODO: maybe this could be cleaned up somehow...
2626                 // TODO: less copypaste code below
2627                 //
2628                 // Y [used by] X
2629                 if(killnotify_actiontype[j] == 0 && !hud_configure) 
2630                 {
2631                         attacker = textShortenToWidth(killnotify_attackers[j], mySize_x - 2 * height, fontsize, stringwidth_colors);
2632
2633                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2634                         pos_attacker = pos + eX * 0.5 * (mySize_x - width_attacker + 2 * height) + eY * 0.5 * fontsize_y + eY * i * height;
2635
2636                         weap_pos = pos + eX * 0.5 * (mySize_x - width_attacker) - eX * height + eY * i * height;
2637                         if(killnotify_deathtype[j] == DEATH_GENERIC)
2638                         {
2639                                 drawpic_skin(weap_pos, "notify_death", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2640                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2641                         }
2642                         else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2643                         {
2644                                 drawpic_skin(weap_pos, "notify_outofammo", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2645                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2646                         }
2647                         else if(killnotify_deathtype[j] == DEATH_KILL)
2648                         {
2649                                 drawpic_skin(weap_pos, "notify_selfkill", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2650                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2651                         }
2652                         else if(killnotify_deathtype[j] == DEATH_CAMP)
2653                         {
2654                                 drawpic_skin(weap_pos, "notify_camping", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2655                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2656                         }
2657                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2658                         {
2659                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2660                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2661                         }
2662                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2663                         {
2664                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2665                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2666                         }
2667                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2668                         {
2669                                 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2670                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2671                         }
2672                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2673                         {
2674                                 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2675                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2676                         }
2677                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2678                         {
2679                                 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2680                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2681                         }
2682                         else if(killnotify_deathtype[j] == DEATH_FALL)
2683                         {
2684                                 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2685                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2686                         }
2687                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2688                         {
2689                                 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2690                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2691                         }
2692                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2693                         {
2694                                 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2695                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2696                         }
2697                         else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2698                         {
2699                                 if(killnotify_victims[j] == "^1RED^7 flag")
2700                                         s = "red";
2701                                 else
2702                                         s = "blue";
2703                                 drawpic_skin(weap_pos, strcat("flag_", s, "_carrying"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2704                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2705                         }
2706                         else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2707                         {
2708                                 if(killnotify_victims[j] == "^1RED^7 flag")
2709                                         s = "red";
2710                                 else
2711                                         s = "blue";
2712                                 drawpic_skin(weap_pos, strcat("flag_", s, "_taken"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2713                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2714                         }
2715                         else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2716                         {
2717                                 if(killnotify_victims[j] == "^1RED^7 flag")
2718                                         s = "red";
2719                                 else
2720                                         s = "blue";
2721                                 drawpic_skin(weap_pos, strcat("flag_", s, "_lost"), '1 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2722                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2723                         }
2724                 }
2725                 // X [did action to] Y
2726                 else
2727                 {
2728                         if(hud_configure)
2729                         {
2730                                 attacker = textShortenToWidth("Player1", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2731                                 victim = textShortenToWidth("Player2", 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2732                                 a = bound(0, (when - j) / 4, 1);
2733                         }
2734                         else
2735                         {
2736                                 attacker = textShortenToWidth(killnotify_attackers[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2737                                 victim = textShortenToWidth(killnotify_victims[j], 0.5 * mySize_x - height, fontsize, stringwidth_colors);
2738                         }
2739                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2740                         width_victim = stringwidth(victim, TRUE, fontsize);
2741                         pos_attacker = pos + eX * 0.5 * ((0.5 * mySize_x - height) - width_attacker) + eY * 0.5 * fontsize_y + eY * i * height;
2742                         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;
2743                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2744
2745                         if(hud_configure) // example actions for config mode
2746                         {
2747                                 drawpic_skin(weap_pos, strcat("weapon", "electro"), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2748                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2749                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2750                         }
2751                         else if(WEP_VALID(killnotify_deathtype[j]))
2752                         {
2753                                 self = get_weaponinfo(killnotify_deathtype[j]);
2754                                 drawpic_skin(weap_pos, strcat("weapon", self.netname), '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2755                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2756                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2757                         }
2758                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2759                         {
2760                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '1 0 0', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2761                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2762                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2763                         }
2764                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2765                         {
2766                                 drawpic_skin(weap_pos, "notify_teamkill", '2 1 0' * height, '0 0 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2767                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2768                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2769                         }
2770                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2771                         {
2772                                 drawpic_skin(weap_pos, "notify_water", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2773                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2774                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2775                         }
2776                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2777                         {
2778                                 drawpic_skin(weap_pos, "notify_slime", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2779                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2780                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2781                         }
2782                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2783                         {
2784                                 drawpic_skin(weap_pos, "notify_lava", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2785                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2786                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2787                         }
2788                         else if(killnotify_deathtype[j] == DEATH_FALL)
2789                         {
2790                                 drawpic_skin(weap_pos, "notify_fall", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2791                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2792                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2793                         }
2794                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2795                         {
2796                                 drawpic_skin(weap_pos, "notify_shootingstar", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2797                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2798                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2799                         }
2800                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2801                         {
2802                                 drawpic_skin(weap_pos, "notify_void", '2 1 0' * height, '1 1 1', HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2803                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2804                                 drawcolorcodedstring(pos_victim, victim, fontsize, HUD_Panel_GetFgAlpha(id) * a, DRAWFLAG_NORMAL);
2805                         }
2806                 }
2807
2808         }
2809
2810         // Info messages
2811         //
2812         entity tm;
2813         vector o;
2814         o = pos;
2815         if(cvar("hud_notify_info_top"))
2816                 o = pos + eY;
2817         else
2818                 o = pos + eY * mySize_y - eY * 2 * height;
2819         
2820         if(spectatee_status && !intermission)
2821         {
2822                 //drawfont = hud_bigfont;
2823                 if(spectatee_status == -1)
2824                         s = "^1Observing";
2825                 else
2826                         s = GetPlayerName(spectatee_status - 1);
2827
2828                 //s = textShortenToWidth(s, mySize_y, 0.5 * height, stringwidth_colors);
2829                 //drawcolorcodedstring(pos + eY * 0.25 * height, s, 0.5 * height, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2830                 //drawfont = hud_font;
2831
2832                 // spectator text in the upper right corner
2833                 if(spectatee_status == -1)
2834                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
2835                 else
2836                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
2837                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2838                 o += eY * fontsize_y;
2839
2840                 if(spectatee_status == -1)
2841                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
2842                 else
2843                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
2844                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2845                 o += eY * fontsize_y;
2846
2847                 s = strcat("^1Press ^3", getcommandkey("server info", "+show_info"), "^1 for gamemode info");
2848                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2849                 o += eY * fontsize_y;
2850
2851                 if(gametype == GAME_ARENA)
2852                         s = "^1Wait for your turn to join";
2853                 else if(gametype == GAME_LMS)
2854                 {
2855                         entity sk;
2856                         sk = playerslots[player_localentnum - 1];
2857                         if(sk.(scores[ps_primary]) >= 666)
2858                                 s = "^1Match has already begun";
2859                         else if(sk.(scores[ps_primary]) > 0)
2860                                 s = "^1You have no more lives left";
2861                         else
2862                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2863                 }
2864                 else
2865                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
2866                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2867                 o += eY * fontsize_y;
2868
2869                 //show restart countdown:
2870                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2871                         float countdown;
2872                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
2873                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
2874                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
2875                         drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2876                         o += eY * fontsize_y;
2877                 }
2878         }
2879         if(warmup_stage && !intermission)
2880         {
2881                 s = "^2Currently in ^1warmup^2 stage!";
2882                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2883                 o += eY * fontsize_y;
2884         }
2885
2886         string blinkcolor;
2887         if(mod(time, 1) >= 0.5)
2888                 blinkcolor = "^1";
2889         else
2890                 blinkcolor = "^3";
2891
2892         if(ready_waiting && !intermission && !spectatee_status)
2893         {
2894                 if(ready_waiting_for_me)
2895                 {
2896                         if(warmup_stage)
2897                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
2898                         else
2899                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
2900                 }
2901                 else
2902                 {
2903                         if(warmup_stage)
2904                                 s = strcat("^2Waiting for others to ready up to end warmup...");
2905                         else
2906                                 s = strcat("^2Waiting for others to ready up...");
2907                 }
2908                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2909                 o += eY * fontsize_y;
2910         }
2911         else if(warmup_stage && !intermission && !spectatee_status)
2912         {
2913                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
2914                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2915                 o += eY * fontsize_y;
2916         }
2917
2918         if(teamplay && !intermission && !spectatee_status && gametype != GAME_CA && teamnagger)
2919         {
2920                 float ts_min, ts_max;
2921                 tm = teams.sort_next;
2922                 if (tm)
2923                 {
2924                         for(; tm.sort_next; tm = tm.sort_next)
2925                         {
2926                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
2927                                         continue;
2928                                 if(!ts_min) ts_min = tm.team_size;
2929                                 else ts_min = min(ts_min, tm.team_size);
2930                                 if(!ts_max) ts_max = tm.team_size;
2931                                 else ts_max = max(ts_max, tm.team_size);
2932                         }
2933                         if ((ts_max - ts_min) > 1)
2934                         {
2935                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
2936                                 tm = GetTeam(myteam, false);
2937                                 if (tm)
2938                                 if (tm.team != COLOR_SPECTATOR)
2939                                 if (tm.team_size == ts_max)
2940                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
2941
2942                                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2943                                 o += eY * fontsize_y;
2944                         }
2945                 }
2946         }
2947         if(hud_configure)
2948         {
2949                 s = "^7Press ^3ESC ^7to show HUD options.";
2950                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2951                 o += eY * fontsize_y;
2952                 s = "^3Doubleclick a panel for panel-specific options.";
2953                 drawcolorcodedstring(o, s, fontsize, HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
2954                 o += eY * fontsize_y;
2955         }
2956 }
2957
2958 // Timer (#5)
2959 //
2960 string seconds_tostring(float sec)
2961 {
2962         float minutes;
2963         minutes = floor(sec / 60);
2964
2965         sec -= minutes * 60;
2966
2967         string s;
2968         s = ftos(100 + sec);
2969
2970         return strcat(ftos(minutes), ":", substring(s, 1, 3));
2971 }
2972
2973 void HUD_Timer(void)
2974 {
2975         float id = HUD_PANEL_TIMER;
2976         vector pos, mySize;
2977         pos = HUD_Panel_GetPos(id);
2978         mySize = HUD_Panel_GetSize(id);
2979
2980         HUD_Panel_DrawBg(id, pos, mySize, 0);
2981         float padding;
2982         padding = HUD_Panel_GetPadding(id);
2983         if(padding)
2984         {
2985                 pos += '1 1 0' * padding;
2986                 mySize -= '2 2 0' * padding;
2987         }
2988
2989         string timer;
2990         float timelimit, elapsedTime, timeleft, minutesLeft;
2991
2992         timelimit = getstatf(STAT_TIMELIMIT);
2993
2994         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2995         timeleft = ceil(timeleft);
2996
2997         minutesLeft = floor(timeleft / 60);
2998
2999         vector timer_color;
3000         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
3001                 timer_color = '1 1 1'; //white
3002         else if(minutesLeft >= 1)
3003                 timer_color = '1 1 0'; //yellow
3004         else
3005                 timer_color = '1 0 0'; //red
3006
3007         if (cvar("hud_timer_increment") || timelimit == 0 || warmup_stage) {
3008                 if (time < getstatf(STAT_GAMESTARTTIME)) {
3009                         //while restart is still active, show 00:00
3010                         timer = seconds_tostring(0);
3011                 } else {
3012                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
3013                         timer = seconds_tostring(elapsedTime);
3014                 }
3015         } else {
3016                 timer = seconds_tostring(timeleft);
3017         }
3018
3019         drawstring_aspect(pos, timer, mySize, mySize_y, timer_color, HUD_Panel_GetFgAlpha(HUD_PANEL_TIMER), DRAWFLAG_NORMAL);
3020 }
3021
3022 // Radar (#6)
3023 //
3024 void HUD_Radar(void)
3025 {
3026         float id = HUD_PANEL_RADAR;
3027         vector pos, mySize;
3028         pos = HUD_Panel_GetPos(id);
3029         mySize = HUD_Panel_GetSize(id);
3030
3031         HUD_Panel_DrawBg(id, pos, mySize, 0);
3032         float padding;
3033         padding = HUD_Panel_GetPadding(id);
3034         if(padding)
3035         {
3036                 pos += '1 1 0' * padding;
3037                 mySize -= '2 2 0' * padding;
3038         }
3039
3040         local float color1, color2; // color already declared as a global in hud.qc
3041         local vector rgb;
3042         local entity tm;
3043         float scale2d, normalsize, bigsize;
3044         float f;
3045
3046         teamradar_origin2d = pos + 0.5 * mySize;
3047         teamradar_size2d = mySize;
3048
3049         if(minimapname == "")
3050                 return;
3051
3052         teamradar_loadcvars();
3053
3054         switch(hud_radar_zoommode)
3055         {
3056                 default:
3057                 case 0:
3058                         f = current_zoomfraction;
3059                         break;
3060                 case 1:
3061                         f = 1 - current_zoomfraction;
3062                         break;
3063                 case 2:
3064                         f = 0;
3065                         break;
3066                 case 3:
3067                         f = 1;
3068                         break;
3069         }
3070
3071         switch(hud_radar_rotation)
3072         {
3073                 case 0:
3074                         teamradar_angle = view_angles_y - 90;
3075                         break;
3076                 default:
3077                         teamradar_angle = 90 * hud_radar_rotation;
3078                         break;
3079         }
3080
3081         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
3082         teamradar_size2d = mySize;
3083
3084         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
3085
3086         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
3087         if(hud_radar_rotation == 0)
3088         {
3089                 // max-min distance must fit the radar in any rotation
3090                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
3091         }
3092         else
3093         {
3094                 vector c0, c1, c2, c3, span;
3095                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
3096                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
3097                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
3098                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
3099                 span = '0 0 0';
3100                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
3101                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
3102
3103                 // max-min distance must fit the radar in x=x, y=y
3104                 bigsize = min(
3105                         teamradar_size2d_x * scale2d / (1.05 * span_x),
3106                         teamradar_size2d_y * scale2d / (1.05 * span_y)
3107                 );
3108         }
3109
3110         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_radar_scale;
3111         if(bigsize > normalsize)
3112                 normalsize = bigsize;
3113
3114         teamradar_size =
3115                   f * bigsize
3116                 + (1 - f) * normalsize;
3117         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
3118                   f * (mi_min + mi_max) * 0.5
3119                 + (1 - f) * view_origin);
3120
3121         color1 = GetPlayerColor(player_localentnum-1);
3122         rgb = GetTeamRGB(color1);
3123
3124         drawsetcliparea(
3125                 pos_x,
3126                 pos_y,
3127                 mySize_x,
3128                 mySize_y
3129         );
3130