@@ -2418,10 +2418,77 @@ int tiecount(void)
24182418 return (deathmatch == 4 ? 2 : 3 );
24192419}
24202420
2421+ /**
2422+ * Gets the absolute score difference from the golden frag snapshot.
2423+ * @return The absolute difference between team1 and team2 snapshot scores.
2424+ */
2425+ int GetGoldenFragSnapshotDifference (void )
2426+ {
2427+ return abs (golden_frag_score_snapshot .team1_score - golden_frag_score_snapshot .team2_score );
2428+ }
2429+
2430+ /**
2431+ * Checks if the current game mode is solo (duel or FFA).
2432+ * @return true if the mode is duel or FFA, false otherwise.
2433+ */
2434+ qbool isDuelOrFFA (void ) {
2435+ return (isDuel () || isFFA ());
2436+ }
2437+
2438+ /**
2439+ * Gets the current absolute frag difference between the top two players / teams.
2440+ * @return The absolute difference in frags. For solo modes (duel/FFA), returns difference
2441+ * between the top two players' frags. For team modes, returns difference between team scores.
2442+ */
2443+ int GetCurrentFragDifference (void ) {
2444+ if (isDuelOrFFA ()) {
2445+ const gedict_t * ed1 = get_ed_scores1 ();
2446+ const gedict_t * ed2 = get_ed_scores2 ();
2447+ if (ed1 && ed2 ) {
2448+ return abs ((int )ed1 -> s .v .frags - (int )ed2 -> s .v .frags );
2449+ }
2450+ }
2451+ return abs (get_scores1 () - get_scores2 ());
2452+ }
2453+
2454+ /**
2455+ * Checks if the golden frag snapshot should be updated mid-match.
2456+ * @return true if k_overtime is set to SD_GOLDEN_FRAG but k_sudden_death is not yet,
2457+ * indicating the match is still in regulation but will use golden frag for overtime.
2458+ */
2459+ qbool shouldUpdateGoldenFragMidMatch (void ) {
2460+ return (int ) cvar ("k_overtime" ) == SD_GOLDEN_FRAG
2461+ && (int ) k_sudden_death != SD_GOLDEN_FRAG ;
2462+ }
2463+
2464+ /**
2465+ * Updates the golden frag score snapshot with current scores.
2466+ * For solo modes (duel/FFA), stores individual player frags.
2467+ * For team modes, stores team scores. This snapshot is used to track
2468+ * the score difference when golden frag overtime begins.
2469+ */
2470+ void updateGoldenFragSnapshot (void ) {
2471+ if (isDuelOrFFA ()) {
2472+ const gedict_t * ed1 = get_ed_scores1 ();
2473+ const gedict_t * ed2 = get_ed_scores2 ();
2474+ if (ed1 && ed2 ) {
2475+ golden_frag_score_snapshot .team1_score = (int ) ed1 -> s .v .frags ;
2476+ golden_frag_score_snapshot .team2_score = (int ) ed2 -> s .v .frags ;
2477+ }
2478+ } else {
2479+ golden_frag_score_snapshot .team1_score = get_scores1 ();
2480+ golden_frag_score_snapshot .team2_score = get_scores2 ();
2481+ }
2482+ }
2483+
24212484// check sudden death end
24222485// call this on player death
24232486void Check_SD (gedict_t * p )
24242487{
2488+ if (shouldUpdateGoldenFragMidMatch ()) {
2489+ updateGoldenFragSnapshot ();
2490+ }
2491+
24252492 if (!match_in_progress )
24262493 {
24272494 return ;
@@ -2463,6 +2530,15 @@ void Check_SD(gedict_t *p)
24632530 }
24642531 return ;
24652532 }
2533+
2534+ case SD_GOLDEN_FRAG : {
2535+ // End when the leader extends the frag lead
2536+ if (GetCurrentFragDifference () > GetGoldenFragSnapshotDifference ()) {
2537+ EndMatch (0 );
2538+ } else {
2539+ updateGoldenFragSnapshot ();
2540+ }
2541+ }
24662542 }
24672543}
24682544
0 commit comments