From 27a2df81964ef01f88d6cc68b246db2286871dc4 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 26 Dec 2019 22:21:17 +0100 Subject: [PATCH] Improve crosshair health display The new implementation has numerous upsides compared to the previous implementation: - It indicates the player's health more accurately using a color gradient well-known among FPS players. Health above 100 is indicated by tinting the crosshair green. - It's always visible, even in screenshots. Due to lack of animation, it also avoids hiding the health status on every loop of the animation (since the crosshair became white). The variable was renamed from `crosshairflash` to `crosshairhealth` to reflect the change. --- config/usage.cfg | 2 +- src/game/hud.cpp | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/config/usage.cfg b/config/usage.cfg index a48066017..a8b5150c5 100644 --- a/config/usage.cfg +++ b/config/usage.cfg @@ -484,7 +484,7 @@ setdesc "crosshairsize" "size of crosshair (in terms of screen size)" "value" setdesc "crosshairhitspeed" "duration for hit crosshair to show following a hit on an opponent (milliseconds)" "value" setdesc "crosshairblend" "determines crosshair opacity (0 = transparent 1 = opaque)" "value" setdesc "crosshairaccamt" "determines blend by accuracy level intensity (when blend by accuracy is enabled)" "value" -setdesc "crosshairflash" "determines whether the crosshair flashes when at critical health (less than the heal amount)" "value" +setdesc "crosshairhealth" "determines whether to color the crosshair depending on the current health" "value" setdesc "crosshairthrob" "determines scale of crosshair throb (size change) effect (like while gaining health)" "value" setdesc "crosshairtex" "determines path to crosshair image file" "file" setdesc "showfps" "display the frames per second counter on the hud;^n0 = no display^n1 = display average fps^n2 = display average fps and best and worst difference^n3 = display average fps and fps range^n4 = display average fps and average/worst frametimes" "value" diff --git a/src/game/hud.cpp b/src/game/hud.cpp index d81980ba4..ed17208ae 100644 --- a/src/game/hud.cpp +++ b/src/game/hud.cpp @@ -1174,11 +1174,38 @@ namespace hud else if(crosshairweapons&2) c = vec::fromcolor(W(game::focus->weapselect, colour)); else if(crosshairtone) skewcolour(c.r, c.g, c.b, crosshairtone); int heal = game::focus->gethealth(game::gamemode, game::mutators); - if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < heal) + if(crosshairflash && game::focus->state == CS_ALIVE) { - int millis = lastmillis%1000; - float amt = (millis <= 500 ? millis/500.f : 1.f-((millis-500)/500.f))*clamp(float(heal-game::focus->health)/float(heal), 0.f, 1.f); - flashcolour(c.r, c.g, c.b, 1.f, 0.f, 0.f, amt); + const float ratio = clamp(float(game::focus->health)/float(heal), 0.0f, 2.0f); + + if(ratio < 0.2f) + { + // Red (critical health level) + c.r = 1.0f; + c.g = 0.0f; + c.b = 0.0f; + } + else if(ratio < 0.6f) + { + // Red-yellow + c.r = 1.0f; + c.g = (ratio-0.2f)/0.4f; + c.b = 0.0f; + } + else if(ratio < 1.0f) + { + // Yellow-white + c.r = 1.0f; + c.g = 1.0f; + c.b = (ratio-0.6f)/0.4f; + } + else + { + // Green (overheal) + c.r = 2.0f - ratio; + c.g = 1.0f; + c.b = 2.0f - ratio; + } } if(crosshairthrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime) {