From: z411 Date: Tue, 10 Nov 2020 09:42:06 +0000 (-0300) Subject: Refactored leads announcer X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a14ee4318e42003b34254ecb1646c48d2d0e9e86;p=xonotic%2Fxonotic-data.pk3dir.git Refactored leads announcer --- diff --git a/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc b/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc index fd7a718b7..d82143d80 100644 --- a/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc +++ b/qcsrc/common/gamemodes/gamemode/deathmatch/sv_deathmatch.qc @@ -6,6 +6,12 @@ MUTATOR_HOOKFUNCTION(dm, Scores_CountFragsRemaining) return true; } +MUTATOR_HOOKFUNCTION(dm, Scores_AnnounceLeads) +{ + // enable leads announcer + return true; +} + MUTATOR_HOOKFUNCTION(dm, FragCenterMessage) { // Use normal notifications in warmup @@ -39,4 +45,4 @@ MUTATOR_HOOKFUNCTION(dm, FragCenterMessage) ); return true; -} \ No newline at end of file +} 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/gamemodes/gamemode/tdm/sv_tdm.qc b/qcsrc/common/gamemodes/gamemode/tdm/sv_tdm.qc index 5e8508896..3bd9cb564 100644 --- a/qcsrc/common/gamemodes/gamemode/tdm/sv_tdm.qc +++ b/qcsrc/common/gamemodes/gamemode/tdm/sv_tdm.qc @@ -70,3 +70,9 @@ MUTATOR_HOOKFUNCTION(tdm, Scores_CountFragsRemaining) // announce remaining frags return true; } + +MUTATOR_HOOKFUNCTION(tdm, Scores_AnnounceLeads) +{ + // enable leads announcer + return true; +} diff --git a/qcsrc/common/notifications/all.inc b/qcsrc/common/notifications/all.inc index 70818b856..e4196239b 100644 --- a/qcsrc/common/notifications/all.inc +++ b/qcsrc/common/notifications/all.inc @@ -224,8 +224,10 @@ MSG_ANNCE_NOTIF(LEAD_TIED, N__ALWAYS, "leadtied", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) MULTITEAM_ANNCE(ROUND_TEAM_WIN, N__ALWAYS, "round_win_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) - MULTITEAM_ANNCE(ROUND_TEAM_SCORES, N__ALWAYS, "scores_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) - MULTITEAM_ANNCE(WINS, N__ALWAYS, "wins_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) + MULTITEAM_ANNCE(TEAM_SCORES, N__ALWAYS, "scores_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) + MULTITEAM_ANNCE(TEAM_WINS, N__ALWAYS, "wins_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) + MULTITEAM_ANNCE(TEAM_LEADS, N__ALWAYS, "leads_%s", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) + MSG_ANNCE_NOTIF(TEAM_LEADS_TIED, N__ALWAYS, "leads_tied", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) MSG_ANNCE_NOTIF(ROUND_OVER, N__ALWAYS, "round_over", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) MSG_ANNCE_NOTIF(ROUND_TIED, N__ALWAYS, "round_tied", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) MSG_ANNCE_NOTIF(ALONE, N__ALWAYS, "alone", CH_INFO, VOL_BASEVOICE, ATTEN_NONE, ANNCE_DEFTIME) diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 35a8f6fd9..05d21abab 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -849,6 +849,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 8906547c4..2874a8410 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -412,6 +412,24 @@ float PlayerScore_Compare(entity t1, entity t2, bool strict) return result.x; } +bool Score_NewLeader() +{ + if(teamplay) { + if (WinningConditionHelper_winnerteam != WinningConditionHelper_winnerteam_last && (WinningConditionHelper_secondteam || WinningConditionHelper_equality)) + { + WinningConditionHelper_winnerteam_last = WinningConditionHelper_winnerteam; + return true; + } + } else { + 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; diff --git a/qcsrc/server/scores.qh b/qcsrc/server/scores.qh index 288eaf0c1..e446a6227 100644 --- a/qcsrc/server/scores.qh +++ b/qcsrc/server/scores.qh @@ -108,6 +108,7 @@ void WinningConditionHelper(entity this); float WinningConditionHelper_topscore; ///< highest score float WinningConditionHelper_secondscore; ///< second highest score float WinningConditionHelper_winnerteam; ///< the color of the winning team, or -1 if none +float WinningConditionHelper_winnerteam_last; float WinningConditionHelper_secondteam; ///< the color of the second team, or -1 if none float WinningConditionHelper_equality; ///< we have no winner entity WinningConditionHelper_winner; ///< the winning player, or NULL if none @@ -142,3 +143,6 @@ string GetTeamScoreString(float tm, float shortString); * nospectators: exclude spectators */ entity PlayerScore_Sort(.float field, int teams, bool strict, bool nospectators); + +// z411 +bool Score_NewLeader(); diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 3a27c66f0..84586cb73 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -1307,7 +1307,7 @@ void NextLevel() // send winner notification if(teamplay) { - Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, APP_TEAM_NUM(WinningConditionHelper_winnerteam, ANNCE_WINS)); + Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, APP_TEAM_NUM(WinningConditionHelper_winnerteam, ANNCE_TEAM_WINS)); } if(autocvar_sv_eventlog) @@ -1445,6 +1445,27 @@ void ClearWinners() FOREACH_CLIENT(IS_PLAYER(it), { it.winning = 0; }); } +void AnnounceNewLeader() +{ + if(teamplay) { + if (WinningConditionHelper_equality) + Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, ANNCE_TEAM_LEADS_TIED); + else + Send_Notification(NOTIF_ALL, NULL, MSG_ANNCE, APP_TEAM_NUM(WinningConditionHelper_winnerteam, ANNCE_TEAM_LEADS)); + } else { + 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); + } + } +} + float WinningCondition_Scores(float limit, float leadlimit) { // TODO make everything use THIS winning condition (except LMS) @@ -1509,21 +1530,10 @@ float WinningCondition_Scores(float limit, float leadlimit) } } - // z411 - if (WinningConditionHelper_winner != WinningConditionHelper_winner_last && (WinningConditionHelper_second || WinningConditionHelper_equality)) - { - 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); - } - - WinningConditionHelper_winner_last = WinningConditionHelper_winner; + // z411 - lead announcer + if(MUTATOR_CALLHOOK(Scores_AnnounceLeads)) { + if (Score_NewLeader()) + AnnounceNewLeader(); } bool fraglimit_reached = (limit && WinningConditionHelper_topscore >= limit); @@ -2304,7 +2314,7 @@ void RunThink(entity this) bool autocvar_sv_freezenonclients; void Physics_Frame() { - if(autocvar_sv_freezenonclients) + if(autocvar_sv_freezenonclients || game_timeout) return; IL_EACH(g_moveables, true,