]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implemented lead announcing
authorz411 <z411@omaera.org>
Sun, 2 Oct 2022 03:05:23 +0000 (00:05 -0300)
committerz411 <z411@omaera.org>
Sun, 2 Oct 2022 03:05:23 +0000 (00:05 -0300)
qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc
qcsrc/common/gamemodes/gamemode/duel/sv_duel.qc
qcsrc/common/notifications/all.inc
qcsrc/server/mutators/events.qh
qcsrc/server/scores.qc
qcsrc/server/scores.qh
qcsrc/server/world.qc

index e622a1942fbee46b6c792aae8abe47df0cad0c83..f4dc6d1d7c559ee6cc447d45256da839141bf81c 100644 (file)
@@ -5,3 +5,9 @@ MUTATOR_HOOKFUNCTION(dm, Scores_CountFragsRemaining)
        // announce remaining frags
        return true;
 }
+
+MUTATOR_HOOKFUNCTION(dm, Scores_AnnounceLeads)
+{
+       // enable leads announcer
+       return true;
+}
index fc662e2a9fa826648cebfcb875b493ef1a4c40db..2cb1c8d5eb0c960c706f4034d6451d13d42e9f2a 100644 (file)
@@ -11,6 +11,12 @@ MUTATOR_HOOKFUNCTION(duel, Scores_CountFragsRemaining)
        return true;
 }
 
+MUTATOR_HOOKFUNCTION(duel, Scores_AnnounceLeads)
+{
+       // enable leads announcer
+       return true;
+}
+
 MUTATOR_HOOKFUNCTION(duel, FilterItemDefinition)
 {
        entity definition = M_ARGV(0, entity);
index 360a3439a61478ac7d649a0c2e26ad247239c37f..da62077c6a3498d6b9d877c93405948537284f29 100644 (file)
     MSG_ANNCE_NOTIF(VOTE_CALL,                  N__ALWAYS, "votecall",          CH_INFO, VOL_BASEVOICE, ATTEN_NONE)
     MSG_ANNCE_NOTIF(VOTE_FAIL,                  N__ALWAYS, "votefail",          CH_INFO, VOL_BASEVOICE, ATTEN_NONE)
 
+    MSG_ANNCE_NOTIF(LEAD_GAINED,                N__ALWAYS, "leadgained",        CH_INFO, VOL_BASEVOICE, ATTEN_NONE)
+    MSG_ANNCE_NOTIF(LEAD_LOST,                  N__ALWAYS, "leadlost",          CH_INFO, VOL_BASEVOICE, ATTEN_NONE)
+    MSG_ANNCE_NOTIF(LEAD_TIED,                  N__ALWAYS, "leadtied",          CH_INFO, VOL_BASEVOICE, ATTEN_NONE)
+
 #undef N___NEVER
 #undef N_GNTLOFF
 #undef N__ALWAYS
index e7f9f897b0fdce206ccae04312aad6bbe17092b1..cb6887242a221d15f2d7e235b600a198c2a314c7 100644 (file)
@@ -865,6 +865,7 @@ MUTATOR_HOOKABLE(FireBullet_Hit, EV_FireBullet_Hit);
 MUTATOR_HOOKABLE(FixPlayermodel, EV_FixPlayermodel);
 
 /** Return error to play frag remaining announcements */
+MUTATOR_HOOKABLE(Scores_AnnounceLeads, EV_NO_ARGS);
 MUTATOR_HOOKABLE(Scores_CountFragsRemaining, EV_NO_ARGS);
 
 #define EV_GrappleHookThink(i, o) \
index 512f61ad231ae5d4255ec197a7b4d0667416220a..67900ae95eb734a24256ca8cf197e05866a932bf 100644 (file)
@@ -419,6 +419,18 @@ float PlayerScore_Compare(entity t1, entity t2, bool strict)
        return result.x;
 }
 
+bool Score_NewLeader()
+{
+       // Returns true if the game leader has changed (no teamplay support yet)
+       if (teamplay) return false;
+       if (WinningConditionHelper_winner != WinningConditionHelper_winner_last && (WinningConditionHelper_second || WinningConditionHelper_equality))
+       {
+               WinningConditionHelper_winner_last = WinningConditionHelper_winner;
+               return true;
+       }
+       return false;
+}
+
 void WinningConditionHelper(entity this)
 {
        float c;
@@ -521,7 +533,13 @@ 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;
index 2b6ea4881045808340260607aaabd596032a6a5f..f01310d82e99ac8459b764a1c371171c54490302 100644 (file)
@@ -111,6 +111,9 @@ float WinningConditionHelper_secondteam;    ///< the color of the second team, o
 float WinningConditionHelper_equality;      ///< we have no winner
 entity WinningConditionHelper_winner;       ///< the winning player, or NULL if none
 entity WinningConditionHelper_second;       ///< the second player, or NULL if none
+entity WinningConditionHelper_winner_last;
+entity WinningConditionHelper_equality_one;
+entity WinningConditionHelper_equality_two;
 float WinningConditionHelper_lowerisbetter; ///< lower is better, duh
 float WinningConditionHelper_zeroisworst;   ///< zero is worst, duh
 #define WINNINGCONDITIONHELPER_LOWERISBETTER_WORST 999999999
index 7f651fa7748291ff5e7090192793cf39c206afa9..d4f503cfaeec608b40c341839c10deeb005536de 100644 (file)
@@ -1427,6 +1427,25 @@ void ClearWinners()
        FOREACH_CLIENT(IS_PLAYER(it) || INGAME(it), { it.winning = 0; });
 }
 
+void AnnounceNewLeader()
+{
+       LOG_INFO("Announce new leader");
+       // Don't announce if in warmup or just started
+       if(warmup_stage || time - game_starttime < 1) return;
+       if(teamplay) return; // Not implemented in teamplay yet. We need an announcer for that.
+
+       if (WinningConditionHelper_equality)
+       {
+               Send_Notification(NOTIF_ONE, WinningConditionHelper_equality_one, MSG_ANNCE, ANNCE_LEAD_TIED);
+               Send_Notification(NOTIF_ONE, WinningConditionHelper_equality_two, MSG_ANNCE, ANNCE_LEAD_TIED);
+       }
+       else
+       {
+               Send_Notification(NOTIF_ONE, WinningConditionHelper_winner, MSG_ANNCE, ANNCE_LEAD_GAINED);
+               Send_Notification(NOTIF_ONE, WinningConditionHelper_second, MSG_ANNCE, ANNCE_LEAD_LOST);
+       }
+}
+
 int fragsleft_last;
 float WinningCondition_Scores(float limit, float leadlimit)
 {
@@ -1493,6 +1512,14 @@ float WinningCondition_Scores(float limit, float leadlimit)
                }
        }
 
+       // Announce new leader if any
+       if(MUTATOR_CALLHOOK(Scores_AnnounceLeads)) {
+               if (Score_NewLeader()) {
+                       LOG_INFO("Pass 2");
+                       AnnounceNewLeader();
+               }
+       }
+
        bool fraglimit_reached = (limit && WinningConditionHelper_topscore >= limit);
        bool leadlimit_reached = (leadlimit && WinningConditionHelper_topscore - WinningConditionHelper_secondscore >= leadlimit);