Merge remote branch 'origin/samual/waypointsprite_edgeoffset'
[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) // draw whole image as it is
18     {
19                 drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
20                 return;
21     }
22         if (theBorderSize_x == 0 && theBorderSize_y == 0) // no border
23         {
24                 // draw only the central part
25                 drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
26                 return;
27         }
28
29         vector dX, dY;
30         vector width, height;
31         vector bW, bH;
32         //pic = draw_UseSkinFor(pic);
33         width = eX * theSize_x;
34         height = eY * theSize_y;
35         if(theSize_x <= theBorderSize_x * 2)
36         {
37                 // not wide enough... draw just left and right then
38                 bW = eX * (0.25 * theSize_x / (theBorderSize_x * 2));
39                 if(theSize_y <= theBorderSize_y * 2)
40                 {
41                         // not high enough... draw just corners
42                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
43                         drawsubpic(theOrigin,                 width * 0.5 + height * 0.5, pic, '0 0 0',           bW + bH, theColor, theAlpha, 0);
44                         drawsubpic(theOrigin + width   * 0.5, width * 0.5 + height * 0.5, pic, eX - bW,           bW + bH, theColor, theAlpha, 0);
45                         drawsubpic(theOrigin + height  * 0.5, width * 0.5 + height * 0.5, pic, eY - bH,           bW + bH, theColor, theAlpha, 0);
46                         drawsubpic(theOrigin + theSize * 0.5, width * 0.5 + height * 0.5, pic, eX + eY - bW - bH, bW + bH, theColor, theAlpha, 0);
47                 }
48                 else
49                 {
50                         dY = theBorderSize_x * eY;
51                         drawsubpic(theOrigin,                             width * 0.5          +     dY, pic, '0 0    0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
52                         drawsubpic(theOrigin + width * 0.5,               width * 0.5          +     dY, pic, '0 0    0' + eX - bW, '0 0.25 0' + bW, theColor, theAlpha, 0);
53                         drawsubpic(theOrigin                        + dY, width * 0.5 + height - 2 * dY, pic, '0 0.25 0',           '0 0.5  0' + bW, theColor, theAlpha, 0);
54                         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);
55                         drawsubpic(theOrigin               + height - dY, width * 0.5          +     dY, pic, '0 0.75 0',           '0 0.25 0' + bW, theColor, theAlpha, 0);
56                         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);
57                 }
58         }
59         else
60         {
61                 if(theSize_y <= theBorderSize_y * 2)
62                 {
63                         // not high enough... draw just top and bottom then
64                         bH = eY * (0.25 * theSize_y / (theBorderSize_y * 2));
65                         dX = theBorderSize_x * eX;
66                         drawsubpic(theOrigin,                                         dX + height * 0.5, pic, '0    0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
67                         drawsubpic(theOrigin + dX,                        width - 2 * dX + height * 0.5, pic, '0.25 0 0',           '0.5  0 0' + bH, theColor, theAlpha, 0);
68                         drawsubpic(theOrigin + width - dX,                            dX + height * 0.5, pic, '0.75 0 0',           '0.25 0 0' + bH, theColor, theAlpha, 0);
69                         drawsubpic(theOrigin              + height * 0.5,             dX + height * 0.5, pic, '0    0 0' + eY - bH, '0.25 0 0' + bH, theColor, theAlpha, 0);
70                         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);
71                         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);
72                 }
73                 else
74                 {
75                         dX = theBorderSize_x * eX;
76                         dY = theBorderSize_x * eY;
77                         drawsubpic(theOrigin,                                        dX          +     dY, pic, '0    0    0', '0.25 0.25 0', theColor, theAlpha, 0);
78                         drawsubpic(theOrigin                  + dX,      width - 2 * dX          +     dY, pic, '0.25 0    0', '0.5  0.25 0', theColor, theAlpha, 0);
79                         drawsubpic(theOrigin          + width - dX,                  dX          +     dY, pic, '0.75 0    0', '0.25 0.25 0', theColor, theAlpha, 0);
80                         drawsubpic(theOrigin          + dY,                          dX + height - 2 * dY, pic, '0    0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
81                         drawsubpic(theOrigin          + dY         + dX, width - 2 * dX + height - 2 * dY, pic, '0.25 0.25 0', '0.5  0.5  0', theColor, theAlpha, 0);
82                         drawsubpic(theOrigin          + dY + width - dX,             dX + height - 2 * dY, pic, '0.75 0.25 0', '0.25 0.5  0', theColor, theAlpha, 0);
83                         drawsubpic(theOrigin + height - dY,                          dX          +     dY, pic, '0    0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
84                         drawsubpic(theOrigin + height - dY         + dX, width - 2 * dX          +     dY, pic, '0.25 0.75 0', '0.5  0.25 0', theColor, theAlpha, 0);
85                         drawsubpic(theOrigin + height - dY + width - dX,             dX          +     dY, pic, '0.75 0.75 0', '0.25 0.25 0', theColor, theAlpha, 0);
86                 }
87         }
88 }
89
90 vector HUD_Get_Num_Color (float x, float maxvalue)
91 {
92         float blinkingamt;
93         vector color;
94         if(x >= maxvalue) {
95                 color_x = sin(2*M_PI*time);
96                 color_y = 1;
97                 color_z = sin(2*M_PI*time);
98         }
99         else if(x > maxvalue * 0.75) {
100                 color_x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
101                 color_y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
102                 color_z = 0;
103         }
104         else if(x > maxvalue * 0.5) {
105                 color_x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
106                 color_y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
107                 color_z = 1 - (x-100)*0.02; // blue value between 1 -> 0
108         }
109         else if(x > maxvalue * 0.25) {
110                 color_x = 1;
111                 color_y = 1;
112                 color_z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
113         }
114         else if(x > maxvalue * 0.1) {
115                 color_x = 1;
116                 color_y = (x-20)*90/27/100; // green value between 0 -> 1
117                 color_z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
118         }
119         else {
120                 color_x = 1;
121                 color_y = 0;
122                 color_z = 0;
123         }
124
125         blinkingamt = (1 - x/maxvalue/0.25);
126         if(blinkingamt > 0)
127         {
128                 color_x = color_x - color_x * blinkingamt * sin(2*M_PI*time);
129                 color_y = color_y - color_y * blinkingamt * sin(2*M_PI*time);
130                 color_z = color_z - color_z * blinkingamt * sin(2*M_PI*time);
131         }
132         return color;
133 }
134
135 float stringwidth_colors(string s, vector theSize)
136 {
137         return stringwidth(s, TRUE, theSize);
138 }
139
140 float stringwidth_nocolors(string s, vector theSize)
141 {
142         return stringwidth(s, FALSE, theSize);
143 }
144
145 #define CENTERPRINT_MAX_LINES 30
146 string centerprint_messages[CENTERPRINT_MAX_LINES];
147 float centerprint_width[CENTERPRINT_MAX_LINES];
148 float centerprint_time;
149 float centerprint_expire;
150 float centerprint_num;
151 float centerprint_offset_hint;
152 vector centerprint_fontsize;
153
154 void centerprint(string strMessage)
155 {
156         float i, j, n, hcount;
157         string s;
158
159         centerprint_fontsize = HUD_GetFontsize("scr_centersize");
160
161         centerprint_expire = min(centerprint_expire, time); // if any of the returns happens, this message will fade out
162
163         if(autocvar_scr_centertime <= 0)
164                 return;
165
166         if(strMessage == "")
167                 return;
168
169         // strip trailing newlines
170         j = strlen(strMessage) - 1;
171         while(substring(strMessage, j, 1) == "\n" && j >= 0)
172                 j = j - 1;
173         strMessage = substring(strMessage, 0, j + 1);
174
175         if(strMessage == "")
176                 return;
177
178         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
179         j = 0;
180         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
181                 j = j + 1;
182         strMessage = substring(strMessage, j, strlen(strMessage) - j);
183         centerprint_offset_hint = j;
184
185         if(strMessage == "")
186                 return;
187
188         // if we get here, we have a message. Initialize its height.
189         centerprint_num = 0;
190
191         n = tokenizebyseparator(strMessage, "\n");
192         i = hcount = 0;
193         for(j = 0; j < n; ++j)
194         {
195                 getWrappedLine_remaining = argv(j);
196                 while(getWrappedLine_remaining)
197                 {
198                         s = getWrappedLine(vid_conwidth * 0.75, centerprint_fontsize, stringwidth_colors);
199                         if(centerprint_messages[i] != s) // don't fade the same message in, looks stupid
200                                 centerprint_time = time;
201                         if(centerprint_messages[i])
202                                 strunzone(centerprint_messages[i]);
203                         centerprint_messages[i] = strzone(s);
204                         centerprint_width[i] = stringwidth(s, TRUE, centerprint_fontsize);
205                         ++i;
206
207                         // half height for empty lines looks better
208                         if(s == "")
209                                 hcount += 0.5;
210                         else
211                                 hcount += 1;
212
213                         if(i >= CENTERPRINT_MAX_LINES)
214                                 break;
215                 }
216         }
217
218         float h, havail;
219         h = centerprint_fontsize_y*hcount;
220
221         havail = vid_conheight;
222         if(autocvar_con_chatpos < 0)
223                 havail -= (-autocvar_con_chatpos + autocvar_con_chat) * autocvar_con_chatsize; // avoid overlapping chat
224         if(havail > vid_conheight - 70)
225                 havail = vid_conheight - 70; // avoid overlapping HUD
226
227 #if 0
228         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
229
230         // here, the centerprint would cover the crosshair. REALLY BAD.
231         forbiddenmin = vid_conheight * 0.5 - h - 16;
232         forbiddenmax = vid_conheight * 0.5 + 16;
233
234         allowedmin = scoreboard_bottom;
235         allowedmax = havail - h;
236         preferred = (havail - h)/2;
237
238
239         // possible orderings (total: 4! / 4 = 6)
240         //  allowedmin allowedmax forbiddenmin forbiddenmax
241         //  forbiddenmin forbiddenmax allowedmin allowedmax
242         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
243         {
244                 // forbidden doesn't matter in this case
245                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
246         }
247         //  allowedmin forbiddenmin allowedmax forbiddenmax
248         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
249         {
250                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
251         }
252         //  allowedmin forbiddenmin forbiddenmax allowedmax
253         else if(allowedmin < forbiddenmin)
254         {
255                 // make sure the forbidden zone is not covered
256                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
257                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
258                 else
259                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
260         }
261         //  forbiddenmin allowedmin allowedmax forbiddenmax
262         else if(allowedmax < forbiddenmax)
263         {
264                 // it's better to leave the allowed zone (overlap with scoreboard) than
265                 // to cover the forbidden zone (crosshair)
266                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
267                         centerprint_start_y = forbiddenmax;
268                 else
269                         centerprint_start_y = forbiddenmin;
270         }
271         //  forbiddenmin allowedmin forbiddenmax allowedmax
272         else
273         {
274                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
275         }
276 #else
277 #endif
278
279         centerprint_num = i;
280
281         centerprint_expire = time + autocvar_scr_centertime;
282 }
283
284 void HUD_DrawCenterPrint (void)
285 {
286         float i;
287         vector pos;
288         string ts;
289         float a, sz;
290
291         if(time - centerprint_time < 0.25)
292                 a = (time - centerprint_time) / 0.25;
293         else
294                 a = bound(0, 1 - 4 * (time - centerprint_expire), 1);
295
296         if(a <= 0)
297                 return;
298
299         sz = 0.8 + (a / 5);
300
301         if(centerprint_num * autocvar_scr_centersize > 24 && scoreboard_active) // 24 = height of Scoreboard text
302                 centerprint_start_y = scoreboard_bottom + centerprint_fontsize_y;
303
304         pos = centerprint_start;
305         for (i=0; i<centerprint_num; i = i + 1)
306         {
307                 ts = centerprint_messages[i];
308                 drawfontscale = sz * '1 1 0';
309                 pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
310                 if (ts != "")
311                 {
312                         drawcolorcodedstring(pos + '0 1 0' * (1 - sz) * 0.5 *centerprint_fontsize_y, ts, centerprint_fontsize, a, DRAWFLAG_NORMAL);
313                         pos_y = pos_y + centerprint_fontsize_y;
314                 }
315                 else
316                         // half height for empty lines looks better
317                         pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
318                 drawfontscale = '1 1 0';
319         }
320 }
321
322 void drawstringright(vector position, string text, vector scale, vector rgb, float alpha, float flag)
323 {
324         position_x -= 2 / 3 * strlen(text) * scale_x;
325         drawstring(position, text, scale, rgb, alpha, flag);
326 }
327
328 void drawstringcenter(vector position, string text, vector scale, vector rgb, float alpha, float flag)
329 {
330         position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
331         drawstring(position, text, scale, rgb, alpha, flag);
332 }
333
334 // return the string of the given race place
335 string race_PlaceName(float pos) {
336         if(pos == 1)
337                 return _("1st");
338         else if(pos == 2)
339                 return _("2nd");
340         else if(pos == 3)
341                 return _("3rd");
342         else
343                 return sprintf(_("%dth"), pos);
344 }
345
346 // return the string of the onscreen race timer
347 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
348 {
349         string col;
350         string timestr;
351         string cpname;
352         string lapstr;
353         lapstr = "";
354
355         if(histime == 0) // goal hit
356         {
357                 if(mytime > 0)
358                 {
359                         timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
360                         col = "^1";
361                 }
362                 else if(mytime == 0)
363                 {
364                         timestr = "+0.0";
365                         col = "^3";
366                 }
367                 else
368                 {
369                         timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
370                         col = "^2";
371                 }
372
373                 if(lapdelta > 0)
374                 {
375                         lapstr = sprintf(_(" (-%dL)"), lapdelta);
376                         col = "^2";
377                 }
378                 else if(lapdelta < 0)
379                 {
380                         lapstr = sprintf(_(" (+%dL)"), -lapdelta);
381                         col = "^1";
382                 }
383         }
384         else if(histime > 0) // anticipation
385         {
386                 if(mytime >= histime)
387                         timestr = strcat("+", ftos_decimals(mytime - histime, TIME_DECIMALS));
388                 else
389                         timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(histime));
390                 col = "^3";
391         }
392         else
393                 col = "^7";
394
395         if(cp == 254)
396                 cpname = _("Start line");
397         else if(cp == 255)
398                 cpname = _("Finish line");
399         else if(cp)
400                 cpname = sprintf(_("Intermediate %d"), cp);
401         else
402                 cpname = _("Finish line");
403
404         if(histime < 0)
405                 return strcat(col, cpname);
406         else if(hisname == "")
407                 return strcat(col, sprintf(_("%s (%s)"), cpname, timestr));
408         else
409                 return strcat(col, sprintf(_("%s (%s %s)"), cpname, timestr, strcat(hisname, col, lapstr)));
410 }
411
412 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
413 float race_CheckName(string net_name) {
414         float i;
415         for (i=RANKINGS_CNT-1;i>=0;--i)
416                 if(grecordholder[i] == net_name)
417                         return i+1;
418         return 0;
419 }
420
421 /*
422 ==================
423 HUD panels
424 ==================
425 */
426
427 // draw the background/borders
428 #define HUD_Panel_DrawBg(alpha)\
429 if(panel_bg != "0")\
430         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));\
431 if(highlightedPanel == hud_configure_active_panel && autocvar__hud_configure)\
432 {\
433         HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
434 } ENDS_WITH_CURLY_BRACE
435
436 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
437 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
438 {
439         if(!length_ratio || !theAlpha)
440                 return;
441         if(length_ratio > 1)
442                 length_ratio = 1;
443         if (baralign == 3)
444         {
445                 if(length_ratio < -1)
446                         length_ratio = -1;
447         }
448         else if(length_ratio < 0)
449                 return;
450
451         vector square;
452         vector width, height;
453         if(vertical) {
454                 pic = strcat(hud_skin_path, "/", pic, "_vertical");
455                 if(precache_pic(pic) == "") {
456                         pic = "gfx/hud/default/progressbar_vertical";
457                 }
458
459         if (baralign == 1) // bottom align
460                         theOrigin_y += (1 - length_ratio) * theSize_y;
461         else if (baralign == 2) // center align
462             theOrigin_y += 0.5 * (1 - length_ratio) * theSize_y;
463         else if (baralign == 3) // center align, positive values down, negative up
464                 {
465                         theSize_y *= 0.5;
466                         if (length_ratio > 0)
467                                 theOrigin_y += theSize_y;
468                         else
469                         {
470                                 theOrigin_y += (1 + length_ratio) * theSize_y;
471                                 length_ratio = -length_ratio;
472                         }
473                 }
474                 theSize_y *= length_ratio;
475
476                 vector bH;
477                 width = eX * theSize_x;
478                 height = eY * theSize_y;
479                 if(theSize_y <= theSize_x * 2)
480                 {
481                         // button not high enough
482                         // draw just upper and lower part then
483                         square = eY * theSize_y * 0.5;
484                         bH = eY * (0.25 * theSize_y / (theSize_x * 2));
485                         drawsubpic(theOrigin,          square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
486                         drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
487                 }
488                 else
489                 {
490                         square = eY * theSize_x;
491                         drawsubpic(theOrigin,                   width   +     square, pic, '0 0    0', '1 0.25 0', theColor, theAlpha, drawflag);
492                         drawsubpic(theOrigin +          square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5  0', theColor, theAlpha, drawflag);
493                         drawsubpic(theOrigin + height - square, width   +     square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
494                 }
495         } else {
496                 pic = strcat(hud_skin_path, "/", pic);
497                 if(precache_pic(pic) == "") {
498                         pic = "gfx/hud/default/progressbar";
499                 }
500
501                 if (baralign == 1) // right align
502                         theOrigin_x += (1 - length_ratio) * theSize_x;
503         else if (baralign == 2) // center align
504             theOrigin_x += 0.5 * (1 - length_ratio) * theSize_x;
505         else if (baralign == 3) // center align, positive values on the right, negative on the left
506                 {
507                         theSize_x *= 0.5;
508                         if (length_ratio > 0)
509                                 theOrigin_x += theSize_x;
510                         else
511                         {
512                                 theOrigin_x += (1 + length_ratio) * theSize_x;
513                                 length_ratio = -length_ratio;
514                         }
515                 }
516                 theSize_x *= length_ratio;
517
518                 vector bW;
519                 width = eX * theSize_x;
520                 height = eY * theSize_y;
521                 if(theSize_x <= theSize_y * 2)
522                 {
523                         // button not wide enough
524                         // draw just left and right part then
525                         square = eX * theSize_x * 0.5;
526                         bW = eX * (0.25 * theSize_x / (theSize_y * 2));
527                         drawsubpic(theOrigin,          square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
528                         drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
529                 }
530                 else
531                 {
532                         square = eX * theSize_y;
533                         drawsubpic(theOrigin,                  height  +     square, pic, '0    0 0', '0.25 1 0', theColor, theAlpha, drawflag);
534                         drawsubpic(theOrigin +         square, theSize - 2 * square, pic, '0.25 0 0', '0.5  1 0', theColor, theAlpha, drawflag);
535                         drawsubpic(theOrigin + width - square, height  +     square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
536                 }
537         }
538 }
539
540 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
541 {
542         if(!alpha)
543                 return;
544
545         string pic;
546         pic = strcat(hud_skin_path, "/num_leading");
547         if(precache_pic(pic) == "") {
548                 pic = "gfx/hud/default/num_leading";
549         }
550
551         drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
552         if(mySize_x/mySize_y > 2)
553                 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);
554         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);
555 }
556
557 // Weapon icons (#0)
558 //
559 entity weaponorder[WEP_MAXCOUNT];
560 void weaponorder_swap(float i, float j, entity pass)
561 {
562         entity h;
563         h = weaponorder[i];
564         weaponorder[i] = weaponorder[j];
565         weaponorder[j] = h;
566 }
567
568 string weaponorder_cmp_str;
569 float weaponorder_cmp(float i, float j, entity pass)
570 {
571         float ai, aj;
572         ai = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[i].weapon), 0);
573         aj = strstrofs(weaponorder_cmp_str, sprintf(" %d ", weaponorder[j].weapon), 0);
574         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)
575 }
576
577 float GetAmmoStat(float i)
578 {
579         switch(i)
580         {
581                 case 0: return STAT_SHELLS;
582                 case 1: return STAT_NAILS;
583                 case 2: return STAT_ROCKETS;
584                 case 3: return STAT_CELLS;
585                 case 4: return STAT_FUEL;
586                 default: return -1;
587         }
588 }
589
590 float GetAmmoTypeForWep(float i)
591 {
592         switch(i)
593         {
594                 case WEP_SHOTGUN: return 0;
595                 case WEP_UZI: return 1;
596                 case WEP_GRENADE_LAUNCHER: return 2;
597                 case WEP_MINE_LAYER: return 2;
598                 case WEP_ELECTRO: return 3;
599                 case WEP_CRYLINK: return 3;
600                 case WEP_HLAC: return 3;
601                 case WEP_MINSTANEX: return 3;
602                 case WEP_NEX: return 3;
603                 case WEP_RIFLE: return 1;
604                 case WEP_HAGAR: return 2;
605                 case WEP_ROCKET_LAUNCHER: return 2;
606                 case WEP_SEEKER: return 2;
607                 case WEP_FIREBALL: return 4;
608                 case WEP_HOOK: return 3;
609                 default: return -1;
610         }
611 }
612
613 void HUD_Weapons(void)
614 {
615         float f, screen_ar;
616         float center_x, center_y;
617     if(hud != HUD_NORMAL) return;
618         if(!autocvar__hud_configure)
619         {
620                 if(!autocvar_hud_panel_weapons) return;
621                 if(spectatee_status == -1) return;
622         }
623         else
624                 hud_configure_active_panel = HUD_PANEL_WEAPONS;
625
626         float timeout = autocvar_hud_panel_weapons_timeout;
627         float timeout_effect_length, timein_effect_length;
628         if (autocvar_hud_panel_weapons_timeout_effect == 0)
629         {
630                 timeout_effect_length = 0;
631                 timein_effect_length = 0;
632         }
633         else
634         {
635                 timeout_effect_length = 0.75;
636                 timein_effect_length = 0.375;
637         }
638
639         if (timeout && time >= weapontime + timeout + timeout_effect_length && !autocvar__hud_configure)
640         {
641                 weaponprevtime = time;
642                 return;
643         }
644
645         HUD_Panel_UpdateCvars(weapons);
646
647         if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
648         {
649                 f = (time - (weapontime + timeout)) / timeout_effect_length;
650                 if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
651                 {
652                         panel_bg_alpha *= (1 - f);
653                         panel_fg_alpha *= (1 - f);
654                 }
655                 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
656                 {
657                         f *= f; // for a cooler movement
658                         center_x = panel_pos_x + panel_size_x/2;
659                         center_y = panel_pos_y + panel_size_y/2;
660                         screen_ar = vid_conwidth/vid_conheight;
661                         if (center_x/center_y < screen_ar) //bottom left
662                         {
663                                 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
664                                         panel_pos_y += f * (vid_conheight - panel_pos_y);
665                                 else //left
666                                         panel_pos_x -= f * (panel_pos_x + panel_size_x);
667                         }
668                         else //top right
669                         {
670                                 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
671                                         panel_pos_x += f * (vid_conwidth - panel_pos_x);
672                                 else //top
673                                         panel_pos_y -= f * (panel_pos_y + panel_size_y);
674                         }
675                 }
676                 weaponprevtime = time - (1 - f) * timein_effect_length;
677         }
678         else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
679         {
680                 f = (time - weaponprevtime) / timein_effect_length;
681                 if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
682                 {
683                         panel_bg_alpha *= (f);
684                         panel_fg_alpha *= (f);
685                 }
686                 if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
687                 {
688                         f *= f; // for a cooler movement
689                         f = 1 - f;
690                         center_x = panel_pos_x + panel_size_x/2;
691                         center_y = panel_pos_y + panel_size_y/2;
692                         screen_ar = vid_conwidth/vid_conheight;
693                         if (center_x/center_y < screen_ar) //bottom left
694                         {
695                                 if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
696                                         panel_pos_y += f * (vid_conheight - panel_pos_y);
697                                 else //left
698                                         panel_pos_x -= f * (panel_pos_x + panel_size_x);
699                         }
700                         else //top right
701                         {
702                                 if ((vid_conwidth - center_x)/center_y < screen_ar) //right
703                                         panel_pos_x += f * (vid_conwidth - panel_pos_x);
704                                 else //top
705                                         panel_pos_y -= f * (panel_pos_y + panel_size_y);
706                         }
707                 }
708         }
709
710         float i, weapid, wpnalpha, weapon_cnt;
711
712         // TODO make this configurable
713         if(weaponorder_bypriority != autocvar_cl_weaponpriority || !weaponorder[0])
714         {
715                 if(weaponorder_bypriority)
716                         strunzone(weaponorder_bypriority);
717                 if(weaponorder_byimpulse)
718                         strunzone(weaponorder_byimpulse);
719
720                 weaponorder_bypriority = strzone(autocvar_cl_weaponpriority);
721                 weaponorder_byimpulse = strzone(W_FixWeaponOrder_BuildImpulseList(W_FixWeaponOrder_ForceComplete(W_NumberWeaponOrder(weaponorder_bypriority))));
722                 weaponorder_cmp_str = strcat(" ", weaponorder_byimpulse, " ");
723
724                 weapon_cnt = 0;
725                 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
726                 {
727                         self = get_weaponinfo(i);
728                         if(self.impulse >= 0)
729                         {
730                                 weaponorder[weapon_cnt] = self;
731                                 ++weapon_cnt;
732                         }
733                 }
734                 for(i = weapon_cnt; i < WEP_MAXCOUNT; ++i)
735                         weaponorder[i] = NULL;
736                 heapsort(weapon_cnt, weaponorder_swap, weaponorder_cmp, world);
737
738                 weaponorder_cmp_str = string_null;
739         }
740
741         HUD_Panel_DrawBg(1);
742         if(panel_bg_padding)
743         {
744                 panel_pos += '1 1 0' * panel_bg_padding;
745                 panel_size -= '2 2 0' * panel_bg_padding;
746         }
747
748         if(autocvar_hud_panel_weapons_fade)
749         {
750                 wpnalpha = 3.2 - 2 * (time - weapontime);
751                 wpnalpha = bound(0.7, wpnalpha, 1) * panel_fg_alpha;
752         }
753         else
754                 wpnalpha = panel_fg_alpha;
755
756         float rows, columns;
757         float aspect = autocvar_hud_panel_weapons_aspect;
758         rows = panel_size_y/panel_size_x;
759         rows = bound(1, floor((sqrt(4 * aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
760
761         columns = ceil(WEP_COUNT/rows);
762         float row, column;
763
764         float a, type, fullammo;
765         float when;
766         when = autocvar_hud_panel_weapons_complainbubble_time;
767         float fadetime;
768         fadetime = autocvar_hud_panel_weapons_complainbubble_fadetime;
769
770         vector color;
771         vector wpnpos;
772         vector wpnsize;
773         
774         vector ammo_color;
775         float ammo_alpha;
776         wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
777         float barsize_x, barsize_y, baroffset_x, baroffset_y;
778         if (autocvar_hud_panel_weapons_ammo)
779         {
780                 ammo_color = stov(autocvar_hud_panel_weapons_ammo_color);
781                 ammo_alpha = panel_fg_alpha * autocvar_hud_panel_weapons_ammo_alpha;
782
783
784                 if(wpnsize_x/wpnsize_y > aspect)
785                 {
786                         barsize_x = aspect * wpnsize_y;
787                         barsize_y = wpnsize_y;
788                         baroffset_x = (wpnsize_x - barsize_x) / 2;
789                 }
790                 else
791                 {
792                         barsize_y = 1/aspect * wpnsize_x;
793                         barsize_x = wpnsize_x;
794                         baroffset_y = (wpnsize_y - barsize_y) / 2;
795                 }
796         }
797
798         float show_accuracy;
799         float weapon_stats;
800         if(autocvar_hud_panel_weapons_accuracy && acc_levels)
801         {
802                 show_accuracy = true;
803                 if (acc_col_x[0] == -1)
804                         for (i = 0; i < acc_levels; ++i)
805                                 acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
806         }
807
808         float weapons_st = getstati(STAT_WEAPONS);
809
810         for(i = 0; i <= WEP_LAST-WEP_FIRST; ++i)
811         {
812                 self = weaponorder[i];
813                 if (!self || self.impulse < 0)
814                         continue;
815                 wpnpos = panel_pos + eX * column * wpnsize_x + eY * row * wpnsize_y;
816
817                 weapid = self.impulse;
818
819                 // draw background behind currently selected weapon
820                 if(self.weapon == activeweapon)
821                         drawpic_aspect_skin(wpnpos, "weapon_current_bg", wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
822
823                 // draw the weapon accuracy
824                 if(show_accuracy)
825                 {
826                         weapon_stats = weapon_accuracy[self.weapon-WEP_FIRST];
827                         if(weapon_stats >= 0)
828                         {
829                                 // find the max level lower than weapon_stats
830                                 float j;
831                                 j = acc_levels-1;
832                                 while ( j && weapon_stats < acc_lev[j] )
833                                         --j;
834
835                                 // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
836                                 float factor;
837                                 factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
838                                 color = acc_col[j];
839                                 color = color + factor * (acc_col[j+1] - color);
840
841                                 drawpic_aspect_skin(wpnpos, "weapon_accuracy", wpnsize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
842                         }
843                 }
844
845                 // draw the weapon icon
846                 if(weapons_st & self.weapons)
847                 {
848                         drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
849
850                         if(autocvar_hud_panel_weapons_label == 1) // weapon number
851                                 drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
852                         else if(autocvar_hud_panel_weapons_label == 2) // bind
853                                 drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
854
855                         // draw ammo status bar
856                         if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
857                         {
858                                 a = 0;
859                                 type = GetAmmoTypeForWep(self.weapon);
860                                 if(type != -1)
861                                         a = getstati(GetAmmoStat(type)); // how much ammo do we have?
862
863                                 if(a > 0)
864                                 {
865                                         switch(type) {
866                                                 case 0: fullammo = autocvar_hud_panel_weapons_ammo_full_shells; break;
867                                                 case 1: fullammo = autocvar_hud_panel_weapons_ammo_full_nails; break;
868                                                 case 2: fullammo = autocvar_hud_panel_weapons_ammo_full_rockets; break;
869                                                 case 3: fullammo = autocvar_hud_panel_weapons_ammo_full_cells; break;
870                                                 case 4: fullammo = autocvar_hud_panel_weapons_ammo_full_fuel; break;
871                                                 default: fullammo = 60;
872                                         }
873
874                                         drawsetcliparea(
875                                                 wpnpos_x + baroffset_x,
876                                                 wpnpos_y + baroffset_y,
877                                                 barsize_x * bound(0, a/fullammo, 1),
878                                                 barsize_y);
879                                         drawpic_aspect_skin(wpnpos, "weapon_ammo", wpnsize, ammo_color, ammo_alpha, DRAWFLAG_NORMAL);
880                                         drawresetcliparea();
881                                 }
882                         }
883                 }
884
885                 // draw a "ghost weapon icon" if you don't have the weapon
886                 else
887                 {
888                         drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
889                 }
890
891                 // draw the complain message
892                 if(time - complain_weapon_time < when + fadetime && self.weapon == complain_weapon && autocvar_hud_panel_weapons_complainbubble)
893                 {
894                         if(fadetime)
895                         {
896                                 if(complain_weapon_time + when > time)
897                                         a = 1;
898                                 else
899                                         a = bound(0, (complain_weapon_time + when + fadetime - time) / fadetime, 1);
900                         }
901                         else
902                         {
903                                 if(complain_weapon_time + when > time)
904                                         a = 1;
905                                 else
906                                         a = 0;
907                         }
908
909                         string s;
910                         if(complain_weapon_type == 0) {
911                                 s = _("Out of ammo");
912                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_outofammo);
913                         }
914                         else if(complain_weapon_type == 1) {
915                                 s = _("Don't have");
916                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_donthave);
917                         }
918                         else {
919                                 s = _("Unavailable");
920                                 color = stov(autocvar_hud_panel_weapons_complainbubble_color_unavailable);
921                         }
922                         float padding = autocvar_hud_panel_weapons_complainbubble_padding;
923                         drawpic_aspect_skin(wpnpos + '1 1 0' * padding, "weapon_complainbubble", wpnsize - '2 2 0' * padding, color, a * panel_fg_alpha, DRAWFLAG_NORMAL);
924                         drawstring_aspect(wpnpos + '1 1 0' * padding, s, wpnsize - '2 2 0' * padding, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
925                 }
926
927                 ++row;
928                 if(row >= rows)
929                 {
930                         row = 0;
931                         ++column;
932                 }
933         }
934
935 }
936
937 // Ammo (#1)
938 //
939 // TODO: macro
940 float GetAmmoItemCode(float i)
941 {
942         switch(i)
943         {
944                 case 0: return IT_SHELLS;
945                 case 1: return IT_NAILS;
946                 case 2: return IT_ROCKETS;
947                 case 3: return IT_CELLS;
948                 case 4: return IT_FUEL;
949                 default: return -1;
950         }
951 }
952
953 string GetAmmoPicture(float i)
954 {
955         switch(i)
956         {
957                 case 0: return "ammo_shells";
958                 case 1: return "ammo_bullets";
959                 case 2: return "ammo_rockets";
960                 case 3: return "ammo_cells";
961                 case 4: return "ammo_fuel";
962                 default: return "";
963         }
964 }
965
966 void DrawAmmoItem(vector myPos, vector mySize, float itemcode, float currently_selected)
967 {
968         float a;
969         if(autocvar__hud_configure)
970         {
971                 currently_selected = (itemcode == 2); //rockets always selected
972                 a = 31 + mod(itemcode*93, 128);
973         }
974         else
975                 a = getstati(GetAmmoStat(itemcode)); // how much ammo do we have of type itemcode?
976
977         vector color;
978         if(a < 10)
979                 color = '0.7 0 0';
980         else
981                 color = '1 1 1';
982
983         float alpha;
984         if(currently_selected)
985                 alpha = 1;
986         else
987                 alpha = 0.7;
988
989         vector picpos, numpos;
990         if(autocvar_hud_panel_ammo_iconalign)
991         {
992                 numpos = myPos;
993                 picpos = myPos + eX * 2 * mySize_y;
994         }
995         else
996         {
997                 numpos = myPos + eX * mySize_y;
998                 picpos = myPos;
999         }
1000
1001         if (currently_selected)
1002                 drawpic_aspect_skin(myPos, "ammo_current_bg", mySize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
1003
1004     if(a > 0 && autocvar_hud_panel_ammo_progressbar)
1005         HUD_Panel_DrawProgressBar(myPos + eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, mySize - eX * autocvar_hud_panel_ammo_progressbar_xoffset * mySize_x, autocvar_hud_panel_ammo_progressbar_name, a/autocvar_hud_panel_ammo_maxammo, 0, 0, color, autocvar_hud_progressbar_alpha * panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1006
1007     if(autocvar_hud_panel_ammo_text)
1008     {
1009         if(a > 0)
1010             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1011         else // "ghost" ammo count
1012             drawstring_aspect(numpos, ftos(a), eX * (2/3) * mySize_x + eY * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1013     }
1014         if(a > 0)
1015                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1016         else // "ghost" ammo icon
1017                 drawpic_aspect_skin(picpos, GetAmmoPicture(itemcode), '1 1 0' * mySize_y, '0 0 0', panel_fg_alpha * alpha * 0.5, DRAWFLAG_NORMAL);
1018 }
1019
1020 void HUD_Ammo(void)
1021 {
1022     if(hud != HUD_NORMAL) return;
1023         if(!autocvar__hud_configure)
1024         {
1025                 if(!autocvar_hud_panel_ammo) return;
1026                 if(spectatee_status == -1) return;
1027         }
1028         else
1029                 hud_configure_active_panel = HUD_PANEL_AMMO;
1030
1031         HUD_Panel_UpdateCvars(ammo);
1032         vector pos, mySize;
1033         pos = panel_pos;
1034         mySize = panel_size;
1035
1036         HUD_Panel_DrawBg(1);
1037         if(panel_bg_padding)
1038         {
1039                 pos += '1 1 0' * panel_bg_padding;
1040                 mySize -= '2 2 0' * panel_bg_padding;
1041         }
1042
1043         float rows, columns, row, column;
1044         vector ammo_size;
1045         if (autocvar_hud_panel_ammo_onlycurrent)
1046                 ammo_size = mySize;
1047         else
1048         {
1049                 rows = mySize_y/mySize_x;
1050                 rows = bound(1, floor((sqrt(4 * (3/1) * rows * AMMO_COUNT + rows * rows) + rows + 0.5) / 2), AMMO_COUNT);
1051                 //                               ^^^ ammo item aspect goes here
1052
1053                 columns = ceil(AMMO_COUNT/rows);
1054
1055                 ammo_size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
1056         }
1057
1058         vector offset;
1059         float newSize;
1060         if(ammo_size_x/ammo_size_y > 3)
1061         {
1062                 newSize = 3 * ammo_size_y;
1063                 offset_x = ammo_size_x - newSize;
1064                 pos_x += offset_x/2;
1065                 ammo_size_x = newSize;
1066         }
1067         else
1068         {
1069                 newSize = 1/3 * ammo_size_x;
1070                 offset_y = ammo_size_y - newSize;
1071                 pos_y += offset_y/2;
1072                 ammo_size_y = newSize;
1073         }
1074
1075         float i, stat_items, currently_selected;
1076         if (autocvar_hud_panel_ammo_onlycurrent)
1077         {
1078                 if(autocvar__hud_configure)
1079                 {
1080                         DrawAmmoItem(pos, ammo_size, 2, true); //show rockets
1081                         return;
1082                 }
1083                 stat_items = getstati(STAT_ITEMS);
1084                 for (i = 0; i < AMMO_COUNT; ++i) {
1085                         currently_selected = stat_items & GetAmmoItemCode(i);
1086                         if (currently_selected)
1087                         {
1088                                 DrawAmmoItem(pos, ammo_size, i, true);
1089                                 return;
1090                         }
1091                 }
1092                 return; // nothing to display
1093         }
1094
1095         stat_items = getstati(STAT_ITEMS);
1096         for (i = 0; i < AMMO_COUNT; ++i) {
1097                 currently_selected = stat_items & GetAmmoItemCode(i);
1098                 DrawAmmoItem(pos + eX * column * (ammo_size_x + offset_x) + eY * row * (ammo_size_y + offset_y), ammo_size, i, currently_selected);
1099                 ++row;
1100                 if(row >= rows)
1101                 {
1102                         row = 0;
1103                         column = column + 1;
1104                 }
1105         }
1106 }
1107
1108 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
1109 {
1110         vector newPos, newSize;
1111         vector picpos, numpos;
1112
1113         if (vertical)
1114         {
1115                 if(mySize_y/mySize_x > 2)
1116                 {
1117                         newSize_y = 2 * mySize_x;
1118                         newSize_x = mySize_x;
1119
1120                         newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1121                         newPos_x = myPos_x;
1122                 }
1123                 else
1124                 {
1125                         newSize_x = 1/2 * mySize_y;
1126                         newSize_y = mySize_y;
1127
1128                         newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1129                         newPos_y = myPos_y;
1130                 }
1131
1132                 if(icon_right_align)
1133                 {
1134                         numpos = newPos;
1135                         picpos = newPos + eY * newSize_x;
1136                 }
1137                 else
1138                 {
1139                         picpos = newPos;
1140                         numpos = newPos + eY * newSize_x;
1141                 }
1142
1143                 newSize_y /= 2;
1144                 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1145                 // make number smaller than icon, it looks better
1146                 // reduce only y to draw numbers with different number of digits with the same y size
1147                 numpos_y += newSize_y * ((1 - 0.7) / 2);
1148                 newSize_y *= 0.7;
1149                 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1150                 return;
1151         }
1152
1153         if(mySize_x/mySize_y > 3)
1154         {
1155                 newSize_x = 3 * mySize_y;
1156                 newSize_y = mySize_y;
1157
1158                 newPos_x = myPos_x + (mySize_x - newSize_x) / 2;
1159                 newPos_y = myPos_y;
1160         }
1161         else
1162         {
1163                 newSize_y = 1/3 * mySize_x;
1164                 newSize_x = mySize_x;
1165
1166                 newPos_y = myPos_y + (mySize_y - newSize_y) / 2;
1167                 newPos_x = myPos_x;
1168         }
1169
1170         if(icon_right_align) // right align
1171         {
1172                 numpos = newPos;
1173                 picpos = newPos + eX * 2 * newSize_y;
1174         }
1175         else // left align
1176         {
1177                 numpos = newPos + eX * newSize_y;
1178                 picpos = newPos;
1179         }
1180
1181         drawstring_aspect(numpos, ftos(x), '2 1 0' * newSize_y, color, panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1182         drawpic_aspect_skin(picpos, icon, '1 1 0' * newSize_y, '1 1 1', panel_fg_alpha * alpha, DRAWFLAG_NORMAL);
1183 }
1184
1185 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float fadelerp)
1186 {
1187         float sz;
1188         sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
1189
1190         DrawNumIcon(myPos + expandingbox_resize_centered_box_offset(sz, mySize, 1), mySize * sz, x, icon, vertical, icon_right_align, color, (1 - fadelerp));
1191 }
1192
1193 // Powerups (#2)
1194 //
1195 void HUD_Powerups(void)
1196 {
1197         float strength_time, shield_time;
1198         if(!autocvar__hud_configure)
1199         {
1200                 if(!autocvar_hud_panel_powerups) return;
1201                 if(spectatee_status == -1) return;
1202                 if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
1203                 if (getstati(STAT_HEALTH) <= 0) return;
1204
1205                 strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
1206                 shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
1207         }
1208         else
1209         {
1210                 hud_configure_active_panel = HUD_PANEL_POWERUPS;
1211
1212                 strength_time = 15;
1213                 shield_time = 27;
1214         }
1215
1216         HUD_Panel_UpdateCvars(powerups);
1217         vector pos, mySize;
1218         pos = panel_pos;
1219         mySize = panel_size;
1220
1221         HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
1222         if(panel_bg_padding)
1223         {
1224                 pos += '1 1 0' * panel_bg_padding;
1225                 mySize -= '2 2 0' * panel_bg_padding;
1226         }
1227
1228         float panel_ar = mySize_x/mySize_y;
1229         float is_vertical = (panel_ar < 1);
1230         vector shield_offset, strength_offset;
1231         if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1232         {
1233                 mySize_x *= 0.5;
1234                 if (autocvar_hud_panel_powerups_flip)
1235                         shield_offset_x = mySize_x;
1236                 else
1237                         strength_offset_x = mySize_x;
1238         }
1239         else
1240         {
1241                 mySize_y *= 0.5;
1242                 if (autocvar_hud_panel_powerups_flip)
1243                         shield_offset_y = mySize_y;
1244                 else
1245                         strength_offset_y = mySize_y;
1246         }
1247
1248         float shield_baralign, strength_baralign;
1249         float shield_iconalign, strength_iconalign;
1250         if (autocvar_hud_panel_powerups_flip)
1251         {
1252                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1253                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1254                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1255                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1256         }
1257         else
1258         {
1259                 shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
1260                 strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
1261                 shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
1262                 strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
1263         }
1264
1265         if(shield_time)
1266         {
1267                 const float maxshield = 30;
1268                 float shield = ceil(shield_time);
1269                 if(autocvar_hud_panel_powerups_progressbar)
1270                 {
1271                         HUD_Panel_GetProgressBarColor(shield);
1272                         HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1273                 }
1274                 if(autocvar_hud_panel_powerups_text)
1275                 {
1276                         if(shield > 1)
1277                                 DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
1278                         if(shield <= 5)
1279                                 DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', bound(0, (shield - shield_time) / 0.5, 1));
1280                 }
1281         }
1282
1283         if(strength_time)
1284         {
1285                 const float maxstrength = 30;
1286                 float strength = ceil(strength_time);
1287                 if(autocvar_hud_panel_powerups_progressbar)
1288                 {
1289                         HUD_Panel_GetProgressBarColor(strength);
1290                         HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1291                 }
1292                 if(autocvar_hud_panel_powerups_text)
1293                 {
1294                         if(strength > 1)
1295                                 DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
1296                         if(strength <= 5)
1297                                 DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', bound(0, (strength - strength_time) / 0.5, 1));
1298                 }
1299         }
1300 }
1301
1302 // Health/armor (#3)
1303 //
1304
1305 // prev_* vars contain the health/armor at the previous FRAME
1306 // set to -1 when player is dead or was not playing
1307 float prev_health, prev_armor;
1308 float health_damagetime, armor_damagetime;
1309 float health_beforedamage, armor_beforedamage;
1310 // old_p_* vars keep track of previous values when smoothing value changes of the progressbar
1311 float old_p_health, old_p_armor;
1312 float old_p_healthtime, old_p_armortime;
1313 // prev_p_* vars contain the health/armor progressbar value at the previous FRAME
1314 // set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
1315 float prev_p_health, prev_p_armor;
1316
1317 void HUD_HealthArmor(void)
1318 {
1319         float armor, health, fuel;
1320         if(!autocvar__hud_configure)
1321         {
1322                 if(!autocvar_hud_panel_healtharmor) return;
1323                 if(hud != HUD_NORMAL) return;
1324                 if(spectatee_status == -1) return;
1325
1326                 health = getstati(STAT_HEALTH);
1327                 if(health <= 0)
1328                 {
1329                         prev_health = -1;
1330                         return;
1331                 }
1332                 armor = getstati(STAT_ARMOR);
1333
1334                 // code to check for spectatee_status changes is in Ent_ClientData()
1335                 // prev_p_health and prev_health can be set to -1 there
1336
1337                 if (prev_p_health == -1)
1338                 {
1339                         // no effect
1340                         health_beforedamage = 0;
1341                         armor_beforedamage = 0;
1342                         health_damagetime = 0;
1343                         armor_damagetime = 0;
1344                         prev_health = health;
1345                         prev_armor = armor;
1346                         old_p_health = health;
1347                         old_p_armor = armor;
1348                         prev_p_health = health;
1349                         prev_p_armor = armor;
1350                 }
1351                 else if (prev_health == -1)
1352                 {
1353                         //start the load effect
1354                         health_damagetime = 0;
1355                         armor_damagetime = 0;
1356                         prev_health = 0;
1357                         prev_armor = 0;
1358                 }
1359                 fuel = getstati(STAT_FUEL);
1360         }
1361         else
1362         {
1363                 hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
1364
1365                 health = 150;
1366                 armor = 75;
1367                 fuel = 20;
1368         }
1369
1370         HUD_Panel_UpdateCvars(healtharmor);
1371         vector pos, mySize;
1372         pos = panel_pos;
1373         mySize = panel_size;
1374
1375         HUD_Panel_DrawBg(1);
1376         if(panel_bg_padding)
1377         {
1378                 pos += '1 1 0' * panel_bg_padding;
1379                 mySize -= '2 2 0' * panel_bg_padding;
1380         }
1381
1382         float baralign = autocvar_hud_panel_healtharmor_baralign;
1383         float iconalign = autocvar_hud_panel_healtharmor_iconalign;
1384
1385     float maxhealth = autocvar_hud_panel_healtharmor_maxhealth;
1386     float maxarmor = autocvar_hud_panel_healtharmor_maxarmor;
1387         if(autocvar_hud_panel_healtharmor == 2) // combined health and armor display
1388         {
1389                 vector v;
1390                 v = healtharmor_maxdamage(health, armor, armorblockpercent);
1391
1392                 float x;
1393                 x = floor(v_x + 1);
1394
1395         float maxtotal = maxhealth + maxarmor;
1396                 string biggercount;
1397                 if(v_z) // NOT fully armored
1398                 {
1399                         biggercount = "health";
1400                         if(autocvar_hud_panel_healtharmor_progressbar)
1401                         {
1402                                 HUD_Panel_GetProgressBarColor(health);
1403                                 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_health, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1404                         }
1405                         if(armor)
1406             if(autocvar_hud_panel_healtharmor_text)
1407                                 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);
1408                 }
1409                 else
1410                 {
1411                         biggercount = "armor";
1412                         if(autocvar_hud_panel_healtharmor_progressbar)
1413                         {
1414                                 HUD_Panel_GetProgressBarColor(armor);
1415                                 HUD_Panel_DrawProgressBar(pos, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, x/maxtotal, 0, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1416                         }
1417                         if(health)
1418             if(autocvar_hud_panel_healtharmor_text)
1419                                 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);
1420                 }
1421         if(autocvar_hud_panel_healtharmor_text)
1422                         DrawNumIcon(pos, mySize, x, biggercount, 0, iconalign, HUD_Get_Num_Color(x, maxtotal), 1);
1423
1424                 if(fuel)
1425                 {
1426                         HUD_Panel_GetProgressBarColor(fuel);
1427                         HUD_Panel_DrawProgressBar(pos, eX * mySize_x + eY * 0.2 * mySize_y, "progressbar", fuel/100, 0, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1428                 }
1429         }
1430         else
1431         {
1432                 float panel_ar = mySize_x/mySize_y;
1433                 float is_vertical = (panel_ar < 1);
1434                 vector health_offset, armor_offset;
1435                 if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
1436                 {
1437                         mySize_x *= 0.5;
1438                         if (autocvar_hud_panel_healtharmor_flip)
1439                                 health_offset_x = mySize_x;
1440                         else
1441                                 armor_offset_x = mySize_x;
1442                 }
1443                 else
1444                 {
1445                         mySize_y *= 0.5;
1446                         if (autocvar_hud_panel_healtharmor_flip)
1447                                 health_offset_y = mySize_y;
1448                         else
1449                                 armor_offset_y = mySize_y;
1450                 }
1451
1452                 float health_baralign, armor_baralign, fuel_baralign;
1453                 float health_iconalign, armor_iconalign;
1454                 if (autocvar_hud_panel_healtharmor_flip)
1455                 {
1456                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1457                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1458                         fuel_baralign = health_baralign;
1459                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1460                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1461                 }
1462                 else
1463                 {
1464                         health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
1465                         armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
1466                         fuel_baralign = armor_baralign;
1467                         health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
1468                         armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
1469                 }
1470
1471                 //if(health)
1472                 {
1473                         if(autocvar_hud_panel_healtharmor_progressbar)
1474                         {
1475                                 HUD_Panel_GetProgressBarColor(health);
1476                                 float p_health, pain_health_alpha;
1477                                 p_health = health;
1478                                 pain_health_alpha = 1;
1479                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1480                                 {
1481                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1482                                         {
1483                                                 if (fabs(prev_health - health) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1484                                                 {
1485                                                         if (time - old_p_healthtime < 1)
1486                                                                 old_p_health = prev_p_health;
1487                                                         else
1488                                                                 old_p_health = prev_health;
1489                                                         old_p_healthtime = time;
1490                                                 }
1491                                                 if (time - old_p_healthtime < 1)
1492                                                 {
1493                                                         p_health += (old_p_health - health) * (1 - (time - old_p_healthtime));
1494                                                         prev_p_health = p_health;
1495                                                 }
1496                                         }
1497                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1498                                         {
1499                                                 if (prev_health - health >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1500                                                 {
1501                                                         if (time - health_damagetime >= 1)
1502                                                                 health_beforedamage = prev_health;
1503                                                         health_damagetime = time;
1504                                                 }
1505                                                 if (time - health_damagetime < 1)
1506                                                 {
1507                                                         float health_damagealpha = 1 - (time - health_damagetime)*(time - health_damagetime);
1508                                                         HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, health_beforedamage/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * health_damagealpha, DRAWFLAG_NORMAL);
1509                                                 }
1510                                         }
1511                                         prev_health = health;
1512
1513                                         if (health <= autocvar_hud_panel_healtharmor_progressbar_gfx_lowhealth)
1514                                         {
1515                                                 float BLINK_FACTOR = 0.15;
1516                                                 float BLINK_BASE = 0.85;
1517                                                 float BLINK_FREQ = 9; 
1518                                                 pain_health_alpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
1519                                         }
1520                                 }
1521                                 HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * pain_health_alpha, DRAWFLAG_NORMAL);
1522                         }
1523                         if(autocvar_hud_panel_healtharmor_text)
1524                                 DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
1525                 }
1526
1527                 if(armor)
1528                 {
1529                         if(autocvar_hud_panel_healtharmor_progressbar)
1530                         {
1531                                 HUD_Panel_GetProgressBarColor(armor);
1532                                 float p_armor;
1533                                 p_armor = armor;
1534                                 if (autocvar_hud_panel_healtharmor_progressbar_gfx)
1535                                 {
1536                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_smooth > 0)
1537                                         {
1538                                                 if (fabs(prev_armor - armor) >= autocvar_hud_panel_healtharmor_progressbar_gfx_smooth)
1539                                                 {
1540                                                         if (time - old_p_armortime < 1)
1541                                                                 old_p_armor = prev_p_armor;
1542                                                         else
1543                                                                 old_p_armor = prev_armor;
1544                                                         old_p_armortime = time;
1545                                                 }
1546                                                 if (time - old_p_armortime < 1)
1547                                                 {
1548                                                         p_armor += (old_p_armor - armor) * (1 - (time - old_p_armortime));
1549                                                         prev_p_armor = p_armor;
1550                                                 }
1551                                         }
1552                                         if (autocvar_hud_panel_healtharmor_progressbar_gfx_damage > 0)
1553                                         {
1554                                                 if (prev_armor - armor >= autocvar_hud_panel_healtharmor_progressbar_gfx_damage)
1555                                                 {
1556                                                         if (time - armor_damagetime >= 1)
1557                                                                 armor_beforedamage = prev_armor;
1558                                                         armor_damagetime = time;
1559                                                 }
1560                                                 if (time - armor_damagetime < 1)
1561                                                 {
1562                                                         float armor_damagealpha = 1 - (time - armor_damagetime)*(time - armor_damagetime);
1563                                                         HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, armor_beforedamage/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * armor_damagealpha, DRAWFLAG_NORMAL);
1564                                                 }
1565                                         }
1566                                         prev_armor = armor;
1567                                 }
1568                                 HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
1569                         }
1570                         if(autocvar_hud_panel_healtharmor_text)
1571                                 DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
1572                 }
1573
1574                 if(fuel)
1575                 {
1576                         if (is_vertical)
1577                                 mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
1578                         else
1579                                 mySize_y *= 0.2;
1580                         if (panel_ar >= 4)
1581                                 mySize_x *= 2; //restore full panel size
1582                         else if (panel_ar < 1/4)
1583                                 mySize_y *= 2; //restore full panel size
1584                         HUD_Panel_GetProgressBarColor(fuel);
1585                         HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
1586                 }
1587         }
1588 }
1589
1590 // Notification area (#4)
1591 //
1592
1593 string Weapon_SuicideMessage(float deathtype)
1594 {
1595         w_deathtype = deathtype;
1596         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_SUICIDEMESSAGE);
1597         return w_deathtypestring;
1598 }
1599
1600 string Weapon_KillMessage(float deathtype)
1601 {
1602         w_deathtype = deathtype;
1603         get_weaponinfo(DEATH_WEAPONOF(deathtype)).weapon_func(WR_KILLMESSAGE);
1604         return w_deathtypestring;
1605 }
1606
1607 #define KN_MAX_ENTRIES 10
1608 float kn_index;
1609 float killnotify_times[KN_MAX_ENTRIES];
1610 float killnotify_deathtype[KN_MAX_ENTRIES];
1611 float killnotify_actiontype[KN_MAX_ENTRIES]; // 0 = "Y [used by] X", 1 = "X [did action to] Y"
1612 string killnotify_attackers[KN_MAX_ENTRIES];
1613 string killnotify_victims[KN_MAX_ENTRIES];
1614 void HUD_KillNotify_Push(string attacker, string victim, float actiontype, float wpn)
1615 {
1616         --kn_index;
1617         if (kn_index == -1)
1618                 kn_index = KN_MAX_ENTRIES-1;
1619         killnotify_times[kn_index] = time;
1620         killnotify_deathtype[kn_index] = wpn;
1621         killnotify_actiontype[kn_index] = actiontype;
1622         if(killnotify_attackers[kn_index])
1623                 strunzone(killnotify_attackers[kn_index]);
1624         killnotify_attackers[kn_index] = strzone(attacker);
1625         if(killnotify_victims[kn_index])
1626                 strunzone(killnotify_victims[kn_index]);
1627         killnotify_victims[kn_index] = strzone(victim);
1628 }
1629
1630 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg) // s1 = attacker, s2 = victim
1631 {
1632         float w;
1633         float alsoprint, gentle;
1634         alsoprint = (autocvar_hud_panel_notify_print || !panel_enabled); // print message to console if: notify panel disabled, or cvar to do so enabled
1635         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
1636         
1637         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
1638                 return;
1639
1640         if(msg == MSG_SUICIDE) {
1641                 w = DEATH_WEAPONOF(type);
1642                 if(WEP_VALID(w)) {
1643                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1644                         if (alsoprint)
1645                                 print("^1", sprintf(Weapon_SuicideMessage(type), strcat(s1, "^1")), "\n");
1646                 } else if (type == DEATH_KILL) {
1647                         HUD_KillNotify_Push(s1, "", 0, DEATH_KILL);
1648                         if (alsoprint)
1649                                 print (sprintf(_("^1%s^1 couldn't take it anymore\n"), s1));
1650                 } else if (type == DEATH_ROT) {
1651                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1652                         if (alsoprint)
1653                                 print (sprintf(_("^1%s^1 died\n"), s1));
1654                 } else if (type == DEATH_NOAMMO) {
1655                         HUD_KillNotify_Push(s1, "", 0, DEATH_NOAMMO);
1656                         if (alsoprint)
1657                                 print (sprintf(_("^7%s^7 committed suicide. What's the point of living without ammo?\n"), s1));
1658                 } else if (type == DEATH_CAMP) {
1659                         HUD_KillNotify_Push(s1, "", 0, DEATH_CAMP);
1660                         if (alsoprint)
1661                                 print (sprintf(_("^1%s^1 thought they found a nice camping ground\n"), s1));
1662                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
1663                         HUD_KillNotify_Push(s1, "", 0, type);
1664                         if (alsoprint)
1665                                 print (sprintf(_("^1%s^1 didn't become friends with the Lord of Teamplay\n"), s1));
1666                 } else if (type == DEATH_CHEAT) {
1667                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1668                         if (alsoprint)
1669                                 print (sprintf(_("^1%s^1 unfairly eliminated themself\n"), s1));
1670                 } else if (type == DEATH_FIRE) {
1671                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1672                         if (alsoprint)
1673                                 print (sprintf(_("^1%s^1 burned to death\n"), s1));
1674                 } else if (type != DEATH_TEAMCHANGE && type != DEATH_QUIET) {
1675                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1676                         if (alsoprint)
1677                                 print (sprintf(_("^1%s^1 couldn't resist the urge to self-destruct\n"), s1));
1678                 } 
1679                 
1680                 if (stof(s2) > 2) // killcount > 2
1681                         print (sprintf(_("^1%s^1 ended it all after a %d kill spree\n"), s1, stof(s2)));
1682         } else if(msg == MSG_KILL) {
1683                 w = DEATH_WEAPONOF(type);
1684                 if(WEP_VALID(w)) {
1685                         if((w == WEP_RIFLE || w == WEP_MINSTANEX) && type & HITTYPE_HEADSHOT) // all headshot weapons go here
1686                                 HUD_KillNotify_Push(s1, s2, 1, DEATH_HEADSHOT);
1687                         else
1688                                 HUD_KillNotify_Push(s1, s2, 1, type);
1689
1690                         if (alsoprint)
1691                                 print("^1", sprintf(Weapon_KillMessage(type), strcat(s2, "^1"), strcat(s1, "^1")), "\n"); // default order: victim, killer
1692                 }
1693                 else if(type == KILL_TEAM_RED || type == KILL_TEAM_BLUE || type == KILL_TEAM_SPREE) {
1694                         HUD_KillNotify_Push(s1, s2, 1, type);
1695                         if(alsoprint)
1696                         {
1697                                 if(gentle) {
1698                                         print (sprintf(_("^1%s^1 took action against a team mate\n"), s1));
1699                                 } else {
1700                                         print (sprintf(_("^1%s^1 mows down a team mate\n"), s1));
1701                                 }
1702                         }
1703                         if (stof(s2) > 2 && type == KILL_TEAM_SPREE) {
1704                                 if(gentle)
1705                                         print (sprintf(_("^1%s^1 ended a %d scoring spree by going against a team mate\n"), s1, stof(s3)));
1706                                 else
1707                                         print (sprintf(_("^1%s^1 ended a %d kill spree by killing a team mate\n"), s1, stof(s3)));
1708                         }
1709                         else if (stof(s2) > 2) {
1710                                 if(gentle)
1711                                         print (sprintf(_("^1%s^1's %s scoring spree was ended by a team mate!\n"), s1, stof(s3)));
1712                                 else
1713                                         print (sprintf(_("^1%s^1's %s kill spree was ended by a team mate!\n"), s1, stof(s3)));
1714                         }
1715                 }
1716                 else if(type == KILL_FIRST_BLOOD)
1717                         print(sprintf(_("^1%s^1 drew first blood\n"), s1));
1718                 else if (type == DEATH_TELEFRAG) {
1719                         HUD_KillNotify_Push(s1, s2, 1, DEATH_TELEFRAG);
1720                         if(gentle)
1721                                 print (sprintf(_("^1%s^1 tried to occupy %s^1's teleport destination space\n"), s2, s1));
1722                         else
1723                                 print (sprintf(_("^1%s^1 was telefragged by %s\n"), s2, s1));
1724                 }
1725                 else if (type == DEATH_DROWN) {
1726                         HUD_KillNotify_Push(s1, s2, 1, DEATH_DROWN);
1727                         if(alsoprint)
1728                                 print (sprintf(_("^1%s^1 was drowned by %s\n"), s2, s1));
1729                 }
1730                 else if (type == DEATH_SLIME) {
1731                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SLIME);
1732                         if(alsoprint)
1733                                 print (sprintf(_("^1%s^1 was slimed by %s\n"), s2, s1));
1734                 }
1735                 else if (type == DEATH_LAVA) {
1736                         HUD_KillNotify_Push(s1, s2, 1, DEATH_LAVA);
1737                         if(alsoprint)
1738                                 print (sprintf(_("^1%s^1 was cooked by %s\n"), s2, s1));
1739                 }
1740                 else if (type == DEATH_FALL) {
1741                         HUD_KillNotify_Push(s1, s2, 1, DEATH_FALL);
1742                         if(alsoprint)
1743                                 print (sprintf(_("^1%s^1 was grounded by %s\n"), s2, s1));
1744                 }
1745                 else if (type == DEATH_SHOOTING_STAR) {
1746                         HUD_KillNotify_Push(s1, s2, 1, DEATH_SHOOTING_STAR);
1747                         if(alsoprint)
1748                                 print (sprintf(_("^1%s^1 was shot into space by %s\n"), s2, s1));
1749                 }
1750                 else if (type == DEATH_SWAMP) {
1751                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1752                         if(alsoprint)
1753                                 print (sprintf(_("^1%s^1 was conserved by %s\n"), s2, s1));
1754                 }
1755                 else if (type == DEATH_HURTTRIGGER)
1756                 {
1757                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1758                         if(alsoprint)
1759                                 print(sprintf(_("^1%s^1 was thrown into a world of hurt by %s\n"), s2, s1));
1760                 } else if(type == DEATH_VHCRUSH) {
1761                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1762                         if(alsoprint)
1763                                 print (sprintf(_("^1%s^1 was crushed by %s\n"), s2, s1));
1764                 } else if(type == DEATH_SBMINIGUN) {
1765                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1766                         if(alsoprint)
1767                                 print (sprintf(_("^1%s^1 got shredded by %s\n"), s2, s1));
1768                 } else if(type == DEATH_SBROCKET) {
1769                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1770                         if(alsoprint)
1771                                 print (sprintf(_("^1%s^1 was blasted to bits by %s\n"), s2, s1));
1772                 } else if(type == DEATH_SBBLOWUP) {
1773                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1774                         if(alsoprint)
1775                                 print (sprintf(_("^1%s^1 got caught in the destruction of %s^1's vehicle\n"), s2, s1));
1776                 } else if(type == DEATH_WAKIGUN) {
1777                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1778                         if(alsoprint)
1779                                 print (sprintf(_("^1%s^1 was bolted down by %s\n"), s2, s1));
1780                 } else if(type == DEATH_WAKIROCKET) {
1781                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1782                         if(alsoprint)
1783                                 print (sprintf(_("^1%s^1 could find no shelter from %s^1's rockets\n"), s2, s1));
1784                 } else if(type == DEATH_WAKIBLOWUP) {
1785                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1786                         if(alsoprint)
1787                                 print (sprintf(_("^1%s^1 dies when %s^1's wakizashi dies.\n"), s2, s1));
1788                 } else if(type == DEATH_RAPTOR_CANNON) {
1789                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1790                         if(alsoprint)
1791                                 print (sprintf(_("^1%s^1 nailed to hell by %s\n"), s2, s1));
1792                 } else if(type == DEATH_RAPTOR_BOMB) {
1793                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1794                         if(alsoprint)
1795                                 print (sprintf(_("^1%s^1 cluster crushed by %s\n"), s2, s1));
1796                 } else if(type == DEATH_RAPTOR_DEATH) {
1797                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1798                         if(alsoprint)
1799                                 print (sprintf(_("^1%s^1 dies when %s^1's raptor dies.\n"), s2, s1));
1800                 } else if(type == DEATH_TURRET) {
1801                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1802                         if(alsoprint)
1803                                 print (sprintf(_("^1%s^1 was pushed into the line of fire by %s\n"), s2, s1));
1804                 } else if(type == DEATH_TOUCHEXPLODE) {
1805                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1806                         if(alsoprint)
1807                                 print (sprintf(_("^1%s^1 was pushed into an accident by %s\n"), s2, s1));
1808                 } else if(type == DEATH_CHEAT) {
1809                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1810                         if(alsoprint)
1811                                 print (sprintf(_("^1%s^1 was unfairly eliminated by %s\n"), s2, s1));
1812                 } else if (type == DEATH_FIRE) {
1813                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1814                         if(alsoprint)
1815                                 print (sprintf(_("^1%s^1 was burnt to death by %s\n"), s2, s1));
1816                 } else if (type == DEATH_CUSTOM) {
1817                         HUD_KillNotify_Push(s1, s2, 1, DEATH_CUSTOM);
1818                         if(alsoprint)
1819                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1820                 } else if (type == DEATH_HURTTRIGGER) {
1821                         HUD_KillNotify_Push(s1, s2, 1, DEATH_HURTTRIGGER);
1822                         if(alsoprint)
1823                                 print("^1", sprintf(s3, strcat(s2, "^1"), strcat(s1, "^1")), "\n");
1824                 } else {
1825                         HUD_KillNotify_Push(s1, s2, 1, DEATH_GENERIC);
1826                         if(alsoprint)
1827                                 print (sprintf(_("^1%s^1 was fragged by %s\n"), s2, s1));
1828                 }
1829         } else if(msg == MSG_SPREE) {
1830                 if(type == KILL_END_SPREE) {
1831                         if(gentle)
1832                                 print (sprintf(_("^1%s^1's %s scoring spree was ended by %s\n"), s1, s2, s3));
1833                         else
1834                                 print (sprintf(_("^1%s^1's %s kill spree was ended by %s\n"), s1, s2, s3));
1835                 } else if(type == KILL_SPREE) {
1836                         if(gentle)
1837                                 print (sprintf(_("^1%s^1 made %s scores in a row\n"), s1, s2));
1838                         else
1839                                 print (sprintf(_("^1%s^1 has %s frags in a row\n"), s1, s2));
1840                 } else if(type == KILL_SPREE_3) {
1841                         if(gentle)
1842                                 print (sprintf(_("%s^7 made a ^1TRIPLE SCORE\n"), s1));
1843                         else
1844                                 print (sprintf(_("%s^7 made a ^1TRIPLE FRAG\n"), s1));
1845                 } else if(type == KILL_SPREE_5) {
1846                         if(gentle)
1847                                 print (sprintf(_("%s^7 unleashes ^1SCORING RAGE\n"), s1));
1848                         else
1849                                 print (sprintf(_("%s^7 unleashes ^1RAGE\n"), s1));
1850                 } else if(type == KILL_SPREE_10) {
1851                         if(gentle)
1852                                 print (sprintf(_("%s^7 made ^1TEN SCORES IN A ROW!\n"), s1));
1853                         else
1854                                 print (sprintf(_("%s^7 starts the ^1MASSACRE!\n"), s1));
1855                 } else if(type == KILL_SPREE_15) {
1856                         if(gentle)
1857                                 print (sprintf(_("%s^7 made ^1FIFTEEN SCORES IN A ROW!\n"), s1));
1858                         else
1859                                 print (sprintf(_("%s^7 executes ^1MAYHEM!\n"), s1));
1860                 } else if(type == KILL_SPREE_20) {
1861                         if(gentle)
1862                                 print (sprintf(_("%s^7 made ^1TWENTY SCORES IN A ROW!\n"), s1));
1863                         else
1864                                 print (sprintf(_("%s^7 is a ^1BERSERKER!\n"), s1));
1865                 } else if(type == KILL_SPREE_25) {
1866                         if(gentle)
1867                                 print (sprintf(_("%s^7 made ^1TWENTY FIVE SCORES IN A ROW!\n"), s1));
1868                         else
1869                                 print (sprintf(_("%s^7 inflicts ^1CARNAGE!\n"), s1));
1870                 } else if(type == KILL_SPREE_30) {
1871                         if(gentle)
1872                                 print (sprintf(_("%s^7 made ^1THIRTY SCORES IN A ROW!\n"), s1));
1873                         else
1874                                 print (sprintf(_("%s^7 unleashes ^1ARMAGEDDON!\n"), s1));
1875                 }
1876         } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
1877                 if (type == DEATH_DROWN) {
1878                         HUD_KillNotify_Push(s1, "", 0, DEATH_DROWN);
1879                         if(alsoprint)
1880                         {
1881                                 if(gentle)
1882                                         print (sprintf(_("^1%s^1 was in the water for too long\n"), s1));
1883                                 else
1884                                         print (sprintf(_("^1%s^1 drowned\n"), s1));
1885                         }
1886                 } else if (type == DEATH_SLIME) {
1887                         HUD_KillNotify_Push(s1, "", 0, DEATH_SLIME);
1888                         if(alsoprint)
1889                                 print (sprintf(_("^1%s^1 was slimed\n"), s1));
1890                 } else if (type == DEATH_LAVA) {
1891                         HUD_KillNotify_Push(s1, "", 0, DEATH_LAVA);
1892                         if(alsoprint)
1893                         {
1894                                 if(gentle)
1895                                         print (sprintf(_("^1%s^1 found a hot place\n"), s1));
1896                                 else
1897                                         print (sprintf(_("^1%s^1 turned into hot slag\n"), s1));
1898                         }
1899                 } else if (type == DEATH_FALL) {
1900                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1901                         if(alsoprint)
1902                         {
1903                                 if(gentle)
1904                                         print (sprintf(_("^1%s^1 tested gravity (and it worked)\n"), s1));
1905                                 else
1906                                         print (sprintf(_("^1%s^1 hit the ground with a crunch\n"), s1));
1907                         }
1908                 } else if (type == DEATH_SHOOTING_STAR) {
1909                         HUD_KillNotify_Push(s1, "", 0, DEATH_SHOOTING_STAR);
1910                         if(alsoprint)
1911                                 print (sprintf(_("^1%s^1 became a shooting star\n"), s1));
1912                 } else if (type == DEATH_SWAMP) {
1913                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1914                         if(alsoprint)
1915                         {
1916                                 if(gentle)
1917                                         print (sprintf(_("^1%s^1 discovered a swamp\n"), s1));
1918                                 else
1919                                         print (sprintf(_("^1%s^1 is now conserved for centuries to come\n"), s1));
1920                         }
1921                 } else if(type == DEATH_TURRET) {
1922                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1923                         if(alsoprint)
1924                                 print (sprintf(_("^1%s^1 was mowed down by a turret \n"), s1));
1925                 } else if (type == DEATH_CUSTOM) {
1926                         HUD_KillNotify_Push(s1, "", 0, DEATH_CUSTOM);
1927                         if(alsoprint)
1928                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1929                 } else if (type == DEATH_HURTTRIGGER) {
1930                         HUD_KillNotify_Push(s1, "", 0, DEATH_HURTTRIGGER);
1931                         if(alsoprint)
1932                                 print("^1", sprintf(s2, strcat(s1, "^1")), "\n");
1933                 } else if(type == DEATH_TOUCHEXPLODE) {
1934                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1935                         if(alsoprint)
1936                                 print (sprintf(_("^1%s^1 died in an accident\n"), s1));
1937                 } else if(type == DEATH_CHEAT) {
1938                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1939                         if(alsoprint)
1940                                 print (sprintf(_("^1%s^1 was unfairly eliminated\n"), s1));
1941                 } else if(type == DEATH_FIRE) {
1942                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1943                         if(alsoprint)
1944                         {
1945                                 if(gentle)
1946                                         print (sprintf(_("^1%s^1 felt a little hot\n"), s1));
1947                                 else
1948                                         print (sprintf(_("^1%s^1 burnt to death\n"), s1));
1949                                 }
1950                 } else {
1951                         HUD_KillNotify_Push(s1, "", 0, DEATH_GENERIC);
1952                         if(alsoprint)
1953                         {
1954                                 if(gentle)
1955                                         print (sprintf(_("^1%s^1 needs a restart\n"), s1));
1956                                 else
1957                                         print (sprintf(_("^1%s^1 died\n"), s1));
1958                         }
1959                 }
1960         } else if(msg == MSG_KILL_ACTION_SPREE) {
1961                 if(gentle)
1962                         print (sprintf(_("^1%s^1 needs a restart after a %d scoring spree\n"), s1, stof(s2)));
1963                 else
1964                         print (sprintf(_("^1%s^1 died with a %d kill spree\n"), s1, stof(s2)));
1965         } else if(msg == MSG_INFO) {
1966                 if(type == INFO_GOTFLAG) { // here, s2 is the flag name
1967                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1968                         print(sprintf(_("%s^7 got the %s\n"), s1, s2));
1969                 } else if(type == INFO_LOSTFLAG) {
1970                         HUD_KillNotify_Push(s1, s2, 0, INFO_LOSTFLAG);
1971                         print(sprintf(_("%s^7 lost the %s\n"), s1, s2));
1972                 } else if(type == INFO_PICKUPFLAG) {
1973                         HUD_KillNotify_Push(s1, s2, 0, INFO_GOTFLAG);
1974                         print(sprintf(_("%s^7 picked up the %s\n"), s1, s2));
1975                 } else if(type == INFO_RETURNFLAG) {
1976                         HUD_KillNotify_Push(s1, s2, 0, INFO_RETURNFLAG);
1977                         print(sprintf(_("%s^7 returned the %s\n"), s1, s2));
1978                 } else if(type == INFO_CAPTUREFLAG) {
1979                         HUD_KillNotify_Push(s1, s2, 0, INFO_CAPTUREFLAG);
1980                         print(sprintf(_("%s^7 captured the %s%s\n"), s1, s2, s3));
1981                 }
1982         } else if(msg == MSG_RACE) {
1983                 if(type == RACE_SERVER_RECORD) {
1984                         HUD_KillNotify_Push(s1, s2, 1, RACE_SERVER_RECORD);
1985                 }
1986                 else if(type == RACE_NEW_RANK) {
1987                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_RANK);
1988                 }
1989                 else if(type == RACE_NEW_TIME) {
1990                         HUD_KillNotify_Push(s1, s2, 1, RACE_NEW_TIME);
1991                 }
1992                 else if(type == RACE_FAIL) {
1993                         HUD_KillNotify_Push(s1, s2, 1, RACE_FAIL);
1994                 }
1995         } else if(msg == MSG_KA) {
1996                 if(type == KA_PICKUPBALL) {
1997                         HUD_KillNotify_Push(s1, s2, 0, KA_PICKUPBALL);
1998                         if(alsoprint)
1999                                 print (sprintf(_("%s^7 has picked up the ball!\n"), s1));
2000                 }
2001                 else if(type == KA_DROPBALL) {
2002                         HUD_KillNotify_Push(s1, s2, 0, KA_DROPBALL);
2003                         if(alsoprint)
2004                                 print(sprintf(_("%s^7 has dropped the ball!\n"), s1));
2005                 }
2006         }
2007 }
2008
2009 #define DAMAGE_CENTERPRINT_SPACER NEWLINES
2010
2011 void HUD_Centerprint(string s1, string s2, float type, float msg)
2012 {
2013         float gentle;
2014         gentle = (autocvar_cl_gentle || autocvar_cl_gentle_messages);
2015         if(msg == MSG_SUICIDE) {
2016                 if (type == DEATH_TEAMCHANGE) {
2017                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("You are now on: %s"), s1)));
2018                 } else if (type == DEATH_AUTOTEAMCHANGE) {
2019                         centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("You have been moved into a different team to improve team balance\nYou are now on: %s"), s1)));
2020                 } else if (type == DEATH_CAMP) {
2021                         if(gentle)
2022                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Reconsider your tactics, camper!")));
2023                         else
2024                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Die camper!")));
2025                 } else if (type == DEATH_NOAMMO) {
2026                         if(gentle)
2027                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You are reinserted into the game for running out of ammo...")));
2028                         else
2029                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You were killed for running out of ammo...")));
2030                 } else if (type == DEATH_ROT) {
2031                         if(gentle)
2032                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You need to preserve your health")));
2033                         else
2034                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You grew too old without taking your medicine")));
2035                 } else if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2036                         if(gentle)
2037                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Don't go against team mates!")));
2038                         else
2039                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Don't shoot your team mates!")));
2040                 } else if (type == DEATH_QUIET) {
2041                         // do nothing
2042                 } else { // generic message
2043                         if(gentle)
2044                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You need to be more careful!")));
2045                         else
2046                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1You killed your own dumb self!")));
2047                 }
2048         } else if(msg == MSG_KILL) {
2049                 if (type == KILL_TEAM_RED || type == KILL_TEAM_BLUE) {
2050                         if(gentle) {
2051                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1Moron! You went against ^7%s^1, a team mate!"), s1)));
2052                         } else {
2053                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1Moron! You fragged ^7%s^1, a team mate!"), s1)));
2054                         }
2055                 } else if (type == KILL_FIRST_BLOOD) {
2056                         if(gentle) {
2057                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First score")));
2058                         } else {
2059                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First blood")));
2060                         }
2061                 } else if (type == KILL_FIRST_VICTIM) {
2062                         if(gentle) {
2063                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First casualty")));
2064                         } else {
2065                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1First victim")));
2066                         }
2067                 } else if (type == KILL_TYPEFRAG) { // s2 contains "advanced kill messages" such as ping, handicap...
2068                         if(gentle) {
2069                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You scored against ^7%s^1 who was typing!"), s1), s2));
2070                         } else {
2071                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You typefragged ^7%s"), s1), s2));
2072                         }
2073                 } else if (type == KILL_TYPEFRAGGED) {
2074                         if(gentle) {
2075                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were scored against by ^7%s^1 while you were typing!"), s1), s2));
2076                         } else {
2077                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were typefragged by ^7%s"), s1), s2));
2078                         }
2079                 } else if (type == KILL_FRAG) {
2080                         if(gentle) {
2081                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^4You scored against ^7%s"), s1), s2));
2082                         } else {
2083                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^4You fragged ^7%s"), s1), s2));
2084                         }
2085                 } else { // generic message
2086                         if(gentle) {
2087                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were scored against by ^7%s"), s1), s2));
2088                         } else {
2089                                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, sprintf(_("^1You were fragged by ^7%s"), s1), s2));
2090                         }
2091                 }
2092         } else if(msg == MSG_KILL_ACTION) {
2093                 // TODO: invent more centerprints here?
2094                 centerprint(strcat(DAMAGE_CENTERPRINT_SPACER, _("^1Watch your step!")));
2095         }
2096 }
2097
2098 void HUD_Notify (void)
2099 {
2100         if(!autocvar__hud_configure)
2101         {
2102                 if(!autocvar_hud_panel_notify) return;
2103         }
2104         else
2105                 hud_configure_active_panel = HUD_PANEL_NOTIFY;
2106
2107         HUD_Panel_UpdateCvars(notify);
2108         vector pos, mySize;
2109         pos = panel_pos;
2110         mySize = panel_size;
2111
2112         HUD_Panel_DrawBg(1);
2113         if(panel_bg_padding)
2114         {
2115                 pos += '1 1 0' * panel_bg_padding;
2116                 mySize -= '2 2 0' * panel_bg_padding;
2117         }
2118
2119         float entries, height;
2120         entries = bound(1, floor(KN_MAX_ENTRIES * mySize_y/mySize_x), KN_MAX_ENTRIES);
2121         height = mySize_y/entries;
2122         
2123         vector fontsize;
2124         float fontheight = height * autocvar_hud_panel_notify_fontsize;
2125         fontsize = '0.5 0.5 0' * fontheight;
2126
2127         float a;
2128         float when;
2129         when = autocvar_hud_panel_notify_time;
2130         float fadetime;
2131         fadetime = autocvar_hud_panel_notify_fadetime;
2132
2133         string s;
2134
2135         vector pos_attacker, pos_victim;
2136         vector weap_pos;
2137         float width_attacker;
2138         string attacker, victim;
2139
2140         float i, j, w, step, limit;
2141         if(autocvar_hud_panel_notify_flip) //order items from the top down
2142         {
2143                 i = 0;
2144                 step = +1;
2145                 limit = entries;
2146         }
2147         else //order items from the bottom up
2148         {
2149                 i = entries - 1;
2150                 step = -1;
2151                 limit = -1;
2152         }
2153
2154         for(j = kn_index;  i != limit;  i += step, ++j)
2155         {
2156                 if(autocvar__hud_configure)
2157                 {
2158                         if (step == +1)
2159                                 a = i;
2160                         else // inverse order
2161                                 a = entries - 1 - i;
2162                         attacker = textShortenToWidth(sprintf(_("Player %d"), a+1), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2163                         victim = textShortenToWidth(sprintf(_("Player %d"), a+2), 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2164                         s = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(a*2.4), WEP_LAST)).netname);
2165                         a = bound(0, (when - a) / 4, 1);
2166                         goto hud_config_notifyprint;
2167                 }
2168
2169                 if (j == KN_MAX_ENTRIES)
2170                         j = 0;
2171
2172                 if(killnotify_times[j] + when > time)
2173                         a = 1;
2174                 else if(fadetime)
2175                 {
2176                         a = bound(0, (killnotify_times[j] + when + fadetime - time) / fadetime, 1);
2177                         if(!a)
2178                         {
2179                                 break;
2180                         }
2181                 }
2182                 else
2183                 {
2184                         break;
2185                 }
2186
2187                 s = "";
2188
2189                 w = -1;
2190                 w = DEATH_WEAPONOF(killnotify_deathtype[j]);
2191
2192                 // TODO: maybe print in team colors?
2193                 //
2194                 // Y [used by] X
2195                 if(killnotify_actiontype[j] == 0) 
2196                 {
2197                         if(killnotify_deathtype[j] == DEATH_GENERIC)
2198                         {
2199                                 s = "notify_death";
2200                         }
2201                         else if(killnotify_deathtype[j] == DEATH_NOAMMO)
2202                         {
2203                                 s = "notify_outofammo";
2204                         }
2205                         else if(killnotify_deathtype[j] == DEATH_KILL)
2206                         {
2207                                 s = "notify_selfkill";
2208                         }
2209                         else if(killnotify_deathtype[j] == DEATH_CAMP)
2210                         {
2211                                 s = "notify_camping";
2212                         }
2213                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2214                         {
2215                                 s = "notify_teamkill_red";
2216                         }
2217                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2218                         {
2219                                 s = "notify_teamkill_blue";
2220                         }
2221                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2222                         {
2223                                 s = "notify_water";
2224                         }
2225                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2226                         {
2227                                 s = "notify_slime";
2228                         }
2229                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2230                         {
2231                                 s = "notify_lava";
2232                         }
2233                         else if(killnotify_deathtype[j] == DEATH_FALL)
2234                         {
2235                                 s = "notify_fall";
2236                         }
2237                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2238                         {
2239                                 s = "notify_shootingstar";
2240                         }
2241                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM)
2242                         {
2243                                 s = "notify_death";
2244                         }
2245                         else if(killnotify_deathtype[j] == INFO_GOTFLAG)
2246                         {
2247                                 if(killnotify_victims[j] == "^1RED^7 flag")
2248                                 {
2249                                         s = "notify_red_taken";
2250                                 }
2251                                 else
2252                                 {
2253                                         s = "notify_blue_taken";
2254                                 }
2255                         }
2256                         else if(killnotify_deathtype[j] == INFO_RETURNFLAG)
2257                         {
2258                                 if(killnotify_victims[j] == "^1RED^7 flag")
2259                                 {
2260                                         s = "notify_red_returned";
2261                                 }
2262                                 else
2263                                 {
2264                                         s = "notify_blue_returned";
2265                                 }
2266                         }
2267                         else if(killnotify_deathtype[j] == INFO_LOSTFLAG)
2268                         {
2269                                 if(killnotify_victims[j] == "^1RED^7 flag")
2270                                 {
2271                                         s = "notify_red_lost";
2272                                 }
2273                                 else
2274                                 {
2275                                         s = "notify_blue_lost";
2276                                 }
2277                         }
2278                         else if(killnotify_deathtype[j] == INFO_CAPTUREFLAG)
2279                         {
2280                                 if(killnotify_victims[j] == "^1RED^7 flag")
2281                                 {
2282                                         s = "notify_red_captured";
2283                                 }
2284                                 else
2285                                 {
2286                                         s = "notify_blue_captured";
2287                                 }
2288                         }
2289                         else if(killnotify_deathtype[j] == KA_DROPBALL)
2290                         {
2291                                 s = "notify_balldropped";
2292                         }
2293                         else if(killnotify_deathtype[j] == KA_PICKUPBALL)
2294                         {
2295                                 s = "notify_ballpickedup";
2296                         }
2297                         
2298                         attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2299                         pos_attacker = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2300                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2301
2302                         if(s != "")
2303                         {
2304                                 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2305                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2306                         }
2307                 }
2308                 // X [did action to] Y
2309                 else
2310                 {
2311                         if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_LASER)
2312                         {
2313                                 s = "notify_melee_laser";
2314                         }
2315                         else if(killnotify_deathtype[j] & HITTYPE_SECONDARY && w == WEP_SHOTGUN)
2316                         {
2317                                 s = "notify_melee_shotgun";
2318                         }
2319                         else if(WEP_VALID(w))
2320                         {
2321                                 self = get_weaponinfo(w);
2322                                 s = strcat("weapon", self.netname);
2323                         }
2324                         else if(killnotify_deathtype[j] == KILL_TEAM_RED)
2325                         {
2326                                 s = "notify_teamkill_red";
2327                         }
2328                         else if(killnotify_deathtype[j] == KILL_TEAM_BLUE)
2329                         {
2330                                 s = "notify_teamkill_red";
2331                         }
2332                         else if(killnotify_deathtype[j] == DEATH_TELEFRAG)
2333                         {
2334                                 s = "notify_telefrag";
2335                         }
2336                         else if(killnotify_deathtype[j] == DEATH_DROWN)
2337                         {
2338                                 s = "notify_water";
2339                         }
2340                         else if(killnotify_deathtype[j] == DEATH_SLIME)
2341                         {
2342                                 s = "notify_slime";
2343                         }
2344                         else if(killnotify_deathtype[j] == DEATH_LAVA)
2345                         {
2346                                 s = "notify_lava";
2347                         }
2348                         else if(killnotify_deathtype[j] == DEATH_FALL)
2349                         {
2350                                 s = "notify_fall";
2351                         }
2352                         else if(killnotify_deathtype[j] == DEATH_SHOOTING_STAR)
2353                         {
2354                                 s = "notify_shootingstar";
2355                         }
2356                         else if(killnotify_deathtype[j] == DEATH_HURTTRIGGER || killnotify_deathtype[j] == DEATH_CUSTOM) // DEATH_CUSTOM is also void, right?
2357                         {
2358                                 s = "notify_void";
2359                         }
2360                         else if(killnotify_deathtype[j] == DEATH_HEADSHOT)
2361                         {
2362                                 s = "notify_headshot";
2363                         }
2364                         else if(killnotify_deathtype[j] == RACE_SERVER_RECORD)
2365                         {
2366                                 s = "race_newrecordserver";
2367                         }
2368                         else if(killnotify_deathtype[j] == RACE_NEW_RANK)
2369                         {
2370                                 s = "race_newrankyellow";
2371                         }
2372                         else if(killnotify_deathtype[j] == RACE_NEW_TIME)
2373                         {
2374                                 s = "race_newtime";
2375                         }
2376                         else if(killnotify_deathtype[j] == RACE_FAIL)
2377                         {
2378                                 s = "race_newfail";
2379                         }
2380
2381                         attacker = textShortenToWidth(killnotify_attackers[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2382                         victim = textShortenToWidth(killnotify_victims[j], 0.48 * mySize_x - height, fontsize, stringwidth_colors);
2383 :hud_config_notifyprint
2384                         width_attacker = stringwidth(attacker, TRUE, fontsize);
2385                         pos_attacker = pos + eX * (0.48 * mySize_x - height - width_attacker) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2386                         pos_victim = pos + eX * (0.52 * mySize_x + height) + eY * ((0.5 * fontsize_y + i * height) + (0.5 * (height - fontheight)));
2387                         weap_pos = pos + eX * 0.5 * mySize_x - eX * height + eY * i * height;
2388
2389                         if(s != "")
2390                         {
2391                                 drawpic_aspect_skin(weap_pos, s, '2 1 0' * height, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
2392                                 drawcolorcodedstring(pos_attacker, attacker, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2393                                 drawcolorcodedstring(pos_victim, victim, fontsize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
2394                         }
2395                 }
2396         }
2397 }
2398
2399 // Timer (#5)
2400 //
2401 // TODO: macro
2402 string seconds_tostring(float sec)
2403 {
2404         float minutes;
2405         minutes = floor(sec / 60);
2406
2407         sec -= minutes * 60;
2408         return sprintf("%d:%02d", minutes, sec);
2409 }
2410
2411 void HUD_Timer(void)
2412 {
2413         if(!autocvar__hud_configure)
2414         {
2415                 if(!autocvar_hud_panel_timer) return;
2416         }
2417         else
2418                 hud_configure_active_panel = HUD_PANEL_TIMER;
2419
2420         HUD_Panel_UpdateCvars(timer);
2421         vector pos, mySize;
2422         pos = panel_pos;
2423         mySize = panel_size;
2424
2425         HUD_Panel_DrawBg(1);
2426         if(panel_bg_padding)
2427         {
2428                 pos += '1 1 0' * panel_bg_padding;
2429                 mySize -= '2 2 0' * panel_bg_padding;
2430         }
2431
2432         string timer;
2433         float timelimit, elapsedTime, timeleft, minutesLeft;
2434
2435         timelimit = getstatf(STAT_TIMELIMIT);
2436
2437         timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
2438         timeleft = ceil(timeleft);
2439
2440         minutesLeft = floor(timeleft / 60);
2441
2442         vector timer_color;
2443         if(minutesLeft >= 5 || warmup_stage || timelimit == 0) //don't use red or yellow in warmup or when there is no timelimit
2444                 timer_color = '1 1 1'; //white
2445         else if(minutesLeft >= 1)
2446                 timer_color = '1 1 0'; //yellow
2447         else
2448                 timer_color = '1 0 0'; //red
2449
2450         if (autocvar_hud_panel_timer_increment || timelimit == 0 || warmup_stage) {
2451                 if (time < getstatf(STAT_GAMESTARTTIME)) {
2452                         //while restart is still active, show 00:00
2453                         timer = seconds_tostring(0);
2454                 } else {
2455                         elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
2456                         timer = seconds_tostring(elapsedTime);
2457                 }
2458         } else {
2459                 timer = seconds_tostring(timeleft);
2460         }
2461
2462         drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2463 }
2464
2465 // Radar (#6)
2466 //
2467 void HUD_Radar(void)
2468 {
2469         if (!autocvar__hud_configure)
2470         {
2471                 if (autocvar_hud_panel_radar == 0) return;
2472                 if (autocvar_hud_panel_radar != 2 && !teamplay) return;
2473         }
2474         else
2475                 hud_configure_active_panel = HUD_PANEL_RADAR;
2476
2477         HUD_Panel_UpdateCvars(radar);
2478         vector pos, mySize;
2479         pos = panel_pos;
2480         mySize = panel_size;
2481
2482         HUD_Panel_DrawBg(1);
2483         if(panel_bg_padding)
2484         {
2485                 pos += '1 1 0' * panel_bg_padding;
2486                 mySize -= '2 2 0' * panel_bg_padding;
2487         }
2488
2489         local float color2;
2490         local entity tm;
2491         float scale2d, normalsize, bigsize;
2492         float f;
2493
2494         teamradar_origin2d = pos + 0.5 * mySize;
2495         teamradar_size2d = mySize;
2496
2497         if(minimapname == "")
2498                 return;
2499
2500         teamradar_loadcvars();
2501
2502         switch(hud_panel_radar_zoommode)
2503         {
2504                 default:
2505                 case 0:
2506                         f = current_zoomfraction;
2507                         break;
2508                 case 1:
2509                         f = 1 - current_zoomfraction;
2510                         break;
2511                 case 2:
2512                         f = 0;
2513                         break;
2514                 case 3:
2515                         f = 1;
2516                         break;
2517         }
2518
2519         switch(hud_panel_radar_rotation)
2520         {
2521                 case 0:
2522                         teamradar_angle = view_angles_y - 90;
2523                         break;
2524                 default:
2525                         teamradar_angle = 90 * hud_panel_radar_rotation;
2526                         break;
2527         }
2528
2529         scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
2530         teamradar_size2d = mySize;
2531
2532         teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
2533
2534         // pixels per world qu to match the teamradar_size2d_x range in the longest dimension
2535         if(hud_panel_radar_rotation == 0)
2536         {
2537                 // max-min distance must fit the radar in any rotation
2538                 bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
2539         }
2540         else
2541         {
2542                 vector c0, c1, c2, c3, span;
2543                 c0 = rotate(mi_min, teamradar_angle * DEG2RAD);
2544                 c1 = rotate(mi_max, teamradar_angle * DEG2RAD);
2545                 c2 = rotate('1 0 0' * mi_min_x + '0 1 0' * mi_max_y, teamradar_angle * DEG2RAD);
2546                 c3 = rotate('1 0 0' * mi_max_x + '0 1 0' * mi_min_y, teamradar_angle * DEG2RAD);
2547                 span = '0 0 0';
2548                 span_x = max4(c0_x, c1_x, c2_x, c3_x) - min4(c0_x, c1_x, c2_x, c3_x);
2549                 span_y = max4(c0_y, c1_y, c2_y, c3_y) - min4(c0_y, c1_y, c2_y, c3_y);
2550
2551                 // max-min distance must fit the radar in x=x, y=y
2552                 bigsize = min(
2553                         teamradar_size2d_x * scale2d / (1.05 * span_x),
2554                         teamradar_size2d_y * scale2d / (1.05 * span_y)
2555                 );
2556         }
2557
2558         normalsize = vlen_maxnorm2d(teamradar_size2d) * scale2d / hud_panel_radar_scale;
2559         if(bigsize > normalsize)
2560                 normalsize = bigsize;
2561
2562         teamradar_size =
2563                   f * bigsize
2564                 + (1 - f) * normalsize;
2565         teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
2566                   f * mi_center
2567                 + (1 - f) * view_origin);
2568
2569         drawsetcliparea(
2570                 pos_x,
2571                 pos_y,
2572                 mySize_x,
2573                 mySize_y
2574         );
2575
2576         draw_teamradar_background(hud_panel_radar_foreground_alpha);
2577
2578         for(tm = world; (tm = find(tm, classname, "radarlink")); )
2579                 draw_teamradar_link(tm.origin, tm.velocity, tm.team);
2580         for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
2581                 draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
2582         for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
2583         {
2584                 color2 = GetPlayerColor(tm.sv_entnum);
2585                 //if(color == COLOR_SPECTATOR || color == color2)
2586                         draw_teamradar_player(tm.origin, tm.angles, GetTeamRGB(color2));
2587         }
2588         draw_teamradar_player(view_origin, view_angles, '1 1 1');
2589
2590         drawresetcliparea();
2591 };
2592
2593 // Score (#7)
2594 //
2595 void HUD_UpdatePlayerTeams();
2596 void HUD_Score_Rankings(vector pos, vector mySize, entity me, float team_count)
2597 {
2598         float score;
2599         entity tm, pl;
2600 #define SCOREPANEL_MAX_ENTRIES 6
2601 #define SCOREPANEL_ASPECTRATIO 2
2602         const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
2603         const vector fontsize = '1 1 0' * (mySize_y/entries);
2604
2605         vector rgb, score_color;
2606         rgb = '1 1 1';
2607         score_color = '1 1 1';
2608
2609         const float name_size = mySize_x*0.75;
2610         const float spacing_size = mySize_x*0.04;
2611         const float highlight_alpha = 0.2;
2612         float i, me_printed, first_pl;
2613         string s;
2614         i, first_pl = 0;
2615         if (autocvar__hud_configure)
2616         {
2617                 float players_per_team;
2618                 if (team_count)
2619                 {
2620                         // show team scores in the first line
2621                         float score_size = mySize_x / team_count;
2622                         players_per_team = max(2, ceil((entries - 1) / team_count));
2623                         for(i=0; i<team_count; ++i) {
2624                                 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
2625                                         HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2626                                 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize_y, GetTeamRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2627                         }
2628                         first_pl = 1;
2629                         pos_y += fontsize_y;
2630                 }
2631                 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
2632                 for (i=first_pl; i<entries; ++i)
2633                 {
2634                         //simulate my score is lower than all displayed players,
2635                         //so that I don't appear at all showing pure rankings.
2636                         //This is to better show the difference between the 2 ranking views
2637                         if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
2638                         {
2639                                 rgb = '1 1 0';
2640                                 drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2641                                 s = GetPlayerName(pl.sv_entnum);
2642                                 score = 7;
2643                         }
2644                         else
2645                         {
2646                                 s = sprintf(_("Player %d"), i + 1 - first_pl);
2647                                 score -= 3;
2648                         }
2649
2650                         if (team_count)
2651                                 score_color = GetTeamRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
2652                         s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
2653                         drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2654                         drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2655                         pos_y += fontsize_y;
2656                 }
2657                 return;
2658         }
2659
2660         if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
2661                 HUD_UpdatePlayerTeams();
2662         if (team_count)
2663         {
2664                 // show team scores in the first line
2665                 float score_size = mySize_x / team_count;
2666                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
2667                         if(tm.team == COLOR_SPECTATOR)
2668                                 continue;
2669                         if (tm.team == myteam)
2670                                 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize_y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2671                         drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
2672                         ++i;
2673                 }
2674                 first_pl = 1;
2675                 pos_y += fontsize_y;
2676                 tm = teams.sort_next;
2677         }
2678         i = first_pl;
2679
2680         do
2681         for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
2682         {
2683                 if ((team_count && pl.team != tm.team) || pl.team == COLOR_SPECTATOR)
2684                         continue;
2685
2686                 if (i == entries-1 && !me_printed && pl != me)
2687                 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
2688                 {
2689                         for (pl = me.sort_next; pl; pl = pl.sort_next)
2690                                 if (pl.team != COLOR_SPECTATOR)
2691                                         break;
2692
2693                         if (pl)
2694                                 rgb = '1 1 0'; //not last but not among the leading players: yellow
2695                         else
2696                                 rgb = '1 0 0'; //last: red
2697                         pl = me;
2698                 }
2699
2700                 if (pl == me)
2701                 {
2702                         if (i == first_pl)
2703                                 rgb = '0 1 0'; //first: green
2704                         me_printed = 1;
2705                         drawfill(pos, eX * mySize_x + eY * fontsize_y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
2706                 }
2707                 if (team_count)
2708                         score_color = GetTeamRGB(pl.team) * 0.8;
2709                 s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
2710                 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
2711                 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2712                 pos_y += fontsize_y;
2713                 ++i;
2714         }
2715         while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != COLOR_SPECTATOR || (tm = tm.sort_next)));
2716 }
2717
2718 void HUD_Score(void)
2719 {
2720         if(!autocvar__hud_configure)
2721         {
2722                 if(!autocvar_hud_panel_score) return;
2723                 if(spectatee_status == -1 && (gametype == GAME_RACE || gametype == GAME_CTS)) return;
2724         }
2725         else
2726                 hud_configure_active_panel = HUD_PANEL_SCORE;
2727
2728         HUD_Panel_UpdateCvars(score);
2729         vector pos, mySize;
2730         pos = panel_pos;
2731         mySize = panel_size;
2732
2733         HUD_Panel_DrawBg(1);
2734         if(panel_bg_padding)
2735         {
2736                 pos += '1 1 0' * panel_bg_padding;
2737                 mySize -= '2 2 0' * panel_bg_padding;
2738         }
2739
2740         float score, distribution;
2741         string sign;
2742         vector distribution_color;
2743         entity tm, pl, me;
2744         me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1];
2745
2746         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
2747                 string timer, distrtimer;
2748
2749                 pl = players.sort_next;
2750                 if(pl == me)
2751                         pl = pl.sort_next;
2752                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
2753                         if(pl.scores[ps_primary] == 0)
2754                                 pl = world;
2755
2756                 score = me.(scores[ps_primary]);
2757                 timer = TIME_ENCODED_TOSTRING(score);
2758
2759                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
2760                         // distribution display
2761                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2762
2763                         distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
2764
2765                         if (distribution <= 0) {
2766                                 distribution_color = '0 1 0';
2767                                 sign = "-";
2768                         }
2769                         else {
2770                                 distribution_color = '1 0 0';
2771                                 sign = "+";
2772                         }
2773                         drawstring_aspect(pos + eX * 0.75 * mySize_x, strcat(sign, distrtimer), eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
2774                 }
2775                 // race record display
2776                 if (distribution <= 0)
2777                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2778                 drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
2779         } else if (!teamplay) { // non-teamgames
2780                 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
2781                 {
2782                         HUD_Score_Rankings(pos, mySize, me, 0);
2783                         return;
2784                 }
2785                 // me vector := [team/connected frags id]
2786                 pl = players.sort_next;
2787                 if(pl == me)
2788                         pl = pl.sort_next;
2789
2790                 if(autocvar__hud_configure)
2791                         distribution = 42;
2792                 else if(pl)
2793                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
2794                 else
2795                         distribution = 0;
2796
2797                 score = me.(scores[ps_primary]);
2798                 if(autocvar__hud_configure)
2799                         score = 123;