X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fmutators%2Fmutator%2Fdamagetext%2Fdamagetext.qc;h=371bf2bbe08a581396a4e4a65d2f6286e51f0ac4;hb=f551090a70789701ca1f042746917295b3237bff;hp=6a33ab34e6268230983db5b642d910a7c8dd7663;hpb=19750cfd8bcf5dc2f30122113f88f06380ba0922;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc index 6a33ab34e..371bf2bbe 100644 --- a/qcsrc/common/mutators/mutator/damagetext/damagetext.qc +++ b/qcsrc/common/mutators/mutator/damagetext/damagetext.qc @@ -2,7 +2,7 @@ #define MUTATOR_DAMAGETEXT_H #ifdef MENUQC -#include +#include #endif #endif @@ -13,7 +13,10 @@ REGISTER_MUTATOR(damagetext, true); #if defined(CSQC) || defined(MENUQC) // no translatable cvar description please AUTOCVAR_SAVE(cl_damagetext, bool, false, "Draw damage dealt where you hit the enemy"); -AUTOCVAR_SAVE(cl_damagetext_format, string, "-%3$$d", "How to format the damage text. 1$ is health, 2$ is armor, 3$ is both"); +AUTOCVAR_SAVE(cl_damagetext_format, string, "-{total}", "How to format the damage text. {health}, {armor}, {total}"); +STATIC_INIT(DamageText_LegacyFormat) { + if (strstrofs(autocvar_cl_damagetext_format, "{", 0) < 0) autocvar_cl_damagetext_format = "-{total}"; +} AUTOCVAR_SAVE(cl_damagetext_color, vector, '1 1 0', "Damage text color"); AUTOCVAR_SAVE(cl_damagetext_color_per_weapon, bool, false, "Damage text uses weapon color"); AUTOCVAR_SAVE(cl_damagetext_size, float, 8, "Damage text font size"); @@ -22,16 +25,20 @@ AUTOCVAR_SAVE(cl_damagetext_alpha_lifetime, float, 3, "Damage text AUTOCVAR_SAVE(cl_damagetext_velocity, vector, '0 0 20', "Damage text move direction"); AUTOCVAR_SAVE(cl_damagetext_offset, vector, '0 -40 0', "Damage text offset"); AUTOCVAR_SAVE(cl_damagetext_accumulate_range, float, 30, "Damage text spawned within this range is accumulated"); +AUTOCVAR_SAVE(cl_damagetext_friendlyfire, bool, true, "Show damage text for friendlyfire too"); +AUTOCVAR_SAVE(cl_damagetext_friendlyfire_color, vector, '1 0 0', "Damage text color for friendlyfire"); #endif #ifdef CSQC CLASS(DamageText, Object) ATTRIB(DamageText, m_color, vector, autocvar_cl_damagetext_color) + ATTRIB(DamageText, m_color_friendlyfire, vector, autocvar_cl_damagetext_friendlyfire_color) ATTRIB(DamageText, m_size, float, autocvar_cl_damagetext_size) ATTRIB(DamageText, alpha, float, autocvar_cl_damagetext_alpha_start) ATTRIB(DamageText, fade_rate, float, 1 / autocvar_cl_damagetext_alpha_lifetime) ATTRIB(DamageText, velocity, vector, autocvar_cl_damagetext_velocity) ATTRIB(DamageText, m_group, int, 0) + ATTRIB(DamageText, m_friendlyfire, bool, false) ATTRIB(DamageText, m_damage, int, 0) ATTRIB(DamageText, m_armordamage, int, 0) ATTRIB(DamageText, m_deathtype, int, 0) @@ -46,13 +53,22 @@ CLASS(DamageText, Object) vector pos = project_3d_to_2d(this.origin) + autocvar_cl_damagetext_offset; if (pos.z >= 0 && this.m_size > 0) { pos.z = 0; - vector rgb = this.m_color; + vector rgb; + if (this.m_friendlyfire) { + rgb = this.m_color_friendlyfire; + } + else { + rgb = this.m_color; + } if (autocvar_cl_damagetext_color_per_weapon) { Weapon w = DEATH_WEAPONOF(this.m_deathtype); if (w != WEP_Null) rgb = w.wpcolor; } - string s = sprintf(autocvar_cl_damagetext_format, this.m_damage, this.m_armordamage, this.m_damage + this.m_armordamage); - drawcolorcodedstring2(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL); + string s = autocvar_cl_damagetext_format; + s = strreplace("{health}", sprintf("%d", this.m_damage), s); + s = strreplace("{armor}", sprintf("%d", this.m_armordamage), s); + s = strreplace("{total}", sprintf("%d", this.m_damage + this.m_armordamage), s); + drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL); } } ATTRIB(DamageText, draw2d, void(DamageText), DamageText_draw2d) @@ -65,9 +81,10 @@ CLASS(DamageText, Object) this.alpha = 1; } - CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _deathtype) { + CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _deathtype, bool _friendlyfire) { CONSTRUCT(DamageText); this.m_group = _group; + this.m_friendlyfire = _friendlyfire; DamageText_update(this, _origin, _health, _armor, _deathtype); } ENDCLASS(DamageText) @@ -83,11 +100,11 @@ AUTOCVAR(sv_damagetext, int, 2, _("<= 0: disabled, >= 1: spectators, >= 2: playe #define SV_DAMAGETEXT_ALL() (autocvar_sv_damagetext >= 3 /* all players */) MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { if (SV_DAMAGETEXT_DISABLED()) return; - const entity attacker = MUTATOR_ARGV(0, entity); - const entity hit = MUTATOR_ARGV(1, entity); if (hit == attacker) return; - const int health = MUTATOR_ARGV(0, int); - const int armor = MUTATOR_ARGV(1, int); - const int deathtype = MUTATOR_ARGV(2, int); + const entity attacker = M_ARGV(0, entity); + const entity hit = M_ARGV(1, entity); if (hit == attacker) return; + const int health = M_ARGV(2, int); + const int armor = M_ARGV(3, int); + const int deathtype = M_ARGV(5, int); const vector location = hit.origin; FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA( if ( @@ -98,13 +115,14 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) { ) { msg_entity = it; WriteHeader(MSG_ONE, damagetext); - WriteShort(MSG_ONE, health); - WriteShort(MSG_ONE, armor); + WriteShort(MSG_ONE, rint(health)); + WriteShort(MSG_ONE, rint(armor)); 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, SAME_TEAM(hit, attacker)); } )); } @@ -118,8 +136,12 @@ NET_HANDLE(damagetext, bool isNew) int group = ReadShort(); vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord()); int deathtype = ReadInt24_t(); + bool friendlyfire = ReadByte(); 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) { @@ -128,7 +150,7 @@ NET_HANDLE(damagetext, bool isNew) } } } - NEW(DamageText, group, location, health, armor, deathtype); + NEW(DamageText, group, location, health, armor, deathtype, friendlyfire); } } #endif @@ -145,20 +167,40 @@ CLASS(XonoticDamageTextSettings, XonoticTab) 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, makeXonoticTextLabel(0, _("Font size:"))); - this.TD(this, 1, 2, makeXonoticSlider(0, 50, 1, "cl_damagetext_size")); + 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); - this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Accumulate range:"))); - this.TD(this, 1, 2, makeXonoticSlider(0, 500, 1, "cl_damagetext_accumulate_range")); + // 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, makeXonoticTextLabel(0, _("Lifetime:"))); - this.TD(this, 1, 2, makeXonoticSlider(0, 10, 1, "cl_damagetext_alpha_lifetime")); + this.TD(this, 1, 1, e = makeXonoticTextLabel(0, _("Color (Friendly Fire):"))); + 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); - this.TD(this, 1, 1, makeXonoticTextLabel(0, _("Color:"))); - this.TD(this, 2, 2, makeXonoticColorpickerString("cl_damagetext_color", "cl_damagetext_color")); } ENDCLASS(XonoticDamageTextSettings) #endif