Xonotic
cl_damagetext.qc File Reference
#include "cl_damagetext.qh"
+ Include dependency graph for cl_damagetext.qc:

Go to the source code of this file.

Classes

class  DamageText
 

Functions

 AUTOCVAR_SAVE (cl_damagetext, bool, true, "Draw damage dealt where you hit the enemy")
 
 AUTOCVAR_SAVE (cl_damagetext_format, string, "-{total}", "How to format the damage text. {health}, {armor}, {total}, {potential}: full damage not capped to target's health, {potential_health}: health damage not capped to target's health")
 
 AUTOCVAR_SAVE (cl_damagetext_format_verbose, bool, false, "{health} shows {potential_health} too when they differ; {total} shows {potential} too when they differ")
 
 AUTOCVAR_SAVE (cl_damagetext_format_hide_redundant, bool, false, "hide {armor} if 0; hide {potential} and {potential_health} when same as actual")
 
 AUTOCVAR_SAVE (cl_damagetext_color, vector, '1 1 0', "Damage text color")
 
 AUTOCVAR_SAVE (cl_damagetext_color_per_weapon, bool, false, "Damage text uses weapon color")
 
 AUTOCVAR_SAVE (cl_damagetext_size_min, float, 10, "Damage text font size for small damage")
 
 AUTOCVAR_SAVE (cl_damagetext_size_min_damage, float, 25, "How much damage is considered small")
 
 AUTOCVAR_SAVE (cl_damagetext_size_max, float, 16, "Damage text font size for large damage")
 
 AUTOCVAR_SAVE (cl_damagetext_size_max_damage, float, 140, "How much damage is considered large")
 
 AUTOCVAR_SAVE (cl_damagetext_alpha_start, float, 1, "Damage text initial alpha")
 
 AUTOCVAR_SAVE (cl_damagetext_alpha_lifetime, float, 3, "Damage text lifetime in seconds")
 
 AUTOCVAR_SAVE (cl_damagetext_velocity_screen, vector, '0 0 0', "Damage text move direction (screen coordinates)")
 
 AUTOCVAR_SAVE (cl_damagetext_velocity_world, vector, '0 0 20', "Damage text move direction (world coordinates relative to player's view)")
 
 AUTOCVAR_SAVE (cl_damagetext_offset_screen, vector, '0 -45 0', "Damage text offset (screen coordinates)")
 
 AUTOCVAR_SAVE (cl_damagetext_offset_world, vector, '0 0 0', "Damage text offset (world coordinates relative to player's view)")
 
 AUTOCVAR_SAVE (cl_damagetext_accumulate_range, float, 30, "Damage text spawned within this range is accumulated")
 
 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, int, 1, "0: never show for friendly fire, 1: when more than 0 damage, 2: always")
 
 AUTOCVAR_SAVE (cl_damagetext_friendlyfire_color, vector, '1 0 0', "Damage text color for friendlyfire")
 
 AUTOCVAR_SAVE (cl_damagetext_2d, bool, true, "Show damagetext in 2D coordinates 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.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, '-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 occurred off-screen")
 
float current_alpha (entity damage_text)
 
 NET_HANDLE (damagetext, bool isNew)
 
 STATIC_INIT (DamageText_LegacyFormat)
 

Function Documentation

◆ AUTOCVAR_SAVE() [1/29]

AUTOCVAR_SAVE ( cl_damagetext  ,
bool  ,
true  ,
"Draw damage dealt where you hit the enemy  
)

Referenced by STATIC_INIT().

+ Here is the caller graph for this function:

◆ AUTOCVAR_SAVE() [2/29]

AUTOCVAR_SAVE ( cl_damagetext_format  ,
string  ,
"-{total}"  ,
"How to format the damage text. {health ,
{armor}  ,
{total}  ,
{potential}:full damage not capped to target 's  health,
{potential_health}:health damage not capped to target 's health  
)

◆ AUTOCVAR_SAVE() [3/29]

AUTOCVAR_SAVE ( cl_damagetext_format_verbose  ,
bool  ,
false  ,
"{health} shows {potential_health} too when they differ; {total} shows {potential} too when they differ"   
)

◆ AUTOCVAR_SAVE() [4/29]

AUTOCVAR_SAVE ( cl_damagetext_format_hide_redundant  ,
bool  ,
false  ,
"hide {armor} if 0; hide {potential} and {potential_health} when same as actual"   
)

◆ AUTOCVAR_SAVE() [5/29]

AUTOCVAR_SAVE ( cl_damagetext_color  ,
vector  ,
'1 1 0'  ,
"Damage text color  
)

◆ AUTOCVAR_SAVE() [6/29]

AUTOCVAR_SAVE ( cl_damagetext_color_per_weapon  ,
bool  ,
false  ,
"Damage text uses weapon color  
)

◆ AUTOCVAR_SAVE() [7/29]

AUTOCVAR_SAVE ( cl_damagetext_size_min  ,
float  ,
10  ,
"Damage text font size for small damage"   
)

◆ AUTOCVAR_SAVE() [8/29]

AUTOCVAR_SAVE ( cl_damagetext_size_min_damage  ,
float  ,
25  ,
"How much damage is considered small"   
)

◆ AUTOCVAR_SAVE() [9/29]

AUTOCVAR_SAVE ( cl_damagetext_size_max  ,
float  ,
16  ,
"Damage text font size for large damage"   
)

◆ AUTOCVAR_SAVE() [10/29]

AUTOCVAR_SAVE ( cl_damagetext_size_max_damage  ,
float  ,
140  ,
"How much damage is considered large"   
)

◆ AUTOCVAR_SAVE() [11/29]

AUTOCVAR_SAVE ( cl_damagetext_alpha_start  ,
float  ,
,
"Damage text initial alpha  
)

◆ AUTOCVAR_SAVE() [12/29]

AUTOCVAR_SAVE ( cl_damagetext_alpha_lifetime  ,
float  ,
,
"Damage text lifetime in seconds"   
)

◆ AUTOCVAR_SAVE() [13/29]

AUTOCVAR_SAVE ( cl_damagetext_velocity_screen  ,
vector  ,
'0 0 0'  ,
"Damage text move direction (screen coordinates)"   
)

◆ AUTOCVAR_SAVE() [14/29]

AUTOCVAR_SAVE ( cl_damagetext_velocity_world  ,
vector  ,
'0 0 20'  ,
"Damage text move direction (world coordinates relative to player's view)"   
)

◆ AUTOCVAR_SAVE() [15/29]

AUTOCVAR_SAVE ( cl_damagetext_offset_screen  ,
vector  ,
'0 -45 0'  ,
"Damage text offset (screen coordinates)"   
)

◆ AUTOCVAR_SAVE() [16/29]

AUTOCVAR_SAVE ( cl_damagetext_offset_world  ,
vector  ,
'0 0 0'  ,
"Damage text offset (world coordinates relative to player's view)"   
)

◆ AUTOCVAR_SAVE() [17/29]

AUTOCVAR_SAVE ( cl_damagetext_accumulate_range  ,
float  ,
30  ,
"Damage text spawned within this range is accumulated"   
)

◆ AUTOCVAR_SAVE() [18/29]

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() [19/29]

AUTOCVAR_SAVE ( cl_damagetext_friendlyfire  ,
int  ,
,
"0: never show for friendly  fire,
1:when more than 0  damage,
2:always"   
)

◆ AUTOCVAR_SAVE() [20/29]

AUTOCVAR_SAVE ( cl_damagetext_friendlyfire_color  ,
vector  ,
'1 0 0'  ,
"Damage text color for friendlyfire"   
)

◆ AUTOCVAR_SAVE() [21/29]

AUTOCVAR_SAVE ( cl_damagetext_2d  ,
bool  ,
true  ,
"Show damagetext in 2D coordinates if the enemy's location is not known"   
)

◆ AUTOCVAR_SAVE() [22/29]

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() [23/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_alpha_start  ,
float  ,
,
"2D damage text initial alpha"   
)

◆ AUTOCVAR_SAVE() [24/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_alpha_lifetime  ,
float  ,
1.  3,
"2D damage text lifetime (alpha fading) in seconds"   
)

◆ AUTOCVAR_SAVE() [25/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_size_lifetime  ,
float  ,
,
"2D damage text lifetime (size shrinking) in seconds"   
)

◆ AUTOCVAR_SAVE() [26/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_velocity  ,
vector  ,
'-25 0 0'  ,
"2D damage text move direction (screen coordinates)"   
)

◆ AUTOCVAR_SAVE() [27/29]

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() [28/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_close_range  ,
float  ,
125  ,
"Always use 2D damagetext for hits closer that this"   
)

◆ AUTOCVAR_SAVE() [29/29]

AUTOCVAR_SAVE ( cl_damagetext_2d_out_of_view  ,
bool  ,
true  ,
"Always use 2D damagetext for hits that occurred off-screen"   
)

◆ current_alpha()

float current_alpha ( entity  damage_text)

Definition at line 202 of file cl_damagetext.qc.

References time.

Referenced by NET_HANDLE().

202  {
203  // alpha doesn't change - actual alpha is always calculated from the initial value
204  return damage_text.alpha - (time - damage_text.hit_time) * damage_text.fade_rate;
205 }
float time
Definition: csprogsdefs.qc:16
+ Here is the caller graph for this function:

◆ NET_HANDLE()

NET_HANDLE ( damagetext  ,
bool  isNew 
)

Definition at line 207 of file cl_damagetext.qc.

References current_alpha(), DTFLAG_BIG_ARMOR, DTFLAG_BIG_HEALTH, DTFLAG_BIG_POTENTIAL, DTFLAG_NO_ARMOR, DTFLAG_NO_POTENTIAL, DTFLAG_SAMETEAM, entity(), flags, g_drawables_2d, health, IL_EACH, make_impure, make_pure, max(), NEW, NULL, project_3d_to_2d(), projected_on_screen(), spectatee_status, vdist, vec2, vector(), vid_conheight, vid_conwidth, and view_origin.

208 {
209  make_pure(this);
210  int server_entity_index = ReadByte();
211  int deathtype = ReadInt24_t();
212  int flags = ReadByte();
213  bool friendlyfire = flags & DTFLAG_SAMETEAM;
214 
215  int health, armor, potential_damage;
216  if (flags & DTFLAG_BIG_HEALTH) health = ReadInt24_t();
217  else health = ReadShort();
218  if (flags & DTFLAG_NO_ARMOR) armor = 0;
219  else if (flags & DTFLAG_BIG_ARMOR) armor = ReadInt24_t();
220  else armor = ReadShort();
221  if (flags & DTFLAG_NO_POTENTIAL) potential_damage = health + armor;
222  else if (flags & DTFLAG_BIG_POTENTIAL) potential_damage = ReadInt24_t();
223  else potential_damage = ReadShort();
224 
225  return = true;
226  if (!isNew) return;
227  if (autocvar_cl_damagetext == 0) return;
228  if (friendlyfire) {
229  if (autocvar_cl_damagetext_friendlyfire == 0) return;
230  if (autocvar_cl_damagetext_friendlyfire == 1 && health == 0 && armor == 0) return;
231  }
232 
233  int client_entity_index = server_entity_index - 1;
234  entity entcs = entcs_receiver(client_entity_index);
235 
236  bool can_use_3d = entcs && entcs.has_origin;
237  bool too_close = vdist(entcs.origin - view_origin, <, autocvar_cl_damagetext_2d_close_range);
238  bool prefer_in_view = autocvar_cl_damagetext_2d_out_of_view && !projected_on_screen(project_3d_to_2d(entcs.origin));
239  bool prefer_2d = spectatee_status != -1 && autocvar_cl_damagetext_2d && (too_close || prefer_in_view);
240 
241  if (can_use_3d && !prefer_2d) {
242  // world coords
243  // 1 as min because shotgun sends damagetext per pellet (see https://gitlab.com/xonotic/xonotic-data.pk3dir/issues/1994).
244  for (entity e = findradius(entcs.origin, max(autocvar_cl_damagetext_accumulate_range, 1)); e; e = e.chain) {
245  if (e.instanceOfDamageText
246  && !e.m_screen_coords // we're using origin for both world coords and screen coords so avoid mismatches
247  && e.m_group == server_entity_index
248  && current_alpha(e) > autocvar_cl_damagetext_accumulate_alpha_rel * autocvar_cl_damagetext_alpha_start) {
249  DamageText_update(e, entcs.origin, e.m_healthdamage + health, e.m_armordamage + armor, e.m_potential_damage + potential_damage, deathtype);
250  return;
251  }
252  }
253  make_impure(NEW(DamageText, server_entity_index, entcs.origin, false, health, armor, potential_damage, deathtype, friendlyfire));
254  } else if (autocvar_cl_damagetext_2d && spectatee_status != -1) {
255  // screen coords only
256  vector screen_pos = vec2(vid_conwidth * autocvar_cl_damagetext_2d_pos.x, vid_conheight * autocvar_cl_damagetext_2d_pos.y);
257  IL_EACH(g_drawables_2d, it.instanceOfDamageText && it.m_screen_coords && it.m_group == server_entity_index, {
258  DamageText_update(it, screen_pos, it.m_healthdamage + health, it.m_armordamage + armor, it.m_potential_damage + potential_damage, deathtype);
259  return;
260  });
261 
262  // when hitting multiple enemies, dmgtext would overlap
263  if (DamageText_screen_first == NULL) {
264  DamageText dt = NEW(DamageText, server_entity_index, screen_pos, true, health, armor, potential_damage, deathtype, friendlyfire);
265  make_impure(dt);
266  DamageText_screen_first = dt;
267  DamageText_screen_count = 1;
268  } else {
269  screen_pos += autocvar_cl_damagetext_2d_overlap_offset * DamageText_screen_count;
270  DamageText_screen_count++;
271  make_impure(NEW(DamageText, server_entity_index, screen_pos, true, health, armor, potential_damage, deathtype, friendlyfire));
272  }
273  }
274 }
float vid_conheight
#define IL_EACH(this, cond, body)
vector project_3d_to_2d(vector vec)
Definition: view.qc:359
#define NEW(cname,...)
Definition: oo.qh:105
entity() spawn
vector view_origin
Definition: main.qh:93
bool projected_on_screen(vector screen_pos)
Definition: view.qc:370
const int DTFLAG_NO_POTENTIAL
Definition: damagetext.qh:11
float vid_conwidth
const int DTFLAG_NO_ARMOR
Definition: damagetext.qh:10
#define make_impure(e)
Definition: oo.qh:15
const int DTFLAG_BIG_POTENTIAL
Definition: damagetext.qh:9
#define NULL
Definition: post.qh:17
float current_alpha(entity damage_text)
#define make_pure(e)
Definition: oo.qh:12
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float spectatee_status
Definition: main.qh:166
float flags
Definition: csprogsdefs.qc:129
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
float health
Definition: progsdefs.qc:137
const int DTFLAG_SAMETEAM
Definition: damagetext.qh:6
#define vec2(...)
Definition: vector.qh:90
const int DTFLAG_BIG_HEALTH
Definition: damagetext.qh:7
const int DTFLAG_BIG_ARMOR
Definition: damagetext.qh:8
IntrusiveList g_drawables_2d
Definition: main.qh:78
+ Here is the call graph for this function:

◆ STATIC_INIT()

STATIC_INIT ( DamageText_LegacyFormat  )

Definition at line 8 of file cl_damagetext.qc.

References AUTOCVAR_SAVE(), localcmd, strstrofs, and vector().

8  {
9  // damagetext used to be off by default and the cvar got saved in people's configs along with the old format
10  // enable damagetext while updating the format for a one time effect
11  if (strstrofs(autocvar_cl_damagetext_format, "{", 0) < 0) {
12  localcmd("\nseta cl_damagetext 1\n");
13  localcmd("\nseta cl_damagetext_format -{total}\n");
14  };
15 }
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function: