Xonotic
DamageText Class Reference
+ Inheritance diagram for DamageText:
+ Collaboration diagram for DamageText:

Public Member Functions

 DamageText ::~ DamageText ()
 
 DamageText ::DamageText (int _group, vector _origin, bool _screen_coords, int _health, int _armor, int _potential_damage, int _deathtype, bool _friendlyfire)
 
void DamageText_draw2d (DamageText this)
 
void DamageText_update (DamageText this, vector _origin, int _health, int _armor, int _potential_damage, int _deathtype)
 
 void (DamageText) draw2d
 

Public Attributes

float alpha = autocvar_cl_damagetext_alpha_start
 
float fade_rate = 0
 
float hit_time = 0
 
int m_armordamage = 0
 
vector m_color = autocvar_cl_damagetext_color
 
vector m_color_friendlyfire = autocvar_cl_damagetext_friendlyfire_color
 
int m_deathtype = 0
 
bool m_friendlyfire = false
 
int m_group = 0
 
int m_healthdamage = 0
 
int m_potential_damage = 0
 
bool m_screen_coords = false
 
float m_shrink_rate = 0
 
float m_size = autocvar_cl_damagetext_size_min
 
string text = string_null
 

Static Public Attributes

static int screen_count = 0
 
static DamageText screen_first = NULL
 

Detailed Description

Definition at line 43 of file cl_damagetext.qc.

Constructor & Destructor Documentation

◆ DamageText ::~ DamageText()

DamageText::DamageText ::~ DamageText ( )
inline

Definition at line 192 of file cl_damagetext.qc.

References ENDCLASS, NULL, and strfree.

192  {
193  strfree(this.text);
194  if (this == DamageText_screen_first) {
195  // start from 0 offset again, hopefully, others (if any) will have faded away by now
196  DamageText_screen_first = NULL;
197  DamageText_screen_count = 0;
198  }
199  }
#define NULL
Definition: post.qh:17
#define strfree(this)
Definition: string.qh:56

Member Function Documentation

◆ DamageText ::DamageText()

DamageText::DamageText ::DamageText ( int  _group,
vector  _origin,
bool  _screen_coords,
int  _health,
int  _armor,
int  _potential_damage,
int  _deathtype,
bool  _friendlyfire 
)
inline

Definition at line 176 of file cl_damagetext.qc.

References CONSTRUCT, fade_rate, g_drawables_2d, and IL_PUSH().

176  {
178  this.m_group = _group;
179  this.m_friendlyfire = _friendlyfire;
180  this.m_screen_coords = _screen_coords;
181  if (_screen_coords) {
182  this.fade_rate = 1 / autocvar_cl_damagetext_2d_alpha_lifetime;
183  this.m_shrink_rate = 1 / autocvar_cl_damagetext_2d_size_lifetime;
184  } else {
185  this.fade_rate = 1 / autocvar_cl_damagetext_alpha_lifetime;
186  this.m_shrink_rate = 0;
187  }
188  DamageText_update(this, _origin, _health, _armor, _potential_damage, _deathtype);
189  IL_PUSH(g_drawables_2d, this);
190  }
void DamageText_update(DamageText this, vector _origin, int _health, int _armor, int _potential_damage, int _deathtype)
bool m_friendlyfire
bool m_screen_coords
#define CONSTRUCT(cname,...)
Definition: oo.qh:111
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
float fade_rate
float m_shrink_rate
IntrusiveList g_drawables_2d
Definition: main.qh:78
+ Here is the call graph for this function:

◆ DamageText_draw2d()

void DamageText::DamageText_draw2d ( DamageText  this)
inline

Definition at line 63 of file cl_damagetext.qc.

References ATTRIB, DEATH_WEAPONOF, DRAWFLAG_NORMAL, drawfontscale, fade_rate, origin, project_3d_to_2d(), size, time, view_angles, and Weapon::wpcolor.

63  {
64  float since_hit = time - this.hit_time;
65  // can't use `dt = hit_time - prev_update_time` because shrinking wouldn't be linear
66  float size = this.m_size - since_hit * this.m_shrink_rate * this.m_size;
67  float alpha_ = this.alpha - since_hit * this.fade_rate;
68  if (alpha_ <= 0 || size <= 0) {
69  delete(this);
70  return;
71  }
72 
73  vector screen_pos;
74  if (this.m_screen_coords) {
75  screen_pos = this.origin + since_hit * autocvar_cl_damagetext_2d_velocity;
76  } else {
77  vector forward, right, up;
78  MAKE_VECTORS(view_angles, forward, right, up);
79  vector world_offset = since_hit * autocvar_cl_damagetext_velocity_world + autocvar_cl_damagetext_offset_world;
80  vector world_pos = this.origin + world_offset.x * forward + world_offset.y * right + world_offset.z * up;
81  screen_pos = project_3d_to_2d(world_pos) + since_hit * autocvar_cl_damagetext_velocity_screen + autocvar_cl_damagetext_offset_screen;
82  }
83  screen_pos.y += size / 2;
84 
85  if (screen_pos.z >= 0) {
86  screen_pos.z = 0;
87  vector rgb;
88  if (this.m_friendlyfire) {
89  rgb = this.m_color_friendlyfire;
90  } else {
91  rgb = this.m_color;
92  }
93  if (autocvar_cl_damagetext_color_per_weapon) {
95  if (w != WEP_Null) rgb = w.wpcolor;
96  }
97 
98  vector drawfontscale_save = drawfontscale;
99  drawfontscale = (size / autocvar_cl_damagetext_size_max) * '1 1 0';
100  screen_pos.y -= drawfontscale.x * size / 2;
101  drawcolorcodedstring2_builtin(screen_pos, this.text, autocvar_cl_damagetext_size_max * '1 1 0', rgb, alpha_, DRAWFLAG_NORMAL);
102  drawfontscale = drawfontscale_save;
103  }
104  }
float hit_time
vector project_3d_to_2d(vector vec)
Definition: view.qc:359
bool m_friendlyfire
vector drawfontscale
Definition: draw.qh:3
vector wpcolor
M: color : waypointsprite color.
Definition: weapon.qh:56
origin
Definition: ent_cs.qc:114
vector m_color_friendlyfire
vector size
Definition: csprogsdefs.qc:114
bool m_screen_coords
#define DEATH_WEAPONOF(t)
Definition: all.qh:41
vector view_angles
Definition: csprogsdefs.qc:150
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
float fade_rate
vector(float skel, float bonenum) _skel_get_boneabs_hidden
fields which are explicitly/manually set are marked with "M", fields set automatically are marked wit...
Definition: weapon.qh:41
float time
Definition: csprogsdefs.qc:16
vector m_color
float m_shrink_rate
+ Here is the call graph for this function:

◆ DamageText_update()

void DamageText::DamageText_update ( DamageText  this,
vector  _origin,
int  _health,
int  _armor,
int  _potential_damage,
int  _deathtype 
)
inline

Definition at line 107 of file cl_damagetext.qc.

References almost_equals_eps(), alpha, DAMAGETEXT_PRECISION_MULTIPLIER, health, map_bound_ranges(), rint(), setorigin(), strcat(), strcpy, strlen(), strstrofs, substring(), substring_range(), and time.

107  {
108  this.m_healthdamage = _health;
109  this.m_armordamage = _armor;
110  this.m_potential_damage = _potential_damage;
111  this.m_deathtype = _deathtype;
112  setorigin(this, _origin);
113  if (this.m_screen_coords) {
114  this.alpha = autocvar_cl_damagetext_2d_alpha_start;
115  } else {
116  this.alpha = autocvar_cl_damagetext_alpha_start;
117  }
118  this.hit_time = time;
119 
124  int potential_health = rint((this.m_potential_damage - this.m_armordamage) / DAMAGETEXT_PRECISION_MULTIPLIER);
125 
126  bool redundant = almost_equals_eps(this.m_healthdamage + this.m_armordamage, this.m_potential_damage, 5);
127 
128  string s = autocvar_cl_damagetext_format;
129  s = strreplace("{armor}", (
130  (this.m_armordamage == 0 && autocvar_cl_damagetext_format_hide_redundant)
131  ? ""
132  : sprintf("%d", armor)
133  ), s);
134  s = strreplace("{potential}", (
135  (redundant && autocvar_cl_damagetext_format_hide_redundant)
136  ? ""
137  : sprintf("%d", potential)
138  ), s);
139  s = strreplace("{potential_health}", (
140  (redundant && autocvar_cl_damagetext_format_hide_redundant)
141  ? ""
142  : sprintf("%d", potential_health)
143  ), s);
144 
145  s = strreplace("{health}", (
146  (health == potential_health || !autocvar_cl_damagetext_format_verbose)
147  ? sprintf("%d", health)
148  : sprintf("%d (%d)", health, potential_health)
149  ), s);
150  s = strreplace("{total}", (
151  (total == potential || !autocvar_cl_damagetext_format_verbose)
152  ? sprintf("%d", total)
153  : sprintf("%d (%d)", total, potential)
154  ), s);
155 
156  // futureproofing: remove any remaining (unknown) format strings in case we add new ones in the future
157  // so players can use them on new servers and still have working damagetext on old ones
158  while (true) {
159  int opening_pos = strstrofs(s, "{", 0);
160  if (opening_pos == -1) break;
161  int closing_pos = strstrofs(s, "}", opening_pos);
162  if (closing_pos == -1 || closing_pos <= opening_pos) break;
163  s = strcat(
164  substring(s, 0, opening_pos),
165  substring_range(s, closing_pos + 1, strlen(s))
166  );
167  }
168 
169  strcpy(this.text, s);
170 
171  this.m_size = map_bound_ranges(potential,
172  autocvar_cl_damagetext_size_min_damage, autocvar_cl_damagetext_size_max_damage,
173  autocvar_cl_damagetext_size_min, autocvar_cl_damagetext_size_max);
174  }
float hit_time
bool m_screen_coords
#define DAMAGETEXT_PRECISION_MULTIPLIER
Definition: damagetext.qh:3
ERASEABLE string substring_range(string s, float b, float e)
Definition: string.qh:273
#define strcpy(this, s)
Definition: string.qh:49
ERASEABLE float map_bound_ranges(float value, float src_min, float src_max, float dest_min, float dest_max)
Same as map_ranges except that values outside the source range are clamped to min or max...
Definition: math.qh:375
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define strstrofs
Definition: dpextensions.qh:42
float health
Definition: progsdefs.qc:137
setorigin(ent, v)
float time
Definition: csprogsdefs.qc:16
ERASEABLE float almost_equals_eps(float a, float b, float times_eps)
Definition: math.qh:229
int m_healthdamage
int m_potential_damage
+ Here is the call graph for this function:

◆ void()

DamageText::void ( DamageText  )

Member Data Documentation

◆ alpha

float DamageText::alpha = autocvar_cl_damagetext_alpha_start

Definition at line 47 of file cl_damagetext.qc.

◆ fade_rate

float DamageText::fade_rate = 0

Definition at line 48 of file cl_damagetext.qc.

◆ hit_time

float DamageText::hit_time = 0

Definition at line 56 of file cl_damagetext.qc.

◆ m_armordamage

int DamageText::m_armordamage = 0

Definition at line 53 of file cl_damagetext.qc.

◆ m_color

vector DamageText::m_color = autocvar_cl_damagetext_color

Definition at line 44 of file cl_damagetext.qc.

◆ m_color_friendlyfire

vector DamageText::m_color_friendlyfire = autocvar_cl_damagetext_friendlyfire_color

Definition at line 45 of file cl_damagetext.qc.

◆ m_deathtype

int DamageText::m_deathtype = 0

Definition at line 55 of file cl_damagetext.qc.

◆ m_friendlyfire

bool DamageText::m_friendlyfire = false

Definition at line 51 of file cl_damagetext.qc.

◆ m_group

int DamageText::m_group = 0

Definition at line 50 of file cl_damagetext.qc.

◆ m_healthdamage

int DamageText::m_healthdamage = 0

Definition at line 52 of file cl_damagetext.qc.

◆ m_potential_damage

int DamageText::m_potential_damage = 0

Definition at line 54 of file cl_damagetext.qc.

◆ m_screen_coords

bool DamageText::m_screen_coords = false

Definition at line 58 of file cl_damagetext.qc.

◆ m_shrink_rate

float DamageText::m_shrink_rate = 0

Definition at line 49 of file cl_damagetext.qc.

◆ m_size

float DamageText::m_size = autocvar_cl_damagetext_size_min

Definition at line 46 of file cl_damagetext.qc.

◆ screen_count

int DamageText::screen_count = 0
static

Definition at line 61 of file cl_damagetext.qc.

◆ screen_first

DamageText DamageText::screen_first = NULL
static

Definition at line 60 of file cl_damagetext.qc.

◆ text

string DamageText::text = string_null

Definition at line 57 of file cl_damagetext.qc.


The documentation for this class was generated from the following file: