]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Damagetext: add possibility to show potential damage
authorFreddy <schro.sb@gmail.com>
Fri, 8 Jul 2016 13:51:22 +0000 (15:51 +0200)
committerFreddy <schro.sb@gmail.com>
Sat, 22 Oct 2016 20:05:19 +0000 (22:05 +0200)
qcsrc/common/mutators/mutator/damagetext/damagetext.qc
qcsrc/server/mutators/events.qh
qcsrc/server/player.qc

index e55b9fcd91527f8b4b82d5a831303c27cf3a6e77..1ac69a47e78eb1880b6ca897479c911aadec40c3 100644 (file)
@@ -37,6 +37,7 @@ CLASS(DamageText, Object)
     ATTRIB(DamageText, m_friendlyfire, bool, false);
     ATTRIB(DamageText, m_damage, int, 0);
     ATTRIB(DamageText, m_armordamage, int, 0);
+    ATTRIB(DamageText, m_potential_damage, int, 0);
     ATTRIB(DamageText, m_deathtype, int, 0);
     ATTRIB(DamageText, time_prev, float, time);
 
@@ -64,24 +65,26 @@ CLASS(DamageText, Object)
             s = strreplace("{health}", sprintf("%d", rint(this.m_damage / DAMAGETEXT_PRECISION_MULTIPLIER)), s);
             s = strreplace("{armor}",  sprintf("%d", rint(this.m_armordamage / DAMAGETEXT_PRECISION_MULTIPLIER)), s);
             s = strreplace("{total}",  sprintf("%d", rint((this.m_damage + this.m_armordamage) / DAMAGETEXT_PRECISION_MULTIPLIER)), s);
+            s = strreplace("{potential}",  sprintf("%d", rint(this.m_potential_damage/DAMAGETEXT_PRECISION_MULTIPLIER)), s);
             drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
         }
     }
     ATTRIB(DamageText, draw2d, void(DamageText), DamageText_draw2d);
 
-    void DamageText_update(DamageText this, vector _origin, int _health, int _armor, int _deathtype) {
+    void DamageText_update(DamageText this, vector _origin, int _health, int _armor, int _potential_damage, int _deathtype) {
         this.m_damage = _health;
         this.m_armordamage = _armor;
+        this.m_potential_damage = _potential_damage;
         this.m_deathtype = _deathtype;
         setorigin(this, _origin);
         this.alpha = autocvar_cl_damagetext_alpha_start;
     }
 
-    CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _deathtype, bool _friendlyfire) {
+    CONSTRUCTOR(DamageText, int _group, vector _origin, int _health, int _armor, int _potential_damage, int _deathtype, bool _friendlyfire) {
         CONSTRUCT(DamageText);
         this.m_group = _group;
         this.m_friendlyfire = _friendlyfire;
-        DamageText_update(this, _origin, _health, _armor, _deathtype);
+        DamageText_update(this, _origin, _health, _armor, _potential_damage, _deathtype);
                IL_PUSH(g_drawables_2d, this);
     }
 ENDCLASS(DamageText)
@@ -102,6 +105,7 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
     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 (
@@ -113,6 +117,7 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
             int flags = SAME_TEAM(hit, attacker); // BIT(0)
             if (health >= DAMAGETEXT_SHORT_LIMIT) flags |= BIT(1);
             if (armor >= DAMAGETEXT_SHORT_LIMIT) flags |= BIT(2);
+            if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) flags |= BIT(3);
 
             msg_entity = it;
             WriteHeader(MSG_ONE, damagetext);
@@ -130,6 +135,8 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
             else WriteShort(MSG_ONE, health * DAMAGETEXT_PRECISION_MULTIPLIER);
             if (armor >= DAMAGETEXT_SHORT_LIMIT) WriteInt24_t(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
             else WriteShort(MSG_ONE, armor * DAMAGETEXT_PRECISION_MULTIPLIER);
+            if (potential_damage >= DAMAGETEXT_SHORT_LIMIT) WriteInt24_t(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
+            else WriteShort(MSG_ONE, potential_damage * DAMAGETEXT_PRECISION_MULTIPLIER);
         }
     ));
 }
@@ -144,11 +151,13 @@ NET_HANDLE(damagetext, bool isNew)
     int flags = ReadByte();
     bool friendlyfire = flags & 1;
 
-    int health, armor;
+    int health, armor, potential_damage;
     if (flags & BIT(1)) health = ReadInt24_t();
     else health = ReadShort();
     if (flags & BIT(2)) armor = ReadInt24_t();
     else armor = ReadShort();
+    if (flags & BIT(3)) potential_damage = ReadInt24_t();
+    else potential_damage = ReadShort();
 
     return = true;
     if (autocvar_cl_damagetext) {
@@ -158,12 +167,12 @@ NET_HANDLE(damagetext, bool isNew)
         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, deathtype);
+                    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, deathtype, friendlyfire));
+        make_impure(NEW(DamageText, group, location, health, armor, potential_damage, deathtype, friendlyfire));
     }
 }
 #endif
@@ -207,6 +216,7 @@ CLASS(XonoticDamageTextSettings, XonoticTab)
                 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);
index 88d731e815d155d46e407d1f0a31f9c48179ab1f..0a5b823fb5b6ac14f2c39690385ca77b338c4804 100644 (file)
@@ -359,6 +359,7 @@ MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
     /** armor     */ i(float,    MUTATOR_ARGV_3_float) \
     /** location  */ i(vector, MUTATOR_ARGV_4_vector) \
     /** deathtype */ i(int,    MUTATOR_ARGV_5_int) \
+    /** potential_damage     */ i(float,    MUTATOR_ARGV_6_float) \
     /**/
 MUTATOR_HOOKABLE(PlayerDamaged, EV_PlayerDamaged);
 
index e270f38df034c3232cdcddbb12ed034f10ace7e0..9df628860318b2a005b4a755f5c8e4d6ad64c759 100644 (file)
@@ -505,9 +505,9 @@ void PlayerDamage(entity this, entity inflictor, entity attacker, float damage,
        {
                WeaponStats_LogDamage(awep.m_id, abot, PS(this).m_weapon.m_id, vbot, dh + da);
        }
-       if (dh + da)
+       if (damage)
        {
-               MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype);
+               MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype, damage);
        }
 
        if (this.health < 1)