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