]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/scores.qc
Merge branch 'master' into z411/bai-server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores.qc
index 5bac7240faa7bfb37be24541a8ab0a4957a3d74f..83c5d5ee5339e96aaef7405e4206837655767d6f 100644 (file)
@@ -26,37 +26,32 @@ float teamscores_flags_primary;
 var .float scores_secondary;
 float scores_flags_secondary;
 
-vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, bool strict) // returns: cmp value, best prio
+// returns cmp value
+int ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, int previous)
 {
        if(fieldflags & SFL_NOT_SORTABLE) // column does not sort
                return previous;
-       if(!strict && !(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort
-               return previous;
-       if((fieldflags & SFL_SORT_PRIO_MASK) < previous.y)
-               return previous;
        if (t1.(field) == t2.(field))
                return previous;
 
-       previous.y = fieldflags & SFL_SORT_PRIO_MASK;
-
        if(fieldflags & SFL_ZERO_IS_WORST)
        {
                if (t1.(field) == 0)
                {
-                       previous.x = -1;
+                       previous = -1;
                        return previous;
                }
                else if (t2.(field) == 0)
                {
-                       previous.x = +1;
+                       previous = +1;
                        return previous;
                }
        }
 
        if (fieldflags & SFL_LOWER_IS_BETTER)
-               previous.x = (t2.(field) - t1.(field));
+               previous = (t2.(field) - t1.(field));
        else
-               previous.x = (t1.(field) - t2.(field));
+               previous = (t1.(field) - t2.(field));
 
        return previous;
 }
@@ -143,7 +138,8 @@ float TeamScore_Add(entity player, float scorefield, float score)
        return TeamScore_AddToTeam(player.team, scorefield, score);
 }
 
-float TeamScore_Compare(entity t1, entity t2, bool strict)
+// strict: compare others fields too besides primary and secondary
+int TeamScore_Compare(entity t1, entity t2, bool strict)
 {
        if(!t1 || !t2) return (!t2) - !t1;
 
@@ -152,19 +148,18 @@ float TeamScore_Compare(entity t1, entity t2, bool strict)
                error("MAX_TEAMSCORE > 2 not supported");
 
        // first compare primary, then others (don't check secondary flag since there are only 2 teamscores)
-       vector result = '0 0 0';
+       int result = 0;
        int i = boolean(teamscores_primary && teamscores_primary == teamscores(1));
-       result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result, strict);
-       if (result.x == 0)
+       result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result);
+       if (result == 0 && strict)
        {
                i = (i + 1) % MAX_TEAMSCORE;
-               result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result, strict);
+               result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result);
+               if (result == 0)
+                       result = t1.team - t2.team;
        }
 
-       if (result.x == 0 && strict)
-               result.x = t1.team - t2.team;
-
-       return result.x;
+       return result;
 }
 
 /*
@@ -228,7 +223,7 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf)
        WriteByte(MSG_ENTITY, welcome_msg_too);
        // welcome message is sent here because it needs to know the gametype
        if (welcome_msg_too)
-               SendWelcomemessage_msg_type(to, false, MSG_ENTITY);
+               SendWelcomeMessage(to, MSG_ENTITY);
        return true;
 }
 
@@ -297,8 +292,8 @@ float PlayerScore_Clear(entity player)
        sk = CS(player).scorekeeper;
        FOREACH(Scores, true, {
                if(sk.(scores(it)) != 0)
-                       if(scores_label(it) != "")
-                               sk.SendFlags |= BIT(i % 16);
+                       //if(scores_label(it) != "")
+                       sk.SendFlags |= (2 ** (i % 16));
                if(i != SP_ELO.m_id)
                        sk.(scores(it)) = 0;
        });
@@ -315,8 +310,8 @@ void Score_ClearAll()
                if (!sk) continue;
                FOREACH(Scores, true, {
                        if(sk.(scores(it)) != 0)
-                               if(scores_label(it) != "")
-                                       sk.SendFlags |= BIT(i % 16);
+                               //if(scores_label(it) != "")
+                               sk.SendFlags |= (2 ** (i % 16));
                        if(i != SP_ELO.m_id)
                                sk.(scores(it)) = 0;
                });
@@ -329,8 +324,8 @@ void Score_ClearAll()
                for(int j = 0; j < MAX_TEAMSCORE; ++j)
                {
                        if(sk.(teamscores(j)) != 0)
-                               if(teamscores_label(j) != "")
-                                       sk.SendFlags |= BIT(j);
+                               //if(teamscores_label(j) != "")
+                               sk.SendFlags |= (2 ** j);
                        sk.(teamscores(j)) = 0;
                }
        }
@@ -377,8 +372,8 @@ float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
        {
                return s.(scores(scorefield));
        }
-       if(scores_label(scorefield) != "")
-               s.SendFlags |= BIT(scorefield.m_id % 16);
+       //if(scores_label(scorefield) != "")
+       s.SendFlags |= (2 ** (scorefield.m_id % 16));
        if(!warmup_stage)
                PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
        s.(scores(scorefield)) += score;
@@ -417,32 +412,51 @@ float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tsc
        return r;
 }
 
+// strict: compare others fields too besides primary and secondary
 float PlayerScore_Compare(entity t1, entity t2, bool strict)
 {
        if(!t1 || !t2) return (!t2) - !t1;
 
-       vector result = '0 0 0';
-
-       result = ScoreField_Compare(t1, t2, scores_primary, scores_flags_primary, result, strict);
+       int result = 0;
+       result = ScoreField_Compare(t1, t2, scores_primary, scores_flags_primary, result);
        // NOTE: if (scores_secondary) doesn't work because it's a field pointer
-       if (result.x == 0 && scores_flags_secondary)
-               result = ScoreField_Compare(t1, t2, scores_secondary, scores_flags_secondary, result, strict);
+       if (result == 0 && scores_flags_secondary)
+               result = ScoreField_Compare(t1, t2, scores_secondary, scores_flags_secondary, result);
 
-       if (result.x == 0)
+       if (result == 0 && strict)
+       {
                FOREACH(Scores, true, {
                        if (scores_flags(it) & SFL_SORT_PRIO_MASK)
                                continue;
                        if (scores_label(it) == "")
                                continue;
                        var .float f = scores(it);
-                       result = ScoreField_Compare(t1, t2, f, scores_flags(it), result, strict);
-                       if (result.x) break;
+                       result = ScoreField_Compare(t1, t2, f, scores_flags(it), result);
+                       if (result) break;
                });
+               if (result == 0)
+                       result = t1.owner.playerid - t2.owner.playerid;
+       }
 
-       if (result.x == 0 && strict)
-               result.x = t1.owner.playerid - t2.owner.playerid;
+       return result;
+}
 
-       return result.x;
+bool Score_NewLeader()
+{
+       if(teamplay) {
+               if (WinningConditionHelper_winnerteam != WinningConditionHelper_winnerteam_last && (WinningConditionHelper_secondteam || WinningConditionHelper_equality))
+               {
+                       WinningConditionHelper_winnerteam_last = WinningConditionHelper_winnerteam;
+                       return true;
+               }
+       } else {
+               if (WinningConditionHelper_winner != WinningConditionHelper_winner_last && (WinningConditionHelper_second || WinningConditionHelper_equality))
+               {
+                       WinningConditionHelper_winner_last = WinningConditionHelper_winner;
+                       return true;
+               }
+       }
+       return false;
 }
 
 void WinningConditionHelper(entity this)
@@ -487,7 +501,7 @@ void WinningConditionHelper(entity this)
                for(t = 0; t < 16; ++t)
                {
                        sk = teamscorekeepers[t];
-                       c = TeamScore_Compare(winnerscorekeeper, sk, 1);
+                       c = TeamScore_Compare(winnerscorekeeper, sk, true);
                        if(c < 0)
                        {
                                WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam;
@@ -497,7 +511,7 @@ void WinningConditionHelper(entity this)
                        }
                        else
                        {
-                               c = TeamScore_Compare(secondscorekeeper, sk, 1);
+                               c = TeamScore_Compare(secondscorekeeper, sk, true);
                                if(c < 0)
                                {
                                        WinningConditionHelper_secondteam = t + 1;
@@ -506,7 +520,7 @@ void WinningConditionHelper(entity this)
                        }
                }
 
-               WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0);
+               WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
                if(WinningConditionHelper_equality)
                        WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1;
 
@@ -547,7 +561,15 @@ void WinningConditionHelper(entity this)
 
                WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0);
                if(WinningConditionHelper_equality)
+               {
+                       WinningConditionHelper_equality_one = WinningConditionHelper_winner;
+                       WinningConditionHelper_equality_two = WinningConditionHelper_second;
                        WinningConditionHelper_winner = WinningConditionHelper_second = NULL;
+               }
+               else
+               {
+                       WinningConditionHelper_equality_one = WinningConditionHelper_equality_two = NULL;
+               }
 
                WinningConditionHelper_topscore = winnerscorekeeper.scores_primary;
                WinningConditionHelper_secondscore = secondscorekeeper.scores_primary;
@@ -734,7 +756,8 @@ string GetTeamScoreString(float tm, float shortString)
        return out;
 }
 
-float PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict)
+// strict: compare others fields too besides primary and secondary
+int PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict)
 {
        if(teams && teamscores_entities_count)
        {
@@ -867,7 +890,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
@@ -915,7 +938,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)));
                }
     });