From e2f8d3f4b25a7abcb3ce03daadd5b9954df4c200 Mon Sep 17 00:00:00 2001 From: z411 Date: Sun, 2 Oct 2022 00:05:23 -0300 Subject: [PATCH] Implemented lead announcing --- .../gamemode/deathmatch/sv_deathmatch.qc | 6 +++++ .../common/gamemodes/gamemode/duel/sv_duel.qc | 6 +++++ qcsrc/common/notifications/all.inc | 4 +++ qcsrc/server/mutators/events.qh | 1 + qcsrc/server/scores.qc | 18 +++++++++++++ qcsrc/server/scores.qh | 3 +++ qcsrc/server/world.qc | 27 +++++++++++++++++++ 7 files changed, 65 insertions(+) diff --git a/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc b/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc index e622a1942..f4dc6d1d7 100644 --- a/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc +++ b/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc @@ -5,3 +5,9 @@ MUTATOR_HOOKFUNCTION(dm, Scores_CountFragsRemaining) // announce remaining frags return true; } + +MUTATOR_HOOKFUNCTION(dm, Scores_AnnounceLeads) +{ + // enable leads announcer + return true; +} diff --git a/qcsrc/common/gamemodes/gamemode/duel/sv_duel.qc b/qcsrc/common/gamemodes/gamemode/duel/sv_duel.qc index fc662e2a9..2cb1c8d5e 100644 --- a/qcsrc/common/gamemodes/gamemode/duel/sv_duel.qc +++ b/qcsrc/common/gamemodes/gamemode/duel/sv_duel.qc @@ -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); diff --git a/qcsrc/common/notifications/all.inc b/qcsrc/common/notifications/all.inc index 360a3439a..da62077c6 100644 --- a/qcsrc/common/notifications/all.inc +++ b/qcsrc/common/notifications/all.inc @@ -202,6 +202,10 @@ 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 diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index e7f9f897b..cb6887242 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -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) \ diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 512f61ad2..67900ae95 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -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; diff --git a/qcsrc/server/scores.qh b/qcsrc/server/scores.qh index 2b6ea4881..f01310d82 100644 --- a/qcsrc/server/scores.qh +++ b/qcsrc/server/scores.qh @@ -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 diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 7f651fa77..d4f503cfa 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -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); -- 2.39.2