Skip to content

Commit 27a2df8

Browse files
committed
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.
1 parent 06f3161 commit 27a2df8

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

config/usage.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ setdesc "crosshairsize" "size of crosshair (in terms of screen size)" "value"
484484
setdesc "crosshairhitspeed" "duration for hit crosshair to show following a hit on an opponent (milliseconds)" "value"
485485
setdesc "crosshairblend" "determines crosshair opacity (0 = transparent 1 = opaque)" "value"
486486
setdesc "crosshairaccamt" "determines blend by accuracy level intensity (when blend by accuracy is enabled)" "value"
487-
setdesc "crosshairflash" "determines whether the crosshair flashes when at critical health (less than the heal amount)" "value"
487+
setdesc "crosshairhealth" "determines whether to color the crosshair depending on the current health" "value"
488488
setdesc "crosshairthrob" "determines scale of crosshair throb (size change) effect (like while gaining health)" "value"
489489
setdesc "crosshairtex" "determines path to crosshair image file" "file"
490490
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"

src/game/hud.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,11 +1174,38 @@ namespace hud
11741174
else if(crosshairweapons&2) c = vec::fromcolor(W(game::focus->weapselect, colour));
11751175
else if(crosshairtone) skewcolour(c.r, c.g, c.b, crosshairtone);
11761176
int heal = game::focus->gethealth(game::gamemode, game::mutators);
1177-
if(crosshairflash && game::focus->state == CS_ALIVE && game::focus->health < heal)
1177+
if(crosshairflash && game::focus->state == CS_ALIVE)
11781178
{
1179-
int millis = lastmillis%1000;
1180-
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);
1181-
flashcolour(c.r, c.g, c.b, 1.f, 0.f, 0.f, amt);
1179+
const float ratio = clamp(float(game::focus->health)/float(heal), 0.0f, 2.0f);
1180+
1181+
if(ratio < 0.2f)
1182+
{
1183+
// Red (critical health level)
1184+
c.r = 1.0f;
1185+
c.g = 0.0f;
1186+
c.b = 0.0f;
1187+
}
1188+
else if(ratio < 0.6f)
1189+
{
1190+
// Red-yellow
1191+
c.r = 1.0f;
1192+
c.g = (ratio-0.2f)/0.4f;
1193+
c.b = 0.0f;
1194+
}
1195+
else if(ratio < 1.0f)
1196+
{
1197+
// Yellow-white
1198+
c.r = 1.0f;
1199+
c.g = 1.0f;
1200+
c.b = (ratio-0.6f)/0.4f;
1201+
}
1202+
else
1203+
{
1204+
// Green (overheal)
1205+
c.r = 2.0f - ratio;
1206+
c.g = 1.0f;
1207+
c.b = 2.0f - ratio;
1208+
}
11821209
}
11831210
if(crosshairthrob > 0 && regentime && game::focus->lastregen && lastmillis-game::focus->lastregen <= regentime)
11841211
{

0 commit comments

Comments
 (0)