]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/playerstats.qc
Measure startup time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / playerstats.qc
index 3a44d71905ec36f071f671f789364f4cfd270c74..7e99bebea7480cfe32a9e32e670b3e58945f2a5e 100644 (file)
@@ -1,11 +1,9 @@
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
-       #include "../dpdefs/progsdefs.qh"
-    #include "../dpdefs/dpextensions.qh"
     #include "constants.qh"
     #include "util.qh"
-    #include "weapons/all.qh"
+    #include <common/weapons/all.qh>
     #include "../server/weapons/accuracy.qh"
     #include "../server/defs.qh"
     #include "playerstats.qh"
@@ -13,7 +11,7 @@
 #endif
 
 #ifdef SVQC
-void PlayerStats_Prematch(void)
+void PlayerStats_Prematch()
 {
        //foobar
 }
@@ -30,7 +28,7 @@ void PlayerStats_GameReport_AddPlayer(entity e)
        else if(IS_BOT_CLIENT(e))
                { s = sprintf("bot#%g#%s", skill, e.cleanname); }
 
-       if((s == "") || find(world, playerstats_id, s)) // already have one of the ID - next one can't be tracked then!
+       if((s == "") || find(NULL, playerstats_id, s)) // already have one of the ID - next one can't be tracked then!
        {
                if(IS_BOT_CLIENT(e))
                        { s = sprintf("bot#%d", e.playerid); }
@@ -108,23 +106,16 @@ float PlayerStats_GameReport_Event(string prefix, string event_id, float value)
 
 void PlayerStats_GameReport_Accuracy(entity p)
 {
-       int i;
-
-       for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-       {
-               entity w = get_weaponinfo(i);
-
-               #define ACCMAC(suffix,field) \
-                       PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", w.netname, suffix), p.accuracy.(field[i-1]));
-
+       #define ACCMAC(suffix, field) \
+               PS_GR_P_ADDVAL(p, sprintf("acc-%s-%s", it.netname, suffix), p.accuracy.(field[i-1]));
+       FOREACH(Weapons, it != WEP_Null, {
                ACCMAC("hit", accuracy_hit)
                ACCMAC("fired", accuracy_fired)
                ACCMAC("cnt-hit", accuracy_cnt_hit)
                ACCMAC("cnt-fired", accuracy_cnt_fired)
                ACCMAC("frags", accuracy_frags)
-
-               #undef ACCMAC
-       }
+       });
+       #undef ACCMAC
 }
 
 void PlayerStats_GameReport_FinalizePlayer(entity p)
@@ -172,35 +163,33 @@ void PlayerStats_GameReport(float finished)
        PlayerScore_Sort(scoreboard_pos, 1, 1, 1);
        if(teamplay) { PlayerScore_TeamStats(); }
 
-       entity p;
-       FOR_EACH_CLIENT(p)
-       {
+       FOREACH_CLIENT(true, {
                // add personal score rank
-               PS_GR_P_ADDVAL(p, PLAYERSTATS_RANK, p.score_dummyfield);
+               PS_GR_P_ADDVAL(it, PLAYERSTATS_RANK, it.score_dummyfield);
 
                // scoreboard data
-               if(p.scoreboard_pos)
+               if(it.scoreboard_pos)
                {
                        // scoreboard is valid!
-                       PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
+                       PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_VALID, 1);
 
                        // add scoreboard position
-                       PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
+                       PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_POS, it.scoreboard_pos);
 
                        // add scoreboard data
-                       PlayerScore_PlayerStats(p);
+                       PlayerScore_PlayerStats(it);
 
                        // if the match ended normally, add winning info
                        if(finished)
                        {
-                               PS_GR_P_ADDVAL(p, PLAYERSTATS_WINS, p.winning);
-                               PS_GR_P_ADDVAL(p, PLAYERSTATS_MATCHES, 1);
+                               PS_GR_P_ADDVAL(it, PLAYERSTATS_WINS, it.winning);
+                               PS_GR_P_ADDVAL(it, PLAYERSTATS_MATCHES, 1);
                        }
                }
 
                // collect final player information
-               PlayerStats_GameReport_FinalizePlayer(p);
-       }
+               PlayerStats_GameReport_FinalizePlayer(it);
+       });
 
        if(autocvar_g_playerstats_gamereport_uri != "")
        {
@@ -209,7 +198,7 @@ void PlayerStats_GameReport(float finished)
                        autocvar_g_playerstats_gamereport_uri,
                        FILE_APPEND,
                        PlayerStats_GameReport_Handler,
-                       world
+                       NULL
                );
        }
        else
@@ -242,17 +231,13 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK);
 
                // accuracy stats
-               entity w;
-               float i;
-               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       w = get_weaponinfo(i);
-                       PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-hit"));
-                       PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-fired"));
-                       PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-hit"));
-                       PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-cnt-fired"));
-                       PlayerStats_GameReport_AddEvent(strcat("acc-", w.netname, "-frags"));
-               }
+               FOREACH(Weapons, it != WEP_Null, {
+                       PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-hit"));
+                       PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-fired"));
+                       PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-hit"));
+                       PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-cnt-fired"));
+                       PlayerStats_GameReport_AddEvent(strcat("acc-", it.netname, "-frags"));
+               });
 
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_3);
                PlayerStats_GameReport_AddEvent(PLAYERSTATS_ACHIEVEMENT_KILL_SPREE_5);
@@ -442,7 +427,7 @@ void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
                                PS_B_IN_DB = db_create();
 
                        // now request the information
-                       uri = strcat(uri, "/player/", uri_escape(uri_escape(joiningplayer.crypto_idfp)), "/elo.txt");
+                       uri = strcat(uri, "/player/", uri_escape(uri_escape(uri_escape(joiningplayer.crypto_idfp))), "/elo.txt");
                        LOG_TRACE("Retrieving playerstats from URL: ", uri, "\n");
                        url_single_fopen(
                                uri,
@@ -469,12 +454,10 @@ void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
                // server has this disabled, kill the DB and set status to idle
                if(PS_B_IN_DB >= 0)
                {
-                       entity player;
-
                        db_close(PS_B_IN_DB);
                        PS_B_IN_DB = -1;
 
-                       FOR_EACH_REALCLIENT(player) { player.playerstats_basicstatus = PS_B_STATUS_IDLE; }
+                       FOREACH_CLIENT(IS_REAL_CLIENT(it), it.playerstats_basicstatus = PS_B_STATUS_IDLE);
                }
        }
 }
@@ -637,7 +620,7 @@ void PlayerStats_PlayerDetail_AddItem(string event, string data)
        LOG_TRACE("Added item ", sprintf("#%s", event), "=", data, " to PS_D_IN_DB\n");
 }
 
-void PlayerStats_PlayerDetail(void)
+void PlayerStats_PlayerDetail()
 {
        // http://stats.xonotic.org/player/me
        if((autocvar_g_playerstats_playerdetail_uri != "") && (crypto_getmyidstatus(0) > 0))
@@ -652,7 +635,7 @@ void PlayerStats_PlayerDetail(void)
                        autocvar_g_playerstats_playerdetail_uri,
                        FILE_APPEND,
                        PlayerStats_PlayerDetail_Handler,
-                       world
+                       NULL
                );
 
                PlayerStats_PlayerDetail_Status = PS_D_STATUS_WAITING;
@@ -670,7 +653,7 @@ void PlayerStats_PlayerDetail(void)
        }
 }
 
-void PlayerStats_PlayerDetail_CheckUpdate(void)
+void PlayerStats_PlayerDetail_CheckUpdate()
 {
        // determine whether we should retrieve playerdetail information again
        float gamecount = cvar("cl_matchcount");
@@ -1030,7 +1013,7 @@ void PlayerInfo_Details()
                //uri = strcat(uri, "/player/", uri_escape(crypto_getmyidfp(0)));
                 uri = strcat(uri, "/player/me");
                print("Retrieving playerstats from URL: ", uri, "\n");
-               url_single_fopen(uri, FILE_APPEND, PlayerInfo_ready, world);
+               url_single_fopen(uri, FILE_APPEND, PlayerInfo_ready, NULL);
        }
 }
 #endif