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