Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
DamageText Class Reference
Inheritance diagram for DamageText:
Collaboration diagram for DamageText:

Public Member Functions

 DamageText (int _group, vector _origin, bool _screen_coords, int _health, int _armor, int _potential_damage, int _deathtype, bool _friendlyfire)
 ~DamageText ()
void DamageText_draw2d (DamageText this)
void DamageText_update (DamageText this, vector _origin, bool screen_coords, 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

Detailed Description

Definition at line 3 of file cl_damagetext.qc.

Constructor & Destructor Documentation

◆ 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 182 of file cl_damagetext.qc.

183 {
185 this.m_group = _group;
186 this.m_friendlyfire = _friendlyfire;
187 this.m_screen_coords = _screen_coords;
188 if (_screen_coords)
189 {
194 }
195 else
196 {
199 this.m_shrink_rate = 0;
200 }
201 DamageText_update(this, _origin, _screen_coords,
202 _health, _armor, _potential_damage, _deathtype);
203 IL_PUSH(g_damagetext, this);
204 }
float autocvar_cl_damagetext_alpha_lifetime
float autocvar_cl_damagetext_2d_alpha_lifetime
float autocvar_cl_damagetext_2d_size_lifetime
DamageText(int _group, vector _origin, bool _screen_coords, int _health, int _armor, int _potential_damage, int _deathtype, bool _friendlyfire)
float m_shrink_rate
bool m_screen_coords
bool m_friendlyfire
float fade_rate
void DamageText_update(DamageText this, vector _origin, bool screen_coords, int _health, int _armor, int _potential_damage, int _deathtype)
IntrusiveList g_damagetext
Definition main.qh:93
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define CONSTRUCT(cname,...)
Definition oo.qh:123

References DamageText(), autocvar_cl_damagetext_2d_alpha_lifetime, autocvar_cl_damagetext_2d_size_lifetime, autocvar_cl_damagetext_alpha_lifetime, CONSTRUCT, DamageText_update(), fade_rate, g_damagetext, IL_PUSH(), m_friendlyfire, m_group, m_screen_coords, and m_shrink_rate.

Referenced by DamageText(), ~DamageText(), DamageText_draw2d(), DamageText_update(), and void().

◆ ~DamageText()

DamageText::~DamageText ( )
inline

Definition at line 206 of file cl_damagetext.qc.

207 {
208 strfree(this.text);
209 --DamageText_screen_count;
210 }
#define strfree(this)
Definition string.qh:59

References DamageText(), strfree, and text.

Member Function Documentation

◆ DamageText_draw2d()

void DamageText::DamageText_draw2d ( DamageText this)
inline

Definition at line 22 of file cl_damagetext.qc.

23 {
24 float since_hit = time - this.hit_time;
25 // can't use `dt = hit_time - prev_update_time` because shrinking wouldn't be linear
26 float size = this.m_size - since_hit * this.m_shrink_rate * this.m_size;
27 float alpha_ = this.alpha - since_hit * this.fade_rate;
28 bool haslifetime = (autocvar_cl_damagetext_lifetime < 0 // negative ignores lifetime
29 || (since_hit < autocvar_cl_damagetext_lifetime));
30 if (alpha_ <= 0 || size <= 0 || !haslifetime)
31 {
33 delete(this);
34 return;
35 }
36
37 vector screen_pos;
38 if (this.m_screen_coords)
39 screen_pos = this.origin + since_hit * autocvar_cl_damagetext_2d_velocity;
40 else
41 {
42 vector forward, right, up;
43 MAKE_VECTORS(view_angles, forward, right, up);
44
45 vector world_offset = since_hit * autocvar_cl_damagetext_velocity_world
47 vector world_pos = this.origin
48 + world_offset.x * forward
49 + world_offset.y * right
50 + world_offset.z * up;
51
52 screen_pos = project_3d_to_2d(world_pos)
55 }
56 screen_pos.y += size / 2;
57
58 // strip trailing spaces
59 string dtext = this.text;
60 int j = strlen(dtext) - 1;
61 while (substring(dtext, j, 1) == " " && j >= 0)
62 --j;
63 if (j < strlen(dtext) - 1)
64 dtext = substring(dtext, 0, j + 1);
65
66 // strip leading spaces
67 j = 0;
68 while (substring(dtext, j, 1) == " " && j < strlen(dtext))
69 ++j;
70 if (j > 0)
71 dtext = substring(dtext, j, strlen(dtext) - j);
72
73 // Center damage text
74 screen_pos.x -= stringwidth(dtext, true, hud_fontsize * 2) * 0.5;
75
76 if (screen_pos.z >= 0)
77 {
78 screen_pos.z = 0;
79 vector rgb;
80 if (this.m_friendlyfire)
81 rgb = this.m_color_friendlyfire;
82 else
83 rgb = this.m_color;
84
86 {
87 Weapon w = DEATH_WEAPONOF(this.m_deathtype);
88 if (w != WEP_Null) rgb = w.m_color;
89 }
90
91 vector drawfontscale_save = drawfontscale;
93 screen_pos.y -= drawfontscale.x * size / 2;
94 drawcolorcodedstring2_builtin(screen_pos, this.text,
96 rgb, alpha_, DRAWFLAG_NORMAL);
97 drawfontscale = drawfontscale_save;
98 }
99 }
vector autocvar_cl_damagetext_offset_screen
vector autocvar_cl_damagetext_velocity_world
float autocvar_cl_damagetext_size_max
vector autocvar_cl_damagetext_offset_world
bool autocvar_cl_damagetext_color_per_weapon
vector autocvar_cl_damagetext_velocity_screen
vector autocvar_cl_damagetext_2d_velocity
vector m_color_friendlyfire
vector m_color
vector m_color
M: color : waypointsprite color.
Definition weapon.qh:59
vector drawfontscale
Definition draw.qh:3
vector hud_fontsize
Definition main.qh:77
const float DRAWFLAG_NORMAL
vector view_angles
float time
vector size
vector origin
#define stringwidth
#define DEATH_WEAPONOF(t)
Definition all.qh:45
#define MAKE_VECTORS(angles, forward, right, up)
Same as the makevectors builtin but uses the provided locals instead of the v_* globals.
#define strlen
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
string substring(string s, float start, float length)
vector
Definition self.qh:92
vector project_3d_to_2d(vector vec)
Definition view.qc:373

References DamageText(), autocvar_cl_damagetext_2d_velocity, autocvar_cl_damagetext_color_per_weapon, autocvar_cl_damagetext_offset_screen, autocvar_cl_damagetext_offset_world, autocvar_cl_damagetext_size_max, autocvar_cl_damagetext_velocity_screen, autocvar_cl_damagetext_velocity_world, DamageText_draw2d(), DEATH_WEAPONOF, DRAWFLAG_NORMAL, drawfontscale, g_damagetext, hud_fontsize, IL_REMOVE(), Weapon::m_color, MAKE_VECTORS, origin, project_3d_to_2d(), size, stringwidth, strlen, substring(), this, time, vector, and view_angles.

Referenced by DamageText_draw2d(), and void().

◆ DamageText_update()

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

Definition at line 102 of file cl_damagetext.qc.

104 {
105 this.m_healthdamage = _health;
106 this.m_armordamage = _armor;
107 this.m_potential_damage = _potential_damage;
108 this.m_deathtype = _deathtype;
109 this.hit_time = time;
110 setorigin(this, _origin);
111 this.m_screen_coords = screen_coords;
112 if (this.m_screen_coords)
114 else
116
117 int health = rint(this.m_healthdamage
119 int armor = rint(this.m_armordamage
121 int total = rint((this.m_healthdamage + this.m_armordamage)
123 int potential = rint(this.m_potential_damage
125 int potential_health = rint((this.m_potential_damage - this.m_armordamage)
127
128 bool redundant = almost_equals_eps(this.m_healthdamage + this.m_armordamage,
129 this.m_potential_damage, 5);
130
132 s = strreplace("{armor}", (
134 ? ""
135 : sprintf("%d", armor)
136 ), s);
137 s = strreplace("{potential}", (
139 ? ""
140 : sprintf("%d", potential)
141 ), s);
142 s = strreplace("{potential_health}", (
144 ? ""
145 : sprintf("%d", potential_health)
146 ), s);
147
148 s = strreplace("{health}", (
149 (health == potential_health || !autocvar_cl_damagetext_format_verbose)
150 ? sprintf("%d", health)
151 : sprintf("%d (%d)", health, potential_health)
152 ), s);
153 s = strreplace("{total}", (
154 (total == potential || !autocvar_cl_damagetext_format_verbose)
155 ? sprintf("%d", total)
156 : sprintf("%d (%d)", total, potential)
157 ), s);
158
159 // futureproofing: remove any remaining (unknown) format strings
160 // in case we add new ones in the future so players can use them
161 // on new servers and still have working damagetext on old ones
162 while (true)
163 {
164 int opening_pos = strstrofs(s, "{", 0);
165 if (opening_pos == -1) break;
166 int closing_pos = strstrofs(s, "}", opening_pos);
167 if (closing_pos == -1 || closing_pos <= opening_pos) break;
168 s = strcat(
169 substring(s, 0, opening_pos),
170 substring_range(s, closing_pos + 1, strlen(s))
171 );
172 }
173
174 strcpy(this.text, s);
175
176 this.m_size = map_bound_ranges(potential,
179 }
bool autocvar_cl_damagetext_format_hide_redundant
float autocvar_cl_damagetext_size_min
float autocvar_cl_damagetext_size_min_damage
float autocvar_cl_damagetext_2d_alpha_start
float autocvar_cl_damagetext_size_max_damage
float autocvar_cl_damagetext_alpha_start
string autocvar_cl_damagetext_format
bool autocvar_cl_damagetext_format_verbose
int m_potential_damage
#define DAMAGETEXT_PRECISION_MULTIPLIER
Definition damagetext.qh:3
#define strstrofs
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:372
ERASEABLE float almost_equals_eps(float a, float b, float times_eps)
Definition math.qh:226
float rint(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float health
Legacy fields for the resources. To be removed.
Definition resources.qh:9
ERASEABLE string substring_range(string s, float b, float e)
Definition string.qh:292
#define strcpy(this, s)
Definition string.qh:52

References DamageText(), almost_equals_eps(), alpha, autocvar_cl_damagetext_2d_alpha_start, autocvar_cl_damagetext_alpha_start, autocvar_cl_damagetext_format, autocvar_cl_damagetext_format_hide_redundant, autocvar_cl_damagetext_format_verbose, autocvar_cl_damagetext_size_max, autocvar_cl_damagetext_size_max_damage, autocvar_cl_damagetext_size_min, autocvar_cl_damagetext_size_min_damage, DAMAGETEXT_PRECISION_MULTIPLIER, health, hit_time, m_armordamage, m_deathtype, m_healthdamage, m_potential_damage, m_screen_coords, m_size, map_bound_ranges(), rint(), strcat(), strcpy, strlen, strstrofs, substring(), substring_range(), text, time, and vector.

Referenced by DamageText().

◆ void()

DamageText::void ( DamageText )

Member Data Documentation

◆ alpha

Definition at line 7 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ fade_rate

float DamageText::fade_rate = 0

Definition at line 8 of file cl_damagetext.qc.

Referenced by DamageText().

◆ hit_time

float DamageText::hit_time = 0

Definition at line 16 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ m_armordamage

int DamageText::m_armordamage = 0

Definition at line 13 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ m_color

vector DamageText::m_color = autocvar_cl_damagetext_color

Definition at line 4 of file cl_damagetext.qc.

◆ m_color_friendlyfire

vector DamageText::m_color_friendlyfire = autocvar_cl_damagetext_friendlyfire_color

Definition at line 5 of file cl_damagetext.qc.

◆ m_deathtype

int DamageText::m_deathtype = 0

Definition at line 15 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ m_friendlyfire

bool DamageText::m_friendlyfire = false

Definition at line 11 of file cl_damagetext.qc.

Referenced by DamageText().

◆ m_group

int DamageText::m_group = 0

Definition at line 10 of file cl_damagetext.qc.

Referenced by DamageText().

◆ m_healthdamage

int DamageText::m_healthdamage = 0

Definition at line 12 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ m_potential_damage

int DamageText::m_potential_damage = 0

Definition at line 14 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ m_screen_coords

bool DamageText::m_screen_coords = false

Definition at line 18 of file cl_damagetext.qc.

Referenced by DamageText(), and DamageText_update().

◆ m_shrink_rate

float DamageText::m_shrink_rate = 0

Definition at line 9 of file cl_damagetext.qc.

Referenced by DamageText().

◆ m_size

float DamageText::m_size = autocvar_cl_damagetext_size_min

Definition at line 6 of file cl_damagetext.qc.

Referenced by DamageText_update().

◆ screen_count

int DamageText::screen_count = 0
static

Definition at line 20 of file cl_damagetext.qc.

◆ text

string DamageText::text = string_null

Definition at line 17 of file cl_damagetext.qc.

Referenced by ~DamageText(), and DamageText_update().


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