]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Refactor frags remaining announcer code and make it work with leadlimit_and_fraglimit 1
authorterencehill <piuntn@gmail.com>
Sun, 22 Mar 2020 09:25:54 +0000 (10:25 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 22 Mar 2020 09:25:54 +0000 (10:25 +0100)
qcsrc/server/g_world.qc

index aa4c5f505ef64290216e1a5dcbc8af5545abbe25..89fee905142073f9dcb6d0aeaa91f8b8ef484e15 100644 (file)
@@ -1737,8 +1737,7 @@ float WinningCondition_Scores(float limit, float leadlimit)
                limit = -limit;
        }
 
-       if(WinningConditionHelper_zeroisworst
-               || (!autocvar_leadlimit_and_fraglimit && limit && leadlimit >= fabs(limit)))
+       if(WinningConditionHelper_zeroisworst)
                leadlimit = 0; // not supported in this mode
 
        if(MUTATOR_CALLHOOK(Scores_CountFragsRemaining))
@@ -1747,39 +1746,40 @@ float WinningCondition_Scores(float limit, float leadlimit)
                if (leaderscore != WinningConditionHelper_topscore ||
                        secondscore != WinningConditionHelper_secondscore)
                {
-                       int fragsleft = 0;
+                       int fragsleft = 0, leadingfragsleft = 0;
 
                        leaderscore = WinningConditionHelper_topscore;
                        secondscore = WinningConditionHelper_secondscore;
 
-                       if (limit)
+                       if (leadlimit)
+                               leadingfragsleft = secondscore + leadlimit - leaderscore;
+                       if (autocvar_leadlimit_and_fraglimit && leadlimit && limit)
                        {
-                               if (leaderscore == limit - 1)
-                                       fragsleft |= BIT(1);
-                               else if (leaderscore == limit - 2)
-                                       fragsleft |= BIT(2);
-                               else if (leaderscore == limit - 3)
-                                       fragsleft |= BIT(3);
+                               fragsleft = limit - leaderscore;
+                               fragsleft = max(leadingfragsleft, fragsleft);
                        }
-                       if (leadlimit)
+                       else
                        {
-                               if (leaderscore == leadlimit + secondscore - 1)
-                                       fragsleft |= BIT(1);
-                               else if (leaderscore == leadlimit + secondscore - 2)
-                                       fragsleft |= BIT(2);
-                               else if (leaderscore == leadlimit + secondscore - 3)
-                                       fragsleft |= BIT(3);
+                               if (limit)
+                               {
+                                       fragsleft = limit - leaderscore;
+                                       if (leadlimit)
+                                               fragsleft = min(fragsleft, leadingfragsleft);
+                               }
+                               else if (leadlimit)
+                                       fragsleft = leadingfragsleft;
                        }
 
-                       fragsleft = fragsleft & -fragsleft; // least significant bit where 1 is set
+                       if (fragsleft > 3)
+                               fragsleft = 0;
 
                        if (fragsleft_last != fragsleft) // do not announce same remaining frags multiple times
                        {
-                               if (fragsleft & BIT(1))
+                               if (fragsleft == 1)
                                        Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_1);
-                               else if (fragsleft & BIT(2))
+                               else if (fragsleft == 2)
                                        Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_2);
-                               else if (fragsleft & BIT(3))
+                               else if (fragsleft == 3)
                                        Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_3);
 
                                fragsleft_last = fragsleft;