Skip to content

Commit 5552536

Browse files
fixed a bug where golden frag snapshot wasn't updated mid match
1 parent 40fc19e commit 5552536

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/client.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,15 +2420,38 @@ int tiecount(void)
24202420
return (deathmatch == 4 ? 2 : 3);
24212421
}
24222422

2423-
int GetGoldenFragScoreAbsDiff(void)
2423+
int GetGoldenFragSnapshotDifference(void)
24242424
{
24252425
return abs(golden_frag_score_snapshot.player1_score - golden_frag_score_snapshot.player2_score);
24262426
}
24272427

2428+
int GetCurrentFragDifference(const gedict_t *ed1, const gedict_t *ed2) {
2429+
return abs((int) ed1->s.v.frags - (int) ed2->s.v.frags);
2430+
}
2431+
2432+
qbool shouldUpdateGoldenFragMidMatch(void) {
2433+
const int overtime_cvar = (int) cvar("k_overtime");
2434+
const qbool shouldUpdate = overtime_cvar == SD_GOLDEN_FRAG && (int) k_sudden_death != SD_GOLDEN_FRAG;
2435+
return shouldUpdate;
2436+
}
2437+
2438+
void updateGoldenFragSnapshot(const gedict_t *ed1, const gedict_t *ed2) {
2439+
golden_frag_score_snapshot.player1_score = (int) ed1->s.v.frags;
2440+
golden_frag_score_snapshot.player2_score = (int) ed2->s.v.frags;
2441+
}
2442+
24282443
// check sudden death end
24292444
// call this on player death
24302445
void Check_SD(gedict_t *p)
24312446
{
2447+
if (shouldUpdateGoldenFragMidMatch()) {
2448+
const gedict_t *ed1 = get_ed_scores1();
2449+
const gedict_t *ed2 = get_ed_scores2();
2450+
if (ed1 && ed2) {
2451+
updateGoldenFragSnapshot(ed1, ed2);
2452+
}
2453+
}
2454+
24322455
if (!match_in_progress)
24332456
{
24342457
return;
@@ -2472,21 +2495,14 @@ void Check_SD(gedict_t *p)
24722495
}
24732496

24742497
case SD_GOLDEN_FRAG: {
2475-
gedict_t *ed1 = get_ed_scores1(), *ed2 = get_ed_scores2();
2476-
int sc = get_scores1() - get_scores2();
2477-
2478-
if (isDuel() && ed1 && ed2)
2479-
{
2480-
sc = ed1->s.v.frags - ed2->s.v.frags;
2481-
}
2482-
2498+
const gedict_t *ed1 = get_ed_scores1();
2499+
const gedict_t *ed2 = get_ed_scores2();
24832500
if (isDuel() && ed1 && ed2)
24842501
{
2485-
if (abs(sc) > GetGoldenFragScoreAbsDiff()) {
2502+
if (GetCurrentFragDifference(ed1, ed2) > GetGoldenFragSnapshotDifference()) {
24862503
EndMatch(0);
24872504
} else {
2488-
golden_frag_score_snapshot.player1_score = (int) ed1->s.v.frags;
2489-
golden_frag_score_snapshot.player2_score = (int) ed2->s.v.frags;
2505+
updateGoldenFragSnapshot(ed1, ed2);
24902506
}
24912507
} // unknown so end match
24922508
else

src/match.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,6 @@ void EndMatch(float skip_log)
483483
{
484484
SpawnicideDisable();
485485
}
486-
golden_frag_score_snapshot.player1_score = -GOLDEN_FRAG_SNAPSHOT_INITIAL_VALUE;
487-
golden_frag_score_snapshot.player2_score = GOLDEN_FRAG_SNAPSHOT_INITIAL_VALUE;
488486
}
489487

490488
void SaveOvertimeStats(void)

0 commit comments

Comments
 (0)