Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_damagetext.qc File Reference
#include "cl_damagetext.qh"
Include dependency graph for cl_damagetext.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  DamageText

Functions

float current_alpha (entity damage_text)
 NET_HANDLE (damagetext, bool isNew)

Function Documentation

◆ current_alpha()

float current_alpha ( entity damage_text)

Definition at line 213 of file cl_damagetext.qc.

214{
215 // alpha doesn't change - actual alpha is always calculated from the initial value
216 return damage_text.alpha - (time - damage_text.hit_time) * damage_text.fade_rate;
217}
float time

References current_alpha(), entity(), float(), and time.

Referenced by current_alpha().

◆ NET_HANDLE()

NET_HANDLE ( damagetext ,
bool isNew )

Definition at line 219 of file cl_damagetext.qc.

220{
221 make_pure(this);
222 int server_entity_index = ReadByte();
223 int deathtype = ReadInt24_t();
224 int flags = ReadByte();
225 bool friendlyfire = flags & DTFLAG_SAMETEAM;
226
227 int health, armor, potential_damage;
229 else health = ReadShort();
230 if (flags & DTFLAG_NO_ARMOR) armor = 0;
231 else if (flags & DTFLAG_BIG_ARMOR) armor = ReadInt24_t();
232 else armor = ReadShort();
233 if (flags & DTFLAG_NO_POTENTIAL) potential_damage = health + armor;
234 else if (flags & DTFLAG_BIG_POTENTIAL) potential_damage = ReadInt24_t();
235 else potential_damage = ReadShort();
236
237 return = true;
238 if (!isNew) return;
239 if (autocvar_cl_damagetext == 0) return;
240 if (friendlyfire)
241 {
243 return;
244
246 && health == 0 && armor == 0)
247 return;
248 }
249
250 int client_entity_index = server_entity_index - 1;
251 entity entcs = entcs_receiver(client_entity_index);
252
253 bool can_use_3d = entcs && entcs.has_origin;
254 bool too_close = vdist(entcs.origin - view_origin, <, autocvar_cl_damagetext_2d_close_range);
256 bool prefer_2d = spectatee_status != -1 && autocvar_cl_damagetext_2d && (too_close || prefer_in_view);
257
258 vector position;
259 bool is2d;
260 entity entDT = NULL; // which DT to update
261
264
265 // check if this entity already has a DamageText for it
266 IL_EACH(g_damagetext, it.m_group == server_entity_index, {
267 // if the time window where damage accumulates closes,
268 // disown the parent entity from this DamageText
269 // and (likely) give the entity a new DT afterwards
270 // this should only cancel damage accumulation for this DT
271
272 if (flags & DTFLAG_STOP_ACCUMULATION
273 || (current_alpha(it) < alphathreshold)
274 || ((autocvar_cl_damagetext_accumulate_lifetime >= 0) // negative never disowns
275 && (time - it.hit_time > autocvar_cl_damagetext_accumulate_lifetime)))
276 {
277 it.m_group = 0;
278 }
279 else
280 {
281 health += it.m_healthdamage;
282 armor += it.m_armordamage;
283 potential_damage += it.m_potential_damage;
284
285 entDT = it;
286 }
287 break;
288 });
289
290 if (can_use_3d && !prefer_2d)
291 {
292 // world coords
293 is2d = false;
294 position = entcs.origin;
295
296 if (entDT)
297 goto updateDT;
298
299 // 3D DamageTexts can later be changed into 2D,
300 // increment this here just in case
301 ++DamageText_screen_count;
302 goto spawnnewDT;
303 }
305 {
306 // screen coords only
307 is2d = true;
310
311 if (entDT)
312 goto updateDT;
313
314 // offset when hitting multiple enemies, dmgtext would overlap
315 position += autocvar_cl_damagetext_2d_overlap_offset * DamageText_screen_count++;
316 goto spawnnewDT;
317 }
318 return;
319
320LABEL(updateDT)
321 DamageText_update(entDT, position, is2d, health, armor, potential_damage, deathtype);
322 return;
323
324LABEL(spawnnewDT)
325 NEW(DamageText, server_entity_index, position, is2d,
326 health, armor, potential_damage, deathtype, friendlyfire);
327 return;
328}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
bool autocvar_cl_damagetext
float autocvar_cl_damagetext_2d_close_range
float autocvar_cl_damagetext_accumulate_alpha_rel
bool autocvar_cl_damagetext_2d_out_of_view
vector autocvar_cl_damagetext_2d_pos
float autocvar_cl_damagetext_alpha_start
vector autocvar_cl_damagetext_2d_overlap_offset
int autocvar_cl_damagetext_friendlyfire
bool autocvar_cl_damagetext_2d
vector view_origin
Definition main.qh:109
IntrusiveList g_damagetext
Definition main.qh:93
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197
#define LABEL(id)
Definition compiler.qh:34
float flags
const int DTFLAG_BIG_HEALTH
Definition damagetext.qh:7
const int DTFLAG_NO_POTENTIAL
Definition damagetext.qh:11
const int DTFLAG_BIG_ARMOR
Definition damagetext.qh:8
const int DTFLAG_SAMETEAM
Definition damagetext.qh:6
const int DTFLAG_BIG_POTENTIAL
Definition damagetext.qh:9
const int DTFLAG_NO_ARMOR
Definition damagetext.qh:10
#define entcs_receiver(...)
Definition ent_cs.qh:65
entity entcs
Definition ent_cs.qh:34
#define IL_EACH(this, cond, body)
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
int ReadInt24_t()
Definition net.qh:355
int ReadByte()
#define NEW(cname,...)
Definition oo.qh:117
#define make_pure(e)
direct use is
Definition oo.qh:13
#define NULL
Definition post.qh:14
float health
Legacy fields for the resources. To be removed.
Definition resources.qh:9
vector
Definition self.qh:92
#define vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition vector.qh:8
#define vec2(...)
Definition vector.qh:90
vector project_3d_to_2d(vector vec)
Definition view.qc:373
bool projected_on_screen(vector screen_pos)
Definition view.qc:379

References autocvar_cl_damagetext, autocvar_cl_damagetext_2d, autocvar_cl_damagetext_2d_close_range, autocvar_cl_damagetext_2d_out_of_view, autocvar_cl_damagetext_accumulate_alpha_rel, autocvar_cl_damagetext_alpha_start, autocvar_cl_damagetext_friendlyfire, DTFLAG_BIG_ARMOR, DTFLAG_BIG_HEALTH, DTFLAG_BIG_POTENTIAL, DTFLAG_NO_ARMOR, DTFLAG_NO_POTENTIAL, DTFLAG_SAMETEAM, entcs, entcs_receiver, entity(), flags, g_damagetext, health, IL_EACH, make_pure, NULL, project_3d_to_2d(), projected_on_screen(), ReadByte(), ReadInt24_t(), spectatee_status, vdist, vector, and view_origin.