]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/scoreboard.qc
Replace usages of mod() with the operator %
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / scoreboard.qc
index 46dcfb4c451f09c46287aa21a5a4bde008c8426e..fd2ab2481a2fcaea5e74c12592da05ba439cc3b5 100644 (file)
@@ -287,19 +287,15 @@ void Cmd_HUD_Help()
                "other gamemodes except DM.\n"));
 }
 
-string HUD_DefaultColumnLayout()
-{
-       return strcat( // fteqcc sucks
-               "ping pl name | ",
-               "-teams,race,lms/kills +freezetag/kills -teams,lms/deaths +freezetag/deaths -teams,lms,race,ka/suicides +freezetag/suicides -race,dm,tdm,ka,freezetag/frags ", // tdm already has this in "score"
-               "+tdm/kills +tdm/deaths +tdm/suicides ",
-               "+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns ",
-               "+lms/lives +lms/rank ",
-               "+kh/caps +kh/pushes +kh/destroyed ",
-               "?+race/laps ?+race/time ?+race/fastest ",
-               "+as/objectives +nexball/faults +nexball/goals +ka/pickups +ka/bckills +ka/bctime +freezetag/revivals ",
-               "-lms,race,nexball/score");
-}
+#define HUD_DefaultColumnLayout() \
+"ping pl name | " \
+"-teams,race,lms/kills +ft,tdm/kills -teams,lms/deaths +ft,tdm/deaths -teams,lms,race,ka/suicides +ft,tdm/suicides -race,dm,tdm,ka,ft/frags " /* tdm already has this in "score" */ \
+"+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns " \
+"+lms/lives +lms/rank " \
+"+kh/caps +kh/pushes +kh/destroyed " \
+"?+race/laps ?+race/time ?+race/fastest " \
+"+as/objectives +nb/faults +nb/goals +ka/pickups +ka/bckills +ka/bctime +ft/revivals " \
+"-lms,race,nb/score"
 
 void Cmd_HUD_SetFields(float argc)
 {
@@ -308,6 +304,16 @@ void Cmd_HUD_SetFields(float argc)
        float have_name = 0, have_primary = 0, have_secondary = 0, have_separator = 0;
        float missing;
 
+       if(!gametype)
+       {
+               // set up a temporary scoreboard layout
+               // no layout can be properly set up until score_info data haven't been received
+               argc = tokenizebyseparator("0 1 ping pl name | score", " ");
+               ps_primary = 0;
+               scores_label[ps_primary] = strzone("score");
+               scores_flags[ps_primary] = SFL_ALLOW_HIDE;
+       }
+
        // TODO: re enable with gametype dependant cvars?
        if(argc < 3) // no arguments provided
                argc = tokenizebyseparator(strcat("0 1 ", autocvar_scoreboard_columns), " ");
@@ -376,7 +382,7 @@ void Cmd_HUD_SetFields(float argc)
                        hud_field[hud_num_fields] = SP_PL;
                } else if(str == "kd" || str == "kdr" || str == "kdratio" || str == "k/d") {
                        hud_field[hud_num_fields] = SP_KDRATIO;
-               } else if(str == "sum" || str == "diff" || str == "f-d") {
+               } else if(str == "sum" || str == "diff" || str == "k-d") {
                        hud_field[hud_num_fields] = SP_SUM;
                } else if(str == "name" || str == "nick") {
                        hud_field[hud_num_fields] = SP_NAME;
@@ -549,7 +555,7 @@ string HUD_GetField(entity pl, float field)
                                        hud_field_icon1 = "gfx/scoreboard/playercolor_shirt";
                                        hud_field_icon1_rgb = colormapPaletteColor(floor(f / 16), 0);
                                        hud_field_icon2 = "gfx/scoreboard/playercolor_pants";
-                                       hud_field_icon2_rgb = colormapPaletteColor(mod(f, 16), 1);
+                                       hud_field_icon2_rgb = colormapPaletteColor(f % 16, 1);
                                }
                        }
                        return GetPlayerName(pl.sv_entnum);
@@ -670,7 +676,7 @@ string HUD_FixScoreboardColumnWidth(float i, string str)
        return str;
 }
 
-void HUD_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_number)
+void HUD_PrintScoreboardItem(vector pos, vector item_size, entity pl, float is_self, float pl_number)
 {
        vector tmp, rgb;
        rgb = Team_ColorRGB(pl.team);
@@ -684,18 +690,17 @@ void HUD_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_numb
                rgb_y = autocvar_scoreboard_color_bg_g + 0.5;
                rgb_z = autocvar_scoreboard_color_bg_b + 0.5; }
 
-       // Layout:
-       tmp_x = sbwidth;
-       tmp_y = hud_fontsize_y * 1.25;
-       tmp_z = 0;
-
+       vector h_pos = pos - '1 1 0';
+       vector h_size = item_size + '2 0 0';
        // alternated rows highlighting
        if(is_self)
-               drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);
-       else if((scoreboard_highlight) && (!mod(pl_number,2)))
-               drawfill(pos - '1 1 0', tmp + '2 0 0', rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL);
+               drawfill(h_pos, h_size, rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);
+       else if((scoreboard_highlight) && (!(pl_number % 2)))
+               drawfill(h_pos, h_size, rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL);
 
+       tmp_x = item_size_x;
        tmp_y = 0;
+       tmp_z = 0;
 
        for(i = 0; i < hud_num_fields; ++i)
        {
@@ -794,6 +799,9 @@ void HUD_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_numb
                        pos_x -= hud_size[i] + hud_fontsize_x;
                }
        }
+
+       if(pl.eliminated)
+               drawfill(h_pos, h_size, '0 0 0', 0.5, DRAWFLAG_NORMAL);
 }
 
 /*
@@ -866,7 +874,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
                column_dim_x = hud_size[i] + hud_fontsize_x;
                if (scoreboard_highlight)
                {
-                       if (mod(i,2))
+                       if (i % 2)
                                drawfill(pos - '0 1 0' - hud_fontsize_x / 2 * '1 0 0', column_dim, '0 0 0', scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);
                }
                drawstring(pos, hud_title[i], hud_fontsize, rgb * 1.5, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
@@ -885,7 +893,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
 
                        if (scoreboard_highlight)
                        {
-                               if (!mod(i,2))
+                               if (!(i % 2))
                                {
                                        if (i == hud_num_fields-1)
                                                column_dim_x = hud_size[i] + hud_fontsize_x / 2 + 1;
@@ -907,6 +915,10 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
        pos_y += 1.25 * hud_fontsize_y; // skip the header
        pos_y += autocvar_scoreboard_border_thickness;
 
+       // item size
+       tmp_x = sbwidth;
+       tmp_y = hud_fontsize_y * 1.25;
+
        // fill the table and draw the rows
        i = 0;
        if (teamplay)
@@ -914,7 +926,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
                {
                        if(pl.team != tm.team)
                                continue;
-                       HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), i);
+                       HUD_PrintScoreboardItem(pos, tmp, pl, (pl.sv_entnum == player_localnum), i);
                        pos_y += 1.25 * hud_fontsize_y;
                        ++i;
                }
@@ -923,7 +935,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
                {
                        if(pl.team == NUM_SPECTATOR)
                                continue;
-                       HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), i);
+                       HUD_PrintScoreboardItem(pos, tmp, pl, (pl.sv_entnum == player_localnum), i);
                        pos_y += 1.25 * hud_fontsize_y;
                        ++i;
                }
@@ -955,7 +967,7 @@ float average_accuracy;
 vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 {
        float i;
-       float weapon_cnt = WEP_COUNT - 3; // either minstanex/nex are hidden, no port-o-launch, no tuba
+       float weapon_cnt = WEP_COUNT - 3; // either vaporizer/vortex are hidden, no port-o-launch, no tuba
        float rows;
        if(autocvar_scoreboard_accuracy_doublerows)
                rows = 2;
@@ -965,7 +977,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        float fontsize = height * 1/3;
        float weapon_height = height * 2/3;
        float weapon_width = sbwidth / weapon_cnt;
-       float g_minstagib = 0;
+       float g_instagib = 0;
 
        drawstring(pos, sprintf(_("Accuracy stats (average %d%%)"), average_accuracy), hud_fontsize, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
        pos_y += 1.25 * hud_fontsize_y + autocvar_scoreboard_border_thickness;
@@ -982,7 +994,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        // column highlighting
        for(i = 0; i < weapon_cnt/rows; ++i)
        {
-               if(!mod(i, 2))
+               if(!(i % 2))
                        drawfill(pos + '1 0 0' * weapon_width * rows * i, '0 1 0' * height * rows + '1 0 0' * weapon_width * rows, '0 0 0', scoreboard_alpha_bg * 0.2, DRAWFLAG_NORMAL);
        }
 
@@ -998,8 +1010,8 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        if(rows == 2)
                pos_x += weapon_width / 2;
 
-       if(switchweapon == WEP_MINSTANEX)
-               g_minstagib = 1; // TODO: real detection for minstagib?
+       if(switchweapon == WEP_VAPORIZER)
+               g_instagib = 1; // TODO: real detection for instagib?
 
        float weapon_stats;
        if(autocvar_scoreboard_accuracy_nocolors)
@@ -1012,7 +1024,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                self = get_weaponinfo(i);
                if (!self.weapon)
                        continue;
-               if ((i == WEP_NEX && g_minstagib) || i == WEP_PORTO || (i == WEP_MINSTANEX && !g_minstagib) || i == WEP_TUBA) // skip port-o-launch, nex || minstanex and tuba
+               if ((i == WEP_VORTEX && g_instagib) || i == WEP_PORTO || (i == WEP_VAPORIZER && !g_instagib) || i == WEP_TUBA) // skip port-o-launch, vortex || vaporizer and tuba
                        continue;
                weapon_stats = weapon_accuracy[i-WEP_FIRST];
 
@@ -1023,14 +1035,14 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        weapon_alpha = 0.2 * scoreboard_alpha_fg;
 
                // weapon icon
-               drawpic_aspect_skin(pos, strcat("weapon", self.netname), '1 0 0' * weapon_width + '0 1 0' * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
+               drawpic_aspect_skin(pos, self.model2, '1 0 0' * weapon_width + '0 1 0' * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
                // the accuracy
                if(weapon_stats >= 0) {
                        weapons_with_stats += 1;
                        average_accuracy += weapon_stats; // store sum of all accuracies in average_accuracy
 
                        string s;
-                       s = sprintf(_("%d%%"), weapon_stats*100);
+                       s = sprintf("%d%%", weapon_stats*100);
 
                        float padding;
                        padding = (weapon_width - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
@@ -1173,7 +1185,7 @@ vector HUD_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_
                p = count_ordinal(i+1);
                if(grecordholder[i] == GetPlayerName(player_localnum))
                        drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha_self, DRAWFLAG_NORMAL);
-               else if(!mod(i, 2) && scoreboard_highlight)
+               else if(!(i % 2) && scoreboard_highlight)
                        drawfill(pos, '1 0 0' * sbwidth + '0 1.25 0' * hud_fontsize_y, hl_rgb, scoreboard_highlight_alpha, DRAWFLAG_NORMAL);
                drawstring(pos, p, '1 1 0' * hud_fontsize_y, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                drawstring(pos + '3 0 0' * hud_fontsize_y, TIME_ENCODED_TOSTRING(t), '1 1 0' * hud_fontsize_y, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
@@ -1330,12 +1342,16 @@ void HUD_DrawScoreboard()
        float specs;
        specs = 0;
        tmp = pos;
+       vector item_size;
+       item_size_x = sbwidth;
+       item_size_y = hud_fontsize_y * 1.25;
+       item_size_z = 0;
        for(pl = players.sort_next; pl; pl = pl.sort_next)
        {
                if(pl.team != NUM_SPECTATOR)
                        continue;
                pos_y += 1.25 * hud_fontsize_y;
-               HUD_PrintScoreboardItem(pos, pl, (pl.sv_entnum == player_localnum), specs);
+               HUD_PrintScoreboardItem(pos, item_size, pl, (pl.sv_entnum == player_localnum), specs);
                ++specs;
        }