]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Scoreboard: allow showing average scores per round
authorterencehill <piuntn@gmail.com>
Wed, 10 May 2023 16:55:31 +0000 (16:55 +0000)
committerbones_was_here <bones_was_here@xonotic.au>
Wed, 10 May 2023 16:55:31 +0000 (16:55 +0000)
.gitlab-ci.yml
_hud_common.cfg
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/scores.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/server/round_handler.qc
qcsrc/server/scores.qc
qcsrc/server/scores_rules.qc

index 8ba5c18061a8b807617a4ab4c6b602c2ae7c154a..4786135071adaff32b7356f565fe81379a46d8d2 100644 (file)
@@ -75,7 +75,7 @@ test_sv_game:
     - wget -nv -O data/maps/stormkeep.waypoints https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints\r
     - wget -nv -O data/maps/stormkeep.waypoints.cache https://gitlab.com/xonotic/xonotic-maps.pk3dir/raw/master/maps/stormkeep.waypoints.cache\r
 \r
-    - EXPECT=fe5dec36cb304c55acee73afd1e09c0a\r
+    - EXPECT=f2226bf353b6ff3dd3c489a742ce4e6a\r
     - HASH=$(${ENGINE} +timestamps 1 +exec serverbench.cfg\r
       | tee /dev/stderr\r
       | sed -e 's,^\[[^]]*\] ,,'\r
index 6339895eafd312488b037769801bb5611e7e5854..c96c90bb9d8c0ba794e1d8c90706b71d3eb2b77f 100644 (file)
@@ -145,6 +145,7 @@ seta hud_panel_scoreboard_team_size_position 0 "where to show the team size (0 =
 seta hud_panel_scoreboard_playerid 0 "show player id (server entity number) next to player's name"
 seta hud_panel_scoreboard_playerid_prefix "#" "player id prefix"
 seta hud_panel_scoreboard_playerid_suffix " " "player id suffix"
+seta hud_panel_scoreboard_scores_per_round "0" "show average scores per round"
 
 seta hud_panel_scoreboard_accuracy_showdelay 2 "how long to delay displaying accuracy below the scoreboard if it's too far down"
 seta hud_panel_scoreboard_accuracy_showdelay_minpos 0.75 "delay displaying the accuracy panel only if its position is lower than this percentage of the screen height from the top"
index 484968a9c39a20ebf3b380c1d90e98d6b87dbb29..566f5a695635fe93419460c58ba81ec955162345 100644 (file)
@@ -106,9 +106,16 @@ float autocvar_hud_panel_scoreboard_minwidth = 0.4;
 bool autocvar_hud_panel_scoreboard_playerid = false;
 string autocvar_hud_panel_scoreboard_playerid_prefix = "#";
 string autocvar_hud_panel_scoreboard_playerid_suffix = " ";
+bool autocvar_hud_panel_scoreboard_scores_per_round;
 
 float scoreboard_time;
 
+SHUTDOWN(scoreboard)
+{
+       if(autocvar_hud_panel_scoreboard_scores_per_round)
+               cvar_set("hud_panel_scoreboard_scores_per_round", "0");
+}
+
 // mode 0: returns translated label
 // mode 1: prints name and description of all the labels
 string Label_getInfo(string label, int mode)
@@ -153,6 +160,7 @@ string Label_getInfo(string label, int mode)
                case "returns":      if (!mode) return CTX(_("SCO^returns"));      else LOG_HELP(strcat("^3", "returns", "            ^7", _("Number of flag returns")));
                case "revivals":     if (!mode) return CTX(_("SCO^revivals"));     else LOG_HELP(strcat("^3", "revivals", "           ^7", _("Number of revivals")));
                case "rounds":       if (!mode) return CTX(_("SCO^rounds won"));   else LOG_HELP(strcat("^3", "rounds", "             ^7", _("Number of rounds won")));
+               case "rounds_pl":    if (!mode) return CTX(_("SCO^rounds played"));else LOG_HELP(strcat("^3", "rounds_pl", "          ^7", _("Number of rounds played")));
                case "score":        if (!mode) return CTX(_("SCO^score"));        else LOG_HELP(strcat("^3", "score", "              ^7", _("Total score")));
                case "suicides":     if (!mode) return CTX(_("SCO^suicides"));     else LOG_HELP(strcat("^3", "suicides", "           ^7", _("Number of suicides")));
                case "sum":          if (!mode) return CTX(_("SCO^sum"));          else LOG_HELP(strcat("^3", "sum", "                ^7", _("Number of kills minus deaths")));
@@ -467,6 +475,13 @@ float HUD_Scoreboard_InputEvent(float bInputType, float nPrimary, float nSeconda
                        }
                }
        }
+       else if(nPrimary == 'r' && (hudShiftState & S_CTRL))
+       {
+               if (!key_pressed)
+                       return true;
+               if (scoreboard_selected_panel == SB_PANEL_SCOREBOARD)
+                       localcmd("toggle hud_panel_scoreboard_scores_per_round\n");
+       }
        else if(nPrimary == 't' && (hudShiftState & S_CTRL))
        {
                if (!key_pressed)
@@ -967,7 +982,7 @@ string Scoreboard_GetName(entity pl)
        return entcs_GetName(pl.sv_entnum);
 }
 
-string Scoreboard_GetField(entity pl, PlayerScoreField field)
+string Scoreboard_GetField(entity pl, PlayerScoreField field, bool per_round)
 {
        float tmp, num, denom;
        int f;
@@ -979,6 +994,9 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
        sbt_field_icon0_rgb = '1 1 1';
        sbt_field_icon1_rgb = '1 1 1';
        sbt_field_icon2_rgb = '1 1 1';
+       int rounds_played = 0;
+       if (per_round)
+               rounds_played = pl.(scores(SP_ROUNDS_PL));
        switch(field)
        {
                case SP_PING:
@@ -1015,6 +1033,8 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                case SP_FRAGS:
                        f = pl.(scores(SP_KILLS));
                        f -= pl.(scores(SP_SUICIDES));
+                       if (rounds_played)
+                               return sprintf("%.1f", f / rounds_played);
                        return ftos(f);
 
                case SP_KDRATIO:
@@ -1023,12 +1043,23 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
 
                        if(denom == 0) {
                                sbt_field_rgb = '0 1 0';
-                               str = sprintf("%d", num);
+                               if (rounds_played)
+                                       str = sprintf("%.1f", num / rounds_played);
+                               else
+                                       str = sprintf("%d", num);
                        } else if(num <= 0) {
                                sbt_field_rgb = '1 0 0';
-                               str = sprintf("%.1f", num/denom);
+                               if (rounds_played)
+                                       str = sprintf("%.2f", num / (denom * rounds_played));
+                               else
+                                       str = sprintf("%.1f", num / denom);
                        } else
-                               str = sprintf("%.1f", num/denom);
+                       {
+                               if (rounds_played)
+                                       str = sprintf("%.2f", num / (denom * rounds_played));
+                               else
+                                       str = sprintf("%.1f", num / denom);
+                       }
                        return str;
 
                case SP_SUM:
@@ -1042,6 +1073,8 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                        } else {
                                sbt_field_rgb = '1 0 0';
                        }
+                       if (rounds_played)
+                               return sprintf("%.1f", f / rounds_played);
                        return ftos(f);
 
                case SP_ELO:
@@ -1067,7 +1100,12 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                        return ftos(fps);
                }
 
+               case SP_ROUNDS_PL:
+                       return ftos(pl.(scores(field)));
+
                case SP_DMG: case SP_DMGTAKEN:
+                       if (rounds_played)
+                               return sprintf("%.2f k", pl.(scores(field)) / (1000 * rounds_played));
                        return sprintf("%.1f k", pl.(scores(field)) / 1000);
 
                default: case SP_SCORE:
@@ -1079,7 +1117,7 @@ string Scoreboard_GetField(entity pl, PlayerScoreField field)
                                sbt_field_rgb = '0 1 1';
                        else
                                sbt_field_rgb = '1 1 1';
-                       return ScoreString(f, tmp);
+                       return ScoreString(f, tmp, rounds_played);
        }
        //return "error";
 }
@@ -1253,7 +1291,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
                        pos.x += sbt_field_size[i] + hud_fontsize.x;
                        continue;
                }
-               str = Scoreboard_GetField(pl, field);
+               str = Scoreboard_GetField(pl, field, autocvar_hud_panel_scoreboard_scores_per_round);
                str = Scoreboard_FixColumnWidth(i, str);
 
                pos.x += sbt_field_size[i] + hud_fontsize.x;
@@ -1289,7 +1327,7 @@ void Scoreboard_DrawItem(vector item_pos, vector rgb, entity pl, bool is_self, i
                                continue;
                        }
 
-                       str = Scoreboard_GetField(pl, field);
+                       str = Scoreboard_GetField(pl, field, autocvar_hud_panel_scoreboard_scores_per_round);
                        str = Scoreboard_FixColumnWidth(i, str);
 
                        if(field == SP_NAME) {
@@ -1358,10 +1396,10 @@ vector Scoreboard_DrawOthers(vector item_pos, vector rgb, int this_team, entity
                if(this_team == NUM_SPECTATOR)
                {
                        if(autocvar_hud_panel_scoreboard_spectators_showping)
-                               field = Scoreboard_GetField(pl, SP_PING);
+                               field = Scoreboard_GetField(pl, SP_PING, autocvar_hud_panel_scoreboard_scores_per_round);
                }
                else if(autocvar_hud_panel_scoreboard_others_showscore)
-                       field = Scoreboard_GetField(pl, SP_SCORE);
+                       field = Scoreboard_GetField(pl, SP_SCORE, autocvar_hud_panel_scoreboard_scores_per_round);
 
                string str = entcs_GetName(pl.sv_entnum);
                if (autocvar_hud_panel_scoreboard_playerid)
@@ -2156,7 +2194,7 @@ string Scoreboard_Fraglimit_Draw(float limit, bool is_leadlimit)
 {
        string s_label = (teamplay) ? teamscores_label(ts_primary) : scores_label(ps_primary);
        int s_flags = (teamplay) ? teamscores_flags(ts_primary) : scores_flags(ps_primary);
-       return sprintf((is_leadlimit ? _("^2+%s %s") : _("^5%s %s")), ScoreString(s_flags, limit),
+       return sprintf((is_leadlimit ? _("^2+%s %s") : _("^5%s %s")), ScoreString(s_flags, limit, 0),
                (s_label == "score") ? CTX(_("SCO^points")) :
                (s_label == "fastest") ? "" : TranslateScoresLabel(s_label));
 }
index 3449f2b53ee5b950b2d2916d8e593509decdece3..e13d3030c300bafe3832ada5c4aeb23f7c431cd8 100644 (file)
@@ -68,6 +68,8 @@ REGISTER_SP(SUICIDES);
 REGISTER_SP(DMG);
 REGISTER_SP(DMGTAKEN);
 
+REGISTER_SP(ROUNDS_PL);
+
 REGISTER_SP(ELO); // not sortable
 REGISTER_SP(FPS); // not sortable
 
index 98418767a15f373428d860b51612a2d445ecf44c..df54e3536b10acdf149037ddacc8b6c4c133da12 100644 (file)
@@ -372,7 +372,7 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(
 }
 
 #ifdef GAMEQC
-string ScoreString(int pFlags, float pValue)
+string ScoreString(int pFlags, float pValue, int rounds_played)
 {
        string valstr;
        float l;
@@ -385,6 +385,8 @@ string ScoreString(int pFlags, float pValue)
                valstr = (pValue < 256 ? count_ordinal(pValue) : _("N/A"));
        else if(pFlags & SFL_TIME)
                valstr = TIME_ENCODED_TOSTRING(pValue, true);
+       else if (rounds_played)
+               valstr = sprintf("%.1f", pValue / rounds_played);
        else
                valstr = ftos(pValue);
 
index 4d011ce97224ec72c2e3f52ef57f20ac5da6d6c7..01933cb348323b7090b7b889c85ae2271d55e094 100644 (file)
@@ -96,7 +96,7 @@ const float TIME_FACTOR = 100;
 #define TIME_DECODE(n) ((n) / TIME_FACTOR)
 
 #ifdef GAMEQC
-string ScoreString(float vflags, float value);
+string ScoreString(float vflags, float value, int rounds_played);
 #endif
 
 vector decompressShortVector(float data);
index b22ba178d61d0c2ecbcb3f398a7868a25b595b0b..bb890e980a628738d1cf96ec9d74a81bf84089c8 100644 (file)
@@ -1,6 +1,7 @@
 #include "round_handler.qh"
 
 #include <common/mapobjects/triggers.qh>
+#include <common/scores.qh>
 #include <common/util.qh>
 #include <server/campaign.qh>
 #include <server/command/vote.qh>
@@ -39,6 +40,9 @@ void round_handler_Think(entity this)
                        int f = this.cnt - 1;
                        if (f == 0)
                        {
+                               FOREACH_CLIENT((IS_PLAYER(it) || INGAME(it)), {
+                                       GameRules_scoring_add(it, ROUNDS_PL, 1);
+                               });
                                this.cnt = 0;
                                this.round_endtime = (this.round_timelimit) ? time + this.round_timelimit : 0;
                                this.nextthink = time;
index 2cedc4aded31c9abce24c8fa5bafdcbe92987bac..5e1c8d9db567b67fd8f3635803cd6dd4266fbd25 100644 (file)
@@ -864,7 +864,7 @@ void Score_NicePrint_Team(entity to, float t, float w)
                        {
                                fl = teamscores_flags(i);
                                sc = sk.(teamscores(i));
-                               s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
+                               s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc, 0));
                        }
        }
        else
@@ -912,7 +912,7 @@ void Score_NicePrint_Player(entity to, entity p, float w)
                {
                        fl = scores_flags(it);
                        sc = sk.(scores(it));
-                       s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
+                       s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc, 0)));
                }
     });
 
index 95f8b482edd65e2fdcf42903658399791cd4ed0f..2db5ae705e489149b83f2367d4129270c7628848 100644 (file)
@@ -58,6 +58,8 @@ void ScoreRules_basics(int teams, float sprio, float stprio, float score_enabled
                ScoreInfo_SetLabel_PlayerScore(SP_ELO, "elo", SFL_NOT_SORTABLE);
        }
 
+       ScoreInfo_SetLabel_PlayerScore(SP_ROUNDS_PL, "rounds_pl", 0);
+
        if(STAT(SHOWFPS))
                ScoreInfo_SetLabel_PlayerScore(SP_FPS, "fps", SFL_NOT_SORTABLE);
 }