]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/scores.qc
Thanks to the previous commit ScoreField_Compare can be simplified by removing the...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / scores.qc
index 5bac7240faa7bfb37be24541a8ab0a4957a3d74f..1b7808db199945ced560261aceebd217a8223ede 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;
 }
 
 /*
@@ -417,32 +412,33 @@ 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.x;
+       return result;
 }
 
 void WinningConditionHelper(entity this)
@@ -487,7 +483,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 +493,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 +502,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;
 
@@ -734,7 +730,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)
        {