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