]> 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>
Wed, 13 Jul 2016 15:46:19 +0000 (17:46 +0200)
qcsrc/common/mutators/mutator/damagetext/damagetext.qc
qcsrc/server/cl_player.qc
qcsrc/server/mutators/events.qh

index 3cca0d9d113b6a44aa385658f87d760f6123c6e2..745e6c42029d82531c25a30150fbdb2cd6614eb5 100644 (file)
@@ -41,6 +41,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)
 
@@ -68,24 +69,26 @@ CLASS(DamageText, Object)
             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);
+            s = strreplace("{potential}",  sprintf("%d", this.m_potential_damage), 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 = 1;
     }
 
-    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);
     }
 ENDCLASS(DamageText)
 #endif
@@ -104,7 +107,8 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
     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 int potential_damage = M_ARGV(4, int);
+    const int deathtype = M_ARGV(6, int);
     const vector location = hit.origin;
     FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
         if (
@@ -117,6 +121,7 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
             WriteHeader(MSG_ONE, damagetext);
             WriteShort(MSG_ONE, rint(health));
             WriteShort(MSG_ONE, rint(armor));
+            WriteShort(MSG_ONE, rint(potential_damage));
             WriteEntity(MSG_ONE, hit);
             WriteCoord(MSG_ONE, location.x);
             WriteCoord(MSG_ONE, location.y);
@@ -133,6 +138,7 @@ NET_HANDLE(damagetext, bool isNew)
 {
     int health = ReadShort();
     int armor = ReadShort();
+    int potential_damage = ReadShort();
     int group = ReadShort();
     vector location = vec3(ReadCoord(), ReadCoord(), ReadCoord());
     int deathtype = ReadInt24_t();
@@ -145,12 +151,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) {
-                    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;
                 }
             }
         }
-        NEW(DamageText, group, location, health, armor, deathtype, friendlyfire);
+        NEW(DamageText, group, location, health, armor, potential_damage, deathtype, friendlyfire);
     }
 }
 #endif
index 50ceba31014316ea5cff9e7c0ee528c3d30f681c..fa5ac0f3e7f8996da2e6c5a20ab84b965b27de67 100644 (file)
@@ -500,9 +500,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, damage, hitloc, deathtype);
        }
 
        if (this.health < 1)
index 257416538f52a5b1c3a9b5c0e09edf81c1dea250..07a795b512e3342da8ce8c3ffdfa6c34ce314134 100644 (file)
@@ -329,8 +329,9 @@ MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
     /** target    */ i(entity, MUTATOR_ARGV_1_entity) \
     /** health    */ i(int,    MUTATOR_ARGV_2_int) \
     /** armor     */ i(int,    MUTATOR_ARGV_3_int) \
-    /** location  */ i(vector, MUTATOR_ARGV_4_vector) \
-    /** deathtype */ i(int,    MUTATOR_ARGV_5_int) \
+    /** potential_damage     */ i(int,    MUTATOR_ARGV_4_int) \
+    /** location  */ i(vector, MUTATOR_ARGV_5_vector) \
+    /** deathtype */ i(int,    MUTATOR_ARGV_6_int) \
     /**/
 MUTATOR_HOOKABLE(PlayerDamaged, EV_PlayerDamaged);