From d5e33d809572dd49367ac9e4ca2ee040a78ad9ef Mon Sep 17 00:00:00 2001 From: otta8634 Date: Sun, 15 Dec 2024 19:01:37 +0800 Subject: [PATCH] Improve player_handicap icon implementation Changed the handicap_total calculation method to average given and taken, instead of multiplying them. Made .handicap_level range from 0 to 16 instead of to 255, so the player_handicap icon will essentially be \xFFF, \xFEE, ..., \xF00 from 1 to 16. Added HANDICAP_MAX_LEVEL_EQUIVALENT, set to 2, the cl_handicap at which .handicap_level 16 is reached. Improved some associated comments. Fixed ".handicap_total" typo. --- qcsrc/client/hud/panel/scoreboard.qc | 4 ++-- qcsrc/server/handicap.qc | 8 ++++---- qcsrc/server/handicap.qh | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 7fb6c512c..5bd5bb96a 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1010,8 +1010,8 @@ string Scoreboard_GetName(entity pl) if (handicap_lvl != 0) { sbt_field_icon_extra1 = "gfx/scoreboard/player_handicap"; - sbt_field_icon_extra1_rgb = '1 0 0' + '0 1 1' * ((255 - handicap_lvl) / 254); - // goes from white to red over level 1 to 255 + sbt_field_icon_extra1_rgb = '1 0 0' + '0 1 1' * ((16 - handicap_lvl) / 15); + // goes from white to red over level 1 to 16 } return entcs_GetName(pl.sv_entnum); } diff --git a/qcsrc/server/handicap.qc b/qcsrc/server/handicap.qc index 12cfbed84..4ff59a729 100644 --- a/qcsrc/server/handicap.qc +++ b/qcsrc/server/handicap.qc @@ -6,7 +6,7 @@ /// \copyright GNU GPLv2 or any later version. #include -#include // for .handicap_total +#include // for .handicap_level #include // for REPLICATE_APPLYCHANGE #include @@ -95,12 +95,12 @@ float Handicap_GetTotalHandicap(entity player, bool receiving) void Handicap_UpdateHandicapLevel(entity player) { - float handicap_total = Handicap_GetTotalHandicap(player, true) * - Handicap_GetTotalHandicap(player, false); + float handicap_total = (Handicap_GetTotalHandicap(player, true) + + Handicap_GetTotalHandicap(player, false)) / 2; if (handicap_total <= 1) player.handicap_level = 0; else - player.handicap_level = map_bound_ranges(handicap_total, 1, 5, 1, 255); + player.handicap_level = floor(map_bound_ranges(handicap_total, 1, HANDICAP_MAX_LEVEL_EQUIVALENT, 1, 16)); } REPLICATE_APPLYCHANGE("cl_handicap_damage_given", { Handicap_UpdateHandicapLevel(this); }); diff --git a/qcsrc/server/handicap.qh b/qcsrc/server/handicap.qh index b31f3273c..39a00e1a5 100644 --- a/qcsrc/server/handicap.qh +++ b/qcsrc/server/handicap.qh @@ -50,7 +50,11 @@ 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 255, 0 meaning no handicap, 1-255 representing handicap "levels" -// ... mapped from 1.0 to 5.0, using given * taken (i.e. both-ways handicap) -// It is networked to the client +// 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. + -- 2.39.2