Merge branch 'martin-t/limit'
authorterencehill <piuntn@gmail.com>
Sun, 5 Apr 2020 12:28:53 +0000 (14:28 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 5 Apr 2020 12:28:53 +0000 (14:28 +0200)
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/stats.qh
qcsrc/server/defs.qh
qcsrc/server/g_world.qc

index a6d1cc941708193c6696c3a2479a3641d26f0eda..08a1a73bb0977148aa8174f48ef67d836aad4ded 100644 (file)
@@ -1604,11 +1604,11 @@ void Scoreboard_Draw()
        draw_endBoldFont();
 
        // Game Info: Game Detail
-       float tl, fl, ll;
-       str = ""; // optionally "^7Limits: "
-       tl = STAT(TIMELIMIT);
-       fl = STAT(FRAGLIMIT);
-       ll = STAT(LEADLIMIT);
+       float tl = STAT(TIMELIMIT);
+       float fl = STAT(FRAGLIMIT);
+       float ll = STAT(LEADLIMIT);
+       float ll_and_fl = STAT(LEADLIMIT_AND_FRAGLIMIT);
+       str = "";
        if(tl > 0)
                str = strcat(str, sprintf(_("^3%1.0f minutes"), tl));
        if(!ISGAMETYPE(LMS))
@@ -1635,7 +1635,14 @@ void Scoreboard_Draw()
                if(ll > 0)
                {
                        if(tl > 0 || fl > 0)
-                               str = strcat(str, "^7 / "); // delimiter
+                       {
+                               // delimiter
+                               if (ll_and_fl && fl > 0)
+                                       str = strcat(str, "^7 & ");
+                               else
+                                       str = strcat(str, "^7 / ");
+                       }
+
                        if(teamplay)
                        {
                                str = strcat(str, sprintf(_("^2+%s %s"), ScoreString(teamscores_flags(ts_primary), ll),
index 14eafaf255ac95ef7781d7a8fef834bf9c40a24a..c5e45e866a9a00df69697a5efe3f58ee86b80151 100644 (file)
@@ -85,6 +85,7 @@ REGISTER_STAT(NB_METERSTART, float)
 /** compressShotOrigin */
 REGISTER_STAT(SHOTORG, int)
 REGISTER_STAT(LEADLIMIT, float, autocvar_leadlimit)
+REGISTER_STAT(LEADLIMIT_AND_FRAGLIMIT, float, autocvar_leadlimit_and_fraglimit)
 
 REGISTER_STAT(LAST_PICKUP, float)
 REGISTER_STAT(HUD, int)
index 9036ee22219f46aa4baf8724c5d2faee709a818a..3b5acfbd0dbb57be9c6ba5d668ce1deea51c7d75 100644 (file)
@@ -141,7 +141,6 @@ float blockSpectators; //if set, new or existing spectators or observers will be
 .float spectatortime; //point in time since the client is spectating or observing
 void checkSpectatorBlock(entity this);
 
-float game_completion_ratio; // 0 at start, 1 near end
 .float winning;
 .float jointime; // time of connecting
 .float startplaytime; // time of switching from spectator to player
index fd8631f31a8657e82d664149f6ba16c83b729b7d..650c249139596cc69df943e447000214f9293d84 100644 (file)
@@ -1705,13 +1705,9 @@ void ShuffleMaplist()
        cvar_set("g_maplist", shufflewords(autocvar_g_maplist));
 }
 
-float leaderscore;
-float secondscore;
 int fragsleft_last;
 float WinningCondition_Scores(float limit, float leadlimit)
 {
-       float limitreached;
-
        // TODO make everything use THIS winning condition (except LMS)
        WinningConditionHelper(NULL);
 
@@ -1741,66 +1737,43 @@ float WinningCondition_Scores(float limit, float leadlimit)
                leadlimit = 0; // not supported in this mode
 
        if(MUTATOR_CALLHOOK(Scores_CountFragsRemaining))
-       // these modes always score in increments of 1, thus this makes sense
        {
-               if (leaderscore != WinningConditionHelper_topscore ||
-                       secondscore != WinningConditionHelper_secondscore)
-               {
-                       int fragsleft = 0, leadingfragsleft = 0;
-
-                       leaderscore = WinningConditionHelper_topscore;
-                       secondscore = WinningConditionHelper_secondscore;
+               float fragsleft = FLOAT_MAX, leadingfragsleft = FLOAT_MAX;
+               if (limit)
+                       fragsleft = limit - WinningConditionHelper_topscore;
+               if (leadlimit)
+                       leadingfragsleft = WinningConditionHelper_secondscore + leadlimit - WinningConditionHelper_topscore;
 
-                       if (limit)
-                               fragsleft = limit - leaderscore;
-                       if (leadlimit)
-                               leadingfragsleft = secondscore + leadlimit - leaderscore;
-
-                       if (autocvar_leadlimit_and_fraglimit && leadlimit)
-                       {
-                               if (limit)
-                                       fragsleft = max(leadingfragsleft, fragsleft);
-                       }
-                       else if (leadlimit)
-                       {
-                               if (limit)
-                                       fragsleft = min(fragsleft, leadingfragsleft);
-                               else
-                                       fragsleft = leadingfragsleft;
-                       }
+               if (limit && leadlimit && autocvar_leadlimit_and_fraglimit)
+                       fragsleft = max(fragsleft, leadingfragsleft);
+               else
+                       fragsleft = min(fragsleft, leadingfragsleft);
 
-                       if (fragsleft_last != fragsleft) // do not announce same remaining frags multiple times
-                       {
-                               if (fragsleft == 1)
-                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_1);
-                               else if (fragsleft == 2)
-                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_2);
-                               else if (fragsleft == 3)
-                                       Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_3);
-
-                               fragsleft_last = fragsleft;
-                       }
+               if (fragsleft_last != fragsleft) // do not announce same remaining frags multiple times
+               {
+                       if (fragsleft == 1)
+                               Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_1);
+                       else if (fragsleft == 2)
+                               Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_2);
+                       else if (fragsleft == 3)
+                               Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_REMAINING_FRAG_3);
+
+                       fragsleft_last = fragsleft;
                }
        }
 
-       limitreached = false;
-       if (limit && WinningConditionHelper_topscore >= limit)
-               limitreached = true;
-       if(leadlimit)
-       {
-               float leadlimitreached;
-               leadlimitreached = (WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
-               if(autocvar_leadlimit_and_fraglimit)
-                       limitreached = (limitreached && leadlimitreached);
-               else
-                       limitreached = (limitreached || leadlimitreached);
-       }
+       bool fraglimit_reached = (limit && WinningConditionHelper_topscore >= limit);
+       bool leadlimit_reached = (leadlimit && WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);
 
-       if(limit)
-               game_completion_ratio = max(game_completion_ratio, bound(0, WinningConditionHelper_topscore / limit, 1));
+       bool limit_reached;
+       // only respect leadlimit_and_fraglimit when both limits are set or the game will never end
+       if (limit && leadlimit && autocvar_leadlimit_and_fraglimit)
+               limit_reached = (fraglimit_reached && leadlimit_reached);
+       else
+               limit_reached = (fraglimit_reached || leadlimit_reached);
 
        return GetWinningCode(
-               WinningConditionHelper_topscore && limitreached,
+               WinningConditionHelper_topscore && limit_reached,
                WinningConditionHelper_equality
        );
 }
@@ -1891,10 +1864,6 @@ Exit deathmatch games upon conditions
 */
 void CheckRules_World()
 {
-       float timelimit;
-       float fraglimit;
-       float leadlimit;
-
        VoteThink();
        MapVote_Think();
 
@@ -1909,9 +1878,10 @@ void CheckRules_World()
                return;
        }
 
-       timelimit = autocvar_timelimit * 60;
-       fraglimit = autocvar_fraglimit;
-       leadlimit = autocvar_leadlimit;
+       float timelimit = autocvar_timelimit * 60;
+       float fraglimit = autocvar_fraglimit;
+       float leadlimit = autocvar_leadlimit;
+       if (leadlimit < 0) leadlimit = 0;
 
        if(warmup_stage || time <= game_starttime) // NOTE: this is <= to prevent problems in the very tic where the game starts
        {
@@ -1936,11 +1906,6 @@ void CheckRules_World()
        float wantovertime;
        wantovertime = 0;
 
-       if(timelimit > game_starttime)
-               game_completion_ratio = (time - game_starttime) / (timelimit - game_starttime);
-       else
-               game_completion_ratio = 0;
-
        if(checkrules_suddendeathend)
        {
                if(!checkrules_suddendeathwarning)