-
-#ifdef SVQC
-AUTOCVAR(sv_damagetext, int, 2, _("<= 0: disabled, >= 1: spectators, >= 2: players, >= 3: all players"));
-#define SV_DAMAGETEXT_DISABLED() (autocvar_sv_damagetext <= 0 /* disabled */)
-#define SV_DAMAGETEXT_SPECTATORS_ONLY() (autocvar_sv_damagetext >= 1 /* spectators only */)
-#define SV_DAMAGETEXT_PLAYERS() (autocvar_sv_damagetext >= 2 /* players */)
-#define SV_DAMAGETEXT_ALL() (autocvar_sv_damagetext >= 3 /* all players */)
-MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
- if (SV_DAMAGETEXT_DISABLED()) return;
- const entity attacker = M_ARGV(0, entity);
- const entity hit = M_ARGV(1, entity); if (hit == attacker) return;
- const float health = M_ARGV(2, float);
- const float armor = M_ARGV(3, float);
- const int deathtype = M_ARGV(5, int);
- const float potential_damage = M_ARGV(6, float);
- const vector location = hit.origin;
- FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
- if (
- (SV_DAMAGETEXT_ALL()) ||
- (SV_DAMAGETEXT_PLAYERS() && it == attacker) ||
- (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_SPEC(it) && it.enemy == attacker) ||
- (SV_DAMAGETEXT_SPECTATORS_ONLY() && IS_OBSERVER(it))
- ) {
- int flags = 0;
- if (SAME_TEAM(hit, attacker)) flags |= DTFLAG_SAMETEAM;
- if (health >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_HEALTH;
- if (armor >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_ARMOR;
- if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) flags |= DTFLAG_BIG_POTENTIAL;
- if (!armor) flags |= DTFLAG_NO_ARMOR;
- if (fabs((armor + health) - potential_damage) < 0.0001) flags |= DTFLAG_NO_POTENTIAL;
-
- msg_entity = it;
- WriteHeader(MSG_ONE, damagetext);
- WriteEntity(MSG_ONE, hit);
- WriteCoord(MSG_ONE, location.x);
- WriteCoord(MSG_ONE, location.y);
- WriteCoord(MSG_ONE, location.z);
- WriteInt24_t(MSG_ONE, deathtype);
- WriteByte(MSG_ONE, flags);
-
- // we need to send a few decimal places to minimize errors when accumulating damage
- // sending them multiplied saves bandwidth compared to using WriteCoord,
- // however if the multiplied damage would be too much for (signed) short, we send an int24
- if (flags & DTFLAG_BIG_HEALTH) WriteInt24_t(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER);
- else WriteShort(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER);
- if (!(flags & DTFLAG_NO_ARMOR))
- {
- if (flags & DTFLAG_BIG_ARMOR) WriteInt24_t(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
- else WriteShort(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
- }
- if (!(flags & DTFLAG_NO_POTENTIAL))
- {
- if (flags & DTFLAG_BIG_POTENTIAL) WriteInt24_t(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
- else WriteShort(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
- }
- }
- ));
-}
-#endif
-
-#ifdef CSQC
-NET_HANDLE(damagetext, bool isNew)
-{
- int group = ReadShort();
- vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord());
- int deathtype = ReadInt24_t();
- int flags = ReadByte();
- bool friendlyfire = flags & DTFLAG_SAMETEAM;
-
- int health, armor, potential_damage;
- if (flags & DTFLAG_BIG_HEALTH) health = ReadInt24_t();
- else health = ReadShort();
- if (flags & DTFLAG_NO_ARMOR) armor = 0;
- else if (flags & DTFLAG_BIG_ARMOR) armor = ReadInt24_t();
- else armor = ReadShort();
- if (flags & DTFLAG_NO_POTENTIAL) potential_damage = health + armor;
- else if (flags & DTFLAG_BIG_POTENTIAL) potential_damage = ReadInt24_t();
- else potential_damage = ReadShort();
-
- return = true;
- if (autocvar_cl_damagetext) {
- if (friendlyfire && !autocvar_cl_damagetext_friendlyfire) {
- return;
- }
- if (autocvar_cl_damagetext_accumulate_range) {
- for (entity e = findradius(location, autocvar_cl_damagetext_accumulate_range); e; e = e.chain) {
- if (e.instanceOfDamageText && e.m_group == group && e.alpha > autocvar_cl_damagetext_accumulate_alpha_rel * autocvar_cl_damagetext_alpha_start) {
- DamageText_update(e, location, e.m_damage + health, e.m_armordamage + armor, e.m_potential_damage + potential_damage, deathtype);
- return;
- }
- }
- }
- make_impure(NEW(DamageText, group, location, health, armor, potential_damage, deathtype, friendlyfire));
- }
-}
-#endif
-
-#ifdef MENUQC
-
-#include <menu/gamesettings.qh>
-
-CLASS(XonoticDamageTextSettings, XonoticTab)
- REGISTER_SETTINGS(damagetext, NEW(XonoticDamageTextSettings));
- ATTRIB(XonoticDamageTextSettings, title, string, _("Damage text"));
- ATTRIB(XonoticDamageTextSettings, intendedWidth, float, 0.9);
- ATTRIB(XonoticDamageTextSettings, rows, float, 15.5);
- ATTRIB(XonoticDamageTextSettings, columns, float, 5);
- INIT(XonoticDamageTextSettings) { this.configureDialog(this); }
- METHOD(XonoticDamageTextSettings, showNotify, void(entity this)) { loadAllCvars(this); }
- METHOD(XonoticDamageTextSettings, fill, void(entity this))
- {
- entity e;
- this.gotoRC(this, 0, 1); this.setFirstColumn(this, this.currentColumn);
- this.TD(this, 1, 3, makeXonoticCheckBox(0, "cl_damagetext", _("Draw damage numbers")));
- this.TR(this);
- this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Font size:")));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TD(this, 1, 2, e = makeXonoticSlider(0, 50, 1, "cl_damagetext_size"));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TR(this);
- this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Accumulate range:")));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TD(this, 1, 2, e = makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range"));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TR(this);
- this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Lifetime:")));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TD(this, 1, 2, e = makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime"));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TR(this);
- this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:")));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color"));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TR(this);
- this.TR(this);
- // friendly fire
- this.TD(this, 1, 3, e = makeXonoticCheckBox(0, "cl_damagetext_friendlyfire", _("Draw damage numbers for friendly fire")));
- setDependent(e, "cl_damagetext", 1, 1);
- this.TR(this);
- this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color:")));
- setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1);
- this.TD(this, 2, 2, e = makeXonoticColorpickerString("cl_damagetext_friendlyfire_color", "cl_damagetext_friendlyfire_color"));
- setDependentAND(e, "cl_damagetext", 1, 1, "cl_damagetext_friendlyfire", 1, 1);
- this.TR(this);
- }
-ENDCLASS(XonoticDamageTextSettings)
-#endif