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) {