]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'Mario/weapon_stats' into 'master'
authorMario <zacjardine@y7mail.com>
Sun, 2 Aug 2015 03:00:19 +0000 (03:00 +0000)
committerMario <zacjardine@y7mail.com>
Sun, 2 Aug 2015 03:00:19 +0000 (03:00 +0000)
Merge branch Mario/weapon_stats (S merge request)

Hides unavailable weapons from the scoreboard, also attempted fix for scoreboard_accuracy_doublerows (was completely misaligned before, aligns properly now, but shows a load of unnecessary tiles).

See merge request !157

qcsrc/client/scoreboard.qc
qcsrc/common/stats.qh
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/all.qh
qcsrc/server/cl_client.qc
qcsrc/server/defs.qh
qcsrc/server/g_world.qc

index 418e1db08b2697239e7d81194fe91e82279d8ff6..8244836892d4f90ac178f48f85cb320bfdaea5a9 100644 (file)
@@ -976,18 +976,39 @@ float HUD_WouldDrawScoreboard() {
 float average_accuracy;
 vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
 {
+       WepSet weapons_stat = WepSet_GetFromStat();
+       WepSet weapons_inmap = WepSet_GetFromStat_InMap();
        int i;
-       int weapon_cnt = WEP_COUNT - 3; // either vaporizer/vortex are hidden, no port-o-launch, no tuba
-       float rows;
-       if(autocvar_scoreboard_accuracy_doublerows)
+       float weapon_stats;
+       int disownedcnt = 0;
+       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+       {
+               self = get_weaponinfo(i);
+               if(!self.weapon)
+                       continue;
+
+               weapon_stats = weapon_accuracy[i-WEP_FIRST];
+
+               if(weapon_stats < 0 && !(weapons_stat & WepSet_FromWeapon(i) || weapons_inmap & WepSet_FromWeapon(i)))
+                       ++disownedcnt;
+       }
+
+       int weapon_cnt = WEP_COUNT - disownedcnt;
+
+       if(weapon_cnt <= 0)
+               return pos;
+
+       int rows;
+       if(autocvar_scoreboard_accuracy_doublerows && weapon_cnt >= floor(WEP_COUNT * 0.5))
                rows = 2;
        else
                rows = 1;
+       int count_perrow = rint(weapon_cnt / rows);
        float height = 40;
        float fontsize = height * 1/3;
        float weapon_height = height * 2/3;
-       float weapon_width = sbwidth / weapon_cnt;
-       float g_instagib = 0;
+       float weapon_width = sbwidth / weapon_cnt / rows;
+       bool g_instagib = false;
 
        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;
@@ -1002,7 +1023,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        drawborderlines(autocvar_scoreboard_border_thickness, pos, tmp, '0 0 0', scoreboard_alpha_bg * 0.75, DRAWFLAG_NORMAL);
 
        // column highlighting
-       for(i = 0; i < weapon_cnt/rows; ++i)
+       for(i = 0; i < count_perrow; ++i)
        {
                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);
@@ -1015,29 +1036,31 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        }
 
        average_accuracy = 0;
-       float weapons_with_stats;
-       weapons_with_stats = 0;
+       int weapons_with_stats = 0;
        if(rows == 2)
                pos.x += weapon_width / 2;
 
        if(switchweapon == WEP_VAPORIZER)
-               g_instagib = 1; // TODO: real detection for instagib?
+               g_instagib = true; // TODO: real detection for instagib?
 
-       float weapon_stats;
        if(autocvar_scoreboard_accuracy_nocolors)
                rgb = '1 1 1';
        else
                Accuracy_LoadColors();
 
+       float oldposx = pos.x;
+       vector tmpos = pos;
+
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
                self = get_weaponinfo(i);
                if (!self.weapon)
                        continue;
-               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];
 
+               if(weapon_stats < 0 && !(weapons_stat & WepSet_FromWeapon(i) || weapons_inmap & WepSet_FromWeapon(i)))
+                       continue;
+
                float weapon_alpha;
                if(weapon_stats >= 0)
                        weapon_alpha = scoreboard_alpha_fg;
@@ -1045,7 +1068,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        weapon_alpha = 0.2 * scoreboard_alpha_fg;
 
                // weapon icon
-               drawpic_aspect_skin(pos, self.model2, '1 0 0' * weapon_width + '0 1 0' * weapon_height, '1 1 1', weapon_alpha, DRAWFLAG_NORMAL);
+               drawpic_aspect_skin(tmpos, 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;
@@ -1060,11 +1083,13 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
                        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);
+                       drawstring(tmpos + '1 0 0' * padding + '0 1 0' * weapon_height, s, '1 1 0' * fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
                }
+               tmpos.x += weapon_width * rows;
                pos.x += weapon_width * rows;
-               if(rows == 2 && i == 6) {
-                       pos.x -= sbwidth;
+               if(rows == 2 && i == count_perrow) {
+                       tmpos.x = oldposx;
+                       tmpos.y += height;
                        pos.y += height;
                }
        }
@@ -1077,7 +1102,7 @@ vector HUD_DrawScoreboardAccuracyStats(vector pos, vector rgb, vector bg_size)
        pos.x -= sbwidth;
        pos.y += height;
 
-       pos.y +=  1.25 * hud_fontsize.y;
+       pos.y += 1.25 * hud_fontsize.y;
        return pos;
 }
 
index b488df1cfd709edacf36401d42990adbd4f4ed93..fa52737631f93bf0599097b28ae9041b71142a27 100644 (file)
@@ -109,9 +109,9 @@ const int STAT_OK_AMMO_CHARGE         = 85;
 const int STAT_OK_AMMO_CHARGEPOOL     = 86;
 const int STAT_FROZEN                 = 87;
 const int STAT_REVIVE_PROGRESS        = 88;
-// 89 empty?
-// 90 empty?
-// 91 empty?
+const int STAT_WEAPONSINMAP           = 89;
+const int STAT_WEAPONSINMAP2          = 90;
+const int STAT_WEAPONSINMAP3          = 91;
 // 92 empty?
 // 93 empty?
 // 94 empty?
index 36f08eff9017bd322cea18f6fc36f8590c714a81..72c92471a9c537435aaeb29ed20072303c7700a3 100644 (file)
@@ -91,6 +91,16 @@ void WepSet_AddStat()
 #endif
 #endif
 }
+void WepSet_AddStat_InMap()
+{
+       addstat(STAT_WEAPONSINMAP, AS_INT, weaponsinmap_x);
+#if WEP_MAXCOUNT > 24
+       addstat(STAT_WEAPONSINMAP2, AS_INT, weaponsinmap_y);
+#if WEP_MAXCOUNT > 48
+       addstat(STAT_WEAPONSINMAP3, AS_INT, weaponsinmap_z);
+#endif
+#endif
+}
 void WriteWepSet(float dst, WepSet w)
 {
 #if WEP_MAXCOUNT > 48
@@ -115,6 +125,18 @@ WepSet WepSet_GetFromStat()
 #endif
        return w;
 }
+WepSet WepSet_GetFromStat_InMap()
+{
+       WepSet w = '0 0 0';
+       w_x = getstati(STAT_WEAPONSINMAP);
+#if WEP_MAXCOUNT > 24
+       w_y = getstati(STAT_WEAPONSINMAP2);
+#if WEP_MAXCOUNT > 48
+       w_z = getstati(STAT_WEAPONSINMAP3);
+#endif
+#endif
+       return w;
+}
 WepSet ReadWepSet()
 {
 #if WEP_MAXCOUNT > 48
index 154f8167e91aa5c7faa2e7be866335c89d4031cf..eab3b0a5ad2879f8f2e2048ff9703444c8062e87 100644 (file)
@@ -55,10 +55,12 @@ typedef vector WepSet;
 WepSet WepSet_FromWeapon(int a);
 #ifdef SVQC
 void WepSet_AddStat();
+void WepSet_AddStat_InMap();
 void WriteWepSet(float dest, WepSet w);
 #endif
 #ifdef CSQC
 WepSet WepSet_GetFromStat();
+WepSet WepSet_GetFromStat_InMap();
 WepSet ReadWepSet();
 #endif
 
index 33491ff0e7bfa49cbbaae33e434094f83c11c084..8ca2f6c35f8771d2b58995bed78c0ca9442ec49a 100644 (file)
@@ -2226,6 +2226,8 @@ void PlayerPreThink (void)
        self.stat_allow_oldvortexbeam = autocvar_g_allow_oldvortexbeam;
        self.stat_leadlimit = autocvar_leadlimit;
 
+       self.weaponsinmap = weaponsInMap;
+
        if(frametime)
        {
                // physics frames: update anticheat stuff
index 9637cc67c8496dd02032e99d3b5a864dfd9211e2..1fbc8d09a50587b2c30094d4fabe2bf8bde001b5 100644 (file)
@@ -255,6 +255,8 @@ void FixClientCvars(entity e);
 // WEAPONTODO: remove this
 WepSet weaponsInMap;
 
+.WepSet weaponsinmap;
+
 .float respawn_countdown; // next number to count
 
 float bot_waypoints_for_items;
index 9c2003cc19d506afbe5de24d4b7e5adf0c7bdacb..c913e86e75a7d5b72346fe6c67b5dbca7f3ea65c 100644 (file)
@@ -785,6 +785,7 @@ void spawnfunc_worldspawn (void)
        WeaponStats_Init();
 
        WepSet_AddStat();
+       WepSet_AddStat_InMap();
        addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
        addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
        addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);