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