]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
fix damage text rounding errors when accumulating damage
authorMartin Taibr <taibr.martin@gmail.com>
Sat, 3 Sep 2016 00:40:30 +0000 (02:40 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Sat, 3 Sep 2016 00:46:26 +0000 (02:46 +0200)
qcsrc/common/mutators/mutator/damagetext/damagetext.qc

index 88af5496b3f17fba8f7dfa57d226616ce6d1a95f..3d4288cd2ebd0908f2a4d33e41b1321ed825df32 100644 (file)
@@ -57,9 +57,9 @@ CLASS(DamageText, Object)
                 if (w != WEP_Null) rgb = w.wpcolor;
             }
             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);
+            s = strreplace("{health}", sprintf("%d", rint(this.m_damage / 100)), s);
+            s = strreplace("{armor}",  sprintf("%d", rint(this.m_armordamage / 100)), s);
+            s = strreplace("{total}",  sprintf("%d", rint((this.m_damage + this.m_armordamage) / 100)), s);
             drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
         }
     }
@@ -108,8 +108,12 @@ MUTATOR_HOOKFUNCTION(damagetext, PlayerDamaged) {
         ) {
             msg_entity = it;
             WriteHeader(MSG_ONE, damagetext);
-            WriteShort(MSG_ONE, rint(health));
-            WriteShort(MSG_ONE, rint(armor));
+
+            // we need a few decimal places to avoid errors when accumulating damage
+            // sending them this way saves bandwidth compared to WriteCoord
+            WriteShort(MSG_ONE, health * 100);
+            WriteShort(MSG_ONE, armor * 100);
+
             WriteEntity(MSG_ONE, hit);
             WriteCoord(MSG_ONE, location.x);
             WriteCoord(MSG_ONE, location.y);