]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge remote-tracking branch 'origin/master' into fruitiex/playerstats
authorFruitieX <fruitiex@gmail.com>
Sun, 22 May 2011 18:42:44 +0000 (21:42 +0300)
committerFruitieX <fruitiex@gmail.com>
Sun, 22 May 2011 18:42:44 +0000 (21:42 +0300)
qcsrc/server/accuracy.qc
qcsrc/server/cl_client.qc
qcsrc/server/cl_player.qc
qcsrc/server/playerstats.qc
qcsrc/server/playerstats.qh

index 4d63fd82002dcb9ea176cfabdedd43f3d4bd5db1..95ddf78e1f9e498ec889ebe4ef8c985c1b000f5b 100644 (file)
@@ -1,8 +1,11 @@
-.entity accuracy;
 .float accuracy_hit[WEP_MAXCOUNT];
 .float accuracy_fired[WEP_MAXCOUNT];
+.float accuracy_cnt_hit[WEP_MAXCOUNT];
+.float accuracy_cnt_fired[WEP_MAXCOUNT];
 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_hit);
 FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_fired);
+FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_cnt_hit);
+FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_cnt_fired);
 
 float accuracy_byte(float n, float d)
 {
@@ -74,6 +77,11 @@ void accuracy_set(entity e, float w, float fired, float hit)
        b = accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w]));
        a.(accuracy_hit[w]) = hit;
        a.(accuracy_fired[w]) = fired;
+
+    if(hit)
+        a.(accuracy_cnt_hit[w]) = 1;
+    a.(accuracy_cnt_fired[w]) = 1;
+
        if(b == accuracy_byte(hit, fired))
                return;
        w = pow(2, w);
@@ -84,6 +92,9 @@ void accuracy_set(entity e, float w, float fired, float hit)
                                a.SendFlags |= w;
 }
 
+.float hit_time;
+.float fired_time;
+
 void accuracy_add(entity e, float w, float fired, float hit)
 {
        entity a;
@@ -97,6 +108,19 @@ void accuracy_add(entity e, float w, float fired, float hit)
                a.(accuracy_hit[w]) += hit;
        if(fired)
                a.(accuracy_fired[w]) += fired;
+
+    if(hit && a.hit_time != time) // only run this once per frame
+    {
+        a.(accuracy_cnt_hit[w]) += 1;
+        a.hit_time = time;
+    }
+
+    if(fired && a.fired_time != time) // only run this once per frame
+    {
+        a.(accuracy_cnt_fired[w]) += 1;
+        a.fired_time = time;
+    }
+
        if(b == accuracy_byte(a.(accuracy_hit[w]), a.(accuracy_fired[w])))
                return;
        w = pow(2, w);
index 561b755c9694b9d2ff05f95fc946dfbd7df31256..3d6adb688214d1866f46f504620796ea246bc512 100644 (file)
@@ -1639,6 +1639,9 @@ void ClientConnect (void)
 
        self.playerid = (playerid_last = playerid_last + 1);
 
+    if(clienttype(self) == CLIENTTYPE_BOT)
+        PlayerStats_AddPlayer(self);
+
        if(autocvar_sv_eventlog)
                GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
 
index c4bcded2805f99d4546ff023ddb27dee68b29eec..04ce7c0d35016166119514aaa3c99e80101638dc 100644 (file)
@@ -1,3 +1,7 @@
+.entity accuracy;
+.float accuracy_frags[WEP_MAXCOUNT];
+FTEQCC_YOU_SUCK_THIS_IS_NOT_UNREFERENCED(accuracy_frags);
+
 float weaponstats_buffer;
 
 void WeaponStats_Init()
@@ -615,6 +619,14 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                race_PreDie();
                DropAllRunes(self);
 
+        // increment frag counter for used weapon type
+        float w;
+        w = DEATH_WEAPONOF(deathtype);
+        if(WEP_VALID(w))
+        if(self.classname == "player")
+        if(self != attacker)
+        attacker.accuracy.(accuracy_frags[w-1]) += 1;
+
                if(deathtype == DEATH_HURTTRIGGER && g_freezetag)
                {
                        PutClientInServer();
index b3ed92210408a1597e2c0ad62a1154fd72aef337..46490a1b6d4983704794f02d792b2514c3e8aa47 100644 (file)
@@ -1,4 +1,5 @@
 float playerstats_db;
+string teamstats_last;
 string playerstats_last;
 string events_last;
 .float playerstats_addedglobalinfo;
@@ -22,6 +23,23 @@ void PlayerStats_Init()
        PlayerStats_AddEvent(PLAYERSTATS_MATCHES);
        PlayerStats_AddEvent(PLAYERSTATS_JOINS);
        PlayerStats_AddEvent(PLAYERSTATS_SCOREBOARD_VALID);
+       PlayerStats_AddEvent(PLAYERSTATS_RANK);
+
+    // accuracy stats
+    entity w;
+    float i;
+    for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+    {
+        w = get_weaponinfo(i);
+
+        PlayerStats_AddEvent(strcat("acc-", w.netname, "-hit"));
+        PlayerStats_AddEvent(strcat("acc-", w.netname, "-fired"));
+
+        PlayerStats_AddEvent(strcat("acc-", w.netname, "-cnt-hit"));
+        PlayerStats_AddEvent(strcat("acc-", w.netname, "-cnt-fired"));
+
+        PlayerStats_AddEvent(strcat("acc-", w.netname, "-frags"));
+    }
 
        PlayerStats_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3);
        PlayerStats_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5);
@@ -48,7 +66,7 @@ void PlayerStats_AddPlayer(entity e)
                e.playerstats_id = strzone(sprintf("bot#%d", e.playerid));
        else
                e.playerstats_id = strzone(sprintf("player#%d", e.playerid));
-       
+
        string key;
        key = sprintf("%s:*", e.playerstats_id);
        
@@ -67,26 +85,26 @@ void PlayerStats_AddPlayer(entity e)
        }
 }
 
-void PlayerStats_AddTeam(float t)
+void PlayerStats_AddTeam(float t) // TODO: doesn't this remain unused?
 {
        if(playerstats_db < 0)
                return;
 
        string key;
-       key = sprintf("team#%d:*", t);
+       key = sprintf("%d", t);
        
        string p;
        p = db_get(playerstats_db, key);
        if(p == "")
        {
-               if(playerstats_last)
+               if(teamstats_last)
                {
-                       db_put(playerstats_db, key, playerstats_last);
-                       strunzone(playerstats_last);
+                       db_put(playerstats_db, key, teamstats_last);
+                       strunzone(teamstats_last);
                }
                else
                        db_put(playerstats_db, key, "#");
-               playerstats_last = strzone(sprintf("team%d", t));
+               teamstats_last = strzone(key);
        }
 }
 
@@ -126,7 +144,7 @@ void PlayerStats_Event(entity e, string event_id, float value)
        db_put(playerstats_db, key, ftos(val));
 }
 
-void PlayerStats_TeamScore(float t, string event_id, float value)
+void PlayerStats_TeamScore(float t, string event_id, float value) // TODO: doesn't this remain unused?
 {
        string key;
        float val;
@@ -158,8 +176,10 @@ void PlayerStats_Sent_URI_Get_Callback(float id, float status, string data)
        M: map name
        S: "hostname" of the server
        C: number of "unpure" cvar changes
-       P: player ID of an existing player; this also sets the owner for all following "n" and "e" lines (lower case!)
+    W: winning team ID
+       P: player ID of an existing player; this also sets the owner for all following "n", "e" and "t" lines (lower case!)
        n: nickname of the player (optional)
+    t: team ID
        e: followed by an event name, a space, and the event count/score
                event names can be:
                        alivetime: total playing time of the player
@@ -170,6 +190,12 @@ void PlayerStats_Sent_URI_Get_Callback(float id, float status, string data)
                        total-<scoreboardname>: total score of that scoreboard item
                        scoreboard-<scoreboardname>: end-of-game score of that scoreboard item (can differ in non-team games)
                        achievement-<achievementname>: achievement counters
+            rank <number>: rank of player
+            acc-<weapon netname>-hit: total damage dealt
+            acc-<weapon netname>-fired: total damage that all fired projectiles *could* have dealt
+            acc-<weapon netname>-cnt-hit: amount of shots that actually hit
+            acc-<weapon netname>-cnt-fired: amount of fired shots
+            acc-<weapon netname>-frags: amount of frags dealt by weapon
 */
 
 //#NO AUTOCVARS START
@@ -177,7 +203,7 @@ void PlayerStats_Shutdown()
 {
        string p, pn;
        string e, en;
-       string nn;
+       string nn, tt;
        float b;
        float i;
        string uri;
@@ -202,21 +228,26 @@ void PlayerStats_Shutdown()
                bufstr_set(b, i++, sprintf("M %s", GetMapname()));
                bufstr_set(b, i++, sprintf("S %s", cvar_string("hostname")));
                bufstr_set(b, i++, sprintf("C %d", cvar_purechanges_count));
-               for(p = playerstats_last; (pn = db_get(playerstats_db, sprintf("%s:*", p))) != ""; p = pn)
-               {
-                       bufstr_set(b, i++, sprintf("P %s", p));
-                       nn = db_get(playerstats_db, sprintf("%s:_netname", p));
-                       if(nn != "")
-                               bufstr_set(b, i++, sprintf("n %s", nn));
-                       for(e = events_last; (en = db_get(playerstats_db, sprintf("*:%s", e))) != ""; e = en)
-                       {
-                               float v;
-                               v = stof(db_get(playerstats_db, sprintf("%s:%s", p, e)));
-                               if(v != 0)
-                                       bufstr_set(b, i++, sprintf("e %s %g", e, v));
-                       }
-               }
-               bufstr_set(b, i++, "");
+        for(p = playerstats_last; (pn = db_get(playerstats_db, sprintf("%s:*", p))) != ""; p = pn)
+        {
+            bufstr_set(b, i++, sprintf("P %s", p));
+            nn = db_get(playerstats_db, sprintf("%s:_netname", p));
+            if(nn != "")
+                bufstr_set(b, i++, sprintf("n %s", nn));
+            if(teams_matter)
+            {
+                tt = db_get(playerstats_db, sprintf("%s:_team", p));
+                bufstr_set(b, i++, sprintf("t %s", tt));
+            }
+            for(e = events_last; (en = db_get(playerstats_db, sprintf("*:%s", e))) != ""; e = en)
+            {
+                float v;
+                v = stof(db_get(playerstats_db, sprintf("%s:%s", p, e)));
+                if(v != 0)
+                    bufstr_set(b, i++, sprintf("e %s %g", e, v));
+            }
+        }
+        bufstr_set(b, i++, "");
 
                if(autocvar_g_playerstats_debug)
                {
@@ -257,6 +288,9 @@ void PlayerStats_AddGlobalInfo(entity p)
        if(p.cvar_cl_allow_uid2name == 1 || clienttype(p) == CLIENTTYPE_BOT)
                db_put(playerstats_db, sprintf("%s:_netname", p.playerstats_id), p.netname);
 
+    if(teams_matter)
+               db_put(playerstats_db, sprintf("%s:_team", p.playerstats_id), ftos(p.team));
+
        if(p.alivetime > 0)
                PlayerStats_Event(p, PLAYERSTATS_JOINS, 1);
 
@@ -264,17 +298,40 @@ void PlayerStats_AddGlobalInfo(entity p)
        p.playerstats_id = string_null;
 }
 
+void PlayerStats_Accuracy(entity p)
+{
+    entity a, w;
+    a = p.accuracy;
+    float i;
+
+    for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+    {
+        w = get_weaponinfo(i);
+
+        PlayerStats_Event(p, strcat("acc-", w.netname, "-hit"), a.accuracy_hit[i-1]);
+        PlayerStats_Event(p, strcat("acc-", w.netname, "-fired"), a.accuracy_fired[i-1]);
+
+        PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-hit"), a.accuracy_cnt_hit[i-1]);
+        PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-fired"), a.accuracy_cnt_fired[i-1]);
+
+        PlayerStats_Event(p, strcat("acc-", w.netname, "-frags"), a.accuracy_frags[i-1]);
+    }
+}
+
 void PlayerStats_EndMatch(float finished)
 {
-       entity p;
+       entity p, winner;
+    winner = PlayerScore_Sort(score_dummyfield);
        FOR_EACH_PLAYER(p)
        {
                PlayerScore_PlayerStats(p);
+               PlayerStats_Accuracy(p);
                PlayerStats_Event(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
                if(finished)
                {
                        PlayerStats_Event(p, PLAYERSTATS_WINS, p.winning);
                        PlayerStats_Event(p, PLAYERSTATS_MATCHES, 1);
+                       PlayerStats_Event(p, PLAYERSTATS_RANK, p.score_dummyfield);
                }
        }
 }
index baaddcbb661ba9d6826a469cb4fd659d71a9d407..f546e560590025c124a4615905e07a2c15252a3e 100644 (file)
@@ -4,6 +4,7 @@ string PLAYERSTATS_WINS = "wins";
 string PLAYERSTATS_MATCHES = "matches";
 string PLAYERSTATS_JOINS = "joins";
 string PLAYERSTATS_SCOREBOARD_VALID = "scoreboardvalid";
+string PLAYERSTATS_RANK = "rank";
 
 string PLAYERSTATS_TOTAL = "total-";
 string PLAYERSTATS_SCOREBOARD = "scoreboard-";