]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/scores.qc
Merge branch 'master' into Mario/target_teleporter_v2
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores.qc
index c66d23ca7c887d10a43dda357177f70ec2b0453c..266f7734b660bae45bad90f29514a869ef182b46 100644 (file)
@@ -1,9 +1,11 @@
 #include "scores.qh"
 
 #include "command/common.qh"
-#include "mutators/all.qh"
+#include "mutators/_mod.qh"
+#include <common/net_linked.qh>
 #include "../common/playerstats.qh"
 #include "../common/teams.qh"
+#include <common/scores.qh>
 
 .entity scorekeeper;
 entity teamscorekeepers[16];
@@ -98,26 +100,26 @@ float TeamScore_AddToTeam(float t, float scorefield, float score)
 {
        entity s;
 
-       if(gameover)
+       if(game_stopped)
                score = 0;
 
        if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
        if(t <= 0 || t >= 16)
        {
-               if(gameover)
+               if(game_stopped)
                        return 0;
                error("Adding score to invalid team!");
        }
        s = teamscorekeepers[t - 1];
        if(!s)
        {
-               if(gameover)
+               if(game_stopped)
                        return 0;
                error("Adding score to unknown team!");
        }
        if(score)
                if(teamscores_label(scorefield) != "")
-                       s.SendFlags |= pow(2, scorefield);
+                       s.SendFlags |= (2 ** scorefield);
        return (s.(teamscores(scorefield)) += score);
 }
 
@@ -185,7 +187,7 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf)
 {
        float i;
        WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
-       WriteInt24_t(MSG_ENTITY, MapInfo_LoadedGametype);
+       WriteRegistered(Gametypes, MSG_ENTITY, MapInfo_LoadedGametype);
        FOREACH(Scores, true, {
                WriteString(MSG_ENTITY, scores_label(it));
                WriteByte(MSG_ENTITY, scores_flags(it));
@@ -198,7 +200,7 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf)
        return true;
 }
 
-void ScoreInfo_Init(float teams)
+void ScoreInfo_Init(int teams)
 {
        if(scores_initialized)
        {
@@ -209,13 +211,13 @@ void ScoreInfo_Init(float teams)
                scores_initialized = new_pure(ent_client_scoreinfo);
                Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity);
        }
-       if(teams >= 1)
+       if(teams & BIT(0))
                TeamScore_Spawn(NUM_TEAM_1, "Red");
-       if(teams >= 2)
+       if(teams & BIT(1))
                TeamScore_Spawn(NUM_TEAM_2, "Blue");
-       if(teams >= 3)
+       if(teams & BIT(2))
                TeamScore_Spawn(NUM_TEAM_3, "Yellow");
-       if(teams >= 4)
+       if(teams & BIT(3))
                TeamScore_Spawn(NUM_TEAM_4, "Pink");
 }
 
@@ -260,12 +262,13 @@ float PlayerScore_Clear(entity player)
 
        if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
 
-       sk = player.scorekeeper;
+       sk = CS(player).scorekeeper;
        FOREACH(Scores, true, {
                if(sk.(scores(it)) != 0)
                        if(scores_label(it) != "")
-                               sk.SendFlags |= pow(2, i % 16);
-               sk.(scores(it)) = 0;
+                               sk.SendFlags |= (2 ** (i % 16));
+               if(i != SP_ELO.m_id)
+                       sk.(scores(it)) = 0;
        });
 
        return 1;
@@ -276,13 +279,14 @@ void Score_ClearAll()
        entity sk;
        float t;
        FOREACH_CLIENTSLOT(true, {
-               sk = it.scorekeeper;
+               sk = CS(it).scorekeeper;
                if (!sk) continue;
                FOREACH(Scores, true, {
                        if(sk.(scores(it)) != 0)
                                if(scores_label(it) != "")
-                                       sk.SendFlags |= pow(2, i % 16);
-                       sk.(scores(it)) = 0;
+                                       sk.SendFlags |= (2 ** (i % 16));
+                       if(i != SP_ELO.m_id)
+                               sk.(scores(it)) = 0;
                });
        });
        for(t = 0; t < 16; ++t)
@@ -294,7 +298,7 @@ void Score_ClearAll()
                {
                        if(sk.(teamscores(j)) != 0)
                                if(teamscores_label(j) != "")
-                                       sk.SendFlags |= pow(2, j);
+                                       sk.SendFlags |= (2 ** j);
                        sk.(teamscores(j)) = 0;
                }
        }
@@ -302,20 +306,20 @@ void Score_ClearAll()
 
 void PlayerScore_Attach(entity player)
 {
-       if(player.scorekeeper)
+       if(CS(player).scorekeeper)
                error("player already has a scorekeeper");
        entity sk = new_pure(scorekeeper);
        sk.owner = player;
        Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity);
-       player.scorekeeper = sk;
+       CS(player).scorekeeper = sk;
 }
 
 void PlayerScore_Detach(entity player)
 {
-       if(!player.scorekeeper)
+       if(!CS(player).scorekeeper)
                error("player has no scorekeeper");
-       remove(player.scorekeeper);
-       player.scorekeeper = NULL;
+       delete(CS(player).scorekeeper);
+       CS(player).scorekeeper = NULL;
 }
 
 float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
@@ -323,22 +327,25 @@ float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
        bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score, player);
        score = M_ARGV(1, float);
 
-       if(gameover)
+       if(game_stopped)
        if(!mutator_returnvalue)
                score = 0;
 
        if(!scores_initialized) return 0; // FIXME remove this when everything uses this system
-       entity s = player.scorekeeper;
+       entity s = CS(player).scorekeeper;
        if(!s)
        {
-               if(gameover)
+               if(game_stopped)
                        return 0;
-               LOG_WARNING("Adding score to unknown player!");
+               LOG_WARN("Adding score to unknown player!");
                return 0;
        }
-       if(score)
-               if(scores_label(scorefield) != "")
-                       s.SendFlags |= pow(2, scorefield.m_id % 16);
+       if(!score)
+       {
+               return s.(scores(scorefield));
+       }
+       if(scores_label(scorefield) != "")
+               s.SendFlags |= (2 ** (scorefield.m_id % 16));
        if(!warmup_stage)
                PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
        return (s.(scores(scorefield)) += score);
@@ -447,8 +454,8 @@ void WinningConditionHelper(entity this)
                WinningConditionHelper_second = NULL;
                winnerscorekeeper = NULL;
                secondscorekeeper = NULL;
-               FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
-                       sk = it.scorekeeper;
+               FOREACH_CLIENT(IS_PLAYER(it), {
+                       sk = CS(it).scorekeeper;
                        c = PlayerScore_Compare(winnerscorekeeper, sk, 1);
                        if(c < 0)
                        {
@@ -466,7 +473,7 @@ void WinningConditionHelper(entity this)
                                        secondscorekeeper = sk;
                                }
                        }
-               ));
+               });
 
                WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
                if(WinningConditionHelper_equality)
@@ -508,7 +515,7 @@ void WinningConditionHelper(entity this)
                strunzone(worldstatus);
        worldstatus = strzone(s);
 
-       FOREACH_CLIENT(true, LAMBDA(
+       FOREACH_CLIENT(true, {
                string s = "";
                if(fullstatus)
                {
@@ -528,7 +535,7 @@ void WinningConditionHelper(entity this)
                if(it.clientstatus)
                        strunzone(it.clientstatus);
                it.clientstatus = strzone(s);
-       ));
+       });
 }
 
 string GetScoreLogLabel(string label, float fl)
@@ -582,7 +589,7 @@ string GetPlayerScoreString(entity pl, float shortString)
         });
                out = substring(out, 0, strlen(out) - 1);
        }
-       else if((sk = pl.scorekeeper))
+       else if((sk = CS(pl).scorekeeper))
        {
                FOREACH(Scores, true, {
                        if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
@@ -677,7 +684,7 @@ float PlayerTeamScore_Compare(entity p1, entity p2, float teams, float strict)
                        return 0;
        }
 
-       return PlayerScore_Compare(p1.scorekeeper, p2.scorekeeper, strict);
+       return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict);
 }
 
 entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators)
@@ -687,9 +694,9 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat
 
        plist = NULL;
 
-       FOREACH_CLIENT(true, LAMBDA(it.(field) = 0));
+       FOREACH_CLIENT(true, { it.(field) = 0; });
 
-       FOREACH_CLIENT(it.scorekeeper,
+       FOREACH_CLIENT(CS(it).scorekeeper,
        {
                if(nospectators)
                        if(it.frags == FRAGS_SPECTATOR)
@@ -746,7 +753,7 @@ float TeamScore_GetCompareValue(float t)
 
        if(t <= 0 || t >= 16)
        {
-               if(gameover)
+               if(game_stopped)
                        return 0;
                error("Reading score of invalid team!");
        }
@@ -821,9 +828,9 @@ void Score_NicePrint_Player(entity to, entity p, float w)
        float fl, sc;
        s = "  ";
 
-       sk = p.scorekeeper;
+       sk = CS(p).scorekeeper;
 
-       s = strcat(s, p.netname);
+       s = strcat(s, playername(p, false));
        for (;;)
        {
                i = strlennocol(s) - NAMEWIDTH;
@@ -855,7 +862,7 @@ void Score_NicePrint_Spectators(entity to)
 
 void Score_NicePrint_Spectator(entity to, entity p)
 {
-       print_to(to, strcat("  ", p.netname));
+       print_to(to, strcat("  ", playername(p, false)));
 }
 
 .float score_dummyfield;
@@ -887,17 +894,17 @@ void Score_NicePrint(entity to)
        }
 
        t = 0;
-       FOREACH_CLIENT(!IS_PLAYER(it), LAMBDA(
+       FOREACH_CLIENT(!IS_PLAYER(it), {
                if (!t)
                        Score_NicePrint_Spectators(to);
                Score_NicePrint_Spectator(to, it);
                t = 1;
-       ));
+       });
 }
 
 void PlayerScore_PlayerStats(entity p)
 {
-       entity s = p.scorekeeper;
+       entity s = CS(p).scorekeeper;
        FOREACH(Scores, true, {
                if(s.(scores(it)) != 0)
                        if(scores_label(it) != "")