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