AUTOCVAR_SAVE(cl_damagetext_accumulate_alpha_rel, float, 0.65, "Only update existing damage text when it's above this much percentage (0 to 1) of the starting alpha");
AUTOCVAR_SAVE(cl_damagetext_friendlyfire, bool, true, "Show damage text for friendlyfire too");
AUTOCVAR_SAVE(cl_damagetext_friendlyfire_color, vector, '1 0 0', "Damage text color for friendlyfire");
-AUTOCVAR_SAVE(cl_damagetext_2d_pos, vector, '0.47 0.47 0', "2D damage text initial position (X and Y between 0 and 1)");
+
+AUTOCVAR_SAVE(cl_damagetext_2d, bool, true, "Show damagetext in 2D coordinated if the enemy's location is not known");
+AUTOCVAR_SAVE(cl_damagetext_2d_pos, vector, '0.47 0.53 0', "2D damage text initial position (X and Y between 0 and 1)");
AUTOCVAR_SAVE(cl_damagetext_2d_alpha_start, float, 1, "2D damage text initial alpha");
-AUTOCVAR_SAVE(cl_damagetext_2d_alpha_lifetime, float, 1.5, "2D damage text lifetime (alpha fading) in seconds");
+AUTOCVAR_SAVE(cl_damagetext_2d_alpha_lifetime, float, 1.3, "2D damage text lifetime (alpha fading) in seconds");
AUTOCVAR_SAVE(cl_damagetext_2d_size_lifetime, float, 3, "2D damage text lifetime (size shrinking) in seconds");
-AUTOCVAR_SAVE(cl_damagetext_2d_velocity, vector, '-20 0 0', "2D damage text move direction (screen coordinates)");
+AUTOCVAR_SAVE(cl_damagetext_2d_velocity, vector, '-25 0 0', "2D damage text move direction (screen coordinates)");
AUTOCVAR_SAVE(cl_damagetext_2d_overlap_offset, vector, '0 -15 0', "Offset 2D damage text by this much to prevent overlapping (screen coordinates)");
+AUTOCVAR_SAVE(cl_damagetext_2d_close_range, float, 125, "Always use 2D damagetext for hits closer that this");
+AUTOCVAR_SAVE(cl_damagetext_2d_out_of_view, bool, true, "Always use 2D damagetext for hits that occured off-screen");
CLASS(DamageText, Object)
ATTRIB(DamageText, m_color, vector, autocvar_cl_damagetext_color);
if (this.text) strunzone(this.text);
this.text = strzone(s);
- float size_range = autocvar_cl_damagetext_size_max - autocvar_cl_damagetext_size_min;
- float damage_range = autocvar_cl_damagetext_size_max_damage - autocvar_cl_damagetext_size_min_damage;
- float scale_factor = size_range / damage_range;
- this.m_size = bound(
- autocvar_cl_damagetext_size_min,
- (potential - autocvar_cl_damagetext_size_min_damage) * scale_factor + autocvar_cl_damagetext_size_min,
- autocvar_cl_damagetext_size_max);
+ this.m_size = map_bound_ranges(potential,
+ autocvar_cl_damagetext_size_min_damage, autocvar_cl_damagetext_size_max_damage,
+ autocvar_cl_damagetext_size_min, autocvar_cl_damagetext_size_max);
}
CONSTRUCTOR(DamageText, int _group, vector _origin, bool _screen_coords, int _health, int _armor, int _potential_damage, int _deathtype, bool _friendlyfire) {
int client_entity_index = server_entity_index - 1;
entity entcs = entcs_receiver(client_entity_index);
- if (!entcs || !entcs.has_origin) {
- // screen coords only
- vector screen_pos = '0 0 0';
- screen_pos.x = vid_conwidth * autocvar_cl_damagetext_2d_pos.x;
- screen_pos.y = vid_conheight * autocvar_cl_damagetext_2d_pos.y;
+ bool can_use_3d = entcs && entcs.has_origin;
+ bool too_close = vdist(entcs.origin - view_origin, <, autocvar_cl_damagetext_2d_close_range);
+ bool prefer_in_view = autocvar_cl_damagetext_2d_out_of_view && !projected_on_screen(project_3d_to_2d(entcs.origin));
+ bool prefer_2d = spectatee_status != -1 && autocvar_cl_damagetext_2d && (too_close || prefer_in_view);
+
+ if (can_use_3d && !prefer_2d) {
+ // world coords
+ if (autocvar_cl_damagetext_accumulate_range) {
+ for (entity e = findradius(entcs.origin, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
+ if (e.instanceOfDamageText
+ && !e.m_screen_coords // we're using origin for both world coords and screen coords so avoid mismatches
+ && e.m_group == server_entity_index
+ && e.alpha > autocvar_cl_damagetext_accumulate_alpha_rel * autocvar_cl_damagetext_alpha_start) {
+ DamageText_update(e, entcs.origin, e.m_healthdamage + health, e.m_armordamage + armor, e.m_potential_damage + potential_damage, deathtype);
+ return;
+ }
+ }
+ }
+ make_impure(NEW(DamageText, server_entity_index, entcs.origin, false, health, armor, potential_damage, deathtype, friendlyfire));
+ } else if (autocvar_cl_damagetext_2d) {
+ // screen coords only
+ vector screen_pos = vec2(vid_conwidth * autocvar_cl_damagetext_2d_pos.x, vid_conheight * autocvar_cl_damagetext_2d_pos.y);
IL_EACH(g_drawables_2d, it.instanceOfDamageText && it.m_screen_coords && it.m_group == server_entity_index, {
DamageText_update(it, screen_pos, it.m_healthdamage + health, it.m_armordamage + armor, it.m_potential_damage + potential_damage, deathtype);
return;
DamageText_screen_count++;
make_impure(NEW(DamageText, server_entity_index, screen_pos, true, health, armor, potential_damage, deathtype, friendlyfire));
}
- } else {
- // world coords
- if (autocvar_cl_damagetext_accumulate_range) {
- for (entity e = findradius(entcs.origin, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
- if (e.instanceOfDamageText
- && !e.m_screen_coords // we're using origin for both world coords and screen coords so avoid mismatches
- && e.m_group == server_entity_index
- && e.alpha > autocvar_cl_damagetext_accumulate_alpha_rel * autocvar_cl_damagetext_alpha_start) {
- DamageText_update(e, entcs.origin, e.m_healthdamage + health, e.m_armordamage + armor, e.m_potential_damage + potential_damage, deathtype);
- return;
- }
- }
- }
- make_impure(NEW(DamageText, server_entity_index, entcs.origin, false, health, armor, potential_damage, deathtype, friendlyfire));
}
}