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

Go to the source code of this file.

Macros

#define SV_DAMAGETEXT_ALL()   (autocvar_sv_damagetext >= 3)
 
#define SV_DAMAGETEXT_DISABLED()   (autocvar_sv_damagetext <= 0)
 
#define SV_DAMAGETEXT_PLAYERS()   (autocvar_sv_damagetext >= 2)
 
#define SV_DAMAGETEXT_SPECTATORS_ONLY()   (autocvar_sv_damagetext >= 1)
 

Functions

 AUTOCVAR (sv_damagetext, int, 2, "<= 0: disabled, >= 1: visible to spectators, >= 2: visible to attacker, >= 3: all players see everyone's damage")
 
 MUTATOR_HOOKFUNCTION (damagetext, PlayerDamaged)
 
 REGISTER_MUTATOR (damagetext, true)
 
bool write_damagetext (entity this, entity client, int sf)
 

Variables

float dent_net_armor
 
float dent_net_deathtype
 
int dent_net_flags
 
float dent_net_health
 
float dent_net_potential
 

Macro Definition Documentation

◆ SV_DAMAGETEXT_ALL

#define SV_DAMAGETEXT_ALL ( )    (autocvar_sv_damagetext >= 3)

Definition at line 10 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ SV_DAMAGETEXT_DISABLED

#define SV_DAMAGETEXT_DISABLED ( )    (autocvar_sv_damagetext <= 0)

Definition at line 7 of file sv_damagetext.qc.

Referenced by MUTATOR_HOOKFUNCTION().

◆ SV_DAMAGETEXT_PLAYERS

#define SV_DAMAGETEXT_PLAYERS ( )    (autocvar_sv_damagetext >= 2)

Definition at line 9 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ SV_DAMAGETEXT_SPECTATORS_ONLY

#define SV_DAMAGETEXT_SPECTATORS_ONLY ( )    (autocvar_sv_damagetext >= 1)

Definition at line 8 of file sv_damagetext.qc.

Referenced by write_damagetext().

Function Documentation

◆ AUTOCVAR()

AUTOCVAR ( sv_damagetext  ,
int  ,
,
"<= 0:  disabled,
>=1:visible to  spectators,
>=2:visible to  attacker,
>=3:all players see everyone 's damage"   
)

◆ MUTATOR_HOOKFUNCTION()

MUTATOR_HOOKFUNCTION ( damagetext  ,
PlayerDamaged   
)

Definition at line 57 of file sv_damagetext.qc.

References almost_equals_eps(), DAMAGETEXT_SHORT_LIMIT, DEATH_WEAPONOF, DTFLAG_BIG_ARMOR, DTFLAG_BIG_HEALTH, DTFLAG_BIG_POTENTIAL, DTFLAG_NO_ARMOR, DTFLAG_NO_POTENTIAL, DTFLAG_SAMETEAM, entity(), flags, health, M_ARGV, new_pure, SAME_TEAM, setthink, SV_DAMAGETEXT_DISABLED, time, and write_damagetext().

57  {
58  if (SV_DAMAGETEXT_DISABLED()) return;
59  entity attacker = M_ARGV(0, entity);
60  entity hit = M_ARGV(1, entity); if (hit == attacker) return;
61  float health = M_ARGV(2, float);
62  float armor = M_ARGV(3, float);
63  int deathtype = M_ARGV(5, int);
64  float potential_damage = M_ARGV(6, float);
65  if(DEATH_WEAPONOF(deathtype) == WEP_VAPORIZER) return;
66  if(deathtype == DEATH_FIRE.m_id || deathtype == DEATH_BUFF.m_id) return; // TODO: exclude damage over time and thorn effects
67 
68  int flags = 0;
69  if (SAME_TEAM(hit, attacker)) flags |= DTFLAG_SAMETEAM;
70  if (health >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_HEALTH;
71  if (armor >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_ARMOR;
72  if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_POTENTIAL;
73  if (!armor) flags |= DTFLAG_NO_ARMOR;
74  if (almost_equals_eps(armor + health, potential_damage, 5)) flags |= DTFLAG_NO_POTENTIAL;
75 
76  entity net_text = new_pure(net_damagetext);
77  net_text.realowner = attacker;
78  net_text.enemy = hit;
79  net_text.dent_net_flags = flags;
80  net_text.dent_net_deathtype = deathtype;
81  net_text.dent_net_health = health;
82  net_text.dent_net_armor = armor;
83  net_text.dent_net_potential = potential_damage;
84 
85  setthink(net_text, SUB_Remove);
86  net_text.nextthink = (time > 10) ? (time + 0.5) : 10; // allow a buffer from start time for clients to load in
87 
88  Net_LinkEntity(net_text, false, 0, write_damagetext);
89 }
entity() spawn
const int DTFLAG_NO_POTENTIAL
Definition: damagetext.qh:11
const int DTFLAG_NO_ARMOR
Definition: damagetext.qh:10
#define DEATH_WEAPONOF(t)
Definition: all.qh:41
const int DTFLAG_BIG_POTENTIAL
Definition: damagetext.qh:9
#define DAMAGETEXT_SHORT_LIMIT
Definition: damagetext.qh:4
#define SAME_TEAM(a, b)
Definition: teams.qh:239
#define M_ARGV(x, type)
Definition: events.qh:17
float flags
Definition: csprogsdefs.qc:129
float health
Definition: progsdefs.qc:137
const int DTFLAG_SAMETEAM
Definition: damagetext.qh:6
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
const int DTFLAG_BIG_HEALTH
Definition: damagetext.qh:7
#define setthink(e, f)
float time
Definition: csprogsdefs.qc:16
ERASEABLE float almost_equals_eps(float a, float b, float times_eps)
Definition: math.qh:229
const int DTFLAG_BIG_ARMOR
Definition: damagetext.qh:8
#define SV_DAMAGETEXT_DISABLED()
Definition: sv_damagetext.qc:7
bool write_damagetext(entity this, entity client, int sf)
+ Here is the call graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( damagetext  ,
true   
)

◆ write_damagetext()

bool write_damagetext ( entity  this,
entity  client,
int  sf 
)

Definition at line 18 of file sv_damagetext.qc.

References DAMAGETEXT_PRECISION_MULTIPLIER, dent_net_armor, dent_net_deathtype, dent_net_flags, dent_net_health, dent_net_potential, DTFLAG_BIG_ARMOR, DTFLAG_BIG_HEALTH, DTFLAG_BIG_POTENTIAL, DTFLAG_NO_ARMOR, DTFLAG_NO_POTENTIAL, enemy, entity(), etof(), flags, health, IS_OBSERVER, IS_SPEC, realowner, SV_DAMAGETEXT_ALL, SV_DAMAGETEXT_PLAYERS, SV_DAMAGETEXT_SPECTATORS_ONLY, WriteByte(), and WriteShort().

Referenced by MUTATOR_HOOKFUNCTION().

19 {
20  entity attacker = this.realowner;
21  entity hit = this.enemy;
22  int flags = this.dent_net_flags;
23  int deathtype = this.dent_net_deathtype;
24  float health = this.dent_net_health;
25  float armor = this.dent_net_armor;
26  float potential_damage = this.dent_net_potential;
27  if (!(
28  (SV_DAMAGETEXT_ALL()) ||
29  (SV_DAMAGETEXT_PLAYERS() && client == attacker) ||
30  (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(client) && client.enemy == attacker) ||
32  )) return false;
33 
34  WriteHeader(MSG_ENTITY, damagetext);
35  WriteByte(MSG_ENTITY, etof(hit));
36  WriteInt24_t(MSG_ENTITY, deathtype);
37  WriteByte(MSG_ENTITY, flags);
38 
39  // we need to send a few decimal places to minimize errors when accumulating damage
40  // sending them multiplied saves bandwidth compared to using WriteCoord,
41  // however if the multiplied damage would be too much for (signed) short, we send an int24
42  if (flags & DTFLAG_BIG_HEALTH) WriteInt24_t(MSG_ENTITY, health * DAMAGETEXT_PRECISION_MULTIPLIER);
43  else WriteShort(MSG_ENTITY, health * DAMAGETEXT_PRECISION_MULTIPLIER);
44  if (!(flags & DTFLAG_NO_ARMOR))
45  {
46  if (flags & DTFLAG_BIG_ARMOR) WriteInt24_t(MSG_ENTITY, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
47  else WriteShort(MSG_ENTITY, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
48  }
49  if (!(flags & DTFLAG_NO_POTENTIAL))
50  {
51  if (flags & DTFLAG_BIG_POTENTIAL) WriteInt24_t(MSG_ENTITY, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
52  else WriteShort(MSG_ENTITY, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
53  }
54  return true;
55 }
float dent_net_armor
entity() spawn
#define IS_OBSERVER(v)
Definition: utils.qh:11
const int DTFLAG_NO_POTENTIAL
Definition: damagetext.qh:11
const int DTFLAG_NO_ARMOR
Definition: damagetext.qh:10
#define DAMAGETEXT_PRECISION_MULTIPLIER
Definition: damagetext.qh:3
const int DTFLAG_BIG_POTENTIAL
Definition: damagetext.qh:9
#define IS_SPEC(v)
Definition: utils.qh:10
entity enemy
Definition: sv_ctf.qh:143
#define SV_DAMAGETEXT_PLAYERS()
Definition: sv_damagetext.qc:9
float dent_net_health
#define SV_DAMAGETEXT_ALL()
float flags
Definition: csprogsdefs.qc:129
float health
Definition: progsdefs.qc:137
float dent_net_deathtype
entity realowner
Definition: common.qh:25
float dent_net_potential
const int DTFLAG_BIG_HEALTH
Definition: damagetext.qh:7
int dent_net_flags
#define SV_DAMAGETEXT_SPECTATORS_ONLY()
Definition: sv_damagetext.qc:8
const int DTFLAG_BIG_ARMOR
Definition: damagetext.qh:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ dent_net_armor

float dent_net_armor

Definition at line 15 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ dent_net_deathtype

float dent_net_deathtype

Definition at line 13 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ dent_net_flags

int dent_net_flags

Definition at line 12 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ dent_net_health

float dent_net_health

Definition at line 14 of file sv_damagetext.qc.

Referenced by write_damagetext().

◆ dent_net_potential

float dent_net_potential

Definition at line 16 of file sv_damagetext.qc.

Referenced by write_damagetext().