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