]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/scoreboard.qc
fix CSQC scoreboard sorting by applying the same rules as on server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / scoreboard.qc
index 05c8df88cfc68f767c1eb268bab64044dc9ef4fa..591f4b0dc6edc9478df5d85b69ff755db78bf5e9 100644 (file)
@@ -19,6 +19,7 @@ string TranslateScoresLabel(string l)
                case "bckills": return CTX(_("SCO^bckills"));
                case "bctime": return CTX(_("SCO^bctime"));
                case "caps": return CTX(_("SCO^caps"));
+               case "captime": return CTX(_("SCO^captime"));
                case "deaths": return CTX(_("SCO^deaths"));
                case "destroyed": return CTX(_("SCO^destroyed"));
                case "drops": return CTX(_("SCO^drops"));
@@ -128,9 +129,25 @@ void HUD_UpdatePlayerTeams()
        */
 }
 
+float HUD_CompareScore(float f, float vl, float vr)
+{
+       if(f & SFL_ZERO_IS_WORST)
+       {
+               if(vl == 0 && vr != 0)
+                       return 1;
+               if(vl != 0 && vr == 0)
+                       return 0;
+       }
+       if(vl > vr)
+               return IS_INCREASING(f);
+       if(vl < vr)
+               return IS_DECREASING(f);
+       return -1;
+}
+
 float HUD_ComparePlayerScores(entity left, entity right)
 {
-       float vl, vr;
+       float vl, vr, r, i;
        vl = GetPlayerColor(left.sv_entnum);
        vr = GetPlayerColor(right.sv_entnum);
 
@@ -153,33 +170,20 @@ float HUD_ComparePlayerScores(entity left, entity right)
                return false;
        }
 
-       vl = left.scores[ps_primary];
-       vr = right.scores[ps_primary];
-       if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
-       {
-               if(vl == 0 && vr != 0)
-                       return 1;
-               if(vl != 0 && vr == 0)
-                       return 0;
-       }
-       if(vl > vr)
-               return IS_INCREASING(scores_flags[ps_primary]);
-       if(vl < vr)
-               return IS_DECREASING(scores_flags[ps_primary]);
+       r = HUD_CompareScore(left.scores[ps_primary], right.scores[ps_primary], scores_flags[ps_primary]);
+       if (r >= 0)
+               return r;
+
+       r = HUD_CompareScore(left.scores[ps_secondary], right.scores[ps_secondary], scores_flags[ps_secondary]);
+       if (r >= 0)
+               return r;
 
-       vl = left.scores[ps_secondary];
-       vr = right.scores[ps_secondary];
-       if(scores_flags[ps_secondary] & SFL_ZERO_IS_WORST)
+       for(i = 0; i < MAX_SCORE; ++i)
        {
-               if(vl == 0 && vr != 0)
-                       return 1;
-               if(vl != 0 && vr == 0)
-                       return 0;
+               r = HUD_CompareScore(left.scores[i], right.scores[i], scores_flags[i]);
+               if (r >= 0)
+                       return r;
        }
-       if(vl > vr)
-               return IS_INCREASING(scores_flags[ps_secondary]);
-       if(vl < vr)
-               return IS_DECREASING(scores_flags[ps_secondary]);
 
        return false;
 }
@@ -198,26 +202,27 @@ void HUD_UpdatePlayerPos(entity player)
 
 float HUD_CompareTeamScores(entity left, entity right)
 {
-       float vl, vr;
+       float i, r;
 
        if(left.team == COLOR_SPECTATOR)
                return 1;
        if(right.team == COLOR_SPECTATOR)
                return 0;
 
-       vl = left.teamscores[ts_primary];
-       vr = right.teamscores[ts_primary];
-       if(vl > vr)
-               return IS_INCREASING(teamscores_flags[ts_primary]);
-       if(vl < vr)
-               return IS_DECREASING(teamscores_flags[ts_primary]);
+       r = HUD_CompareScore(left.teamscores[ts_primary], right.teamscores[ts_primary], teamscores_flags[ts_primary]);
+       if (r >= 0)
+               return r;
 
-       vl = left.teamscores[ts_secondary];
-       vr = right.teamscores[ts_secondary];
-       if(vl > vr)
-               return IS_INCREASING(teamscores_flags[ts_secondary]);
-       if(vl < vr)
-               return IS_DECREASING(teamscores_flags[ts_secondary]);
+       r = HUD_CompareScore(left.teamscores[ts_secondary], right.teamscores[ts_secondary], teamscores_flags[ts_secondary]);
+       if (r >= 0)
+               return r;
+
+       for(i = 0; i < MAX_SCORE; ++i)
+       {
+               r = HUD_CompareScore(left.teamscores[i], right.teamscores[i], teamscores_flags[i]);
+               if (r >= 0)
+                       return r;
+       }
 
        return false;
 }
@@ -254,6 +259,7 @@ void Cmd_HUD_Help()
        print(_("^3kd^7                       The kill-death ratio\n"));
        print(_("^3caps^7                     How often a flag (CTF) or a key (KeyHunt) was captured\n"));
        print(_("^3pickups^7                  How often a flag (CTF) or a key (KeyHunt) or a ball (Keepaway) was picked up\n"));
+       print(_("^3captime^7                  Time of fastest cap (CTF)\n"));
        print(_("^3fckills^7                  Number of flag carrier kills\n"));
        print(_("^3returns^7                  Number of flag returns\n"));
        print(_("^3drops^7                    Number of flag drops\n"));
@@ -304,24 +310,24 @@ void Cmd_HUD_SetFields(float argc)
 {
        float i, j, slash;
        string str, pattern;
-       float have_name, have_primary, have_secondary, have_separator;
+       float have_name = 0, have_primary = 0, have_secondary = 0, have_separator = 0;
        float missing;
 
        // TODO: re enable with gametype dependant cvars?
        if(argc < 3) // no arguments provided
-               argc = tokenizebyseparator(strcat("x ", autocvar_scoreboard_columns), " ");
+               argc = tokenizebyseparator(strcat("0 1 ", autocvar_scoreboard_columns), " ");
 
        if(argc < 3)
-               argc = tokenizebyseparator(strcat("x ", HUD_DefaultColumnLayout()), " ");
+               argc = tokenizebyseparator(strcat("0 1 ", HUD_DefaultColumnLayout()), " ");
 
        if(argc == 3)
        {
                if(argv(2) == "default")
-                       argc = tokenizebyseparator(strcat("x ", HUD_DefaultColumnLayout()), " ");
+                       argc = tokenizebyseparator(strcat("0 1 ", HUD_DefaultColumnLayout()), " ");
                else if(argv(2) == "all")
                {
                        string s;
-                       s = "ping pl color name |";
+                       s = "ping pl name |";
                        for(i = 0; i < MAX_SCORE; ++i)
                        {
                                if(i != ps_primary)
@@ -332,16 +338,17 @@ void Cmd_HUD_SetFields(float argc)
                        if(ps_secondary != ps_primary)
                                s = strcat(s, " ", scores_label[ps_secondary]);
                        s = strcat(s, " ", scores_label[ps_primary]);
-                       argc = tokenizebyseparator(strcat("x ", s), " ");
+                       argc = tokenizebyseparator(strcat("0 1 ", s), " ");
                }
        }
 
 
        hud_num_fields = 0;
 
-       hud_fontsize = HUD_GetFontsize("hud_fontsize"); 
+       hud_fontsize = HUD_GetFontsize("hud_fontsize");
 
-       for(i = 0; i < argc - 1; ++i)
+       draw_beginBoldFont();
+       for(i = 1; i < argc - 1; ++i)
        {
                float nocomplain;
                str = argv(i+1);
@@ -477,6 +484,7 @@ void Cmd_HUD_SetFields(float argc)
        }
 
        hud_field[hud_num_fields] = SP_END;
+       draw_endBoldFont();
 }
 
 // MOVEUP::
@@ -787,7 +795,7 @@ void HUD_PrintScoreboardItem(vector pos, entity pl, float is_self, float pl_numb
 vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_size)
 {
        float body_table_height, i;
-       vector tmp, column_dim;
+       vector tmp = '0 0 0', column_dim = '0 0 0';
        entity pl;
 
        body_table_height = 1.25 * hud_fontsize_y * max(1, tm.team_size); // no player? show 1 empty line
@@ -840,6 +848,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
        }
 
        // print the strings of the columns headers and draw the columns
+       draw_beginBoldFont();
        for(i = 0; i < hud_num_fields; ++i)
        {
                if(hud_field[i] == SP_SEPARATOR)
@@ -882,6 +891,7 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
                        pos_x -= hud_fontsize_x;
                }
        }
+       draw_endBoldFont();
 
        pos_x = xmin;
        pos_y += 1.25 * hud_fontsize_y; // skip the header
@@ -949,7 +959,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 
        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;
-       vector tmp;
+       vector tmp = '0 0 0';
        tmp_x = sbwidth;
        tmp_y = height * rows;
 
@@ -985,14 +995,14 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 
        if (!acc_levels)
                rgb = '1 1 1';
-       else if (acc_col_x[0] == -1)
+       else if (acc_col[0] == '-1 0 0')
                for (i = 0; i < acc_levels; ++i)
                        acc_col[i] = stov(cvar_string(strcat("accuracy_color", ftos(i))));
 
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
                self = get_weaponinfo(i);
-               if not(self.weapons)
+               if not(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
                        continue;
@@ -1086,7 +1096,7 @@ vector HUD_DrawMapStats(vector pos, vector rgb, vector bg_size) {
        pos_y += 1.25 * hud_fontsize_y + autocvar_scoreboard_border_thickness;
        
        // draw table   
-       vector tmp;
+       vector tmp = '0 0 0';
        tmp_x = sbwidth;
        tmp_y = hud_fontsize_y * rows;
 
@@ -1127,7 +1137,7 @@ vector HUD_DrawScoreboardRankings(vector pos, entity pl,  vector rgb, vector bg_
        pos_y += hud_fontsize_y;
        drawstring(pos, _("Rankings"), hud_fontsize, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
        pos_y += hud_fontsize_y + autocvar_scoreboard_border_thickness;
-       vector tmp;
+       vector tmp = '0 0 0';
        tmp_x = sbwidth;
        tmp_y = 1.25 * hud_fontsize_y * RANKINGS_RECEIVED_CNT;
 
@@ -1220,7 +1230,9 @@ void HUD_DrawScoreboard()
        // Heading
        vector sb_heading_fontsize;
        sb_heading_fontsize = hud_fontsize * 2;
+       draw_beginBoldFont();
        drawstring(pos, _("Scoreboard"), sb_heading_fontsize, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
+       draw_endBoldFont();
 
        pos_y += sb_heading_fontsize_y + hud_fontsize_y * 0.25;
 
@@ -1236,6 +1248,7 @@ void HUD_DrawScoreboard()
                        if(tm.team == COLOR_SPECTATOR)
                                continue;
 
+                       draw_beginBoldFont();
                        rgb = GetTeamRGB(tm.team);
                        str = ftos(tm.(teamscores[ts_primary]));
                        drawstring(pos + team_score_baseoffset - eX * stringwidth(str, FALSE, hud_fontsize * 1.5), str, hud_fontsize * 1.5, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
@@ -1245,11 +1258,23 @@ void HUD_DrawScoreboard()
                                str = ftos(tm.(teamscores[ts_secondary]));
                                drawstring(pos + team_score_baseoffset - eX * stringwidth(str, FALSE, hud_fontsize) + eY * hud_fontsize_y * 1.5, str, hud_fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                        }
+                       draw_endBoldFont();
+
                        pos = HUD_Scoreboard_MakeTable(pos, tm, rgb, bg_size);
                }
+
+#ifdef GMQCC
+               rgb = '0 0 0';
+#endif
+               rgb_x = autocvar_scoreboard_color_bg_r;
+               rgb_y = autocvar_scoreboard_color_bg_g;
+               rgb_z = autocvar_scoreboard_color_bg_b;
        }
        else
        {
+#ifdef GMQCC
+               rgb = '0 0 0';
+#endif
                rgb_x = autocvar_scoreboard_color_bg_r;
                rgb_y = autocvar_scoreboard_color_bg_g;
                rgb_z = autocvar_scoreboard_color_bg_b;
@@ -1272,7 +1297,7 @@ void HUD_DrawScoreboard()
                        drawcolorcodedstring(pos, sprintf(_("All-time fastest: %d ^7(%s^7)"), race_speedaward_alltimebest, race_speedaward_alltimebest_holder), hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                        pos_y += 1.25 * hud_fontsize_y;
                }
-               pos = HUD_DrawScoreboardRankings(pos, pl, rgb, bg_size);
+               pos = HUD_DrawScoreboardRankings(pos, playerslots[player_localnum], rgb, bg_size);
        }
        else if(autocvar_scoreboard_accuracy && spectatee_status != -1 && !warmup_stage) {
                if(teamplay)
@@ -1302,7 +1327,9 @@ void HUD_DrawScoreboard()
 
        if(specs)
        {
+               draw_beginBoldFont();
                drawstring(tmp, _("Spectators"), hud_fontsize, '1 1 1', scoreboard_alpha_fg, DRAWFLAG_NORMAL);
+               draw_endBoldFont();
                pos_y += 1.25 * hud_fontsize_y;
        }
 
@@ -1361,9 +1388,29 @@ void HUD_DrawScoreboard()
                }
        }
 
-
        pos_y += 1.2 * hud_fontsize_y;
        drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, hud_fontsize)), str, hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
 
+       // print information about respawn status
+       float respawn_time = getstatf(STAT_RESPAWN_TIME);
+       if(respawn_time)
+       {
+               if(respawn_time < 0)
+               {
+                       // a negative number means we are awaiting respawn, time value is still the same
+                       respawn_time *= -1; // remove mark now that we checked it
+                       respawn_time = max(time, respawn_time); // don't show a negative value while the server is respawning the player (lag)
+                       
+                       str = sprintf(_("^1Respawning in ^3%s^1 seconds..."), ftos_decimals(respawn_time - time, autocvar_scoreboard_respawntime_decimals));
+               }
+               else if(time < respawn_time)
+                       str = sprintf(_("You are dead, wait ^3%s^7 seconds before respawning"), ftos_decimals(respawn_time - time, autocvar_scoreboard_respawntime_decimals));
+               else if(time >= respawn_time)
+                       str = sprintf(_("You are dead, press ^2%s^7 to respawn"), getcommandkey("jump", "+jump"));
+
+               pos_y += 1.2 * hud_fontsize_y;
+               drawcolorcodedstring(pos + '0.5 0 0' * (sbwidth - stringwidth(str, TRUE, hud_fontsize)), str, hud_fontsize, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
+       }
+
        scoreboard_bottom = pos_y + 2 * hud_fontsize_y;
 }