From 9dd1a5d2304c1fc97fb646dc79340a177f3c575d Mon Sep 17 00:00:00 2001 From: otta8634 Date: Mon, 16 Dec 2024 00:47:58 +0800 Subject: [PATCH] Calculate average handicap over a match and send to XonStat Added .handicap_avg_given_sum and .handicap_avg_taken_sum. Currently it doesn't include self-damage which *is* influenced by handicap. - Including this would require minimum 2 but probably 4 more entity fields, so I'm not sure it's really necessary. The given and taken handicaps are sent to XonStat separately. --- qcsrc/common/playerstats.qc | 12 ++++++++++++ qcsrc/common/playerstats.qh | 2 ++ qcsrc/server/client.qc | 2 ++ qcsrc/server/handicap.qh | 12 +++++++++--- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 83b7a87da4..c90d4577cf 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -56,6 +56,8 @@ void PlayerStats_GameReport_Reset_All() strfree(it.playerstats_id); PlayerStats_GameReport_AddEvent(sprintf("kills-%d", it.playerid)); PlayerStats_GameReport_AddPlayer(it); + it.handicap_avg_given_sum = 0; + it.handicap_avg_taken_sum = 0; }); FOREACH(Scores, true, { string label = scores_label(it); @@ -255,6 +257,12 @@ void PlayerStats_GameReport(bool finished) } } + // handicap + const float given = GameRules_scoring_add(it, DMG, 0); + const float taken = GameRules_scoring_add(it, DMGTAKEN, 0); + PlayerStats_GameReport_Event_Player(it, PLAYERSTATS_HANDICAP_GIVEN, given <= 0 ? 1 : it.handicap_avg_given_sum / given); + PlayerStats_GameReport_Event_Player(it, PLAYERSTATS_HANDICAP_TAKEN, taken <= 0 ? 1 : it.handicap_avg_taken_sum / taken); + // collect final player information PlayerStats_GameReport_FinalizePlayer(it); }); @@ -303,6 +311,8 @@ void PlayerStats_GameReport_Init() // initiated before InitGameplayMode so that PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_VALID); PlayerStats_GameReport_AddEvent(PLAYERSTATS_SCOREBOARD_POS); PlayerStats_GameReport_AddEvent(PLAYERSTATS_RANK); + PlayerStats_GameReport_AddEvent(PLAYERSTATS_HANDICAP_GIVEN); + PlayerStats_GameReport_AddEvent(PLAYERSTATS_HANDICAP_TAKEN); // accuracy stats FOREACH(Weapons, it != WEP_Null, { @@ -390,6 +400,8 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status) * achievement-: achievement counters (their "count" is usually 1 if nonzero at all) * kills-: number of kills against the indexed player * rank : rank of player + * handicapgiven: average handicap on given (dealt) damage throughout the match + * handicaptaken: average handicap on taken (received) damage throughout the match * acc--hit: total damage dealt * acc--fired: total damage that all fired projectiles *could* have dealt * acc--cnt-hit: amount of shots that actually hit diff --git a/qcsrc/common/playerstats.qh b/qcsrc/common/playerstats.qh index 9fff940f24..a2d20894f0 100644 --- a/qcsrc/common/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -37,6 +37,8 @@ const string PLAYERSTATS_JOINS = "joins"; const string PLAYERSTATS_SCOREBOARD_VALID = "scoreboardvalid"; const string PLAYERSTATS_RANK = "rank"; const string PLAYERSTATS_SCOREBOARD_POS = "scoreboardpos"; +const string PLAYERSTATS_HANDICAP_GIVEN = "handicapgiven"; +const string PLAYERSTATS_HANDICAP_TAKEN = "handicaptaken"; const string PLAYERSTATS_TOTAL = "total-"; const string PLAYERSTATS_SCOREBOARD = "scoreboard-"; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index cb38762e6f..fe4b3e0810 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2816,11 +2816,13 @@ void PlayerFrame (entity this) if (this.score_frame_dmg) { + this.handicap_avg_given_sum += this.score_frame_dmg * Handicap_GetTotalHandicap(this, false); GameRules_scoring_add(this, DMG, this.score_frame_dmg); this.score_frame_dmg = 0; } if (this.score_frame_dmgtaken) { + this.handicap_avg_taken_sum += this.score_frame_dmgtaken * Handicap_GetTotalHandicap(this, true); GameRules_scoring_add(this, DMGTAKEN, this.score_frame_dmgtaken); this.score_frame_dmgtaken = 0; } diff --git a/qcsrc/server/handicap.qh b/qcsrc/server/handicap.qh index 39a00e1a5c..99c25705a5 100644 --- a/qcsrc/server/handicap.qh +++ b/qcsrc/server/handicap.qh @@ -50,11 +50,17 @@ float Handicap_GetTotalHandicap(entity player, bool receiving); /// \param[in] player Player to check. void Handicap_UpdateHandicapLevel(entity player); -#define HANDICAP_MAX_LEVEL_EQUIVALENT 2.0 - -.int handicap_level; // This int ranges 0 to 16, 0 meaning no handicap, 1 to 16 representing handicap "levels" mapped // from 1.0 to HANDICAP_MAX_LEVEL_EQUIVALENT, using (given + taken)/2 (i.e. both-ways handicap). // It is networked to the client. // The levels are mostly meaningless, just used to determine the player_handicap icon color. +.int handicap_level; + +#define HANDICAP_MAX_LEVEL_EQUIVALENT 2.0 + +// These store the player's total "average-sum" given/taken damage handicaps respectively. +// average-sum refers to the arithmetic sum of damage taken/given, weighted by respective handicap. +// To calculate the average handicap, divide by damage taken/given. +.float handicap_avg_given_sum; +.float handicap_avg_taken_sum; -- 2.39.5