]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/sbar.qc
CTF!
[divverent/nexuiz.git] / data / qcsrc / client / sbar.qc
1
2 float last_weapon;
3 float activeweapon;
4 float weapontime;
5
6 float sb_lines; // still don't know what to do with that NOTE: check dp's sbar.c to see what that should be
7
8 vector sbar;
9 vector sbar_fontsize;
10 float sbar_alpha_fg;
11 float sbar_hudselector;
12 /*
13 entity sortedPlayers;
14 entity sortedTeams;
15
16 .float sb_frags;
17 .float sb_team;
18 .float sb_player;
19 .float sb_caps;
20 */
21 float ps_primary, ps_secondary;
22 float ts_primary, ts_secondary;
23
24 entity team1, team2, team3, team4, teamspec;
25
26 void CSQC_kh_hud();
27 void CSQC_ctf_hud();
28 void MapVote_Draw();
29 void Sbar_FinaleOverlay()
30 {
31         /*vector pos;
32         pos_x = (vid_conwidth - 1)/2;
33         pos_y = 16;
34         pos_z = 0;*/
35         
36         //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
37         
38         //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
39         MapVote_Draw();
40 }
41
42 void Sbar_DrawWeapon(float nr, float fade, float active)
43 {
44         vector pos, vsize, color;
45         float value;
46         
47         value = (active) ? 1 : 0.6;
48         color_x = color_y = color_z = value;
49         
50         if(sbar_hudselector == 1)
51         {
52                 // width = 300, height = 100
53                 const float w_width = 32, w_height = 12, w_space = 2, font_size = 8;
54                 
55                 pos_x = (vid_conwidth - w_width * 9) * 0.5 + w_width * nr;
56                 pos_y = (vid_conheight - w_height);
57                 pos_z = 0;
58                 vsize_x = w_width;
59                 vsize_y = w_height;
60                 vsize_z = 0;
61                 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
62                 pos_x += w_space;
63                 pos_y += w_space;
64                 vsize_x = font_size;
65                 vsize_y = font_size;
66                 vsize_z = 0;
67                 drawstring(pos, ftos(nr+1), vsize, '1 1 0', sbar_alpha_fg, 0);
68
69         }
70         else
71         {
72                 // width = 300, height = 100
73                 const float w2_width = 300, w2_height = 100, w2_space = 10;
74                 const float w2_scale = 0.4;
75
76                 pos_x = vid_conwidth - (w2_width + w2_space) * w2_scale;
77                 pos_y = (w2_height + w2_space) * w2_scale * nr + w2_space;
78                 pos_z = 0;
79                 vsize_x = w2_width * w2_scale;
80                 vsize_y = w2_height * w2_scale;
81                 vsize_z = 0;
82                 
83                 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
84         }
85 }
86 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float a, float dflags)
87 {
88         float l, i;
89         string str, tmp;
90         float minus;
91         vector vsize;
92
93         vsize_x = vsize_y = lettersize;
94         vsize_z = 0;
95
96         if(num < 0)
97         {
98                 minus = true;
99                 num = -num;
100                 pos_x -= lettersize;
101         } else
102                 minus = false;
103         
104         if(digits < 0)
105         {
106                 tmp = ftos(num);
107                 digits = -digits;
108                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
109         } else
110                 str = ftos(num);
111         
112         l = strlen(str);
113
114         if(l > digits)
115         {
116                 str = substring(str, l-digits, 999);
117                 l = strlen(str);
118         } else if(l < digits)
119                 pos_x += (digits-l) * lettersize;
120
121         if(minus)
122         {
123                 drawpic(sbar + pos, "gfx/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
124                 pos_x += lettersize;
125         }
126
127         for(i = 0; i < l; ++i)
128         {
129                 drawpic(sbar + pos, strcat("gfx/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
130                 pos_x += lettersize;
131         }
132 }
133
134 void Cmd_Sbar_SetFields(float argc);
135 void Sbar_InitScores()
136 {
137         float i, f, primary_prio, secondary_prio;
138
139         ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
140         for(i = 0; i < MAX_SCORE; ++i)
141         {
142                 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
143                 if(f == SFL_SORT_PRIO_PRIMARY)
144                         ps_primary = i;
145                 if(f == SFL_SORT_PRIO_SECONDARY)
146                         ps_secondary = i;
147         }
148         if(ps_secondary == -1)
149                 ps_secondary = ps_primary;
150         
151         for(i = 0; i < MAX_TEAMSCORE; ++i)
152         {
153                 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
154                 if(f == SFL_SORT_PRIO_PRIMARY)
155                         ts_primary = i;
156                 if(f == SFL_SORT_PRIO_SECONDARY)
157                         ts_secondary = i;
158         }
159         if(ts_secondary == -1)
160                 ts_secondary = ts_primary;
161
162         Cmd_Sbar_SetFields(0);
163 }
164
165 void Sbar_UpdatePlayerPos(entity pl);
166 void Sbar_UpdatePlayerTeams()
167 {
168         float Team;
169         entity pl, tmp;
170         float num;
171
172         num = 0;
173         for(pl = players.sort_next; pl; pl = pl.sort_next)
174         {
175                 num += 1;
176                 Team = GetPlayerColor(pl.sv_entnum);
177                 if(pl.team != Team)
178                 {
179                         tmp = GetTeam(pl.team, false);
180                         tmp.team_size -= 1;
181                         tmp = GetTeam(Team, true);
182                         tmp.team_size += 1;
183                         
184                         pl.team = Team;
185
186                         tmp = pl.sort_prev;
187                         Sbar_UpdatePlayerPos(pl);
188                         if(tmp)
189                                 pl = tmp;
190                         else
191                                 pl = players.sort_next;
192                 }
193         }
194         //print(strcat("PNUM: ", ftos(num), "\n"));
195 }
196
197 float Sbar_ComparePlayerScores(entity left, entity right)
198 {
199         float vl, vr;
200         vl = GetPlayerColor(left.sv_entnum);
201         vr = GetPlayerColor(right.sv_entnum);
202         
203         if(vl > vr)
204                 return true;
205         if(vl < vr)
206                 return false;
207
208         vl = left.scores[ps_primary];
209         vr = right.scores[ps_primary];
210         if(vl > vr)
211                 return IS_INCREASING(scores_flags[ps_primary]);
212         if(vl < vr)
213                 return IS_DECREASING(scores_flags[ps_primary]);
214         
215         vl = left.scores[ps_secondary];
216         vr = right.scores[ps_secondary];
217         if(vl > vr)
218                 return IS_INCREASING(scores_flags[ps_secondary]);
219         if(vl < vr)
220                 return IS_DECREASING(scores_flags[ps_secondary]);
221         
222         return false;
223 }
224
225 void Sbar_UpdatePlayerPos(entity player)
226 {
227         for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
228         {
229                 SORT_SWAP(player, other);
230         }
231         for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
232         {
233                 SORT_SWAP(other, player);
234         }
235 }
236
237 float Sbar_CompareTeamScores(entity left, entity right)
238 {
239         float vl, vr;
240         
241         vl = left.teamscores[ts_primary];
242         vr = right.teamscores[ts_primary];
243         if(vl > vr)
244                 return IS_INCREASING(teamscores_flags[ts_primary]);
245         if(vl < vr)
246                 return IS_DECREASING(teamscores_flags[ts_primary]);
247         
248         vl = left.teamscores[ts_secondary];
249         vr = right.teamscores[ts_secondary];
250         if(vl > vr)
251                 return IS_INCREASING(teamscores_flags[ts_secondary]);
252         if(vl < vr)
253                 return IS_DECREASING(teamscores_flags[ts_secondary]);
254
255         return false;
256 }
257
258 void Sbar_UpdateTeamPos(entity Team)
259 {
260         for(other = Team.sort_next; other && Sbar_ComparePlayerScores(Team, other); other = Team.sort_next)
261         {
262                 if(other.team == COLOR_SPECTATOR)
263                         break;
264                 SORT_SWAP(Team, other);
265         }
266         for(other = Team.sort_prev; other != teams && Sbar_ComparePlayerScores(other, Team); other = Team.sort_prev)
267         {
268                 SORT_SWAP(other, Team);
269         }
270 }
271
272 void Cmd_Sbar_Help(float argc)
273 {
274         print("You can modify the scoreboard using the\n");
275         print("^3|---------------------------------------------------------------|\n");
276         print("^1 TO BE DONE\n");
277         print("Usage:\n");
278         print("^2sbar_columns_set default\n");
279         print("^2sbar_columns_set ^7filed1 field2 ...\n");
280         print("The following field names are recognized (case INsensitive):\n");
281         print("You can use a ^3|^7 to start the right-aligned fields.\n");
282         
283         print("^3name^7 or ^3nick^7             Name of a player\n");
284         print("^3ping^7                     Ping time\n\n");
285         print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
286         print("                         The kill-death ratio\n");
287
288         print("Before a field you can put a + or - sign, then a comma separated list\n");
289         print("of game types, then a slash, to make the field show up only in these\n");
290         print("or in all but these game types.\n");
291
292 /*
293         print("^3caps^7 or ^3captures^7         Number of flags captured\n");
294         print("^3rets^7 or ^3returns^7          Number of flags returned\n");
295         print("^3frags^7 or ^3kills^7           Frags\n");
296         print("^3deaths^7 or ^3dths^7           Number of deaths\n");
297         */
298         local float i;
299         print("Additional columns:\n");
300         for(i = 0; i < MAX_SCORE; ++i)
301         {
302                 if(scores_label[i] != "")
303                         print(strcat(scores_label[i], "\n"));
304         }
305 }
306
307 #define MIN_NAMELEN 24
308 #define MAX_NAMELEN 24
309
310 string Sbar_DefaultColumnLayout()
311 {
312         return "ping name | +kh,ctf/caps -ctf,kh/kills -ctf,kh/deaths -lms/score +lms/lives +lms/place";
313         /*
314         switch(gametype)
315         {
316                 case GAME_CTF: return "ping name | caps score";
317                 case GAME_KEYHUNT: return "ping name | caps kills score";
318                 default: return "ping name | score";
319                         // TODO: add other gametypes
320         }
321         */
322 }
323
324 void Cmd_Sbar_SetFields(float argc)
325 {
326         float i, j, slash;
327         string str, pattern, subpattern;
328         float digit;
329
330         // TODO: re enable with gametype dependant cvars?
331         if(argc < 2) // no arguments provided
332                 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
333
334         if(argc < 2)
335                 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
336
337         if(argc == 2)
338         {
339                 if(argv(1) == "default")
340                         argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
341                 else if(argv(1) == "all")
342                 {
343                         string s;
344                         s = "ping name |";
345                         for(i = 0; i < MAX_SCORE; ++i)
346                         {
347                                 if(i != ps_primary)
348                                 if(i != ps_secondary)
349                                 if(scores_label[i] != "")
350                                         s = strcat(s, " ", scores_label[i]);
351                         }
352                         if(ps_secondary != ps_primary)
353                                 s = strcat(s, " ", scores_label[ps_secondary]);
354                         s = strcat(s, " ", scores_label[ps_primary]);
355                         argc = tokenizebyseparator(strcat("x ", s), " ");
356                 }
357         }
358                 
359         
360         argc = min(MAX_SBAR_FIELDS, argc);
361         sbar_num_fields = 0;
362
363         drawfont = sbar_font;
364         digit = stringwidth("0123456789", FALSE) / 10;
365
366         subpattern = strcat(",", GametypeNameFromType(gametype), ",");
367
368         argc = min(argc-1, MAX_SBAR_FIELDS-1);
369         for(i = 0; i < argc; ++i)
370         {
371                 str = argv(i+1);
372
373                 slash = strstrofs(str, "/", 0);
374                 if(slash >= 0)
375                 {
376                         pattern = substring(str, 0, slash);
377                         str = substring(str, slash + 1, strlen(str) - (slash + 1));
378
379                         if(substring(pattern, 0, 1) == "-")
380                         {
381                                 pattern = substring(pattern, 1, strlen(pattern) - 1);
382                                 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
383                                         continue;
384                         }
385                         else
386                         {
387                                 if(substring(pattern, 0, 1) == "+")
388                                         pattern = substring(pattern, 1, strlen(pattern) - 1);
389                                 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
390                                         continue;
391                         }
392                 }
393
394                 strunzone(sbar_title[sbar_num_fields]);
395                 sbar_title[sbar_num_fields] = strzone(str);
396                 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
397                 str = strtolower(str);
398
399                 if(str == "ping") {
400                         sbar_field[sbar_num_fields] = SP_PING;
401                 } else if(str == "name" || str == "nick") {
402                         sbar_field[sbar_num_fields] = SP_NAME;
403                         sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
404                 } else if(str == "|") {
405                         sbar_field[sbar_num_fields] = SP_SEPARATOR;
406                 } else {
407                         for(j = 0; j < MAX_SCORE; ++j)
408                                 if(str == strtolower(scores_label[j]))
409                                         goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
410 :notfound
411                         print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
412                         continue;
413 :found
414                         sbar_field[sbar_num_fields] = j;
415                 }
416                 ++sbar_num_fields;
417         }
418         sbar_field[sbar_num_fields] = SP_END;
419 }
420
421 // MOVEUP::
422 vector sbar_field_rgb;
423 string Sbar_GetField(entity pl, float field)
424 {
425         float tmp, num, denom, f;
426         string str;
427         sbar_field_rgb = '1 1 1';
428         switch(field)
429         {
430                 case SP_PING:
431                         str = bufstr_get(databuf, DATABUF_PING + pl.sv_entnum);
432                         tmp = max(0, min(220, stof(str)-80)) / 220;
433                         sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
434                         return str;
435                 
436                 case SP_NAME:
437                         return getplayerkey(pl.sv_entnum, "name");
438
439                 case SP_KDRATIO:
440                         num = pl.(scores[SP_KILLS]);
441                         denom = pl.(scores[SP_DEATHS]);
442
443                         if(denom == 0) {
444                                 sbar_field_rgb = '0 1 0';
445                                 str = ftos(num);
446                         } else if(num <= 0) {
447                                 sbar_field_rgb = '1 0 0';
448                                 str = ftos(num/denom);
449                         } else
450                                 str = ftos(num/denom);
451                 
452                         tmp = strstrofs(str, ".", 0);
453                         if(tmp > 0)
454                                 str = substring(str, 0, tmp+2);
455                         return str;
456                         
457                 default:
458                         tmp = pl.(scores[field]);
459                         f = scores_flags[field];
460                         if(field == ps_primary)
461                                 sbar_field_rgb = '1 1 0';
462                         else if(field == ps_secondary)
463                                 sbar_field_rgb = '0 1 1';
464                         else
465                                 sbar_field_rgb = '1 1 1';
466                         if(!tmp)
467                                 if(f & SFL_HIDE_ZERO)
468                                         return "";
469                         return ftos(tmp);
470         }
471         //return "error";
472 }
473
474 // shamelessly stolen from menu QC :P <- as if I would steal YOUR code pfft ;)
475 float textLengthUpToWidth(string theText, float maxWidth, float handleColors)
476 {
477         // STOP.
478         // The following function is SLOW.
479         // For your safety and for the protection of those around you...
480         // DO NOT CALL THIS AT HOME.
481         // No really, don't.
482         if(stringwidth(theText, handleColors) <= maxWidth)
483                 return strlen(theText); // yeah!
484
485         // binary search for right place to cut string
486         float left, right, middle; // this always works
487         left = 0;
488         right = strlen(theText); // this always fails
489         do
490         {
491                 middle = floor((left + right) / 2);
492                 if(stringwidth(substring(theText, 0, middle), handleColors) <= maxWidth)
493                         left = middle;
494                 else
495                         right = middle;
496         }
497         while(left < right - 1);
498
499         // NOTE: when color codes are involved, this binary search is,
500         // mathematically, BROKEN. However, it is obviously guaranteed to
501         // terminate, as the range still halves each time - but nevertheless, it is
502         // guaranteed that it finds ONE valid cutoff place (where "left" is in
503         // range, and "right" is outside).
504
505         return left;
506 }
507 string textShortenToWidth(string theText, float maxWidth, float handleColors)
508 {
509         if(stringwidth(theText, handleColors) <= maxWidth)
510                 return theText;
511         else
512                 return strcat(substring(theText, 0, textLengthUpToWidth(theText, maxWidth - stringwidth("...", handleColors), handleColors)), "...");
513 }
514
515 float xmin, xmax, ymin, ymax, sbwidth, sbheight;
516
517 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
518 {
519         vector tmp;
520         string str;
521         float i, field, len;
522         float is_spec;
523         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
524
525         // Layout:
526         tmp_z = 0;
527         if(is_self)
528         {
529                 tmp_x = sbwidth;
530                 tmp_y = sbar_fontsize_y;
531                 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
532         }       
533         tmp_y = 0;
534         
535         for(i = 0; i < sbar_num_fields; ++i)
536         {
537                 field = sbar_field[i];
538                 if(field == SP_SEPARATOR)
539                         break;
540
541                 if(is_spec && field != SP_NAME && field != SP_PING) {
542                         pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
543                         continue;
544                 }
545                 str = Sbar_GetField(pl, field);
546
547                 if(field == SP_NAME)
548                 {
549                         float realsize;
550                         float j;
551                         realsize = sbar_size[i];
552                         if(i+1 < sbar_num_fields)
553                                 if(sbar_field[i+1] == SP_SEPARATOR)
554                                 {
555                                         realsize = (xmax - xmin) / sbar_fontsize_x;
556                                         for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
557                                                 realsize -= sbar_size[j] + 1;
558                                         realsize += 1;
559                                 }
560                         str = textShortenToWidth(str, realsize, TRUE);
561                 }
562                 len = stringwidth(str, TRUE);
563                 
564                 if(sbar_size[i] < len)
565                         sbar_size[i] = len;
566
567                 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
568
569                 if(field == SP_NAME) {
570                         tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
571                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
572                 } else {
573                         tmp_x = len*sbar_fontsize_x + sbar_fontsize_x;
574                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
575                 }
576         }
577         
578         if(sbar_field[i] == SP_SEPARATOR)
579         {
580                 pos_x = xmax;
581                 for(i = sbar_num_fields-1; i > 0; --i)
582                 {
583                         field = sbar_field[i];
584                         if(field == SP_SEPARATOR)
585                                 break;
586                         
587                         if(is_spec && field != SP_NAME && field != SP_PING) {
588                                 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
589                                 continue;
590                         }
591                         
592                         str = Sbar_GetField(pl, field);
593
594                         if(field == SP_NAME)
595                                 str = textShortenToWidth(str, sbar_size[i], TRUE);
596                         len = stringwidth(str, TRUE);
597
598                         if(sbar_size[i] < len)
599                                 sbar_size[i] = len;
600
601                         if(field == SP_NAME) {
602                                 tmp_x = sbar_fontsize_x*len; // left or right aligned? let's put it right...
603                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
604                         } else {
605                                 tmp_x = sbar_fontsize_x*len; //strlen(str);
606                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
607                         }
608                         pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
609                 }
610         }
611 }
612
613 void Sbar_DrawScoreboard()
614 {
615         //float xmin, ymin, xmax, ymax;
616         vector rgb, pos, tmp, sbar_save;
617         entity pl, tm;
618         float specs, i;
619         float center_x;
620
621         sbar_fontsize = Sbar_GetFontsize();
622         if(sbar_fontsize_x == 0)
623                 sbar_fontsize = '8 8 0';
624         if(sbar_fontsize_y == 0)
625                 sbar_fontsize_y = sbar_fontsize_x;
626         
627         xmin = vid_conwidth / 5;
628         ymin = 20;
629
630         xmax = vid_conwidth - xmin;
631         ymax = vid_conheight - 0.2*vid_conheight;
632
633         sbwidth = xmax - xmin;
634         sbheight = ymax - ymin;
635
636         center_x = xmin + 0.5*sbwidth;
637
638         //Sbar_UpdateFields();
639
640         // Initializes position
641         //pos_x = xmin;
642         pos_y = ymin;
643         pos_z = 0;
644
645         // Heading
646         drawfont = sbar_font;
647         pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
648         drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
649         pos_x = xmin;
650         pos_y += 24 + 4;
651
652         // Titlebar background:
653         tmp_x = sbwidth;
654         tmp_y = sbar_fontsize_y;
655         drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
656         
657         for(i = 0; i < sbar_num_fields; ++i)
658         {
659                 if(sbar_field[i] == SP_SEPARATOR)
660                         break;
661                 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
662                 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
663         }
664         
665         if(sbar_field[i] == SP_SEPARATOR)
666         {
667                 pos_x = xmax + sbar_fontsize_x;
668                 tmp_y = tmp_z = 0;
669                 for(i = sbar_num_fields-1; i > 0; --i)
670                 {
671                         if(sbar_field[i] == SP_SEPARATOR)
672                                 break;
673
674                         pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
675                         /**
676                          * FTEQCC BUG!
677                          * Using the following line will fuck it all up:
678                          **
679                          * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
680                          */
681                         tmp_x = sbar_fontsize_x*sbar_size[i];
682                         tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
683                         drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
684                 }
685         }
686                 
687         pos_x = xmin;
688         pos_y += 1.5 * sbar_fontsize_y;
689
690         sbar_save = sbar;
691         sbar = '0 0 0';
692         
693         if(teamplay)
694         {
695                 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
696                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
697                 {
698                         if(!tm.team_size || tm.team == COLOR_SPECTATOR)
699                                 continue;
700
701                         rgb = GetTeamRGB(tm.team);
702
703                         pos_x = xmin - 4*24;
704                         // TODO: Print primary and secondary scores!
705                         
706                         pos_x = xmin;
707
708                         specs = tm.team_size;
709
710                         if(specs < 2)
711                                 specs = 2;
712                         
713                         tmp_x = sbwidth;
714                         tmp_y = 1.25 * sbar_fontsize_y * specs;
715                         drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
716                         
717                         for(pl = players.sort_next; pl; pl = pl.sort_next)
718                         {
719                                 if(pl.team != tm.team)
720                                         continue;
721                                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
722                                 pos_y += 1.25 * sbar_fontsize_y;
723                                 tmp_y -= 1.25 * sbar_fontsize_y;
724                         }
725                         pos_y += tmp_y + 1.5 * sbar_fontsize_y;
726                 }
727                 // rgb := tempvector :)
728                 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
729                 pos_y += 3 * sbar_fontsize_y;
730                 specs = 0;
731                 for(pl = players.sort_next; pl; pl = pl.sort_next)
732                 {
733                         if(pl.team != COLOR_SPECTATOR)
734                                 continue;
735                         //drawcolorcodedstring(pos, getplayerkey(pl.sb_player, "name"), '8 8 0', 1, 0);
736                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
737                         pos += '0 1.25 0' * sbar_fontsize_y;
738                         ++specs;
739                 }
740                         
741                 if(specs)
742                         drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
743         } else {
744                 pos_x = xmin;
745                 for(pl = players.sort_next; pl; pl = pl.sort_next)
746                 {
747                         if(pl.team == COLOR_SPECTATOR)
748                                 continue;
749                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
750                         pos_y += 1.25 * sbar_fontsize_y;
751                         tmp_y -= 1.25 * sbar_fontsize_y;
752                 }
753
754                 // rgb := tempvector :)
755                 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
756                 pos_y += 3 * sbar_fontsize_y;
757                 specs = 0;
758                 for(pl = players.sort_next; pl; pl = pl.sort_next)
759                 {
760                         if(pl.team != COLOR_SPECTATOR)
761                                 continue;
762                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
763                         pos += '0 1.25 0' * sbar_fontsize_y;
764                         ++specs;
765                 }
766                         
767                 if(specs)
768                         drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
769         }
770         sbar = sbar_save;
771 }
772
773 void Sbar_Score(float margin)
774 {
775         float timelimit, timeleft, minutes, seconds, distribution, myplace, score;
776         vector sbar_save, place;
777         entity tm, pl, me;
778         sbar_save = sbar;
779
780         sbar_y = vid_conheight - (32+12);
781         sbar_x -= margin;
782         
783         place = '-48 -12 0';
784         if(teamplay)
785         {
786                 // Layout:
787                 //
788                 //   team1 team3 team4
789                 //
790                 //         TEAM2
791                 //for(i = 0; i < 4; ++i)
792                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
793                 {
794                         if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
795                                 continue;
796                         // -32*4 = -128
797                         score = tm.(teamscores[ts_primary]);
798                         if(tm.team == myteam)
799                                 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
800                         else
801                         {
802                                 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
803                                 place_x -= 4*12;
804                         }
805                 }
806         } else {
807                 // me vector := [team/connected frags id]
808                 myplace = 0;
809                 for(me = players.sort_next; me; me = me.sort_next)
810                 {
811                         if(me.team != COLOR_SPECTATOR)
812                                 ++myplace;
813                         if(me.sv_entnum == player_localentnum - 1)
814                                 break;
815                 }
816                 pl = players;
817                 if(pl == me)
818                         pl = pl.sort_next;
819                 
820                 if(pl) {
821                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
822                 } else
823                         distribution = 0;
824                 
825                 if(myplace == 1)
826                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
827                 else if(myplace == 2)
828                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
829                 else
830                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
831
832                 score = me.(scores[ps_primary]);
833                 if(distribution >= 0)
834                 {
835                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
836                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
837                 } else if(distribution >= -5)
838                 {
839                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
840                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
841                 } else {
842                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
843                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
844                 }
845         }
846         timelimit = getstatf(STAT_TIMELIMIT);
847         if(timelimit)
848         {
849                 timeleft = max(0, timelimit * 60 - time);
850                 minutes = floor(timeleft / 60);
851                 seconds = floor(timeleft - minutes*60);
852                 if(minutes >= 5)
853                 {
854                         Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
855                         drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
856                         Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
857                 } else if(minutes >= 1)
858                 {
859                         Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
860                         drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 0', sbar_alpha_fg, 0);
861                         Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
862                 } else {
863                         Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
864                 }
865         } else {
866                 minutes = floor(time / 60);
867                 seconds = floor(time - minutes*60);
868                 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
869                 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', '1 1 1', sbar_alpha_fg, 0);
870                 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
871         }
872         sbar = sbar_save;
873 }
874
875 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
876 {
877         float x, score;
878         pos_x += 72;
879         
880         if(teamplay)
881                 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
882         else
883                 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
884         x = pos_x;
885         pos_x += 5*8;
886         score = pl.(scores[ps_primary]);
887         pos_x -= stringwidth(ftos(score), FALSE)*8;
888         drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
889         pos_x = x;
890         if(is_self)
891         {
892                 pos_x += 48;
893                 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
894                 pos_x += 8;
895         } else
896                 pos_x += 56;
897         drawcolorcodedstring(pos, getplayerkey(pl.sv_entnum, "name"), '8 8 0', 1, 0);
898 }
899
900 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
901 {
902         float x;
903         pos_x += 72;
904         
905         if(teamplay)
906                 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
907         else
908                 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
909         x = pos_x;
910         pos_x += 5*8;
911         pos_x -= stringwidth(ftos(frags), FALSE)*8;
912         drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
913         pos_x = x;
914         if(is_self)
915         {
916                 pos_x += 48;
917                 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
918                 pos_x += 8;
919         } else
920                 pos_x += 56;
921         drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
922 }
923
924 void Sbar_MiniDeathmatchOverlay(vector pos)
925 {
926         float numlines, up, down, score;
927         entity me, tm, pl;
928         float miniscoreboard_size;
929         miniscoreboard_size = cvar("sbar_miniscoreboard_size");
930         
931         if(miniscoreboard_size == 0)
932                 return;
933         pos_y = vid_conheight - 8;
934         
935         if(miniscoreboard_size < 0)
936                 numlines = (vid_conheight - sbar_y + 7) / 8;
937         else
938                 numlines = miniscoreboard_size;
939
940         // give up if there isn't enough room
941         if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
942                 return;
943
944         // me vector := [team/connected frags id]
945         for(me = players.sort_next; me; me = me.sort_next)
946         {
947                 if(me.sv_entnum == player_localentnum - 1)
948                         break;
949         }
950
951         if(teamplay)
952                 numlines -= numteams;
953
954         // figure out how many players above and below we can show
955         up = floor(numlines/2);
956         down = up;
957         if((up + down) > numlines)
958                 down = numlines - up;
959
960         // render bottom-up
961         for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
962         {
963                 if(pl.team == COLOR_SPECTATOR)
964                         continue;
965                 Sbar_MiniscoreItem(pos, pl, false);
966                 pos_y -= 9;
967                 --down;
968         }
969         Sbar_MiniscoreItem(pos, me, true);
970         pos_y -= 9;
971         up += down; // if there weren't enough lines below... add them
972         for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
973         {
974                 if(pl.team == COLOR_SPECTATOR)
975                         continue;
976                 Sbar_MiniscoreItem(pos, pl, false);
977                 pos_y -= 9;
978                 --up;
979         }
980
981         if(teamplay)
982         {
983                 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
984                 for(; tm; tm = tm.sort_prev)
985                 {
986                         if(!tm.team_size || tm.team == COLOR_SPECTATOR)
987                                 continue;
988                         score = tm.(teamscores[ts_primary]);
989                         Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
990                         pos_y -= 9;
991                 }
992         }
993 }
994
995 void Sbar_Draw (void)
996 {
997         float i;
998         float x, fade;
999         float stat_items;
1000
1001         //Sbar_SortFrags();
1002         Sbar_UpdatePlayerTeams();
1003
1004         sb_lines = 24;
1005         
1006         if (sb_showscores)
1007                 Sbar_DrawScoreboard();
1008         else if (intermission == 1)
1009         {
1010                 Sbar_DrawScoreboard();
1011                 return;
1012         }
1013         else if (intermission == 2)
1014                 Sbar_FinaleOverlay();
1015         else
1016         {
1017                 if (sb_showscores || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1018                 {
1019                         sbar_x = (vid_conwidth - 640.0)*0.5;
1020                         sbar_y = vid_conheight - 47;
1021                         //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1022                         //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1023                         Sbar_DrawScoreboard ();
1024                 }
1025                 else
1026                 {
1027                         if (sb_lines && sbar_hudselector == 1)
1028                         {
1029                                 stat_items = getstati(STAT_ITEMS);
1030
1031                                 sbar_x = (vid_conwidth - 320.0)*0.5;
1032                                 sbar_y = vid_conheight - 24.0 - 16.0;
1033                                 sbar_z = 0;
1034                         
1035                                 fade = 3.2 - 2 * (time - weapontime);
1036                                 fade = bound(0.7, fade, 1);
1037
1038                                 x = 1.0;
1039                                 for(i = 0; i < 8; ++i)
1040                                 {
1041                                         if(stat_items & x)
1042                                         {
1043                                                 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1044                                         }
1045                                         x *= 2;
1046                                 }
1047                                 x *= 2*2*2*2;
1048                                 if(stat_items & x)
1049                                 {
1050                                         Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1051                                 }
1052
1053                                 // armor
1054                                 x = getstati(STAT_ARMOR);
1055                                 if (x > 0)
1056                                 {
1057                                         // "gfx/sb_armor"
1058                                         //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1059                                         drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1060                                         if(x > 200)
1061                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1062                                         else if(x > 100)
1063                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1064                                         else if(x > 50)
1065                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1066                                         else if(x > 25)
1067                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1068                                         else
1069                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1070                                 }
1071
1072                                 // health
1073                                 x = getstati(STAT_HEALTH);
1074                                 if (x != 0)
1075                                 {
1076                                         // "gfx/sb_health"
1077                                         //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1078                                         drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1079                                         if(x > 200)
1080                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1081                                         else if(x > 100)
1082                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1083                                         else if(x > 50)
1084                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1085                                         else if(x > 25)
1086                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1087                                         else
1088                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1089                                 }
1090
1091                                 // ammo
1092                                 x = getstati(STAT_AMMO);
1093                                 if ((stat_items & (NEX_IT_SHELLS | NEX_IT_BULLETS | NEX_IT_ROCKETS | NEX_IT_CELLS)) || x != 0)
1094                                 {
1095                                         if (stat_items & NEX_IT_SHELLS)
1096                                                 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1097                                         else if (stat_items & NEX_IT_BULLETS)
1098                                                 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1099                                         else if (stat_items & NEX_IT_ROCKETS)
1100                                                 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1101                                         else if (stat_items & NEX_IT_CELLS)
1102                                                 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1103                                         if(x > 10)
1104                                                 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1105                                         else
1106                                                 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1107                                 }
1108
1109                                 if (sbar_x + 320 + 160 <= vid_conwidth)
1110                                         Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1111                                 if (sbar_x > 0)
1112                                         Sbar_Score(16);
1113                                 // The margin can be at most 8 to support 640x480 console size:
1114                                 //   320 + 2 * (144 + 16) = 640
1115                         }
1116                         else if (sb_lines)
1117                         {
1118                         
1119                                 stat_items = getstati(STAT_ITEMS);
1120                         
1121                                 sbar_x = (vid_conwidth - 640.0)*0.5;
1122                                 sbar_y = vid_conheight - 47;
1123                                 sbar_z = 0;
1124
1125                                 fade = 3 - 2 * (time - weapontime);
1126
1127                                 x = 1.0;
1128                                 for(i = 0; i < 8; ++i)
1129                                 {
1130                                         if(stat_items & x)
1131                                         {
1132                                                 Sbar_DrawWeapon(i+1, fade, (i + 2 == activeweapon));
1133                                         }
1134                                         x *= 2;
1135                                 }
1136                                 x *= 2*2*2*2;
1137                                 if(stat_items & x)
1138                                 {
1139                                         Sbar_DrawWeapon(0, fade, (activeweapon == 1));
1140                                 }
1141
1142                                 if (sb_lines > 24)
1143                                         drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1144                                 else
1145                                         drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1146
1147                                 // armor
1148                                 // (340-3*24) = 268
1149                                 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1150
1151                                 // health
1152                                 // (154-3*24) = 82
1153                                 x = getstati(STAT_HEALTH);
1154                                 if(x > 100)
1155                                         Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1156                                 else if(x <= 25 && time - floor(time) > 0.5)
1157                                         Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1158                                 else
1159                                         Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1160
1161                                 // AK dont draw ammo for the laser
1162                                 x = getstati(STAT_AMMO);
1163                                 if(activeweapon != 12)
1164                                 {
1165                                         // (519-3*24) = 447
1166                                         if (stat_items & NEX_IT_SHELLS)
1167                                                 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1168                                         else if (stat_items & NEX_IT_BULLETS)
1169                                                 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1170                                         else if (stat_items & NEX_IT_ROCKETS)
1171                                                 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1172                                         else if (stat_items & NEX_IT_CELLS)
1173                                                 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1174                                         if(x > 10)
1175                                                 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1176                                         else
1177                                                 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1178                                 }
1179
1180                                 if (sb_lines > 24)
1181                                         drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
1182
1183                                 if (sbar_x + 600 + 160 <= vid_conwidth)
1184                                         Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
1185
1186                                 if (sbar_x > 0)
1187                                         Sbar_Score(-16);
1188                                 // Because:
1189                                 //   Mini scoreboard uses 12*4 per other team, that is, 144
1190                                 //   pixels when there are four teams...
1191                                 //   Nexuiz by default sets vid_conwidth to 800... makes
1192                                 //   sbar_x == 80...
1193                                 //   so we need to shift it by 64 pixels to the right to fit
1194                                 //   BUT: then it overlaps with the image that gets drawn
1195                                 //   for viewsize 100! Therefore, just account for 3 teams,
1196                                 //   that is, 96 pixels mini scoreboard size, needing 16 pixels
1197                                 //   to the right!
1198                         }
1199                 
1200                 
1201                         if(gametype == GAME_KEYHUNT)
1202                         {
1203                                 CSQC_kh_hud();
1204                         } else if(gametype == GAME_CTF)
1205                         {
1206                                 CSQC_ctf_hud();
1207                         }
1208                 }
1209         }
1210 }
1211
1212 void CSQC_ctf_hud(void)
1213 {
1214         // cvar("sbar_flagstatus_right") move the flag icons right
1215         // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
1216         float redflag, blueflag;
1217         float stat_items;
1218         vector pos;
1219         
1220         stat_items = getstati(STAT_ITEMS);
1221         redflag = (stat_items/32768) & 3;
1222         blueflag = (stat_items/131072) & 3;
1223
1224         /**
1225          * FTEQCC BUG!
1226          * For some reason now not even THAT works there...
1227          * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
1228          **
1229          * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
1230          ** Should try those later:
1231          * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
1232          * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
1233          */
1234         
1235         if(cvar("sbar_flagstatus_right"))
1236                 pos_x = vid_conwidth - 10 - sbar_x - 64;
1237         else
1238                 pos_x = 10 - sbar_x;
1239         
1240         pos_z = 0;
1241
1242         if(sbar_hudselector == 1)
1243                 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
1244         else
1245                 pos_y = -117;
1246
1247         pos += sbar;
1248
1249         switch(redflag)
1250         {
1251         case 1: drawpic(pos, "gfx/sb_flag_red_taken", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1252         case 2: drawpic(pos, "gfx/sb_flag_red_lost", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1253         case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '0 0 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
1254         }
1255
1256         pos_y -= 64;
1257         
1258         switch(blueflag)
1259         {
1260         case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '0 0 0', '1 1 1', 1, 0); break;
1261         case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '0 0 0', '1 1 1', 1, 0); break;
1262         case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '0 0 0', '1 1 1', 1, 0); break;
1263         }
1264 }