]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/sbar.qc
fix typo
[divverent/nexuiz.git] / data / qcsrc / client / sbar.qc
1
2 float last_weapon;
3 float weapontime;
4
5 float sb_lines; // still don't know what to do with that NOTE: check dp's sbar.c to see what that should be
6
7 vector sbar;
8 float sbar_alpha_fg;
9 float sbar_hudselector;
10
11 float ps_primary, ps_secondary;
12 float ts_primary, ts_secondary;
13
14 void CSQC_kh_hud();
15 void CSQC_ctf_hud();
16 void MapVote_Draw();
17 void Sbar_FinaleOverlay()
18 {
19         /*vector pos;
20         pos_x = (vid_conwidth - 1)/2;
21         pos_y = 16;
22         pos_z = 0;*/
23         
24         //drawpic(pos, "gfx/finale", '0 0 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
25         
26         //drawstring(pos, "END", sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
27         MapVote_Draw();
28 }
29
30 float weaponspace[10];
31 float weapon_first, weapon_last;
32 void Sbar_DrawWeapon_Clear()
33 {
34         float idx;
35         weapon_first = -2;
36         weapon_last = -1;
37         for(idx = 0; idx < 10; ++idx)
38                 weaponspace[idx] = 0;
39         for(idx = 0; idx <= 23; ++idx)
40         {
41                 if(weaponimpulse[idx] >= 0)
42                 {
43                         if(weapon_first < 0)
44                                 weapon_first = idx;
45                         weapon_last = idx;
46                 }
47         }
48 }
49 void Sbar_DrawWeapon(float nr, float fade, float active)
50 {
51         vector pos, vsize, color;
52         float value, idx, imp, sp;
53
54         imp = weaponimpulse[nr];
55         if(imp == 0)
56                 idx = 9;
57         else
58                 idx = imp - 1;
59         
60         value = (active) ? 1 : 0.6;
61         color_x = color_y = color_z = value;
62         
63         if(sbar_hudselector == 1)
64         {
65                 // width = 300, height = 100
66                 const float w_width = 32, w_height = 12, w_space = 2, font_size = 8;
67
68                 sp = weaponspace[idx] + 1;
69                 weaponspace[idx] = sp;
70                 
71                 pos_x = (vid_conwidth - w_width * 9) * 0.5 + w_width * idx;
72                 pos_y = (vid_conheight - w_height * sp);
73                 pos_z = 0;
74                 vsize_x = w_width;
75                 vsize_y = w_height;
76                 vsize_z = 0;
77                 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
78                 pos_x += w_space;
79                 pos_y += w_space;
80                 vsize_x = font_size;
81                 vsize_y = font_size;
82                 vsize_z = 0;
83                 drawstring(pos, ftos(imp), vsize, '1 1 0', sbar_alpha_fg, 0);
84         }
85         else
86         {
87                 // width = 300, height = 100
88                 const float w2_width = 300, w2_height = 100, w2_space = 10;
89                 const float w2_scale = 0.4;
90
91                 float f;
92                 f = 9 / (weapon_last + 1 - weapon_first);
93
94                 pos_x = vid_conwidth - (w2_width + w2_space) * w2_scale * f;
95                 pos_y = (w2_height + w2_space) * w2_scale * nr * f + w2_space;
96                 pos_z = 0;
97                 vsize_x = w2_width * w2_scale * f;
98                 vsize_y = w2_height * w2_scale * f;
99                 vsize_z = 0;
100                 
101                 drawpic(pos, strcat("gfx/inv_weapon", ftos(nr)), vsize, color, value * fade * sbar_alpha_fg, 0);
102         }
103 }
104 void Sbar_DrawXNum (vector pos, float num, float digits, float lettersize, vector rgb, float a, float dflags)
105 {
106         float l, i;
107         string str, tmp;
108         float minus;
109         vector vsize;
110
111         vsize_x = vsize_y = lettersize;
112         vsize_z = 0;
113
114         if(num < 0)
115         {
116                 minus = true;
117                 num = -num;
118                 pos_x -= lettersize;
119         } else
120                 minus = false;
121         
122         if(digits < 0)
123         {
124                 tmp = ftos(num);
125                 digits = -digits;
126                 str = strcat(substring("0000000000", 0, digits - strlen(tmp)), tmp);
127         } else
128                 str = ftos(num);
129         
130         l = strlen(str);
131
132         if(l > digits)
133         {
134                 str = substring(str, l-digits, 999);
135                 l = strlen(str);
136         } else if(l < digits)
137                 pos_x += (digits-l) * lettersize;
138
139         if(minus)
140         {
141                 drawpic(sbar + pos, "gfx/num_minus", vsize, rgb, a * sbar_alpha_fg, dflags);
142                 pos_x += lettersize;
143         }
144
145         for(i = 0; i < l; ++i)
146         {
147                 drawpic(sbar + pos, strcat("gfx/num_", substring(str, i, 1)), vsize, rgb, a * sbar_alpha_fg, dflags);
148                 pos_x += lettersize;
149         }
150 }
151
152 void Cmd_Sbar_SetFields(float argc);
153 void Sbar_InitScores()
154 {
155         float i, f;
156
157         ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
158         for(i = 0; i < MAX_SCORE; ++i)
159         {
160                 f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
161                 if(f == SFL_SORT_PRIO_PRIMARY)
162                         ps_primary = i;
163                 if(f == SFL_SORT_PRIO_SECONDARY)
164                         ps_secondary = i;
165         }
166         if(ps_secondary == -1)
167                 ps_secondary = ps_primary;
168         
169         for(i = 0; i < MAX_TEAMSCORE; ++i)
170         {
171                 f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
172                 if(f == SFL_SORT_PRIO_PRIMARY)
173                         ts_primary = i;
174                 if(f == SFL_SORT_PRIO_SECONDARY)
175                         ts_secondary = i;
176         }
177         if(ts_secondary == -1)
178                 ts_secondary = ts_primary;
179
180         Cmd_Sbar_SetFields(0);
181 }
182
183 void Sbar_UpdatePlayerPos(entity pl);
184 float SetTeam(entity pl, float Team);
185 //float lastpnum;
186 void Sbar_UpdatePlayerTeams()
187 {
188         float Team;
189         entity pl, tmp;
190         float num;
191
192         num = 0;
193         for(pl = players.sort_next; pl; pl = pl.sort_next)
194         {
195                 num += 1;
196                 Team = GetPlayerColor(pl.sv_entnum);
197                 if(SetTeam(pl, Team))
198                 {
199                         tmp = pl.sort_prev;
200                         Sbar_UpdatePlayerPos(pl);
201                         if(tmp)
202                                 pl = tmp;
203                         else
204                                 pl = players.sort_next;
205                 }
206         }
207         /*
208         if(num != lastpnum)
209                 print(strcat("PNUM: ", ftos(num), "\n"));
210         lastpnum = num;
211         */
212 }
213
214 float Sbar_ComparePlayerScores(entity left, entity right)
215 {
216         float vl, vr;
217         vl = GetPlayerColor(left.sv_entnum);
218         vr = GetPlayerColor(right.sv_entnum);
219
220         if(!left.gotscores)
221                 vl = COLOR_SPECTATOR;
222         if(!right.gotscores)
223                 vr = COLOR_SPECTATOR;
224         
225         if(vl > vr)
226                 return true;
227         if(vl < vr)
228                 return false;
229
230         if(vl == COLOR_SPECTATOR)
231         {
232                 // FIRST the one with scores (spectators), THEN the ones without (downloaders)
233                 // no other sorting
234                 if(!left.gotscores && right.gotscores)
235                         return true;
236                 return false;
237         }
238
239         vl = left.scores[ps_primary];
240         vr = right.scores[ps_primary];
241         if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
242         {
243                 if(vl == 0 && vr != 0)
244                         return 1;
245                 if(vl != 0 && vr == 0)
246                         return 0;
247         }
248         if(vl > vr)
249                 return IS_INCREASING(scores_flags[ps_primary]);
250         if(vl < vr)
251                 return IS_DECREASING(scores_flags[ps_primary]);
252         
253         vl = left.scores[ps_secondary];
254         vr = right.scores[ps_secondary];
255         if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
256         {
257                 if(vl == 0 && vr != 0)
258                         return 1;
259                 if(vl != 0 && vr == 0)
260                         return 0;
261         }
262         if(vl > vr)
263                 return IS_INCREASING(scores_flags[ps_secondary]);
264         if(vl < vr)
265                 return IS_DECREASING(scores_flags[ps_secondary]);
266         
267         return false;
268 }
269
270 void Sbar_UpdatePlayerPos(entity player)
271 {
272         for(other = player.sort_next; other && Sbar_ComparePlayerScores(player, other); other = player.sort_next)
273         {
274                 SORT_SWAP(player, other);
275         }
276         for(other = player.sort_prev; other != players && Sbar_ComparePlayerScores(other, player); other = player.sort_prev)
277         {
278                 SORT_SWAP(other, player);
279         }
280 }
281
282 float Sbar_CompareTeamScores(entity left, entity right)
283 {
284         float vl, vr;
285
286         if(left.team == COLOR_SPECTATOR)
287                 return 1;
288         if(right.team == COLOR_SPECTATOR)
289                 return 0;
290         
291         vl = left.teamscores[ts_primary];
292         vr = right.teamscores[ts_primary];
293         if(vl > vr)
294                 return IS_INCREASING(teamscores_flags[ts_primary]);
295         if(vl < vr)
296                 return IS_DECREASING(teamscores_flags[ts_primary]);
297         
298         vl = left.teamscores[ts_secondary];
299         vr = right.teamscores[ts_secondary];
300         if(vl > vr)
301                 return IS_INCREASING(teamscores_flags[ts_secondary]);
302         if(vl < vr)
303                 return IS_DECREASING(teamscores_flags[ts_secondary]);
304
305         return false;
306 }
307
308 void Sbar_UpdateTeamPos(entity Team)
309 {
310         for(other = Team.sort_next; other && Sbar_CompareTeamScores(Team, other); other = Team.sort_next)
311         {
312                 SORT_SWAP(Team, other);
313         }
314         for(other = Team.sort_prev; other != teams && Sbar_CompareTeamScores(other, Team); other = Team.sort_prev)
315         {
316                 SORT_SWAP(other, Team);
317         }
318 }
319
320 void Cmd_Sbar_Help(float argc)
321 {
322         print("You can modify the scoreboard using the\n");
323         print("^3|---------------------------------------------------------------|\n");
324         print("^1 TO BE DONE\n");
325         print("Usage:\n");
326         print("^2sbar_columns_set default\n");
327         print("^2sbar_columns_set ^7filed1 field2 ...\n");
328         print("The following field names are recognized (case INsensitive):\n");
329         print("You can use a ^3|^7 to start the right-aligned fields.\n");
330         
331         print("^3name^7 or ^3nick^7             Name of a player\n");
332         print("^3ping^7                     Ping time\n\n");
333         print("^3kd^7 or ^3kdr^7 or ^3kdratio^7 or ^3k/d\n");
334         print("                         The kill-death ratio\n");
335
336         print("Before a field you can put a + or - sign, then a comma separated list\n");
337         print("of game types, then a slash, to make the field show up only in these\n");
338         print("or in all but these game types.\n");
339
340         print("The special game type names 'teams' and 'noteams' can be used to\n");
341         print("include/exclude ALL teams/noteams game modes.\n");
342
343         local float i;
344         print("Additional columns:\n");
345         for(i = 0; i < MAX_SCORE; ++i)
346         {
347                 if(scores_label[i] != "")
348                         print(strcat(scores_label[i], "\n"));
349         }
350 }
351
352 #define MIN_NAMELEN 24
353 #define MAX_NAMELEN 24
354
355 string Sbar_DefaultColumnLayout()
356 {
357         return strcat( // fteqcc sucks
358                 "ping pl name | ",
359                 "+noteams/kills +noteams/deaths +noteams/suicides -noteams,tdm/frags ", // tdm already has this in "score"
360                 "+kh/caps +kh/pushes +kh/destroyed ",
361                 "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
362                 "-lms/score");
363 }
364
365 void Cmd_Sbar_SetFields(float argc)
366 {
367         float i, j, slash;
368         string str, pattern, subpattern, subpattern2;
369         float digit;
370         float have_name, have_primary, have_secondary, have_separator;
371         float missing;
372
373         // TODO: re enable with gametype dependant cvars?
374         if(argc < 2) // no arguments provided
375                 argc = tokenizebyseparator(strcat("x ", cvar_string("sbar_columns")), " ");
376
377         if(argc < 2)
378                 argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
379
380         if(argc == 2)
381         {
382                 if(argv(1) == "default")
383                         argc = tokenizebyseparator(strcat("x ", Sbar_DefaultColumnLayout()), " ");
384                 else if(argv(1) == "all")
385                 {
386                         string s;
387                         s = "ping pl color name |";
388                         for(i = 0; i < MAX_SCORE; ++i)
389                         {
390                                 if(i != ps_primary)
391                                 if(i != ps_secondary)
392                                 if(scores_label[i] != "")
393                                         s = strcat(s, " ", scores_label[i]);
394                         }
395                         if(ps_secondary != ps_primary)
396                                 s = strcat(s, " ", scores_label[ps_secondary]);
397                         s = strcat(s, " ", scores_label[ps_primary]);
398                         argc = tokenizebyseparator(strcat("x ", s), " ");
399                 }
400         }
401                 
402         
403         sbar_num_fields = 0;
404
405         drawfont = sbar_font;
406         digit = stringwidth("0123456789", FALSE) / 10;
407
408         subpattern = strcat(",", GametypeNameFromType(gametype), ",");
409         if(teamplay)
410                 subpattern2 = ",teams,";
411         else
412                 subpattern2 = ",noteams,";
413
414         for(i = 0; i < argc - 1; ++i)
415         {
416                 str = argv(i+1);
417
418                 slash = strstrofs(str, "/", 0);
419                 if(slash >= 0)
420                 {
421                         pattern = substring(str, 0, slash);
422                         str = substring(str, slash + 1, strlen(str) - (slash + 1));
423
424                         if(substring(pattern, 0, 1) == "-")
425                         {
426                                 pattern = substring(pattern, 1, strlen(pattern) - 1);
427                                 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) >= 0)
428                                         continue;
429                                 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) >= 0)
430                                         continue;
431                         }
432                         else
433                         {
434                                 if(substring(pattern, 0, 1) == "+")
435                                         pattern = substring(pattern, 1, strlen(pattern) - 1);
436                                 if(strstrofs(strcat(",", pattern, ","), subpattern, 0) < 0)
437                                 if(strstrofs(strcat(",", pattern, ","), subpattern2, 0) < 0)
438                                         continue;
439                         }
440                 }
441
442                 strunzone(sbar_title[sbar_num_fields]);
443                 sbar_title[sbar_num_fields] = strzone(str);
444                 sbar_size[sbar_num_fields] = stringwidth(str, FALSE);
445                 str = strtolower(str);
446
447                 if(str == "ping") {
448                         sbar_field[sbar_num_fields] = SP_PING;
449                 } else if(str == "pl") {
450                         sbar_field[sbar_num_fields] = SP_PL;
451                 } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
452                         sbar_field[sbar_num_fields] = SP_KDRATIO;
453                 } else if(str == "name" || str == "nick") {
454                         sbar_field[sbar_num_fields] = SP_NAME;
455                         sbar_size[sbar_num_fields] = MIN_NAMELEN; // minimum size? any use?
456                         have_name = 1;
457                 } else if(str == "|") {
458                         sbar_field[sbar_num_fields] = SP_SEPARATOR;
459                         have_separator = 1;
460                 } else {
461                         for(j = 0; j < MAX_SCORE; ++j)
462                                 if(str == strtolower(scores_label[j]))
463                                         goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
464 :notfound
465                         if(str == "frags")
466                         {
467                                 j = SP_FRAGS;
468                         }
469                         else
470                         {
471                                 print(strcat("^1Error:^7 Unknown score field: '", str, "'\n"));
472                                 continue;
473                         }
474 :found
475                         sbar_field[sbar_num_fields] = j;
476                         if(j == ps_primary)
477                                 have_primary = 1;
478                         if(j == ps_secondary)
479                                 have_secondary = 1;
480                 }
481                 ++sbar_num_fields;
482                 if(sbar_num_fields >= MAX_SBAR_FIELDS)
483                         break;
484         }
485
486         if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
487                 have_primary = 1;
488         if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
489                 have_secondary = 1;
490         if(ps_primary == ps_secondary)
491                 have_secondary = 1;
492         missing = !have_primary + !have_secondary + !have_separator + !have_name;
493
494         if(sbar_num_fields+missing < MAX_SBAR_FIELDS)
495         {
496                 if(!have_name)
497                 {
498                         strunzone(sbar_title[sbar_num_fields]);
499                         for(i = sbar_num_fields; i > 0; --i)
500                         {
501                                 sbar_title[i] = sbar_title[i-1];
502                                 sbar_size[i] = sbar_size[i-1];
503                                 sbar_field[i] = sbar_field[i-1];
504                         }
505                         sbar_title[0] = strzone("name");
506                         sbar_field[0] = SP_NAME;
507                         sbar_size[0] = MIN_NAMELEN; // minimum size? any use?
508                         ++sbar_num_fields;
509                         print("fixed missing field 'name'\n");
510
511                         if(!have_separator)
512                         {
513                                 strunzone(sbar_title[sbar_num_fields]);
514                                 for(i = sbar_num_fields; i > 1; --i)
515                                 {
516                                         sbar_title[i] = sbar_title[i-1];
517                                         sbar_size[i] = sbar_size[i-1];
518                                         sbar_field[i] = sbar_field[i-1];
519                                 }
520                                 sbar_title[1] = strzone("|");
521                                 sbar_field[1] = SP_SEPARATOR;
522                                 sbar_size[1] = stringwidth("|", FALSE);
523                                 ++sbar_num_fields;
524                                 print("fixed missing field '|'\n");
525                         }
526                 }
527                 else if(!have_separator)
528                 {
529                         strunzone(sbar_title[sbar_num_fields]);
530                         sbar_title[sbar_num_fields] = strzone("|");
531                         sbar_size[sbar_num_fields] = stringwidth("|", FALSE);
532                         sbar_field[sbar_num_fields] = SP_SEPARATOR;
533                         ++sbar_num_fields;
534                         print("fixed missing field '|'\n");
535                 }
536
537                 if(!have_secondary)
538                 {
539                         strunzone(sbar_title[sbar_num_fields]);
540                         sbar_title[sbar_num_fields] = strzone(scores_label[ps_secondary]);
541                         sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
542                         sbar_field[sbar_num_fields] = ps_secondary;
543                         ++sbar_num_fields;
544                         print("fixed missing field '", scores_label[ps_secondary], "'\n");
545                 }
546
547                 if(!have_primary)
548                 {
549                         strunzone(sbar_title[sbar_num_fields]);
550                         sbar_title[sbar_num_fields] = strzone(scores_label[ps_primary]);
551                         sbar_size[sbar_num_fields] = stringwidth(sbar_title[sbar_num_fields], FALSE);
552                         sbar_field[sbar_num_fields] = ps_primary;
553                         ++sbar_num_fields;
554                         print("fixed missing field '", scores_label[ps_primary], "'\n");
555                 }
556         }
557
558         sbar_field[sbar_num_fields] = SP_END;
559 }
560
561 // MOVEUP::
562 vector sbar_field_rgb;
563 string sbar_field_icon0;
564 string sbar_field_icon1;
565 string sbar_field_icon2;
566 vector sbar_field_icon0_rgb;
567 vector sbar_field_icon1_rgb;
568 vector sbar_field_icon2_rgb;
569 float sbar_field_icon0_alpha;
570 float sbar_field_icon1_alpha;
571 float sbar_field_icon2_alpha;
572 string Sbar_GetField(entity pl, float field)
573 {
574         float tmp, num, denom, f;
575         string str;
576         sbar_field_rgb = '1 1 1';
577         sbar_field_icon0 = "";
578         sbar_field_icon1 = "";
579         sbar_field_icon2 = "";
580         sbar_field_icon0_rgb = '1 1 1';
581         sbar_field_icon1_rgb = '1 1 1';
582         sbar_field_icon2_rgb = '1 1 1';
583         sbar_field_icon0_alpha = 1;
584         sbar_field_icon1_alpha = 1;
585         sbar_field_icon2_alpha = 1;
586         switch(field)
587         {
588                 case SP_PING:
589                         if not(pl.gotscores)
590                                 return "\x8D\x8D\x8D"; // >>> sign
591                         str = getplayerkey(pl.sv_entnum, "ping");
592                         if(str == "0")
593                                 return "N/A";
594                         tmp = max(0, min(220, stof(str)-80)) / 220;
595                         sbar_field_rgb = '1 1 1' - '0 1 1'*tmp;
596                         return str;
597                 
598                 case SP_PL:
599                         if not(pl.gotscores)
600                                 return "N/A";
601                         str = getplayerkey(pl.sv_entnum, "pl");
602                         if(str == "0")
603                                 return "";
604                         tmp = bound(0, stof(str), 20) / 20; // 20% is REALLY BAD pl
605                         sbar_field_rgb = '1 0.5 0.5' - '0 0.5 0.5'*tmp;
606                         return str;
607                 
608                 case SP_NAME:
609                         if(!teamplay)
610                         {
611                                 f = stof(getplayerkey(pl.sv_entnum, "colors"));
612                                 if(ready_waiting && pl.ready)
613                                 {
614                                         sbar_field_icon0 = "gfx/sb_player_ready";
615                                 }
616                                 else
617                                 {
618                                         sbar_field_icon0 = "gfx/sb_playercolor_base";
619                                         sbar_field_icon1 = "gfx/sb_playercolor_shirt";
620                                         sbar_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
621                                         sbar_field_icon2 = "gfx/sb_playercolor_pants";
622                                         sbar_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
623                                 }
624                         }
625                         return GetPlayerName(pl.sv_entnum);
626
627                 case SP_FRAGS:
628                         f = pl.(scores[SP_KILLS]);
629                         f -= pl.(scores[SP_SUICIDES]);
630                         return ftos(f);
631
632                 case SP_KDRATIO:
633                         num = pl.(scores[SP_KILLS]);
634                         denom = pl.(scores[SP_DEATHS]);
635
636                         if(denom == 0) {
637                                 sbar_field_rgb = '0 1 0';
638                                 str = ftos(num);
639                         } else if(num <= 0) {
640                                 sbar_field_rgb = '1 0 0';
641                                 str = ftos(num/denom);
642                         } else
643                                 str = ftos(num/denom);
644                 
645                         tmp = strstrofs(str, ".", 0);
646                         if(tmp > 0)
647                                 str = substring(str, 0, tmp+2);
648                         return str;
649                         
650                 default:
651                         tmp = pl.(scores[field]);
652                         f = scores_flags[field];
653                         if(field == ps_primary)
654                                 sbar_field_rgb = '1 1 0';
655                         else if(field == ps_secondary)
656                                 sbar_field_rgb = '0 1 1';
657                         else
658                                 sbar_field_rgb = '1 1 1';
659                         return ScoreString(f, tmp);
660         }
661         //return "error";
662 }
663
664 float xmin, xmax, ymin, ymax, sbwidth;
665 float sbar_fixscoreboardcolumnwidth_len;
666 float sbar_fixscoreboardcolumnwidth_iconlen;
667 float sbar_fixscoreboardcolumnwidth_marginlen;
668
669 float stringwidth_colors(string s)
670 {
671         return stringwidth(s, TRUE);
672 }
673
674 float stringwidth_nocolors(string s)
675 {
676         return stringwidth(s, FALSE);
677 }
678
679 string Sbar_FixScoreboardColumnWidth(float i, string str)
680 {
681         float field, maxsize, j, f;
682         vector sz;
683         field = sbar_field[i];
684
685         if(field == SP_NAME) // name gets all remaining space
686         {
687                 maxsize = (xmax - xmin) / sbar_fontsize_x;
688                 for(j = 0; j < sbar_num_fields; ++j) if(j != i) if(sbar_field[j] != SP_SEPARATOR)
689                         maxsize -= sbar_size[j] + 1;
690                 maxsize += 1;
691                 str = textShortenToWidth(str, maxsize, stringwidth_colors);
692                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, TRUE);
693         }
694         else
695                 sbar_fixscoreboardcolumnwidth_len = stringwidth(str, FALSE);
696         
697         sbar_fixscoreboardcolumnwidth_iconlen = 0;
698
699         if(sbar_field_icon0 != "")
700         {
701                 sz = drawgetimagesize(sbar_field_icon0);
702                 f = sz_x / sz_y;
703                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
704                         sbar_fixscoreboardcolumnwidth_iconlen = f;
705         }
706
707         if(sbar_field_icon1 != "")
708         {
709                 sz = drawgetimagesize(sbar_field_icon1);
710                 f = sz_x / sz_y;
711                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
712                         sbar_fixscoreboardcolumnwidth_iconlen = f;
713         }
714
715         if(sbar_field_icon2 != "")
716         {
717                 sz = drawgetimagesize(sbar_field_icon2);
718                 f = sz_x / sz_y;
719                 if(sbar_fixscoreboardcolumnwidth_iconlen < f)
720                         sbar_fixscoreboardcolumnwidth_iconlen = f;
721         }
722
723         sbar_fixscoreboardcolumnwidth_iconlen *= sbar_fontsize_y / sbar_fontsize_x; // fix icon aspect
724
725         if(sbar_fixscoreboardcolumnwidth_iconlen != 0 && sbar_fixscoreboardcolumnwidth_len != 0)
726                 sbar_fixscoreboardcolumnwidth_marginlen = stringwidth(" ", FALSE);
727         else
728                 sbar_fixscoreboardcolumnwidth_marginlen = 0;
729
730         f = sbar_fixscoreboardcolumnwidth_len + sbar_fixscoreboardcolumnwidth_marginlen + sbar_fixscoreboardcolumnwidth_iconlen;
731         if(sbar_size[i] < f)
732                 sbar_size[i] = f;
733
734         return str;
735 }
736
737 void Sbar_PrintScoreboardItem(vector pos, entity pl, float is_self)
738 {
739         vector tmp;
740         string str;
741         float i, field;
742         float is_spec;
743         is_spec = (GetPlayerColor(pl.sv_entnum) == COLOR_SPECTATOR);
744
745         // Layout:
746         tmp_z = 0;
747         if(is_self)
748         {
749                 tmp_x = sbwidth;
750                 tmp_y = sbar_fontsize_y;
751                 drawfill(pos - '1 1 0', tmp + '2 2 0', '1 1 1', 0.3, DRAWFLAG_NORMAL);
752         }       
753         tmp_y = 0;
754         
755         for(i = 0; i < sbar_num_fields; ++i)
756         {
757                 field = sbar_field[i];
758                 if(field == SP_SEPARATOR)
759                         break;
760
761                 if(is_spec && field != SP_NAME && field != SP_PING) {
762                         pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
763                         continue;
764                 }
765                 str = Sbar_GetField(pl, field);
766                 str = Sbar_FixScoreboardColumnWidth(i, str);
767
768                 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
769
770                 if(field == SP_NAME) {
771                         tmp_x = sbar_fontsize_x*(sbar_size[i] - sbar_fixscoreboardcolumnwidth_iconlen - sbar_fixscoreboardcolumnwidth_marginlen) + sbar_fontsize_x;
772                         drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
773                 } else {
774                         tmp_x = sbar_fixscoreboardcolumnwidth_len*sbar_fontsize_x + sbar_fontsize_x;
775                         drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
776                 }
777
778                 tmp_x = sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
779                 if(sbar_field_icon0 != "")
780                         drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, 0);
781                 if(sbar_field_icon1 != "")
782                         drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha, 0);
783                 if(sbar_field_icon2 != "")
784                         drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha, 0);
785         }
786         
787         if(sbar_field[i] == SP_SEPARATOR)
788         {
789                 pos_x = xmax;
790                 for(i = sbar_num_fields-1; i > 0; --i)
791                 {
792                         field = sbar_field[i];
793                         if(field == SP_SEPARATOR)
794                                 break;
795                         
796                         if(is_spec && field != SP_NAME && field != SP_PING) {
797                                 pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
798                                 continue;
799                         }
800                         
801                         str = Sbar_GetField(pl, field);
802                         str = Sbar_FixScoreboardColumnWidth(i, str);
803
804                         if(field == SP_NAME) {
805                                 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; // left or right aligned? let's put it right...
806                                 drawcolorcodedstring(pos - tmp, str, sbar_fontsize, 1, DRAWFLAG_NORMAL);
807                         } else {
808                                 tmp_x = sbar_fontsize_x*sbar_fixscoreboardcolumnwidth_len; //strlen(str);
809                                 drawstring(pos - tmp, str, sbar_fontsize, sbar_field_rgb, 1, DRAWFLAG_NORMAL);
810                         }
811
812                         tmp_x = sbar_fontsize_x*sbar_size[i];
813                         if(sbar_field_icon0 != "")
814                                 drawpic(pos - tmp, sbar_field_icon0, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon0_alpha, 0);
815                         if(sbar_field_icon1 != "")
816                                 drawpic(pos - tmp, sbar_field_icon1, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon1_rgb, sbar_field_icon1_alpha, 0);
817                         if(sbar_field_icon2 != "")
818                                 drawpic(pos - tmp, sbar_field_icon2, '0 1 0' * sbar_fontsize_y + '1 0 0' * sbar_fontsize_x * sbar_fixscoreboardcolumnwidth_iconlen, sbar_field_icon2_rgb, sbar_field_icon2_alpha, 0);
819
820                         pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
821                 }
822         }
823 }
824
825 float lastpingstime;
826 float scoreboard_bottom;
827 void Sbar_DrawScoreboard()
828 {
829         //float xmin, ymin, xmax, ymax;
830         vector rgb, pos, tmp, sbar_save;
831         entity pl, tm;
832         float specs, i;
833         float center_x;
834
835         if(time > lastpingstime + 10)
836         {
837                 localcmd("pings\n");
838                 lastpingstime = time;
839         }
840
841         sbwidth = Sbar_GetWidth(6.5 * sbar_fontsize_y);
842
843         xmin = 0.5 * (vid_conwidth - sbwidth);
844         ymin = 45;
845
846         xmax = vid_conwidth - xmin;
847     ymax = vid_conheight - 0.2*vid_conheight;
848
849         center_x = xmin + 0.5*sbwidth;
850
851         //Sbar_UpdateFields();
852
853         // Initializes position
854         //pos_x = xmin;
855         pos_y = ymin;
856         pos_z = 0;
857
858         // Heading
859         drawfont = sbar_bigfont;
860         pos_x = center_x - stringwidth("Scoreboard", TRUE)*0.5*24;
861         drawstring(pos, "Scoreboard", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
862         pos_x = xmin;
863         pos_y += 24 + 4;
864
865         // Titlebar background:
866         tmp_x = sbwidth;
867         tmp_y = sbar_fontsize_y;
868         drawfill(pos - '1 1 0', tmp + '2 2 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
869         
870         drawfont = sbar_font;
871
872         for(i = 0; i < sbar_num_fields; ++i)
873         {
874                 if(sbar_field[i] == SP_SEPARATOR)
875                         break;
876                 drawstring(pos, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
877                 pos_x += sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
878         }
879         
880         if(sbar_field[i] == SP_SEPARATOR)
881         {
882                 pos_x = xmax + sbar_fontsize_x;
883                 tmp_y = tmp_z = 0;
884                 for(i = sbar_num_fields-1; i > 0; --i)
885                 {
886                         if(sbar_field[i] == SP_SEPARATOR)
887                                 break;
888
889                         pos_x -= sbar_fontsize_x*sbar_size[i] + sbar_fontsize_x;
890                         /**
891                          * FTEQCC BUG!
892                          * Using the following line will mess it all up:
893                          **
894                          * tmp_x = sbar_size[i] - strlen(sbar_title[i])*8;
895                          */
896                         tmp_x = sbar_fontsize_x*sbar_size[i];
897                         tmp_x -= stringwidth(sbar_title[i], FALSE)*sbar_fontsize_x;
898                         drawstring(pos + tmp, sbar_title[i], sbar_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
899                 }
900         }
901                 
902         pos_x = xmin;
903         pos_y += 1.5 * sbar_fontsize_y;
904
905         sbar_save = sbar;
906         sbar = '0 0 0';
907         
908         if(teamplay)
909         {
910                 //for(tm = sortedTeams.sort_next; tm; tm = tm.sort_next)
911                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
912                 {
913                         if(!tm.team_size || tm.team == COLOR_SPECTATOR)
914                                 continue;
915
916                         rgb = GetTeamRGB(tm.team);
917
918                         pos_x = xmin;
919
920                         Sbar_DrawXNum(
921                                 pos - '6.5 0 0' * sbar_fontsize_y,
922                                 tm.(teamscores[ts_primary]),
923                                 4, sbar_fontsize_y * 1.5, rgb, 1, DRAWFLAG_NORMAL);
924
925                         if(ts_primary != ts_secondary)
926                         Sbar_DrawXNum(
927                                 pos - '4.5 0 0' * sbar_fontsize_y + '0 1.5 0' * sbar_fontsize_y,
928                                 tm.(teamscores[ts_secondary]),
929                                 4, sbar_fontsize_y * 1, rgb, 1, DRAWFLAG_NORMAL);
930                         
931                         specs = tm.team_size;
932
933                         if(specs < 2)
934                                 specs = 2;
935                         
936                         tmp_x = sbwidth;
937                         tmp_y = 1.25 * sbar_fontsize_y * specs;
938                         drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, 0.2, DRAWFLAG_NORMAL);
939                         
940                         for(pl = players.sort_next; pl; pl = pl.sort_next)
941                         {
942                                 if(pl.team != tm.team)
943                                         continue;
944                                 Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
945                                 pos_y += 1.25 * sbar_fontsize_y;
946                                 tmp_y -= 1.25 * sbar_fontsize_y;
947                         }
948                         pos_y += tmp_y + 1.5 * sbar_fontsize_y;
949                 }
950                 // rgb := tempvector :)
951                 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
952                 pos_y += 3 * sbar_fontsize_y;
953                 specs = 0;
954                 for(pl = players.sort_next; pl; pl = pl.sort_next)
955                 {
956                         if(pl.team != COLOR_SPECTATOR)
957                                 continue;
958                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
959                         pos += '0 1.25 0' * sbar_fontsize_y;
960                         ++specs;
961                 }
962                         
963                 if(specs)
964                         drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
965         } else {
966                 pos_x = xmin;
967                 for(pl = players.sort_next; pl; pl = pl.sort_next)
968                 {
969                         if(pl.team == COLOR_SPECTATOR)
970                                 continue;
971                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
972                         pos_y += 1.25 * sbar_fontsize_y;
973                         tmp_y -= 1.25 * sbar_fontsize_y;
974                 }
975
976                 // rgb := tempvector :)
977                 rgb = pos + '0 1.5 0' * sbar_fontsize_y;
978                 pos_y += 3 * sbar_fontsize_y;
979                 specs = 0;
980                 for(pl = players.sort_next; pl; pl = pl.sort_next)
981                 {
982                         if(pl.team != COLOR_SPECTATOR)
983                                 continue;
984                         Sbar_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localentnum - 1));
985                         pos += '0 1.25 0' * sbar_fontsize_y;
986                         ++specs;
987                 }
988                         
989                 if(specs)
990                         drawstring(rgb, "Spectators", sbar_fontsize, '1 1 1', 1, 0);
991         }
992
993         string str;
994         float tl, fl;
995         str = strcat("playing on ^2", shortmapname, "^7");
996         tl = getstatf(STAT_TIMELIMIT);
997         fl = getstatf(STAT_FRAGLIMIT);
998         if(gametype == GAME_LMS)
999         {
1000                 if(tl > 0)
1001                         str = strcat(str, " for up to ^1", ftos(tl), " minutes^7");
1002         }
1003         else
1004         {
1005                 if(tl > 0)
1006                         str = strcat(str, " for ^1", ftos(tl), " minutes^7");
1007                 if(fl > 0)
1008                 {
1009                         if(tl > 0)
1010                                 str = strcat(str, " or");
1011                         if(teamplay)
1012                         {
1013                                 str = strcat(str, " until ^3", ScoreString(teamscores_flags[ts_primary], fl));
1014                                 if(teamscores_label[ts_primary] == "score")
1015                                         str = strcat(str, " points^7");
1016                                 else if(teamscores_label[ts_primary] == "fastest")
1017                                         str = strcat(str, " is beaten^7");
1018                                 else
1019                                         str = strcat(str, " ", teamscores_label[ts_primary]);
1020                         }
1021                         else
1022                         {
1023                                 str = strcat(str, " until ^3", ScoreString(scores_flags[ps_primary], fl));
1024                                 if(scores_label[ps_primary] == "score")
1025                                         str = strcat(str, " points^7");
1026                                 else if(scores_label[ps_primary] == "fastest")
1027                                         str = strcat(str, " is beaten^7");
1028                                 else
1029                                         str = strcat(str, " ", scores_label[ps_primary]);
1030                         }
1031                 }
1032         }
1033         
1034
1035         pos_y += 1.2 * sbar_fontsize_y;
1036         drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - sbar_fontsize_x * stringwidth(str, TRUE)), str, sbar_fontsize, 0.8, 0);
1037         
1038         sbar = sbar_save;
1039         scoreboard_bottom = pos_y + 2 * sbar_fontsize_y;
1040 }
1041
1042 string MakeRaceString(float cp, float mytime, float histime, float lapdelta, string hisname)
1043 {
1044         string col;
1045         string timestr;
1046         string cpname;
1047         string lapstr;
1048         lapstr = "";
1049
1050         if(histime == 0) // goal hit
1051         {
1052                 if(mytime > 0)
1053                 {
1054                         timestr = strcat("+", ftos_decimals(+mytime, 1));
1055                         col = "^1";
1056                 }
1057                 else if(mytime == 0)
1058                 {
1059                         timestr = "+0.0";
1060                         col = "^3";
1061                 }
1062                 else
1063                 {
1064                         timestr = strcat("-", ftos_decimals(-mytime, 1));
1065                         col = "^2";
1066                 }
1067
1068                 if(lapdelta > 0)
1069                 {
1070                         lapstr = strcat(" (-", ftos(lapdelta), "L)");
1071                         col = "^2";
1072                 }
1073                 else if(lapdelta < 0)
1074                 {
1075                         lapstr = strcat(" (+", ftos(-lapdelta), "L)");
1076                         col = "^1";
1077                 }
1078         }
1079         else if(histime > 0) // anticipation
1080         {
1081                 if(mytime >= histime)
1082                         timestr = strcat("+", ftos_decimals(mytime - histime, 1));
1083                 else
1084                         timestr = mmsss(histime * 10);
1085                 col = "^3";
1086         }
1087         else
1088                 col = "^7";
1089
1090         if(cp)
1091                 cpname = strcat("Intermediate ", ftos(cp));
1092         else
1093                 cpname = "Finish line";
1094         
1095         if(histime < 0)
1096                 return strcat(col, cpname);
1097         else if(hisname == "")
1098                 return strcat(col, cpname, " (", timestr, ")");
1099         else
1100                 return strcat(col, cpname, " (", timestr, " ", strcat(hisname, col, lapstr), ")");
1101 }
1102
1103 void dummyfunction(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8)
1104 {
1105 }
1106
1107 void Sbar_Score(float margin)
1108 {
1109         float timelimit, minutes, seconds, timeleft, minutesLeft, secondsLeft, distribution, myplace, score;
1110         vector sbar_save, place, timer_color;
1111         entity tm, pl, me;
1112         sbar_save = sbar;
1113         
1114         myteam = GetPlayerColor(player_localentnum - 1);
1115
1116         sbar_y = vid_conheight - (32+12);
1117         sbar_x -= margin;
1118         
1119         place = '-48 -12 0';
1120         if(teamplay)
1121         {
1122                 // Layout:
1123                 //
1124                 //   team1 team3 team4
1125                 //
1126                 //         TEAM2
1127                 //for(i = 0; i < 4; ++i)
1128                 for(tm = teams.sort_next; tm; tm = tm.sort_next)
1129                 {
1130                         if(tm.team == COLOR_SPECTATOR || !tm.team_size) // no players? don't display
1131                                 continue;
1132                         // -32*4 = -128
1133                         score = tm.(teamscores[ts_primary]);
1134                         if(tm.team == myteam)
1135                                 Sbar_DrawXNum('-128 0 0', score, 4, 32, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
1136                         else
1137                         {
1138                                 Sbar_DrawXNum(place, score, 4, 12, GetTeamRGB(tm.team), 1, DRAWFLAG_NORMAL);
1139                                 place_x -= 4*12;
1140                         }
1141                 }
1142         } else {
1143                 // me vector := [team/connected frags id]
1144                 myplace = 0;
1145                 for(me = players.sort_next; me; me = me.sort_next)
1146                 {
1147                         if(me.team != COLOR_SPECTATOR)
1148                                 ++myplace;
1149                         if(me.sv_entnum == player_localentnum - 1)
1150                                 break;
1151                 }
1152                 pl = players;
1153                 if(pl == me)
1154                         pl = pl.sort_next;
1155                 
1156                 if(pl) {
1157                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
1158                 } else
1159                         distribution = 0;
1160                 
1161                 if(myplace == 1)
1162                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 1', 1, DRAWFLAG_NORMAL);
1163                 else if(myplace == 2)
1164                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 1 0', 1, DRAWFLAG_NORMAL);
1165                 else
1166                         Sbar_DrawXNum('-36 -12 0', myplace, 3, 12, '1 0 0', 1, DRAWFLAG_NORMAL);
1167
1168                 score = me.(scores[ps_primary]);
1169                 if(distribution >= 0)
1170                 {
1171                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 1', 1, DRAWFLAG_NORMAL);
1172                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 1', 1, DRAWFLAG_NORMAL);
1173                 } else if(distribution >= -5)
1174                 {
1175                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 1 0', 1, DRAWFLAG_NORMAL);
1176                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 1 0', 1, DRAWFLAG_NORMAL);
1177                 } else {
1178                         Sbar_DrawXNum('-84 -12 0', distribution, 4, 12, ' 1 0 0', 1, DRAWFLAG_NORMAL);
1179                         Sbar_DrawXNum('-128 0 0', score, 4, 32, '1 0 0', 1, DRAWFLAG_NORMAL);
1180                 }
1181         }
1182         
1183         //draw the remaining or elapsed time
1184         timelimit = getstatf(STAT_TIMELIMIT);
1185         if(timelimit > 0)
1186         {
1187                 timeleft = max(0, timelimit * 60 + getstatf(STAT_GAMESTARTTIME) - time);
1188                 timeleft = ceil(timeleft);
1189                 minutesLeft = floor(timeleft / 60);
1190                 secondsLeft = timeleft - minutesLeft*60;
1191                 
1192                 if(minutesLeft >= 5) {
1193                         timer_color = '1 1 1'; //white
1194                 } else if(minutesLeft >= 1) {
1195                         timer_color = '1 1 0'; //yellow
1196                 } else {
1197                         timer_color = '1 0 0'; //red
1198                 }
1199                 
1200                 if (warmup_stage) {
1201                         timer_color = '1 1 1'; //don't use red or yellow for timer during warmup
1202                 }
1203                 
1204                 if (cvar("sbar_increment_maptime")) {
1205                         if (time < getstatf(STAT_GAMESTARTTIME)) {
1206                                 //while restart is still active, show negative counter
1207                                 minutes = 0;
1208                                 seconds = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1209                         } else {
1210                                 float elapsedTime;
1211                                 elapsedTime = floor(time - getstatf(STAT_GAMESTARTTIME)); //127
1212                                 minutes = floor(elapsedTime / 60);
1213                                 seconds = elapsedTime - minutes*60;
1214                         }
1215                 } else {
1216                         minutes = minutesLeft;
1217                         seconds = secondsLeft;
1218                 }
1219                 
1220                 if(minutesLeft >= 1 || (cvar("sbar_increment_maptime") && minutes >= 1) ) {
1221                         Sbar_DrawXNum('-72 32 0', minutes, 3, 12, timer_color, 1, DRAWFLAG_NORMAL);
1222                         drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', timer_color, sbar_alpha_fg, 0);
1223                 }
1224                 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, timer_color, 1, DRAWFLAG_NORMAL);
1225         } else {
1226                 timer_color = '1 1 1'; //white
1227                 minutes = floor(time / 60);
1228                 seconds = floor(time - minutes*60);
1229                 Sbar_DrawXNum('-72 32 0', minutes, 3, 12, timer_color, 1, DRAWFLAG_NORMAL);
1230                 drawpic(sbar + '-36 32 0', "gfx/num_colon", '12 12 0', timer_color, sbar_alpha_fg, 0);
1231                 Sbar_DrawXNum('-24 32 0', seconds, -2, 12, timer_color, 1, DRAWFLAG_NORMAL);
1232         }
1233
1234         if(gametype == GAME_RACE)
1235         {
1236                 drawfont = sbar_bigfont;
1237                 float a;
1238                 vector m;
1239                 string s, forcetime;
1240
1241                 m = '0.5 0 0' * vid_conwidth + '0 0.25 0' * vid_conheight;
1242
1243                 if(race_checkpointtime)
1244                 {
1245
1246                         a = bound(0, 2 - (time - race_checkpointtime), 1);
1247                         s = "";
1248                         forcetime = "";
1249                         if(a > 0) // just hit a checkpoint?
1250                         {
1251                                 if(race_time && race_previousbesttime)
1252                                         s = MakeRaceString(race_checkpoint, race_time / 10 - race_previousbesttime / 10, 0, 0, race_previousbestname);
1253                                 else
1254                                         s = MakeRaceString(race_checkpoint, 0, -1, 0, race_previousbestname);
1255                                 if(race_time)
1256                                         forcetime = mmsss(race_time);
1257                         }
1258                         else
1259                         {
1260                                 if(race_laptime && race_nextbesttime)
1261                                 {
1262                                         a = bound(0, 2 - ((race_laptime + race_nextbesttime/10) - time), 1);
1263                                         if(a > 0) // next one?
1264                                         {
1265                                                 s = MakeRaceString(race_nextcheckpoint, time - race_laptime, race_nextbesttime / 10, 0, race_nextbestname);
1266                                         }
1267                                 }
1268                         }
1269
1270                         if(s != "" && a > 0)
1271                         {
1272                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1273                                 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1274                         }
1275
1276                         if(forcetime != "")
1277                         {
1278                                 float sz;
1279                                 a = bound(0, 1 - 2 * (time - race_checkpointtime), 1);
1280                                 sz = 1.2 / (a + 0.2);
1281                                 drawstring(m - '0 0 0' - '0 16 0' * (sz - 1) - '16 0 0' * sz * stringwidth(forcetime, FALSE), forcetime, '32 32 0' * sz, '1 1 1', sbar_alpha_fg * a, 0);
1282                                 a = 1 - a;
1283                         }
1284                         else
1285                                 a = 1;
1286
1287                         if(race_laptime)
1288                         {
1289                                 s = mmsss(10*(time - race_laptime));
1290                                 drawstring(m - '0 0 0' - '16 0 0' * stringwidth(s, FALSE), s, '32 32 0', '1 1 1', sbar_alpha_fg * a, 0);
1291                         }
1292                 }
1293                 else
1294                 {
1295                         if(race_mycheckpointtime)
1296                         {
1297                                 a = bound(0, 2 - (time - race_mycheckpointtime), 1);
1298                                 s = MakeRaceString(race_mycheckpoint, race_mycheckpointdelta / 10, -!race_mycheckpointenemy, race_mycheckpointlapsdelta, race_mycheckpointenemy);
1299                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1300                                 drawcolorcodedstring(m - '0 16 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1301                         }
1302                         if(race_othercheckpointtime && race_othercheckpointenemy != "")
1303                         {
1304                                 a = bound(0, 2 - (time - race_othercheckpointtime), 1);
1305                                 s = MakeRaceString(race_othercheckpoint, -race_othercheckpointdelta / 10, -!race_othercheckpointenemy, race_othercheckpointlapsdelta, race_othercheckpointenemy);
1306                                 dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1307                                 drawcolorcodedstring(m - '0 0 0' - '8 0 0' * stringwidth(s, TRUE), s, '16 16 0', sbar_alpha_fg * a, 0);
1308                         }
1309                 }
1310
1311                 drawfont = sbar_font;
1312         }
1313
1314         sbar = sbar_save;
1315 }
1316
1317 void Sbar_MiniscoreItem(vector pos, entity pl, float is_self)
1318 {
1319         float x, score;
1320         pos_x += 72;
1321         
1322         if(teamplay)
1323                 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(pl.team)*0.5, 1, DRAWFLAG_NORMAL);
1324         else
1325                 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1326         x = pos_x;
1327         pos_x += 5*8;
1328         score = pl.(scores[ps_primary]);
1329         pos_x -= stringwidth(ftos(score), FALSE)*8;
1330         drawstring(pos, ftos(score), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1331         pos_x = x;
1332         if(is_self)
1333         {
1334                 pos_x += 48;
1335                 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1336                 pos_x += 8;
1337         } else
1338                 pos_x += 56;
1339         drawcolorcodedstring(pos, GetPlayerName(pl.sv_entnum), '8 8 0', 1, 0);
1340 }
1341
1342 void Sbar_MiniscoreTeamItem(vector pos, float color, float frags, float is_self)
1343 {
1344         float x;
1345         pos_x += 72;
1346         
1347         if(teamplay)
1348                 drawfill(pos + '0 1 0', '40 6 0', GetTeamRGB(color)*0.5, 1, DRAWFLAG_NORMAL);
1349         else
1350                 drawfill(pos + '0 1 0', '40 6 0', '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
1351         x = pos_x;
1352         pos_x += 5*8;
1353         pos_x -= stringwidth(ftos(frags), FALSE)*8;
1354         drawstring(pos, ftos(frags), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1355         pos_x = x;
1356         if(is_self)
1357         {
1358                 pos_x += 48;
1359                 drawstring(pos, "\x0D", '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1360                 pos_x += 8;
1361         } else
1362                 pos_x += 56;
1363         drawstring(pos, GetTeamName(color), '8 8 0', '1 1 1', 1, DRAWFLAG_NORMAL);
1364 }
1365
1366 void Sbar_MiniDeathmatchOverlay(vector pos)
1367 {
1368         float numlines, up, down, score;
1369         entity me, tm, pl;
1370         float miniscoreboard_size;
1371         miniscoreboard_size = cvar("sbar_miniscoreboard_size");
1372         
1373         if(miniscoreboard_size == 0)
1374                 return;
1375         pos_y = vid_conheight - 8;
1376         
1377         if(miniscoreboard_size < 0)
1378                 numlines = (vid_conheight - sbar_y + 7) / 8;
1379         else
1380                 numlines = miniscoreboard_size;
1381
1382         // give up if there isn't enough room
1383         if(pos_x >= vid_conwidth || pos_y >= vid_conheight || numlines < 1)
1384                 return;
1385
1386         // me vector := [team/connected frags id]
1387         for(me = players.sort_next; me; me = me.sort_next)
1388         {
1389                 if(me.sv_entnum == player_localentnum - 1)
1390                         break;
1391         }
1392
1393         if(teamplay)
1394                 numlines -= numteams;
1395
1396         // figure out how many players above and below we can show
1397         up = floor(numlines/2);
1398         down = up;
1399         if((up + down) > numlines)
1400                 down = numlines - up;
1401
1402         // render bottom-up
1403         for(pl = me.sort_next; pl && down > 0; pl = pl.sort_next)
1404         {
1405                 if(pl.team == COLOR_SPECTATOR)
1406                         continue;
1407                 Sbar_MiniscoreItem(pos, pl, false);
1408                 pos_y -= 9;
1409                 --down;
1410         }
1411         Sbar_MiniscoreItem(pos, me, true);
1412         pos_y -= 9;
1413         up += down; // if there weren't enough lines below... add them
1414         for(pl = me.sort_prev; pl && up > 0; pl = pl.sort_prev)
1415         {
1416                 if(pl.team == COLOR_SPECTATOR)
1417                         continue;
1418                 Sbar_MiniscoreItem(pos, pl, false);
1419                 pos_y -= 9;
1420                 --up;
1421         }
1422
1423         if(teamplay)
1424         {
1425                 for(tm = teams.sort_next; tm.sort_next; tm = tm.sort_next);
1426                 for(; tm; tm = tm.sort_prev)
1427                 {
1428                         if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1429                                 continue;
1430                         score = tm.(teamscores[ts_primary]);
1431                         Sbar_MiniscoreTeamItem(pos, tm.team, score, (tm.team == me.team));
1432                         pos_y -= 9;
1433                 }
1434         }
1435 }
1436
1437 float Sbar_WouldDrawScoreboard ()
1438 {
1439         if (sb_showscores)
1440                 return 1;
1441         else if (intermission == 1)
1442                 return 1;
1443         else if (intermission == 2)
1444                 return 1;
1445         else if (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard"))
1446                 return 1;
1447         else if(sb_showscores_force)
1448                 return 1;
1449         return 0;
1450 }
1451
1452 void CSQC_Strength_Timer() {
1453         float stat_items;
1454         stat_items = getstati(STAT_ITEMS);
1455         if not(stat_items & IT_STRENGTH)
1456                 if not(stat_items & IT_INVINCIBLE)
1457                         return;
1458         
1459         if (getstati(STAT_HEALTH) <= 0)
1460                 return;
1461         
1462         vector pos, picsize, number_position;
1463         float strength_time, invincibility_time, countdown_fontsize;
1464
1465         picsize = '40 40 0';
1466         countdown_fontsize = 22;
1467         
1468         //element will be positioned on the right side of the screen:
1469         pos_x = vid_conwidth - picsize_x - 10; //margin 10 from right border
1470         number_position_x = pos_x - 5/*margin to the left from image*/ - countdown_fontsize*2/*width of text*/;
1471         
1472         pos_y = 180;
1473         number_position_y = pos_y;
1474         
1475         //now calculate the values Sbar_DrawXNum() will be called with:
1476         number_position_x = number_position_x - sbar_x; //relative to sbar coordinates
1477         number_position_y = number_position_y - sbar_y; //relative to sbar coordinates
1478         number_position_y += 10; //center number vertically to the icon
1479         
1480         pos_z = number_position_z = 0;
1481         
1482         //strength
1483         if (stat_items & IT_STRENGTH) {
1484                 drawpic(pos, "gfx/sb_str", picsize, '0 0.086 0.953'/*strength color*/, 1, DRAWFLAG_NORMAL);
1485                 strength_time = getstatf(STAT_STRENGTH_FINISHED) - time;
1486                 if (strength_time > 0) { //show countdown once we received the valid stats-value
1487                         Sbar_DrawXNum(number_position, ceil(strength_time), 2, countdown_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1488                 }
1489                 
1490                 //add some margin to the invincibility icon
1491                 pos_y             += picsize_y + 10;
1492                 number_position_y += picsize_y + 10;
1493         }
1494         
1495         //invincibility
1496         if (stat_items & IT_INVINCIBLE) {
1497                 drawpic(pos, "gfx/sb_invinc", picsize, '0.976 0 0.165'/*invincibility color*/, 1, DRAWFLAG_NORMAL);
1498                 invincibility_time = getstatf(STAT_INVINCIBLE_FINISHED) - time;
1499                 if (invincibility_time > 0) { //show countdown once we received the valid stats-value
1500                         Sbar_DrawXNum(number_position, ceil(invincibility_time), 2, countdown_fontsize, '1 1 1', 1, DRAWFLAG_NORMAL);
1501                 }
1502         }
1503 }
1504
1505 #define CENTERPRINT_MAX_LINES 30
1506 string centerprint_messages[CENTERPRINT_MAX_LINES]; 
1507 float centerprint_width[CENTERPRINT_MAX_LINES]; 
1508 vector centerprint_start;
1509 float centerprint_expire;
1510 float centerprint_num;
1511 float centerprint_offset_hint;
1512 vector centerprint_fontsize;
1513
1514 void centerprint(string strMessage)
1515 {
1516         float i, j, n, hcount;
1517         string s;
1518
1519         centerprint_fontsize = Sbar_GetFontsize("scr_centersize");
1520         
1521         // delete old centerprint messages
1522         for (i=0; i<centerprint_num; ++i)
1523         {
1524                 if(centerprint_messages[i])
1525                 {
1526                         strunzone(centerprint_messages[i]);
1527                         centerprint_messages[i] = string_null;
1528                         centerprint_width[i] = 0;
1529                 }
1530         }
1531
1532         if(strMessage == "")
1533                 return;
1534
1535         // strip trailing newlines
1536         j = strlen(strMessage) - 1;
1537         while(substring(strMessage, j, 1) == "\n" && j >= 0)
1538                 j = j - 1;
1539         strMessage = substring(strMessage, 0, j + 1);
1540         
1541         if(strMessage == "")
1542                 return;
1543
1544         // strip leading newlines and remember them, they are a hint that the message should be lower on the screen
1545         j = 0;
1546         while(substring(strMessage, j, 1) == "\n" && j < strlen(strMessage))
1547                 j = j + 1;
1548         strMessage = substring(strMessage, j, strlen(strMessage) - j);
1549         centerprint_offset_hint = j;
1550         
1551         // TODO if we're parsing centerprints now anyway, why not word wrap them?
1552         n = tokenizebyseparator(strMessage, "\n");
1553         i = hcount = 0;
1554         for(j = 0; j < n; ++j)
1555         {
1556                 getWrappedLine_remaining = argv(j);
1557                 while(getWrappedLine_remaining)
1558                 {
1559                         s = getWrappedLine(vid_conwidth * 0.75 / centerprint_fontsize_x, stringwidth_colors);
1560                         centerprint_messages[i] = strzone(s);
1561                         centerprint_width[i] = stringwidth(s, TRUE);
1562                         ++i;
1563
1564                         // half height for empty lines looks better
1565                         if(s == "")
1566                                 hcount += 0.5;
1567                         else
1568                                 hcount += 1;
1569
1570                         if(i >= CENTERPRINT_MAX_LINES)
1571                                 break;
1572                 }
1573         }
1574
1575         float h, havail;
1576         h = centerprint_fontsize_y*hcount;
1577
1578         havail = vid_conheight;
1579         if(cvar("con_chatpos") < 0)
1580                 havail -= (-cvar("con_chatpos") + cvar("con_chat")) * cvar("con_chatsize"); // avoid overlapping chat
1581
1582         centerprint_start_x = 0;
1583
1584 #if 0
1585         float forbiddenmin, forbiddenmax, allowedmin, allowedmax, preferred;
1586
1587         // here, the centerprint would cover the crosshair. REALLY BAD.
1588         forbiddenmin = vid_conheight * 0.5 - h - 16;
1589         forbiddenmax = vid_conheight * 0.5 + 16;
1590
1591         allowedmin = scoreboard_bottom;
1592         allowedmax = havail - h;
1593         preferred = (havail - h)/2;
1594
1595
1596         // possible orderings (total: 4! / 4 = 6)
1597         //  allowedmin allowedmax forbiddenmin forbiddenmax
1598         //  forbiddenmin forbiddenmax allowedmin allowedmax
1599         if(allowedmax < forbiddenmin || allowedmin > forbiddenmax)
1600         {
1601                 // forbidden doesn't matter in this case
1602                 centerprint_start_y = bound(allowedmin, preferred, allowedmax);
1603         }
1604         //  allowedmin forbiddenmin allowedmax forbiddenmax
1605         else if(allowedmin < forbiddenmin && allowedmax < forbiddenmax)
1606         {
1607                 centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1608         }
1609         //  allowedmin forbiddenmin forbiddenmax allowedmax
1610         else if(allowedmin < forbiddenmin)
1611         {
1612                 // make sure the forbidden zone is not covered
1613                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1614                         centerprint_start_y = bound(allowedmin, preferred, forbiddenmin);
1615                 else
1616                         centerprint_start_y = bound(forbiddenmax, preferred, allowedmin);
1617         }
1618         //  forbiddenmin allowedmin allowedmax forbiddenmax
1619         else if(allowedmax < forbiddenmax)
1620         {
1621                 // it's better to leave the allowed zone (overlap with scoreboard) than
1622                 // to cover the forbidden zone (crosshair)
1623                 if(preferred > (forbiddenmin + forbiddenmax) * 0.5)
1624                         centerprint_start_y = forbiddenmax;
1625                 else
1626                         centerprint_start_y = forbiddenmin;
1627         }
1628         //  forbiddenmin allowedmin forbiddenmax allowedmax
1629         else
1630         {
1631                 centerprint_start_y = bound(forbiddenmax, preferred, allowedmax);
1632         }
1633 #else
1634         centerprint_start_y =
1635                 min(
1636                         max(
1637                                 max(scoreboard_bottom, vid_conheight * 0.5 + 16),
1638                                 (havail - h)/2
1639                         ),
1640                         havail - h
1641                 );
1642 #endif
1643
1644         centerprint_num = i;
1645         centerprint_expire = time + cvar("scr_centertime");
1646 }
1647
1648 void Sbar_DrawCenterPrint (void)
1649 {
1650         float i;
1651         vector pos;
1652         string ts;
1653
1654         if(time > centerprint_expire)
1655                 return;
1656         
1657         pos = centerprint_start;
1658         for (i=0; i<centerprint_num; i = i + 1)
1659         {
1660                 pos_x = (vid_conwidth - centerprint_fontsize_x * centerprint_width[i]) * 0.5;
1661                 ts = centerprint_messages[i];
1662                 if (ts != "")
1663                 {
1664                         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1665                         drawcolorcodedstring(pos, ts, centerprint_fontsize, 1, DRAWFLAG_NORMAL);
1666                         pos_y = pos_y + centerprint_fontsize_y;
1667                 }
1668                 else
1669                         // half height for empty lines looks better
1670                         pos_y = pos_y + centerprint_fontsize_y * 0.5;
1671         }
1672 }
1673
1674 vector Sbar_DrawNoteLine(vector offset, string s)
1675 {
1676         dummyfunction(0, 0, 0, 0, 0, 0, 0, 0); // work around DP bug (set OFS_PARAM5 to 0)
1677         drawcolorcodedstring(
1678                 offset - sbar_fontsize_x * '1 0 0' * stringwidth(s, TRUE),
1679                 s,
1680                 sbar_fontsize,
1681                 sbar_alpha_fg,
1682                 0
1683         );
1684         return offset + sbar_fontsize_y * '0 1 0';
1685 }
1686
1687 void Sbar_Draw (void)
1688 {
1689         float i;
1690         float x, fade;
1691         float stat_items, stat_weapons;
1692         vector o; o = '1 0 0' * vid_conwidth;
1693         string s;
1694
1695         sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");
1696         
1697         if(spectatee_status)
1698         {
1699                 if(spectatee_status == -1)
1700                         s = "^1Observing";
1701                 else
1702                         s = strcat("^1Spectating ^7", GetPlayerName(spectatee_status - 1));
1703                 o = Sbar_DrawNoteLine(o, s);
1704
1705                 if(spectatee_status == -1)
1706                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 to spectate");
1707                 else
1708                         s = strcat("^1Press ^3", getcommandkey("primary fire", "+attack"), "^1 for another player");
1709                 o = Sbar_DrawNoteLine(o, s);
1710
1711                 if(spectatee_status == -1)
1712                         s = strcat("^1Use ^3", getcommandkey("next weapon", "weapnext"), "^1 or ^3", getcommandkey("previous weapon", "weapprev"), "^1 to change the speed");
1713                 else
1714                         s = strcat("^1Press ^3", getcommandkey("secondary fire", "+attack2"), "^1 to observe");
1715                 o = Sbar_DrawNoteLine(o, s);
1716
1717                 if(gametype == GAME_ARENA)
1718                         s = "^1Wait for your turn to join";
1719                 else if(gametype == GAME_LMS)
1720                 {
1721                         entity sk;
1722                         sk = playerslots[player_localentnum - 1];
1723                         if(sk.(scores[ps_primary]) >= 666)
1724                                 s = "^1Match has already begun";
1725                         else if(sk.(scores[ps_primary]) > 0)
1726                                 s = "^1You have no more lives left";
1727                         else
1728                                 s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1729                 }
1730                 else
1731                         s = strcat("^1Press ^3", getcommandkey("jump", "+jump"), "^1 to join");
1732                 o = Sbar_DrawNoteLine(o, s);
1733                 
1734                 //show restart countdown:
1735                 if (time < getstatf(STAT_GAMESTARTTIME)) {
1736                         float countdown;
1737                         //we need to ceil, otherwise the countdown would be off by .5 when using round()
1738                         countdown = ceil(getstatf(STAT_GAMESTARTTIME) - time);
1739                         s = strcat("^1Game starts in ^3", ftos(countdown), "^1 seconds");
1740                         o = Sbar_DrawNoteLine(o, s);
1741                 }
1742         }
1743         if(warmup_stage)
1744         {
1745                 s = "^2Currently in ^1warmup^2 stage!";
1746                 o = Sbar_DrawNoteLine(o, s);
1747         }
1748
1749         // move more important stuff more to the middle so its more visible
1750         o_y = vid_conheight * 0.66;
1751
1752         string blinkcolor;
1753         if(mod(time, 1) >= 0.5)
1754                 blinkcolor = "^1";
1755         else
1756                 blinkcolor = "^3";
1757
1758         if(ready_waiting)
1759         {
1760                 if(ready_waiting_for_me)
1761                 {
1762                         if(warmup_stage) 
1763                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " to end warmup");
1764                         else
1765                                 s = strcat(blinkcolor, "Press ^3", getcommandkey("ready", "ready"), blinkcolor, " once you are ready");
1766                 }
1767                 else
1768                 {
1769                         if(warmup_stage) 
1770                                 s = strcat("^2Waiting for others to ready up to end warmup...");
1771                         else
1772                                 s = strcat("^2Waiting for others to ready up...");
1773                 }
1774                 o = Sbar_DrawNoteLine(o, s);
1775         }
1776         else if(warmup_stage) 
1777         {
1778                 s = strcat("^2Press ^3", getcommandkey("ready", "ready"), "^2 to end warmup");
1779                 o = Sbar_DrawNoteLine(o, s);
1780         }
1781         if(vote_waiting)
1782         {
1783                 s = strcat("^2A vote has been called for ^1", vote_called_vote);
1784                 o = Sbar_DrawNoteLine(o, s);
1785
1786                 if(vote_waiting_for_me)
1787                 {
1788                         s = strcat(blinkcolor, "Press ^3", getcommandkey("vote yes", "vyes"), blinkcolor, " to accept");
1789                         o = Sbar_DrawNoteLine(o, s);
1790
1791                         s = strcat(blinkcolor, "Press ^3", getcommandkey("vote no", "vno"), blinkcolor, " to reject");
1792                         o = Sbar_DrawNoteLine(o, s);
1793
1794                         s = strcat(blinkcolor, "Press ^3", getcommandkey("vote abstain", "vabstain"), blinkcolor, " to abstain");
1795                         o = Sbar_DrawNoteLine(o, s);
1796                 }
1797                 else
1798                 {
1799                         s = strcat("^2Waiting for others to vote...");
1800                         o = Sbar_DrawNoteLine(o, s);
1801                 }
1802         }
1803         if(teamplay)
1804         {
1805                 entity tm;
1806                 float ts_min, ts_max;
1807                 tm = teams.sort_next;
1808                 if (tm)
1809                 {
1810                         for(; tm.sort_next; tm = tm.sort_next)
1811                         {
1812                                 if(!tm.team_size || tm.team == COLOR_SPECTATOR)
1813                                         continue;
1814                                 if(!ts_min) ts_min = tm.team_size;
1815                                 else ts_min = min(ts_min, tm.team_size);
1816                                 if(!ts_max) ts_max = tm.team_size;
1817                                 else ts_max = max(ts_max, tm.team_size);
1818                         }
1819                         if ((ts_max - ts_min) > 1)
1820                         {
1821                                 s = strcat(blinkcolor, "Teamnumbers are unbalanced!");
1822                                 tm = GetTeam(myteam, false);
1823                                 if (tm)
1824                                 if (tm.team != COLOR_SPECTATOR)
1825                                 if (tm.team_size == ts_max)
1826                                         s = strcat(s, " Press ^3", getcommandkey("team menu", "menu_showteamselect"), blinkcolor, " to adjust");
1827
1828                                 o = Sbar_DrawNoteLine(o, s);
1829                         }
1830                 }
1831         }
1832
1833         //Sbar_SortFrags();
1834         Sbar_UpdatePlayerTeams();
1835
1836         sb_lines = 24;
1837
1838         if (sb_showscores)
1839         {
1840                 Sbar_DrawScoreboard();
1841                 Sbar_DrawCenterPrint();
1842         }
1843         else if (intermission == 1)
1844         {
1845                 Sbar_DrawScoreboard();
1846                 Sbar_DrawCenterPrint();
1847                 return;
1848         }
1849         else if (intermission == 2)
1850         {
1851                 Sbar_FinaleOverlay();
1852                 Sbar_DrawCenterPrint();
1853         }
1854         else
1855         {
1856                 if (sb_showscores || sb_showscores_force || (getstati(STAT_HEALTH) <= 0 && cvar("cl_deathscoreboard")))
1857                 {
1858                         sbar_x = (vid_conwidth - 640.0)*0.5;
1859                         sbar_y = vid_conheight - 47;
1860                         //Sbar_DrawAlphaPic (sbar_x, sbar_y, sb_scorebar, sbar_alpha_bg.value);
1861                         //drawpic('0 0 0', "gfx/scorebar", '0 0 0', '1 1 1', cvar("sbar_alpha_bg"), 0);
1862                         Sbar_DrawScoreboard ();
1863                 }
1864                 else
1865                 {
1866                         if (sb_lines && sbar_hudselector == 1)
1867                         {
1868                                 stat_items = getstati(STAT_ITEMS);
1869                                 stat_weapons = getstati(STAT_WEAPONS);
1870
1871                                 sbar_x = (vid_conwidth - 320.0)*0.5;
1872                                 sbar_y = vid_conheight - 24.0 - 16.0;
1873                                 sbar_z = 0;
1874                         
1875                                 fade = 3.2 - 2 * (time - weapontime);
1876                                 fade = bound(0.7, fade, 1);
1877
1878                                 x = 1.0;
1879                                 Sbar_DrawWeapon_Clear();
1880                                 for(i = 1; i <= 24; ++i)
1881                                 {
1882                                         if(weaponimpulse[i-1] >= 0)
1883                                         if(stat_weapons & x)
1884                                         {
1885                                                 Sbar_DrawWeapon(i-1, fade, (i == activeweapon));
1886                                         }
1887                                         x *= 2;
1888                                 }
1889
1890                                 // armor
1891                                 x = getstati(STAT_ARMOR);
1892                                 if (x > 0)
1893                                 {
1894                                         // "gfx/sb_armor"
1895                                         //Sbar_DrawStretchPic (72, 0, sb_armor[0], sbar_alpha_fg.value, 24, 24);
1896                                         drawpic(sbar + '72 0 0', "gfx/sb_armor", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1897                                         if(x > 200)
1898                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0 1 0', 1, 0);
1899                                         else if(x > 100)
1900                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1901                                         else if(x > 50)
1902                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1903                                         else if(x > 25)
1904                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1905                                         else
1906                                                 Sbar_DrawXNum('0 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1907                                 }
1908
1909                                 // health
1910                                 x = getstati(STAT_HEALTH);
1911                                 if (x != 0)
1912                                 {
1913                                         // "gfx/sb_health"
1914                                         //Sbar_DrawStretchPic (184, 0, sb_health, sbar_alpha_fg.value, 24, 24);
1915                                         drawpic(sbar + '184 0 0', "gfx/sb_health", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1916                                         if(x > 200)
1917                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0 1 0', 1, 0);
1918                                         else if(x > 100)
1919                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.2 1 0', 1, 0);
1920                                         else if(x > 50)
1921                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1922                                         else if(x > 25)
1923                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '1 1 0.2', 1, 0);
1924                                         else
1925                                                 Sbar_DrawXNum('112 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1926                                 }
1927
1928                                 // ammo
1929                                 x = getstati(STAT_AMMO);
1930                                 if ((stat_items & IT_AMMO) || x != 0)
1931                                 {
1932                                         if (stat_items & IT_SHELLS)
1933                                                 drawpic(sbar + '296 0 0', "gfx/sb_shells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1934                                         else if (stat_items & IT_NAILS)
1935                                                 drawpic(sbar + '296 0 0', "gfx/sb_bullets", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1936                                         else if (stat_items & IT_ROCKETS)
1937                                                 drawpic(sbar + '296 0 0', "gfx/sb_rocket", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1938                                         else if (stat_items & IT_CELLS)
1939                                                 drawpic(sbar + '296 0 0', "gfx/sb_cells", '24 24 0', '1 1 1', sbar_alpha_fg, 0);
1940                                         if(x > 10)
1941                                                 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1942                                         else
1943                                                 Sbar_DrawXNum('224 0 0', x, 3, 24, '0.7 0 0', 1, 0);
1944                                 }
1945
1946                                 if (sbar_x + 320 + 160 <= vid_conwidth)
1947                                         Sbar_MiniDeathmatchOverlay(sbar + '320 0 0');
1948                                 if (sbar_x > 0)
1949                                         Sbar_Score(16);
1950                                 // The margin can be at most 8 to support 640x480 console size:
1951                                 //   320 + 2 * (144 + 16) = 640
1952                         }
1953                         else if (sb_lines)
1954                         {
1955                         
1956                                 stat_items = getstati(STAT_ITEMS);
1957                                 stat_weapons = getstati(STAT_WEAPONS);
1958                         
1959                                 sbar_x = (vid_conwidth - 640.0)*0.5;
1960                                 sbar_y = vid_conheight - 47;
1961                                 sbar_z = 0;
1962
1963                                 fade = 3 - 2 * (time - weapontime);
1964
1965                                 x = 1.0;
1966                                 Sbar_DrawWeapon_Clear();
1967                                 for(i = 1; i <= 24; ++i)
1968                                 {
1969                                         if(weaponimpulse[i-1] >= 0)
1970                                         if(stat_weapons & x)
1971                                         {
1972                                                 Sbar_DrawWeapon(i-1, fade, (i == activeweapon));
1973                                         }
1974                                         x *= 2;
1975                                 }
1976
1977                                 if (sb_lines > 24)
1978                                         drawpic(sbar, "gfx/sbar", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1979                                 else
1980                                         drawpic(sbar, "gfx/sbar_minimal", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
1981
1982                                 // armor
1983                                 // (340-3*24) = 268
1984                                 Sbar_DrawXNum('268 12 0', getstati(STAT_ARMOR), 3, 24, '0.6 0.7 0.8', 1, 0);
1985
1986                                 // health
1987                                 // (154-3*24) = 82
1988                                 x = getstati(STAT_HEALTH);
1989                                 if(x > 100)
1990                                         Sbar_DrawXNum('82 12 0', x, 3, 24, '1 1 1', 1, 0);
1991                                 else if(x <= 25 && time - floor(time) > 0.5)
1992                                         Sbar_DrawXNum('82 12 0', x, 3, 24, '0.7 0 0', 1, 0);
1993                                 else
1994                                         Sbar_DrawXNum('81 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
1995
1996                                 x = getstati(STAT_AMMO);
1997                                 if ((stat_items & IT_AMMO) || x != 0)
1998                                 {
1999                                         // (519-3*24) = 447
2000                                         if (stat_items & IT_SHELLS)
2001                                                 drawpic(sbar + '519 0 0', "gfx/sb_shells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2002                                         else if (stat_items & IT_NAILS)
2003                                                 drawpic(sbar + '519 0 0', "gfx/sb_bullets", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2004                                         else if (stat_items & IT_ROCKETS)
2005                                                 drawpic(sbar + '519 0 0', "gfx/sb_rocket", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2006                                         else if (stat_items & IT_CELLS)
2007                                                 drawpic(sbar + '519 0 0', "gfx/sb_cells", '0 0 0', '1 1 1', sbar_alpha_fg, 0);
2008                                         if(x > 10)
2009                                                 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.6 0.7 0.8', 1, 0);
2010                                         else
2011                                                 Sbar_DrawXNum('447 12 0', x, 3, 24, '0.7 0 0', 1, 0);
2012                                 }
2013
2014                                 if (sb_lines > 24)
2015                                         drawpic(sbar, "gfx/sbar_overlay", '0 0 0', '1 1 1', 1, DRAWFLAG_MODULATE);
2016
2017                                 if (sbar_x + 600 + 160 <= vid_conwidth)
2018                                         Sbar_MiniDeathmatchOverlay (sbar + '600 0 0');
2019
2020                                 if (sbar_x > 0)
2021                                         Sbar_Score(-16);
2022                                 // Because:
2023                                 //   Mini scoreboard uses 12*4 per other team, that is, 144
2024                                 //   pixels when there are four teams...
2025                                 //   Nexuiz by default sets vid_conwidth to 800... makes
2026                                 //   sbar_x == 80...
2027                                 //   so we need to shift it by 64 pixels to the right to fit
2028                                 //   BUT: then it overlaps with the image that gets drawn
2029                                 //   for viewsize 100! Therefore, just account for 3 teams,
2030                                 //   that is, 96 pixels mini scoreboard size, needing 16 pixels
2031                                 //   to the right!
2032                         }
2033                         
2034                         //show strength/invincibility ICON and timer:
2035                         CSQC_Strength_Timer();
2036
2037                         if(gametype == GAME_KEYHUNT)
2038                         {
2039                                 CSQC_kh_hud();
2040                         } else if(gametype == GAME_CTF)
2041                         {
2042                                 CSQC_ctf_hud();
2043                         }
2044                 }
2045                 Sbar_DrawCenterPrint();
2046         }
2047 }
2048
2049 void CSQC_ctf_hud(void)
2050 {
2051         // cvar("sbar_flagstatus_right") move the flag icons right
2052         // cvar("sbar_flagstatus_pos") pixel position of the nexuiz flagstatus icons
2053         float redflag, blueflag;
2054         float stat_items;
2055         vector pos;
2056         
2057         stat_items = getstati(STAT_ITEMS);
2058         redflag = (stat_items/IT_RED_FLAG_TAKEN) & 3;
2059         blueflag = (stat_items/IT_BLUE_FLAG_TAKEN) & 3;
2060
2061         /**
2062          * FTEQCC BUG!
2063          * For some reason now not even THAT works there...
2064          * Maybe the minus' precedence screws it up? The last one there, maybe I should use brackets
2065          **
2066          * pos_x = (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - sbar_x - 64 : 10 - sbar_x;
2067          ** Should try those later:
2068          * pos_x = (cvar("sbar_flagstatus_right")) ? (vid_conwidth - 10 - sbar_x - 64) : (10 - sbar_x);
2069          * pos_x = ( (cvar("sbar_flagstatus_right")) ? vid_conwidth - 10 - 64 : 10 ) - sbar_x;
2070          */
2071         
2072         if(cvar("sbar_flagstatus_right"))
2073                 pos_x = vid_conwidth - 10 - sbar_x - 64;
2074         else
2075                 pos_x = 10 - sbar_x;
2076         
2077         pos_z = 0;
2078
2079         if(sbar_hudselector == 1)
2080                 pos_y = (vid_conheight - sbar_y) - cvar("sbar_flagstatus_pos") - 64;
2081         else
2082                 pos_y = -117;
2083
2084         pos += sbar;
2085
2086         switch(redflag)
2087         {
2088         case 1: drawpic(pos, "gfx/sb_flag_red_taken", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
2089         case 2: drawpic(pos, "gfx/sb_flag_red_lost", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
2090         case 3: drawpic(pos, "gfx/sb_flag_red_carrying", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
2091         default:
2092                 if(stat_items & IT_CTF_SHIELDED)
2093                         if(myteam == COLOR_TEAM2)
2094                                 drawpic(pos, "gfx/sb_flag_red_shielded", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
2095         }
2096
2097         pos_y -= 64;
2098         
2099         switch(blueflag)
2100         {
2101         case 1: drawpic(pos, "gfx/sb_flag_blue_taken", '128 64 0', '1 1 1', 1, 0); break;
2102         case 2: drawpic(pos, "gfx/sb_flag_blue_lost", '128 64 0', '1 1 1', 1, 0); break;
2103         case 3: drawpic(pos, "gfx/sb_flag_blue_carrying", '128 64 0', '1 1 1', 1, 0); break;
2104         default:
2105                 if(stat_items & IT_CTF_SHIELDED)
2106                         if(myteam == COLOR_TEAM1)
2107                                 drawpic(pos, "gfx/sb_flag_blue_shielded", '128 64 0', '1 1 1', 1, DRAWFLAG_NORMAL); break;
2108         }
2109 }