seta hud_dynamic_follow 1 "HUD moves around following player's movement (effect shared with cl_followmodel, can be enabled independently from it though)"
seta hud_dynamic_follow_scale 0.01 "HUD following scale"
+seta hud_dynamic_shake 1 "shake the HUD when hurt"
+seta hud_dynamic_shake_damage_max 90 "damage value at which the HUD shake effect is maximum"
+seta hud_dynamic_shake_damage_min 10 "damage value at which the HUD shake effect is minimum"
+seta hud_dynamic_shake_scale 0.4 "HUD shake scale"
+
seta hud_showbinds 1 "what to show in the HUD to indicate certain keys to press: 0 display commands, 1 bound keys, 2 both"
seta hud_showbinds_limit 2 "maximum number of bound keys to show for a command. 0 for unlimited"
set _hud_showbinds_reload 0 "set it to 1 to reload binds if you changed any. It is reset to 0 automatically"
HUD_Mod_CTF_Reset();
}
+float autocvar_hud_dynamic_shake;
+float autocvar_hud_dynamic_shake_damage_max;
+float autocvar_hud_dynamic_shake_damage_min;
+float autocvar_hud_dynamic_shake_scale;
+float hud_dynamic_shake_x[10] = {0, 1, -0.7, 0.5, -0.3, 0.2, -0.1, 0.1, 0.0, 0};
+float hud_dynamic_shake_y[10] = {0, 0.4, 0.8, -0.2, -0.6, 0.0, 0.3, 0.1, -0.1, 0};
+bool Hud_Shake_Update()
+{
+ if(time - hud_dynamic_shake_time < 0)
+ return false;
+
+ float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
+ float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
+ int i = floor(elapsed_time);
+ if(i >= 9)
+ return false;
+
+ float f = elapsed_time - i;
+ hud_dynamic_shake_ofs.x = ((1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1]) * vid_conwidth * 0.27;
+ hud_dynamic_shake_ofs.y = ((1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1]) * vid_conheight * 0.27;
+ hud_dynamic_shake_ofs.z = 0;
+ hud_dynamic_shake_ofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
+ return true;
+}
+
void calc_followmodel_ofs(entity view);
void Hud_Dynamic_Frame()
{
if (fabs(hud_dynamic_ofs.x) < 0.001) hud_dynamic_ofs.x = 0;
if (fabs(hud_dynamic_ofs.y) < 0.001) hud_dynamic_ofs.y = 0;
if (fabs(hud_dynamic_ofs.z) < 0.001) hud_dynamic_ofs.z = 0;
+
+ float health = STAT(HEALTH);
+ if(autocvar_hud_dynamic_shake > 0 && !autocvar__hud_configure && health > 0)
+ {
+ if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
+ hud_dynamic_shake_factor = 0;
+ else
+ {
+ float new_hud_dynamic_shake_factor = 0;
+ if(prev_health - health >= autocvar_hud_dynamic_shake_damage_min && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min)
+ {
+ float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
+ new_hud_dynamic_shake_factor = (prev_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
+ if(new_hud_dynamic_shake_factor >= 1)
+ new_hud_dynamic_shake_factor = 1;
+ if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
+ {
+ hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
+ hud_dynamic_shake_time = time;
+ }
+ }
+ if(hud_dynamic_shake_factor)
+ if(!Hud_Shake_Update())
+ hud_dynamic_shake_factor = 0;
+ }
+ }
}
void HUD_Main()
float autocvar_hud_dynamic_follow;
float autocvar_hud_dynamic_follow_scale;
+vector hud_dynamic_shake_ofs;
+float hud_dynamic_shake_factor;
+float hud_dynamic_shake_time;
+
// shared across viewmodel effects and dynamic hud code
vector cl_followmodel_ofs;
float cl_followmodel_time;
panel_bg_padding = panel.current_panel_bg_padding; \
panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha; \
} \
+ if(hud_dynamic_shake_factor > 0) panel_pos += hud_dynamic_shake_ofs; \
if(hud_dynamic_ofs.y) panel_pos.x += hud_dynamic_ofs.y * vid_conwidth; \
if(hud_dynamic_ofs.z) panel_pos.y += hud_dynamic_ofs.z * vid_conheight; \
if(hud_dynamic_ofs.x) { \