]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/scoreboard.qc
Merge remote-tracking branch 'origin/master' into samual/notification_rewrite
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / scoreboard.qc
index 0984f7ce1a512b4b8cd24729a30ddbca24caeae2..e4e3767f1c2a5207c107c13ea607d5df4d8d76fb 100644 (file)
@@ -129,9 +129,25 @@ void HUD_UpdatePlayerTeams()
        */
 }
 
+float HUD_CompareScore(float vl, float vr, float f)
+{
+       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);
 
@@ -154,33 +170,23 @@ 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]);
+
+       if (left.sv_entnum < right.sv_entnum)
+               return true;
 
        return false;
 }
@@ -199,26 +205,30 @@ void HUD_UpdatePlayerPos(entity player)
 
 float HUD_CompareTeamScores(entity left, entity right)
 {
-       float vl, vr;
+       float i, r;
 
        if(left.team == FL_SPECTATOR)
                return 1;
        if(right.team == FL_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;
+       }
+
+       if (left.team < right.team)
+               return true;
 
        return false;
 }
@@ -306,7 +316,7 @@ 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?
@@ -791,7 +801,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
@@ -955,7 +965,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;
 
@@ -988,12 +998,10 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                g_minstagib = 1; // TODO: real detection for minstagib?
 
        float weapon_stats;
-
-       if (!acc_levels)
+       if(autocvar_scoreboard_accuracy_nocolors)
                rgb = '1 1 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))));
+       else
+               Accuracy_LoadColors();
 
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
@@ -1023,20 +1031,8 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        float padding;
                        padding = (weapon_width - stringwidth(s, FALSE, '1 0 0' * fontsize)) / 2; // center the accuracy value
 
-                       if (acc_levels)
-                       {
-                               // find the max level lower than weapon_stats
-                               float j;
-                               j = acc_levels-1;
-                               while ( j && weapon_stats < acc_lev[j] )
-                                       --j;
-
-                               // inject color j+1 in color j, how much depending on how much weapon_stats is higher than level j
-                               float factor;
-                               factor = (weapon_stats - acc_lev[j]) / (acc_lev[j+1] - acc_lev[j]);
-                               rgb = acc_col[j];
-                               rgb = rgb + factor * (acc_col[j+1] - rgb);
-                       }
+                       if(!autocvar_scoreboard_accuracy_nocolors)
+                               rgb = Accuracy_GetColor(weapon_stats);
 
                        drawstring(pos + '1 0 0' * padding + '0 1 0' * weapon_height, s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                }
@@ -1048,7 +1044,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        }
 
        if(weapons_with_stats)
-               average_accuracy = floor(average_accuracy / weapons_with_stats);
+               average_accuracy = floor((average_accuracy * 100 / weapons_with_stats) + 0.5);
 
        if(rows == 2)
                pos_x -= weapon_width / 2;
@@ -1092,7 +1088,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;
 
@@ -1133,7 +1129,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;
 
@@ -1258,9 +1254,19 @@ void HUD_DrawScoreboard()
 
                        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;
@@ -1283,7 +1289,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)
@@ -1385,10 +1391,9 @@ void HUD_DrawScoreboard()
                {
                        // a negative number means we are awaiting respawn, time value is still the same
                        respawn_time *= -1; // remove mark now that we checked it
-                       if(time >= respawn_time) // don't show a negative value while the server is respawning the player (lag)
-                               str = _("^1Respawning...");
-                       else
-                               str = sprintf(_("^1Respawning in ^3%s^1 seconds..."), ftos_decimals(respawn_time - time, autocvar_scoreboard_respawntime_decimals));
+                       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));